Created
April 7, 2021 19:14
-
-
Save jonesbusy/7a74db90f2eae1d0725ddba44e32b2b3 to your computer and use it in GitHub Desktop.
nexus_cleanup_policies.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.sonatype.nexus.cleanup.storage.CleanupPolicyStorage | |
import org.sonatype.nexus.cleanup.storage.CleanupPolicyComponent | |
def isCleanupPolicyExists(String name) { | |
def cleanupPolicyStorage = container.lookup(CleanupPolicyStorage.class.getName()) | |
return cleanupPolicyStorage.exists(name) | |
} | |
def deleteCleanupPolicy(String name) { | |
def cleanupPolicyStorage = container.lookup(CleanupPolicyStorage.class.getName()) | |
def cleanupPolicyComponent = container.lookup(CleanupPolicyComponent.class.getName()) | |
if (cleanupPolicyStorage.exists(name)) { | |
cleanupPolicyStorage.remove(cleanupPolicyStorage.get(name)) | |
return true | |
} | |
return false | |
} | |
def createPolicy(String policyName, String description, String format, String lastDownloaded, | |
String lastBlobUpdated, String regex = null, Boolean isPrerelease = false) { | |
def policyStorage = container.lookup(CleanupPolicyStorage.class.getName()) | |
def cleanupPolicy = policyStorage.newCleanupPolicy() | |
cleanupPolicy.setName(policyName) | |
cleanupPolicy.setNotes(description) | |
cleanupPolicy.setMode('delete') | |
cleanupPolicy.setFormat(format) | |
def criteria = [:] | |
if (lastDownloaded) { | |
criteria['lastDownloaded'] = lastDownloaded | |
} | |
if (lastBlobUpdated) { | |
criteria['lastBlobUpdated'] = lastBlobUpdated | |
} | |
if (regex) { | |
criteria['regex'] = regex | |
} | |
if (isPrerelease) { | |
criteria['isPrerelease'] = 'true' | |
} | |
cleanupPolicy.setCriteria(criteria) | |
policyStorage.add(cleanupPolicy) | |
} | |
def updatePolicy(String policyName, String description, String format, String lastDownloaded, | |
String lastBlobUpdated, String regex = null, Boolean isPrerelease = false) { | |
def policyStorage = container.lookup(CleanupPolicyStorage.class.getName()) | |
def cleanupPolicy = policyStorage.get(policyName) | |
cleanupPolicy.setName(policyName) | |
cleanupPolicy.setNotes(description) | |
cleanupPolicy.setMode('delete') | |
cleanupPolicy.setFormat(format) | |
def criteria = [:] | |
if (lastDownloaded) { | |
criteria['lastDownloaded'] = lastDownloaded | |
} | |
if (lastBlobUpdated) { | |
criteria['lastBlobUpdated'] = lastBlobUpdated | |
} | |
if (regex) { | |
criteria['regex'] = regex | |
} | |
if (isPrerelease) { | |
criteria['isPrerelease'] = 'true' | |
} | |
cleanupPolicy.setCriteria(criteria) | |
policyStorage.update(cleanupPolicy) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment