Skip to content

Commit

Permalink
Merge pull request #21 from TimmyOtool/master
Browse files Browse the repository at this point in the history
feat: add artifactId search
  • Loading branch information
chenlingmin authored Mar 10, 2023
2 parents 026777a + 0e5f6e0 commit 9bddcb3
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 18 deletions.
32 changes: 20 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'com.nongfenqi.nexus.plugin'
version '1.0.3'
version '1.1.0'


apply plugin: 'java'
Expand All @@ -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'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,53 @@ public Response content(
return commitAndReturn(ok.build(), tx);
}

@GET
@Path("artifactId")
@Produces(APPLICATION_JSON)
public List<String> 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)
Expand Down Expand Up @@ -191,6 +238,19 @@ private String latestVersion(String repositoryName, String groupId, String artif
return null;
}

private String searchResults2RundeckXOArtifact(ComponentSearchResult componentSearchResult) {
String artifactId = null;
List<AssetSearchResult> assets = componentSearchResult.getAssets();
Map<String, Object> attributes = assets.get(0).getAttributes();
Map<String, Object> content = (Map<String, Object>) 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<AssetSearchResult> assets = componentSearchResult.getAssets();
Expand Down

0 comments on commit 9bddcb3

Please sign in to comment.