diff --git a/Dockerfile b/Dockerfile index 000beec..16f5165 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,27 +1,35 @@ -FROM sonatype/nexus3 +FROM openjdk:8 as builder +COPY . . +RUN ./gradlew jar + +#FROM sonatype/nexus3:3.49.0 +FROM klo2k/nexus3 +#docker build . -t nex --platform linux/arm64/v8 +#export DOCKER_DEFAULT_PLATFORM=linux/arm64/v8 +#docker run -v $PWD/nexus-data:/nexus-data -p 8081:8081 nex #Nexus 3 version to use -ARG NEXUS_VERSION=3.6.0 -ARG RUNDECK_PLUGIN_VERSION=1.0.1 +ARG NEXUS_VERSION=3.49.0 +ARG RUNDECK_PLUGIN_VERSION=1.1.0 USER root # Stop Nexus 3 -CMD ["bin/nexus", "stop"] +#CMD ["bin/nexus", "stop"] # Copy and Configure Nexus Rundeck Plugin RUN mkdir -p system/com/nongfenqi/nexus/plugin/${RUNDECK_PLUGIN_VERSION} -ADD build/libs/nexus3-rundeck-plugin-${RUNDECK_PLUGIN_VERSION}.jar \ - system/com/nongfenqi/nexus/plugin/${RUNDECK_PLUGIN_VERSION}/nexus3-rundeck-plugin-${RUNDECK_PLUGIN_VERSION}.jar -RUN chmod 644 system/com/nongfenqi/nexus/plugin/${RUNDECK_PLUGIN_VERSION}/nexus3-rundeck-plugin-${RUNDECK_PLUGIN_VERSION}.jar -RUN echo "bundle.mvn\:com.nongfenqi.nexus.plugin/nexus3-rundeck-plugin/"${RUNDECK_PLUGIN_VERSION}" = mvn:com.nongfenqi.nexus.plugin/nexus3-rundeck-plugin/"${RUNDECK_PLUGIN_VERSION} \ - >> etc/karaf/profile.cfg \ - && echo "reference\:file\:com/nongfenqi/nexus/plugin/"${RUNDECK_PLUGIN_VERSION}"/nexus3-rundeck-plugin-"${RUNDECK_PLUGIN_VERSION}".jar = 200" \ - >> etc/karaf/startup.properties +COPY --from=builder build/libs/nexus3-rundeck-plugin-${RUNDECK_PLUGIN_VERSION}.jar \ + $NEXUS_HOME/system/com/nongfenqi/nexus/plugin/${RUNDECK_PLUGIN_VERSION}/nexus3-rundeck-plugin-${RUNDECK_PLUGIN_VERSION}.jar + + +RUN chmod 644 $NEXUS_HOME/system/com/nongfenqi/nexus/plugin/$RUNDECK_PLUGIN_VERSION/nexus3-rundeck-plugin-$RUNDECK_PLUGIN_VERSION.jar \ + && echo "bundle.mvn\:com.nongfenqi.nexus.plugin/nexus3-rundeck-plugin/$RUNDECK_PLUGIN_VERSION = mvn:com.nongfenqi.nexus.plugin/nexus3-rundeck-plugin/$RUNDECK_PLUGIN_VERSION" >> $NEXUS_HOME/etc/karaf/profile.cfg \ + && echo "reference\:file\:com/nongfenqi/nexus/plugin/$RUNDECK_PLUGIN_VERSION/nexus3-rundeck-plugin-$RUNDECK_PLUGIN_VERSION.jar = 200" >> $NEXUS_HOME/etc/karaf/startup.properties USER nexus # Start Nexus 3 -CMD ["bin/nexus", "run"] +#CMD ["bin/nexus", "run"] diff --git a/README.md b/README.md index 0e7917b..099d513 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,16 @@ Now you can add url options from the nexus3 to rundeck. The plugin provides the following new HTTP resources : -- `http://NEXUS_HOST/service/siesta/rundeck/maven/options/version` : return a json array with the version of the matching artifacts. +- `http://NEXUS_HOST/service/rest/rundeck/maven/options/artifactId` : return a json array with the artifacts of the matching group. + Parameters (all optional) : + - `r` : repository ID to search in (null for searching in all indexed repositories) + - `g` : groupId of the artifacts to match + - `v` : versions of the artifacts to match + - `p` : packaging of the artifacts to match ('jar', 'war', etc) + - `c` : classifier of the artifacts to match ('sources', 'javadoc', etc) + - `l` : limit - max number of results to return, default value is 50 + +- `http://NEXUS_HOST/service/rest/rundeck/maven/options/version` : return a json array with the version of the matching artifacts. Parameters (all optional) : - `r` : repository ID to search in (null for searching in all indexed repositories) - `g` : groupId of the artifacts to match @@ -37,7 +46,7 @@ The plugin provides the following new HTTP resources : - `c` : classifier of the artifacts to match ('sources', 'javadoc', etc) - `l` : limit - max number of results to return, default value is 10 -- `http://NEXUS_HOST/service/siesta/rundeck/maven/options/content` : return artifact stream +- `http://NEXUS_HOST/service/rest/rundeck/maven/options/content` : return artifact stream Parameters (all required) : - `r` : repository ID to search in (null for searching in all indexed repositories) - `g` : groupId of the artifacts to match diff --git a/build.gradle b/build.gradle index 5701b66..89f81b5 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ group 'com.nongfenqi.nexus.plugin' -version '1.0.3' +version '1.1.0' apply plugin: 'java' @@ -24,9 +24,9 @@ repositories { dependencies { testCompile group: 'junit', name: 'junit', version: '4.12' - compileOnly group: 'org.sonatype.nexus', name: 'nexus-plugin-api', version: '3.38.1-01' - compileOnly group: 'org.sonatype.nexus', name: 'nexus-repository', version: '3.38.1-01' - compileOnly group: 'org.sonatype.nexus', name: 'nexus-rest', version: '3.38.1-01' + compileOnly group: 'org.sonatype.nexus', name: 'nexus-plugin-api', version: '3.49.0-02' + compileOnly group: 'org.sonatype.nexus', name: 'nexus-repository', version: '3.49.0-02' + compileOnly group: 'org.sonatype.nexus', name: 'nexus-rest', version: '3.49.0-02' compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.16.18' } diff --git a/src/main/java/com/nongfenqi/nexus/plugin/rundeck/RundeckMavenResource.java b/src/main/java/com/nongfenqi/nexus/plugin/rundeck/RundeckMavenResource.java index 0aad5ee..8580bfa 100644 --- a/src/main/java/com/nongfenqi/nexus/plugin/rundeck/RundeckMavenResource.java +++ b/src/main/java/com/nongfenqi/nexus/plugin/rundeck/RundeckMavenResource.java @@ -135,6 +135,53 @@ public Response content( return commitAndReturn(ok.build(), tx); } + @GET + @Path("artifactId") + @Produces(APPLICATION_JSON) + public List artifactId( + @DefaultValue("50") @QueryParam("l") int limit, + @QueryParam("r") String repository, + @QueryParam("g") String groupId, + @QueryParam("v") String version, + @QueryParam("c") String classifier, + @QueryParam("p") String extension + ) { + log.debug("param value, limit: {}, repository: {}, groupId: {}, version: {}, classifier: {}, extension: {}", limit, repository, groupId, version, classifier, extension); + + SearchRequest.Builder searchRequestBuilder = SearchRequest.builder(); + searchRequestBuilder.searchFilter("format", "maven2"); + + if (!isBlank(repository)) { + searchRequestBuilder.searchFilter("repository_name", repository); + } + if (!isBlank(groupId)) { + searchRequestBuilder.searchFilter("attributes.maven2.groupId", groupId); + } + if (!isBlank(version)) { + searchRequestBuilder.searchFilter("attributes.maven2.version", version); + } + + classifier = !isBlank(classifier) ? classifier : ""; + searchRequestBuilder.searchFilter("assets.attributes.maven2.classifier", classifier); + + if (!isBlank(extension)) { + searchRequestBuilder.searchFilter("assets.attributes.maven2.extension", extension); + } + + searchRequestBuilder.offset(0) + .limit(limit) + .sortField("assets.attributes.content.last_modified") + .sortDirection(SortDirection.DESC); + + SearchRequest searchRequest = searchRequestBuilder.build(); + log.debug("rundeck maven version query: {}", searchRequest); + + SearchResponse result = searchService.search(searchRequest); + return result.getSearchResults().stream() + .map(this::searchResults2RundeckXOArtifact) + .collect(Collectors.toList()); + } + @GET @Path("version") @Produces(APPLICATION_JSON) @@ -191,6 +238,19 @@ private String latestVersion(String repositoryName, String groupId, String artif return null; } + private String searchResults2RundeckXOArtifact(ComponentSearchResult componentSearchResult) { + String artifactId = null; + List assets = componentSearchResult.getAssets(); + Map attributes = assets.get(0).getAttributes(); + Map content = (Map) attributes.get("maven2"); + + if (content != null && content.containsKey("artifactId")) { + artifactId = (String) content.get("artifactId"); + } + + return artifactId; + } + private RundeckXO searchResults2RundeckXO(ComponentSearchResult componentSearchResult) { String version = componentSearchResult.getVersion(); List assets = componentSearchResult.getAssets();