Created
July 16, 2018 16:45
-
-
Save Malinskiy/647b5fd9e0a97b861b471b2f4b71bbc2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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.yaml.snakeyaml.Yaml | |
import org.sonatype.nexus.blobstore.api.BlobStoreException | |
import org.sonatype.nexus.repository.maven.VersionPolicy | |
import org.sonatype.nexus.repository.maven.LayoutPolicy | |
log.info(args) | |
Yaml yaml = new Yaml() | |
def config = yaml.load(args) | |
log.info(config.toString()) | |
if (config.containsKey('maven2')) { | |
config.maven2.each { | |
group -> | |
def createdRepos = createMavenProxies(group.proxy) | |
createMavenGroup(group.name, createdRepos) | |
} | |
} | |
// https://github.com/sonatype/nexus-public/blob/master/plugins/nexus-script-plugin/src/main/java/org/sonatype/nexus/script/plugin/internal/provisioning/RepositoryApiImpl.groovy | |
// https://github.com/sonatype/nexus-public/blob/master/plugins/nexus-script-plugin/src/main/java/org/sonatype/nexus/script/plugin/RepositoryApi.java | |
void createMavenGroup(String name, List < String > repos) { | |
if (repository.repositoryManager.exists(name)) { | |
repository.repositoryManager.delete(name) | |
} | |
createBlobStorage(name) | |
repository.createMavenGroup(name, repos, name) | |
} | |
List < String > createMavenProxies(List requirement) { | |
List < String > repos = [] | |
requirement.each { | |
log.info("name: ${it.name}") | |
log.info("url: ${it.url}") | |
def internalName = it.name | |
if (repository.repositoryManager.exists(internalName)) { | |
log.info("repository $internalName already exists") | |
repository.repositoryManager.delete(internalName) | |
} | |
createBlobStorage(internalName) | |
repository.createMavenProxy( | |
internalName, it.url, | |
internalName, // The BlobStore the Repository should use | |
true, // Whether or not the Repository should enforce strict content types | |
VersionPolicy.MIXED, // https://github.com/sonatype/nexus-public/blob/master/plugins/nexus-repository-maven/src/main/java/org/sonatype/nexus/repository/maven/VersionPolicy.java | |
LayoutPolicy.PERMISSIVE // https://github.com/sonatype/nexus-public/blob/master/plugins/nexus-repository-maven/src/main/java/org/sonatype/nexus/repository/maven/LayoutPolicy.java | |
) | |
repos << internalName | |
} | |
return repos | |
} | |
void createBlobStorage(String name) { | |
if (blobStore.blobStoreManager.exists(name)) { | |
log.info("storage '$name' exists") | |
} else { | |
try { | |
log.info("creating storage '$name'") | |
blobStore.createFileBlobStore(name, name) | |
} catch (BlobStoreException e) { | |
log.info("something goes wrong: " + e.message) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment