Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it easier to use with custom repositories #687

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,16 @@
public class ArtifactoryRepositoryImpl extends BaseMavenRepository {
private static final Logger LOGGER = Logger.getLogger(ArtifactoryRepositoryImpl.class.getName());

private static final String ARTIFACTORY_URL = "https://repo.jenkins-ci.org/";
private static final String ARTIFACTORY_API_URL = "https://repo.jenkins-ci.org/api/";
private static final String ARTIFACTORY_URL = Environment.getString("ARTIFACTORY_URL", "https://repo.jenkins-ci.org/");
private static final String ARTIFACTORY_API_URL = Environment.getString("ARTIFACTORY_API_URL", "https://repo.jenkins-ci.org/api/");
private static final String ARTIFACTORY_REPOSITORY = Environment.getString("ARTIFACTORY_REPOSITORY", "releases");

private static final String ARTIFACTORY_AQL_URL = ARTIFACTORY_API_URL + "search/aql";
private static final String ARTIFACTORY_MANIFEST_URL = ARTIFACTORY_URL + "%s/%s!/META-INF/MANIFEST.MF";
private static final String ARTIFACTORY_ZIP_ENTRY_URL = ARTIFACTORY_URL + "%s/%s!%s";
private static final String ARTIFACTORY_FILE_URL = ARTIFACTORY_URL + "%s/%s";

private static final String AQL_QUERY = "items.find({\"repo\":{\"$eq\":\"releases\"},\"$or\":[{\"name\":{\"$match\":\"*.hpi\"}},{\"name\":{\"$match\":\"*.jpi\"}},{\"name\":{\"$match\":\"*.war\"}},{\"name\":{\"$match\":\"*.pom\"}}]}).include(\"repo\", \"path\", \"name\", \"modified\", \"created\", \"sha256\", \"actual_sha1\", \"size\")";
private static final String AQL_QUERY = "items.find({\"repo\":{\"$eq\":\"" + ARTIFACTORY_REPOSITORY + "\"},\"$or\":[{\"name\":{\"$match\":\"*.hpi\"}},{\"name\":{\"$match\":\"*.jpi\"}},{\"name\":{\"$match\":\"*.war\"}},{\"name\":{\"$match\":\"*.pom\"}}]}).include(\"repo\", \"path\", \"name\", \"modified\", \"created\", \"sha256\", \"actual_sha1\", \"size\")";

private final String username;
private final String password;
Expand Down Expand Up @@ -231,7 +233,7 @@ private String getUri(ArtifactCoordinates a) {

@Override
public Manifest getManifest(MavenArtifact artifact) throws IOException {
try (InputStream is = getFileContent(String.format(ARTIFACTORY_MANIFEST_URL, "releases", getUri(artifact.artifact)))) {
try (InputStream is = getFileContent(String.format(ARTIFACTORY_MANIFEST_URL, ARTIFACTORY_REPOSITORY, getUri(artifact.artifact)))) {
return new Manifest(is);
}
}
Expand Down Expand Up @@ -269,7 +271,7 @@ private File getFile(final String url) throws IOException {
try {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
OkHttpClient client = builder.build();
Request request = new Request.Builder().url(url).get().build();
Request request = new Request.Builder().addHeader("Authorization", Credentials.basic(username, password)).url(url).get().build();
final Response response = client.newCall(request).execute();
if (response.isSuccessful()) {
try (final ResponseBody body = HttpHelper.body(response)) {
Expand Down Expand Up @@ -308,7 +310,7 @@ private File getFile(final String url) throws IOException {

@Override
public InputStream getZipFileEntry(MavenArtifact artifact, String path) throws IOException {
return getFileContent(String.format(ARTIFACTORY_ZIP_ENTRY_URL, "releases", getUri(artifact.artifact), StringUtils.prependIfMissing(path, "/")));
return getFileContent(String.format(ARTIFACTORY_ZIP_ENTRY_URL, ARTIFACTORY_REPOSITORY, getUri(artifact.artifact), StringUtils.prependIfMissing(path, "/")));
}

@Override
Expand All @@ -319,7 +321,7 @@ public File resolve(ArtifactCoordinates artifact) throws IOException {
if (localFile.exists()) {
return localFile;
}
return getFile(String.format(ARTIFACTORY_FILE_URL, "releases", uri));
return getFile(String.format(ARTIFACTORY_FILE_URL, ARTIFACTORY_REPOSITORY, uri));
}

private static final File LOCAL_REPO = new File(new File(System.getProperty("user.home")), ".m2/repository");
Expand Down