aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Kristina Chodorow <kchodorow@google.com>2015-07-16 10:06:51 +0000
committerGravatar Philipp Wollermann <philwo@google.com>2015-07-17 13:17:03 +0000
commit0ae855bf1cce8dd38e280560a8d068135df4843d (patch)
tree948f6f8f8c7cfe6782d2a98ea7c24d55e8e894c0 /src
parent638c5480cf89569a38e8a6d7bad5e32222e381c0 (diff)
Add repository fallback on Maven Central
-- MOS_MIGRATED_REVID=98387436
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/google/devtools/build/workspace/maven/DefaultModelResolver.java47
1 files changed, 32 insertions, 15 deletions
diff --git a/src/main/java/com/google/devtools/build/workspace/maven/DefaultModelResolver.java b/src/main/java/com/google/devtools/build/workspace/maven/DefaultModelResolver.java
index 68b9b095fe..eb0c430bd7 100644
--- a/src/main/java/com/google/devtools/build/workspace/maven/DefaultModelResolver.java
+++ b/src/main/java/com/google/devtools/build/workspace/maven/DefaultModelResolver.java
@@ -15,6 +15,7 @@
package com.google.devtools.build.workspace.maven;
import com.google.common.collect.Lists;
+import com.google.devtools.build.lib.bazel.repository.MavenConnector;
import org.apache.maven.model.Parent;
import org.apache.maven.model.Repository;
import org.apache.maven.model.building.ModelSource;
@@ -45,23 +46,39 @@ class DefaultModelResolver implements ModelResolver {
public ModelSource resolveModel(String groupId, String artifactId, String version)
throws UnresolvableModelException {
for (Repository repository : repositories) {
- try {
- UrlModelSource urlModelSource = new UrlModelSource(new URL(repository.getUrl()
- + groupId.replaceAll("\\.", "/") + "/" + artifactId + "/" + version + "/" + artifactId
- + "-" + version + ".pom"));
- if (urlModelSource.getInputStream().available() != 0) {
- return urlModelSource;
- }
- } catch (MalformedURLException e) {
- throw new UnresolvableModelException(e.getMessage(), groupId, artifactId, version, e);
- } catch (IOException e) {
- // The artifact could not be fetched from the current repo, just move on and check the next
- // one.
+ UrlModelSource modelSource = getModelSource(
+ repository.getUrl(), groupId, artifactId, version);
+ if (modelSource != null) {
+ return modelSource;
}
}
- throw new UnresolvableModelException("Could not find any repositories that knew how to "
- + "resolve the artifact (checked " + Arrays.toString(repositories.toArray()) + ")",
- groupId, artifactId, version);
+ UrlModelSource modelSource = getModelSource(
+ MavenConnector.getMavenCentral().getUrl(), groupId, artifactId, version);
+ if (modelSource == null) {
+ throw new UnresolvableModelException("Could not find any repositories that knew how to "
+ + "resolve the artifact (checked " + Arrays.toString(repositories.toArray()) + ")",
+ groupId, artifactId, version);
+ }
+ return modelSource;
+ }
+
+ private UrlModelSource getModelSource(
+ String url, String groupId, String artifactId, String version)
+ throws UnresolvableModelException {
+ try {
+ UrlModelSource urlModelSource = new UrlModelSource(new URL(url
+ + groupId.replaceAll("\\.", "/") + "/" + artifactId + "/" + version + "/" + artifactId
+ + "-" + version + ".pom"));
+ if (urlModelSource.getInputStream().available() != 0) {
+ return urlModelSource;
+ }
+ } catch (MalformedURLException e) {
+ throw new UnresolvableModelException(e.getMessage(), groupId, artifactId, version, e);
+ } catch (IOException e) {
+ // The artifact could not be fetched from the current repo, just move on and check the next
+ // one.
+ }
+ return null;
}
@Override