diff options
-rwxr-xr-x | src/test/shell/bazel/generate_workspace_test.sh | 10 | ||||
-rw-r--r-- | src/tools/generate_workspace/src/main/java/com/google/devtools/build/workspace/maven/Rule.java | 17 |
2 files changed, 25 insertions, 2 deletions
diff --git a/src/test/shell/bazel/generate_workspace_test.sh b/src/test/shell/bazel/generate_workspace_test.sh index d96e35e2cb..fff3690812 100755 --- a/src/test/shell/bazel/generate_workspace_test.sh +++ b/src/test/shell/bazel/generate_workspace_test.sh @@ -69,8 +69,13 @@ public class $groupId { } } EOF + local jar_path=$pkg_dir/$artifactId-$version.jar ${bazel_javabase}/bin/javac $TEST_TMPDIR/$groupId.java - ${bazel_javabase}/bin/jar cf $pkg_dir/$artifactId-$version.jar $TEST_TMPDIR/$groupId.class + ${bazel_javabase}/bin/jar cf $jar_path $TEST_TMPDIR/$groupId.class + + local sha1=$(shasum $jar_path | awk '{print $1}') + echo -n $sha1 > $jar_path.sha1 + echo $sha1 } function get_workspace_file() { @@ -83,7 +88,7 @@ function get_build_file() { function test_pom() { # Create a maven repo - make_artifact blorp glorp 1.2.3 + local sha1=$(make_artifact blorp glorp 1.2.3) # Create a pom that references the artifacts. cat > $TEST_TMPDIR/pom.xml <<EOF @@ -118,6 +123,7 @@ EOF assert_contains "artifact = \"blorp:glorp:1.2.3\"," ws assert_contains "repository = \"http://localhost:$fileserver_port/\"," ws + assert_contains "sha1 = \"$sha1\"," ws assert_contains "\"@blorp_glorp//jar\"," build } diff --git a/src/tools/generate_workspace/src/main/java/com/google/devtools/build/workspace/maven/Rule.java b/src/tools/generate_workspace/src/main/java/com/google/devtools/build/workspace/maven/Rule.java index 1cd5d78ed5..2b24f4c879 100644 --- a/src/tools/generate_workspace/src/main/java/com/google/devtools/build/workspace/maven/Rule.java +++ b/src/tools/generate_workspace/src/main/java/com/google/devtools/build/workspace/maven/Rule.java @@ -15,6 +15,7 @@ package com.google.devtools.build.workspace.maven; import com.google.common.collect.Sets; +import com.google.common.io.CharStreams; import com.google.devtools.build.lib.bazel.repository.MavenConnector; import com.google.devtools.build.lib.events.Event; @@ -23,6 +24,10 @@ import org.apache.maven.model.Dependency; import org.eclipse.aether.artifact.Artifact; import org.eclipse.aether.artifact.DefaultArtifact; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; import java.util.Set; /** @@ -32,6 +37,7 @@ public final class Rule { private final Artifact artifact; private final Set<String> parents; private String repository; + private String sha1; public Rule(String artifactStr) throws InvalidRuleException { try { @@ -99,6 +105,16 @@ public final class Rule { + " attribute manually")); } else { this.repository = url.substring(0, uriStart); + String jarSha1Url = url.replaceAll("pom$", "jar.sha1"); + try { + // Download the sha1 of the jar file from the repository. + HttpURLConnection connection = (HttpURLConnection) new URL(jarSha1Url).openConnection(); + connection.setInstanceFollowRedirects(true); + connection.connect(); + this.sha1 = CharStreams.toString(new InputStreamReader(connection.getInputStream())); + } catch (IOException e) { + handler.handle(Event.warn("Failed to download the sha1 at " + jarSha1Url)); + } } } @@ -120,6 +136,7 @@ public final class Rule { + " name = \"" + name() + "\",\n" + " artifact = \"" + toMavenArtifactString() + "\",\n" + (hasCustomRepository() ? " repository = \"" + repository + "\",\n" : "") + + (sha1 != null ? " sha1 = \"" + sha1 + "\",\n" : "") + ")"); return builder.toString(); } |