Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: nongfenqi/nexus3-rundeck-plugin
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1.0.1
Choose a base ref
...
head repository: nongfenqi/nexus3-rundeck-plugin
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref

Commits on Oct 10, 2017

  1. Update Dockerfile

    chenlingmin authored Oct 10, 2017
    Copy the full SHA
    2959ff9 View commit details

Commits on Nov 7, 2017

  1. Copy the full SHA
    b8b9dec View commit details

Commits on Nov 10, 2017

  1. Merge pull request #10 from bezda/patch-1

    Support value "LATEST" as metaversion
    chenlingmin authored Nov 10, 2017
    Copy the full SHA
    43148f9 View commit details

Commits on Feb 8, 2019

  1. Add docker hub link in Readme file

    Add the link to docker hub website in the readme file
    lordudun authored Feb 8, 2019
    Copy the full SHA
    687085c View commit details

Commits on Feb 11, 2019

  1. Merge pull request #12 from lordudun/master

    Add docker hub link in Readme file
    chenlingmin authored Feb 11, 2019
    Copy the full SHA
    d1b3535 View commit details

Commits on Apr 1, 2020

  1. #15 compatibility with nexus 3.19

    Gregor Tudan committed Apr 1, 2020
    Copy the full SHA
    d3291c7 View commit details

Commits on Apr 3, 2020

  1. Merge pull request #16 from gtudan/15

    compatibility with nexus 3.19
    chenlingmin authored Apr 3, 2020
    Copy the full SHA
    0215b9a View commit details

Commits on Sep 17, 2020

  1. fix folder version

    matejsp committed Sep 17, 2020
    Copy the full SHA
    b3a4685 View commit details
  2. fix folder version

    matejsp committed Sep 17, 2020
    Copy the full SHA
    33fe661 View commit details
  3. fix folder version

    matejsp committed Sep 17, 2020
    Copy the full SHA
    cafa4b0 View commit details
  4. bump version

    matejsp committed Sep 17, 2020
    Copy the full SHA
    48f3a91 View commit details

Commits on Jan 20, 2021

  1. Update build.gradle

    matejsp authored Jan 20, 2021
    Copy the full SHA
    1816f03 View commit details
  2. Update build.gradle

    matejsp authored Jan 20, 2021
    Copy the full SHA
    56c0de4 View commit details
  3. Update build.gradle

    matejsp authored Jan 20, 2021
    Copy the full SHA
    dcac3fc View commit details
  4. Copy the full SHA
    7a3def6 View commit details

Commits on Jan 21, 2021

  1. Merge pull request #17 from matejsp/master

    Fixes for nexus 3.29
    chenlingmin authored Jan 21, 2021
    Copy the full SHA
    d4e3c47 View commit details

Commits on Apr 29, 2022

  1. Compatibility with nexus 3.38

    * upgrade gradle nexus dependencies
    * fix java.lang.NoSuchMethodError: org.sonatype.nexus.repository.search.SearchService.searchUnrestricted exception by switching to SearchService.search method
    * change data model to nexus 3.38 SearchService.search function model
    kugacz committed Apr 29, 2022
    Copy the full SHA
    e615e11 View commit details

Commits on May 6, 2022

  1. Merge pull request #18 from kugacz/compatibility-with-nexus-3.38

    Compatibility with nexus 3.38
    chenlingmin authored May 6, 2022
    Copy the full SHA
    1c54066 View commit details

Commits on May 17, 2022

  1. Compatibility with nexus 3.38 - null pointer exception when the class…

    …ifier is not set
    
    * nexus 3.38 requires the classifier to be set (at least empty) otherwise it is throwing a null pointer exception
    kugacz committed May 17, 2022
    Copy the full SHA
    63fd22d View commit details

Commits on May 18, 2022

  1. Merge pull request #19 from kugacz/master

    Compatibility with nexus 3.38 - null pointer exception when the class…
    chenlingmin authored May 18, 2022
    Copy the full SHA
    026777a View commit details

Commits on Mar 10, 2023

  1. Copy the full SHA
    0e5f6e0 View commit details
  2. Merge pull request #21 from TimmyOtool/master

    feat: add artifactId search
    chenlingmin authored Mar 10, 2023
    Copy the full SHA
    9bddcb3 View commit details
  3. fix: sort artifact results

    TimmyOtool committed Mar 10, 2023
    Copy the full SHA
    4f752fe View commit details
  4. Merge pull request #22 from TimmyOtool/master

    fix: sort artifact results
    chenlingmin authored Mar 10, 2023
    Copy the full SHA
    5695198 View commit details
Showing with 141 additions and 57 deletions.
  1. +20 −12 Dockerfile
  2. +12 −3 README.md
  3. +4 −4 build.gradle
  4. +104 −37 src/main/java/com/nongfenqi/nexus/plugin/rundeck/RundeckMavenResource.java
  5. +1 −1 src/main/java/com/nongfenqi/nexus/plugin/rundeck/RundeckXO.java
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.0-SNAPSHOT
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"]
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
@@ -53,7 +62,7 @@ Note that if you want to retrieve the artifact from your Rundeck script, you can

### Docker repository

Welcome to contribute
https://hub.docker.com/r/chenlmdocker/docker-nexus3/

### Npm repository

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.1'
version '1.1.1'


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.5.0-02'
compileOnly group: 'org.sonatype.nexus', name: 'nexus-repository', version: '3.5.0-02'
compileOnly group: 'org.sonatype.nexus', name: 'nexus-rest', version: '3.5.0-02'
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'
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017 黑牛
* Copyright 2017
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
@@ -17,18 +17,12 @@
*/
package com.nongfenqi.nexus.plugin.rundeck;

import com.google.common.base.Supplier;
import org.apache.http.client.utils.DateUtils;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.sort.FieldSortBuilder;
import org.elasticsearch.search.sort.SortOrder;
import org.sonatype.nexus.repository.search.*;
import org.sonatype.goodies.common.ComponentSupport;
import org.sonatype.nexus.blobstore.api.Blob;
import org.sonatype.nexus.repository.Repository;
import org.sonatype.nexus.repository.manager.RepositoryManager;
import org.sonatype.nexus.repository.search.SearchService;
import org.sonatype.nexus.repository.storage.Asset;
import org.sonatype.nexus.repository.storage.Bucket;
import org.sonatype.nexus.repository.storage.StorageFacet;
@@ -38,15 +32,21 @@
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import javax.ws.rs.*;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
import java.util.*;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Supplier;
import java.util.stream.Collectors;

import static com.google.common.base.Preconditions.checkNotNull;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
import static org.elasticsearch.index.query.QueryBuilders.termQuery;
import static org.sonatype.nexus.common.text.Strings2.isBlank;

@Named
@@ -84,6 +84,9 @@ public Response content(


// default version
if ("LATEST".equals(version)) {
version = null;
}
version = Optional.ofNullable(version).orElse(latestVersion(
repositoryName, groupId, artifactId, classifier, extension
));
@@ -111,11 +114,13 @@ public Response content(
return commitAndReturn(NOT_FOUND, tx);
}

String folderVersion = version.replaceAll("-\\d{8}\\.\\d{6}\\-\\d+", "-SNAPSHOT");
String fileName = artifactId + "-" + version + (isBlank(classifier) ? "" : ("-" + classifier)) + "." + extension;
String path = groupId.replace(".", "/") +
"/" + artifactId +
"/" + version +
"/" + folderVersion +
"/" + fileName;

Asset asset = tx.findAssetWithProperty("name", path, bucket);
log.debug("rundeck download asset: {}", asset);
if (null == asset) {
@@ -130,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.maven2.artifactId")
.sortDirection(SortDirection.ASC);

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)
@@ -144,34 +196,37 @@ public List<RundeckXO> version(

log.debug("param value, repository: {}, limit: {}, groupId: {}, artifactId: {}, classifier: {}, extension: {}", repository, limit, groupId, artifactId, classifier, extension);

BoolQueryBuilder query = boolQuery();
query.filter(termQuery("format", "maven2"));
SearchRequest.Builder searchRequestBuilder = SearchRequest.builder();
searchRequestBuilder.searchFilter("format", "maven2");

if (!isBlank(repository)) {
query.filter(termQuery("repository_name", repository));
searchRequestBuilder.searchFilter("repository_name", repository);
}
if (!isBlank(groupId)) {
query.filter(termQuery("attributes.maven2.groupId", groupId));
searchRequestBuilder.searchFilter("attributes.maven2.groupId", groupId);
}
if (!isBlank(artifactId)) {
query.filter(termQuery("attributes.maven2.artifactId", artifactId));
}
if (!isBlank(classifier)) {
query.filter(termQuery("assets.attributes.maven2.classifier", classifier));
searchRequestBuilder.searchFilter("attributes.maven2.artifactId", artifactId);
}

classifier = !isBlank(classifier) ? classifier : "";
searchRequestBuilder.searchFilter("assets.attributes.maven2.classifier", classifier);

if (!isBlank(extension)) {
query.filter(termQuery("assets.attributes.maven2.extension", extension));
}

log.debug("rundeck maven version query: {}", query);
SearchResponse result = searchService.search(
query,
Collections.singletonList(new FieldSortBuilder("assets.attributes.content.last_modified").order(SortOrder.DESC)),
0,
limit
);
return Arrays.stream(result.getHits().hits())
.map(this::his2RundeckXO)
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::searchResults2RundeckXO)
.collect(Collectors.toList());
}

@@ -183,11 +238,23 @@ private String latestVersion(String repositoryName, String groupId, String artif
return null;
}

private RundeckXO his2RundeckXO(SearchHit hit) {
String version = (String) hit.getSource().get("version");
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;
}

List<Map<String, Object>> assets = (List<Map<String, Object>>) hit.getSource().get("assets");
Map<String, Object> attributes = (Map<String, Object>) assets.get(0).get("attributes");
private RundeckXO searchResults2RundeckXO(ComponentSearchResult componentSearchResult) {
String version = componentSearchResult.getVersion();
List<AssetSearchResult> assets = componentSearchResult.getAssets();
Map<String, Object> attributes = assets.get(0).getAttributes();
Map<String, Object> content = (Map<String, Object>) attributes.get("content");
String lastModifiedTime = "null";
if (content != null && content.containsKey("last_modified")) {
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017 黑牛
* Copyright 2017
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the