-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #108 from thiagofigueiro/fix-repository-nexus3.21
fix: ``repository create`` command on Nexus 3.21.0
- Loading branch information
Showing
5 changed files
with
130 additions
and
5 deletions.
There are no files selected for viewing
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
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
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
87 changes: 87 additions & 0 deletions
87
src/nexuscli/api/script/groovy/nexus3-cli-repository-create_3.21.0.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import groovy.json.JsonSlurper | ||
import org.sonatype.nexus.repository.config.Configuration | ||
import org.sonatype.nexus.repository.manager.RepositoryManager | ||
|
||
|
||
class Repository { | ||
Map<String,Map<String,Object>> properties = new HashMap<String, Object>() | ||
} | ||
|
||
if (args != "") { | ||
log.info("Creating repository with args [${args}]") | ||
def rep = convertJsonFileToRepo(args) | ||
log.debug("Got repo [${rep}]") | ||
def output = createRepository(rep) | ||
|
||
return output | ||
} | ||
|
||
def createRepository(Repository repo) { | ||
def conf = createConfiguration(repo) | ||
|
||
try { | ||
repository.createRepository(conf) | ||
} | ||
catch (Exception e) { | ||
return e | ||
} | ||
|
||
return null | ||
} | ||
|
||
def convertJsonFileToRepo(String jsonData) { | ||
def inputJson = new JsonSlurper().parseText(jsonData) | ||
log.debug("Creating repository object for [${inputJson}]") | ||
Repository repo = new Repository() | ||
inputJson.each { | ||
repo.properties.put(it.key, it.value) | ||
} | ||
|
||
log.debug("Created repository object [${repo}]") | ||
return repo | ||
} | ||
|
||
//def repositoryManager = container.lookup(RepositoryManager.class.getName()) | ||
|
||
def createConfiguration(Repository repo) { | ||
repositoryManager = container.lookup(RepositoryManager.class.getName()) | ||
Configuration conf = repositoryManager.newConfiguration() | ||
|
||
conf.with { | ||
repositoryName = getName(repo) | ||
recipeName = getRecipeName(repo) | ||
online = getOnline(repo) | ||
attributes = repo.properties.get("attributes") as Map | ||
} | ||
|
||
// https://github.com/thiagofigueiro/nexus3-cli/issues/77 | ||
try { | ||
policy_name = conf.attributes.cleanup.policyName | ||
log.info("policy name is ${policy_name.getClass()}") | ||
if (policy_name.getClass() == java.util.ArrayList) { | ||
Set set = new HashSet(policy_name) | ||
conf.attributes.cleanup.policyName = set | ||
log.info("Converted to ${set.getClass()}") | ||
} | ||
} | ||
catch (java.lang.NullPointerException e) { | ||
log.info("No cleanup policy provided; that's ok.") | ||
} | ||
|
||
return conf | ||
} | ||
|
||
def getName(Repository repo){ | ||
String name = repo.getProperties().get("name") | ||
return name | ||
} | ||
|
||
def getRecipeName(Repository repo){ | ||
String recipeName = repo.getProperties().get("recipeName") | ||
return recipeName | ||
} | ||
|
||
def getOnline(Repository repo){ | ||
String online = repo.getProperties().get("online") | ||
return online | ||
} |
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