diff options
author | 2017-08-23 19:32:49 +0200 | |
---|---|---|
committer | 2017-08-24 13:58:50 +0200 | |
commit | 7a7c41d7d342cd427e74f091b55690eed13e280d (patch) | |
tree | 9dff41110751ad6e1a0b0a12e15a11e8d8f8e9ac /src/test | |
parent | 49bb72377153fc208708267f90791644f389bd31 (diff) |
Pull maven -src jars when available alongside jars re:
https://github.com/bazelbuild/bazel/issues/308
RELNOTES: None.
PiperOrigin-RevId: 166219871
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/rules/repository/JarDecompressorTest.java | 57 | ||||
-rwxr-xr-x | src/test/shell/bazel/maven_test.sh | 23 | ||||
-rwxr-xr-x | src/test/shell/bazel/remote_helpers.sh | 7 |
3 files changed, 76 insertions, 11 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/rules/repository/JarDecompressorTest.java b/src/test/java/com/google/devtools/build/lib/rules/repository/JarDecompressorTest.java index 37cfa8daa3..11dfdbbb2f 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/repository/JarDecompressorTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/repository/JarDecompressorTest.java @@ -16,9 +16,10 @@ package com.google.devtools.build.lib.rules.repository; import static com.google.common.truth.Truth.assertThat; +import com.google.common.base.Optional; import com.google.devtools.build.lib.bazel.repository.DecompressorDescriptor; -import com.google.devtools.build.lib.bazel.repository.DecompressorValue; import com.google.devtools.build.lib.bazel.repository.JarDecompressor; +import com.google.devtools.build.lib.bazel.rules.workspace.MavenJarRule; import com.google.devtools.build.lib.testutil.Scratch; import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.Path; @@ -32,35 +33,69 @@ import org.junit.runners.JUnit4; */ @RunWith(JUnit4.class) public class JarDecompressorTest { - private DecompressorDescriptor.Builder descriptorBuilder; + private DecompressorDescriptor.Builder jarDescriptorBuilder; + private DecompressorDescriptor.Builder srcjarDescriptorBuilder; + private JarDecompressor decompressor; @Before public void setUpFs() throws Exception { Scratch fs = new Scratch(); Path dir = fs.dir("/whatever/external/tester"); Path jar = fs.file("/foo.jar", "I'm a jar"); + Path srcjar = fs.file("/foo-sources.jar", "I'm a source jar"); FileSystemUtils.createDirectoryAndParents(dir); - descriptorBuilder = DecompressorDescriptor.builder() - .setDecompressor(JarDecompressor.INSTANCE) - .setTargetName("tester") - .setTargetKind("http_jar rule") - .setRepositoryPath(dir) - .setArchivePath(jar); + jarDescriptorBuilder = + DecompressorDescriptor.builder() + .setDecompressor(JarDecompressor.INSTANCE) + .setTargetName("tester") + .setTargetKind(MavenJarRule.NAME) + .setRepositoryPath(dir) + .setArchivePath(jar); + srcjarDescriptorBuilder = + DecompressorDescriptor.builder() + .setDecompressor(JarDecompressor.INSTANCE) + .setTargetName("tester") + .setTargetKind(MavenJarRule.NAME) + .setRepositoryPath(dir) + .setArchivePath(srcjar); + decompressor = (JarDecompressor) jarDescriptorBuilder.build().getDecompressor(); } @Test - public void testTargets() throws Exception { - Path outputDir = DecompressorValue.decompress(descriptorBuilder.build()); + public void testTargetsWithSources() throws Exception { + Path outputDir = + decompressor.decompressWithSrcjar( + jarDescriptorBuilder.build(), Optional.fromNullable(srcjarDescriptorBuilder.build())); assertThat(outputDir.exists()).isTrue(); + assertThat(outputDir.getRelative("jar/foo.jar").exists()).isTrue(); + assertThat(outputDir.getRelative("jar/foo-sources.jar").exists()).isTrue(); String buildContent = new String(FileSystemUtils.readContentAsLatin1(outputDir.getRelative("jar/BUILD.bazel"))); assertThat(buildContent).contains("java_import"); + assertThat(buildContent).contains("srcjar = 'foo-sources.jar'"); assertThat(buildContent).contains("filegroup"); } @Test + public void testTargetsWithoutSources() throws Exception { + Path outputDir = + decompressor.decompressWithSrcjar(jarDescriptorBuilder.build(), Optional.absent()); + assertThat(outputDir.exists()).isTrue(); + assertThat(outputDir.getRelative("jar/foo.jar").exists()).isTrue(); + assertThat(outputDir.getRelative("jar/foo-sources.jar").exists()).isFalse(); + String buildContent = + new String(FileSystemUtils.readContentAsLatin1(outputDir.getRelative("jar/BUILD.bazel"))); + assertThat(buildContent).contains("java_import"); + assertThat(buildContent).doesNotContain("srcjar = 'foo-sources.jar'"); + assertThat(buildContent).contains("filegroup"); + } + + @Test + // Note: WORKSPACE gen is not affected by presence or absence of Optional arg to + // decompressWithSrcjar public void testWorkspaceGen() throws Exception { - Path outputDir = DecompressorValue.decompress(descriptorBuilder.build()); + Path outputDir = + decompressor.decompressWithSrcjar(jarDescriptorBuilder.build(), Optional.absent()); assertThat(outputDir.exists()).isTrue(); String workspaceContent = new String( FileSystemUtils.readContentAsLatin1(outputDir.getRelative("WORKSPACE"))); diff --git a/src/test/shell/bazel/maven_test.sh b/src/test/shell/bazel/maven_test.sh index 04e217c6f5..7a14c20bd6 100755 --- a/src/test/shell/bazel/maven_test.sh +++ b/src/test/shell/bazel/maven_test.sh @@ -17,6 +17,8 @@ # Test //external mechanisms # +set -euo pipefail + # Load the test setup defined in the parent directory CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "${CURRENT_DIR}/../integration_test_setup.sh" \ @@ -85,6 +87,27 @@ EOF expect_log "Tra-la!" } +# makes sure both jar and srcjar are downloaded +function test_maven_jar_downloads() { + serve_artifact com.example.carnivore carnivore 1.23 + + cat > WORKSPACE <<EOF +maven_jar( + name = 'endangered', + artifact = "com.example.carnivore:carnivore:1.23", + repository = 'http://127.0.0.1:$fileserver_port/', +) +bind(name = 'mongoose', actual = '@endangered//jar') +EOF + + bazel run //zoo:ball-pit >& $TEST_log || fail "Expected run to succeed" + output_base="$(bazel info output_base)" + test -e "${output_base}/external/endangered/jar/carnivore-1.23.jar" \ + || fail "jar not downloaded to expected place" + test -e "${output_base}/external/endangered/jar/carnivore-1.23-sources.jar" \ + || fail "srcjar not downloaded to expected place" +} + function test_maven_jar_404() { setup_zoo serve_not_found diff --git a/src/test/shell/bazel/remote_helpers.sh b/src/test/shell/bazel/remote_helpers.sh index 7903063c82..ff76585140 100755 --- a/src/test/shell/bazel/remote_helpers.sh +++ b/src/test/shell/bazel/remote_helpers.sh @@ -14,6 +14,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +set -euo pipefail + case "${PLATFORM}" in darwin|freebsd) function nc_l() { @@ -68,8 +70,10 @@ public class Mongoose { EOF ${bazel_javabase}/bin/javac $pkg_dir/Mongoose.java test_jar=$TEST_TMPDIR/libcarnivore.jar + test_srcjar=$TEST_TMPDIR/libcarnivore-sources.jar cd ${TEST_TMPDIR} ${bazel_javabase}/bin/jar cf $test_jar carnivore/Mongoose.class + ${bazel_javabase}/bin/jar cf $test_srcjar carnivore/Mongoose.java sha256=$(sha256sum $test_jar | cut -f 1 -d ' ') # OS X doesn't have sha1sum, so use openssl. sha1=$(openssl sha1 $test_jar | cut -f 2 -d ' ') @@ -168,11 +172,14 @@ function create_artifact() { else make_test_jar local artifact=$test_jar + local srcjar_artifact=$test_srcjar fi maven_path=$PWD/$(echo $group_id | sed 's/\./\//g')/$artifact_id/$version mkdir -p $maven_path openssl sha1 $artifact > $maven_path/$artifact_id-$version.$packaging.sha1 + openssl sha1 $srcjar_artifact > $maven_path/$artifact_id-$version-sources.$packaging.sha1 mv $artifact $maven_path/$artifact_id-$version.$packaging + mv $srcjar_artifact $maven_path/$artifact_id-$version-sources.$packaging } function serve_artifact() { |