aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java
diff options
context:
space:
mode:
authorGravatar Kristina Chodorow <kchodorow@google.com>2015-06-11 16:03:22 +0000
committerGravatar Philipp Wollermann <philwo@google.com>2015-06-12 11:44:45 +0000
commit81d2162f489dcd4b93af728440e7fbef573bc04b (patch)
tree53b36dbc4483e303247d595398b67ab78ad416c2 /src/main/java
parent18740ae69405be0cbe6c335a37039e2cf5e95265 (diff)
Simplify maven_jar to just take a single artifact descriptor
-- MOS_MIGRATED_REVID=95743586
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/repository/MavenJarFunction.java22
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/MavenJarRule.java33
2 files changed, 29 insertions, 26 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/MavenJarFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/MavenJarFunction.java
index be475f1ff9..8861beb8ab 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/repository/MavenJarFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/MavenJarFunction.java
@@ -141,9 +141,7 @@ public class MavenJarFunction extends HttpArchiveFunction {
private static final String MAVEN_CENTRAL_URL = "http://central.maven.org/maven2/";
private final String name;
- private final String groupId;
- private final String artifactId;
- private final String version;
+ private final String artifact;
private final Path outputDirectory;
@Nullable
private final String sha1;
@@ -152,10 +150,15 @@ public class MavenJarFunction extends HttpArchiveFunction {
public MavenDownloader(String name, AttributeMap mapper, Path outputDirectory) {
this.name = name;
- this.groupId = mapper.get("group_id", Type.STRING);
- this.artifactId = mapper.get("artifact_id", Type.STRING);
- this.version = mapper.get("version", Type.STRING);
this.outputDirectory = outputDirectory;
+
+ if (!mapper.get("artifact", Type.STRING).isEmpty()) {
+ this.artifact = mapper.get("artifact", Type.STRING);
+ } else {
+ this.artifact = mapper.get("group_id", Type.STRING) + ":"
+ + mapper.get("artifact_id", Type.STRING) + ":"
+ + mapper.get("version", Type.STRING);
+ }
this.sha1 = (mapper.has("sha1", Type.STRING)) ? mapper.get("sha1", Type.STRING) : null;
if (mapper.has("repository", Type.STRING)
@@ -199,7 +202,12 @@ public class MavenJarFunction extends HttpArchiveFunction {
RepositorySystemSession session = newRepositorySystemSession(system);
ArtifactRequest artifactRequest = new ArtifactRequest();
- Artifact artifact = new DefaultArtifact(groupId + ":" + artifactId + ":" + version);
+ Artifact artifact;
+ try {
+ artifact = new DefaultArtifact(this.artifact);
+ } catch (IllegalArgumentException e) {
+ throw new IOException(e.getMessage());
+ }
artifactRequest.setArtifact(artifact);
artifactRequest.setRepositories(repositories);
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/MavenJarRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/MavenJarRule.java
index cc0870ba1c..a24d01b955 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/MavenJarRule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/workspace/MavenJarRule.java
@@ -33,21 +33,17 @@ public class MavenJarRule implements RuleDefinition {
@Override
public RuleClass build(Builder builder, RuleDefinitionEnvironment environment) {
return builder
- /* <!-- #BLAZE_RULE(maven_jar).ATTRIBUTE(artifact_id) -->
- The artifactId of the Maven dependency.
- ${SYNOPSIS}
- <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
- .add(attr("artifact_id", Type.STRING).mandatory())
- /* <!-- #BLAZE_RULE(maven_jar).ATTRIBUTE(group_id) -->
- The groupId of the Maven dependency.
- ${SYNOPSIS}
- <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
- .add(attr("group_id", Type.STRING).mandatory())
- /* <!-- #BLAZE_RULE(maven_jar).ATTRIBUTE(version) -->
- The version of the Maven dependency.
+ /* <!-- #BLAZE_RULE(maven_jar).ATTRIBUTE(artifact) -->
+ A description of a Maven artifact.
${SYNOPSIS}
+
+ <p>These descriptions are of the form &lt;groupId&gt:&lt;artifactId&gt;:&lt;version&gt;,
+ see <a href="#maven_jar_examples">the documentation below</a> for an example.
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */
- .add(attr("version", Type.STRING).mandatory())
+ .add(attr("artifact", Type.STRING))
+ .add(attr("artifact_id", Type.STRING).undocumented("deprecated"))
+ .add(attr("group_id", Type.STRING).undocumented("deprecated"))
+ .add(attr("version", Type.STRING).undocumented("deprecated"))
/* <!-- #BLAZE_RULE(maven_jar).ATTRIBUTE(repository) -->
A URL for a Maven repository to fetch the jar from.
${SYNOPSIS}
@@ -88,7 +84,7 @@ ${ATTRIBUTE_SIGNATURE}
${ATTRIBUTE_DEFINITION}
-<h4 id="http_jar_examples">Examples</h4>
+<h4 id="maven_jar_examples">Examples</h4>
Suppose that the current repostory contains a java_library target that needs to depend on Guava.
Using Maven, this dependency would be defined in the pom.xml file as:
@@ -101,17 +97,16 @@ Using Maven, this dependency would be defined in the pom.xml file as:
</dependency>
</pre>
-In Bazel, the following lines can be added to the WORKSPACE file:
+With Bazel, add the following lines to the WORKSPACE file:
<pre>
maven_jar(
name = "guava",
- group_id = "com.google.guava",
- artifact_id = "guava",
- version = "18.0",
+ artifact = "com.google.guava:guava:18.0",
+ sha1 = "d664fbfc03d2e5ce9cab2a44fb01f1d0bf9dfebeccc1a473b1f9ea31f79f6f99",
)
</pre>
-<p>Targets would specify <code>@guava//jar</code> as a dependency to depend on this jar.</p>
+<p>Targets can specify <code>@guava//jar</code> as a dependency to depend on this jar.</p>
<!-- #END_BLAZE_RULE -->*/