46
46
public class ArtifactoryRepositoryImpl extends BaseMavenRepository {
47
47
private static final Logger LOGGER = Logger .getLogger (ArtifactoryRepositoryImpl .class .getName ());
48
48
49
- private static final String ARTIFACTORY_URL = "https://repo.jenkins-ci.org/" ;
50
- private static final String ARTIFACTORY_API_URL = "https://repo.jenkins-ci.org/api/" ;
49
+ private static final String ARTIFACTORY_URL = Environment .getString ("ARTIFACTORY_URL" , "https://repo.jenkins-ci.org/" );
50
+ private static final String ARTIFACTORY_API_URL = Environment .getString ("ARTIFACTORY_API_URL" , "https://repo.jenkins-ci.org/api/" );
51
+ private static final String ARTIFACTORY_REPOSITORY = Environment .getString ("ARTIFACTORY_REPOSITORY" , "releases" );
52
+
51
53
private static final String ARTIFACTORY_AQL_URL = ARTIFACTORY_API_URL + "search/aql" ;
52
54
private static final String ARTIFACTORY_MANIFEST_URL = ARTIFACTORY_URL + "%s/%s!/META-INF/MANIFEST.MF" ;
53
55
private static final String ARTIFACTORY_ZIP_ENTRY_URL = ARTIFACTORY_URL + "%s/%s!%s" ;
54
56
private static final String ARTIFACTORY_FILE_URL = ARTIFACTORY_URL + "%s/%s" ;
55
57
56
- 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\" )" ;
58
+ 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\" )" ;
57
59
58
60
private final String username ;
59
61
private final String password ;
@@ -236,7 +238,7 @@ private String getUri(ArtifactCoordinates a) {
236
238
237
239
@ Override
238
240
public Manifest getManifest (MavenArtifact artifact ) throws IOException {
239
- try (InputStream is = getFileContent (String .format (ARTIFACTORY_MANIFEST_URL , "releases" , getUri (artifact .artifact )))) {
241
+ try (InputStream is = getFileContent (String .format (ARTIFACTORY_MANIFEST_URL , ARTIFACTORY_REPOSITORY , getUri (artifact .artifact )))) {
240
242
return new Manifest (is );
241
243
}
242
244
}
@@ -274,7 +276,7 @@ private File getFile(final String url) throws IOException {
274
276
try {
275
277
OkHttpClient .Builder builder = new OkHttpClient .Builder ();
276
278
OkHttpClient client = builder .build ();
277
- Request request = new Request .Builder ().url (url ).get ().build ();
279
+ Request request = new Request .Builder ().addHeader ( "Authorization" , Credentials . basic ( username , password )). url (url ).get ().build ();
278
280
final Response response = client .newCall (request ).execute ();
279
281
if (response .isSuccessful ()) {
280
282
try (final ResponseBody body = HttpHelper .body (response )) {
@@ -313,7 +315,7 @@ private File getFile(final String url) throws IOException {
313
315
314
316
@ Override
315
317
public InputStream getZipFileEntry (MavenArtifact artifact , String path ) throws IOException {
316
- return getFileContent (String .format (ARTIFACTORY_ZIP_ENTRY_URL , "releases" , getUri (artifact .artifact ), StringUtils .prependIfMissing (path , "/" )));
318
+ return getFileContent (String .format (ARTIFACTORY_ZIP_ENTRY_URL , ARTIFACTORY_REPOSITORY , getUri (artifact .artifact ), StringUtils .prependIfMissing (path , "/" )));
317
319
}
318
320
319
321
@ Override
@@ -324,7 +326,7 @@ public File resolve(ArtifactCoordinates artifact) throws IOException {
324
326
if (localFile .exists ()) {
325
327
return localFile ;
326
328
}
327
- return getFile (String .format (ARTIFACTORY_FILE_URL , "releases" , uri ));
329
+ return getFile (String .format (ARTIFACTORY_FILE_URL , ARTIFACTORY_REPOSITORY , uri ));
328
330
}
329
331
330
332
private static final File LOCAL_REPO = new File (new File (System .getProperty ("user.home" )), ".m2/repository" );
0 commit comments