Skip to content

Commit

Permalink
fix: cleanup-policy commands
Browse files Browse the repository at this point in the history
Sonatype made a breaking change to the groovy API in 3.20.0;
org.sonatype.nexus.cleanup.storage.CleanupPolicy no longer exists.
  • Loading branch information
thiagofigueiro committed Feb 22, 2020
1 parent 2673245 commit 6cfcc9e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from setuptools import find_packages, setup

package_name = 'nexus3-cli'
package_version = '3.0.0'
package_version = '3.0.1'

requires = [
'click>=7.0.0,<8',
Expand Down
22 changes: 13 additions & 9 deletions src/nexuscli/api/script/groovy/nexus3-cli-cleanup-policy.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import groovy.json.JsonSlurper
import groovy.json.JsonBuilder
import java.util.concurrent.TimeUnit

import org.sonatype.nexus.cleanup.storage.CleanupPolicy
import org.sonatype.nexus.cleanup.storage.CleanupPolicyStorage
import static org.sonatype.nexus.repository.search.DefaultComponentMetadataProducer.IS_PRERELEASE_KEY
import static org.sonatype.nexus.repository.search.DefaultComponentMetadataProducer.LAST_BLOB_UPDATED_KEY
Expand All @@ -17,7 +16,7 @@ def cleanupPolicyStorage = container.lookup(CleanupPolicyStorage.class.getName()
try {
parsed_args = new JsonSlurper().parseText(args)
} catch(Exception ex) {
// "list" operation
log.debug("list")
def policies = []
cleanupPolicyStorage.getAll().each {
policies << toJsonString(it)
Expand All @@ -35,6 +34,7 @@ if (parsed_args.name == null) {

// "get" operation
if (parsed_args.size() == 1) {
log.debug("get")
existingPolicy = cleanupPolicyStorage.get(parsed_args.name)
return toJsonString(existingPolicy)
}
Expand All @@ -54,14 +54,18 @@ if (cleanupPolicyStorage.exists(parsed_args.name)) {

// "create" operation
format = parsed_args.format == "all" ? "ALL_FORMATS" : parsed_args.format

log.debug("Creating Cleanup Policy <name=${parsed_args.name}>")
cleanupPolicy = new CleanupPolicy(
name: parsed_args.name,
notes: parsed_args.notes,
format: format,
mode: 'deletion',
criteria: criteriaMap
)
cleanupPolicy = cleanupPolicyStorage.newCleanupPolicy()

log.debug("Configuring Cleanup Policy <policy=${cleanupPolicy}>")
cleanupPolicy.setName(parsed_args.name)
cleanupPolicy.setNotes(parsed_args.notes)
cleanupPolicy.setFormat(format)
cleanupPolicy.setMode('deletion')
cleanupPolicy.setCriteria(criteriaMap)

log.debug("Adding Cleanup Policy <policy=${cleanupPolicy}>")
cleanupPolicyStorage.add(cleanupPolicy)
return toJsonString(cleanupPolicy)

Expand Down

0 comments on commit 6cfcc9e

Please sign in to comment.