aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/com/google/devtools/build/android/BUILD1
-rw-r--r--src/test/java/com/google/devtools/build/android/ideinfo/ArtifactLocationConverterTest.java106
-rw-r--r--src/test/java/com/google/devtools/build/android/ideinfo/BUILD52
-rw-r--r--src/test/java/com/google/devtools/build/android/ideinfo/JarFilterTest.java255
-rw-r--r--src/test/java/com/google/devtools/build/android/ideinfo/PackageParserTest.java281
-rw-r--r--src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java10
6 files changed, 0 insertions, 705 deletions
diff --git a/src/test/java/com/google/devtools/build/android/BUILD b/src/test/java/com/google/devtools/build/android/BUILD
index 9c66a43b2a..77bb8dfa07 100644
--- a/src/test/java/com/google/devtools/build/android/BUILD
+++ b/src/test/java/com/google/devtools/build/android/BUILD
@@ -1,7 +1,6 @@
filegroup(
name = "srcs",
srcs = glob(["**"]) + [
- "//src/test/java/com/google/devtools/build/android/ideinfo:srcs",
"//src/test/java/com/google/devtools/build/android/idlclass:srcs",
"//src/test/java/com/google/devtools/build/android/dexer:srcs",
"//src/test/java/com/google/devtools/build/android/junctions:srcs",
diff --git a/src/test/java/com/google/devtools/build/android/ideinfo/ArtifactLocationConverterTest.java b/src/test/java/com/google/devtools/build/android/ideinfo/ArtifactLocationConverterTest.java
deleted file mode 100644
index 9fac92c48c..0000000000
--- a/src/test/java/com/google/devtools/build/android/ideinfo/ArtifactLocationConverterTest.java
+++ /dev/null
@@ -1,106 +0,0 @@
-// Copyright 2016 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.android.ideinfo;
-
-import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.fail;
-
-import com.google.common.base.Joiner;
-import com.google.devtools.build.lib.ideinfo.androidstudio.PackageManifestOuterClass.ArtifactLocation;
-import com.google.devtools.common.options.OptionsParsingException;
-import java.nio.file.Paths;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-/**
- * Tests {@link ArtifactLocationConverter}.
- */
-@RunWith(JUnit4.class)
-public class ArtifactLocationConverterTest {
-
- private ArtifactLocationConverter converter;
-
- @Before
- public final void init() throws Exception {
- converter = new ArtifactLocationConverter();
- }
-
- @Test
- public void testConverterSourceArtifact() throws Exception {
- ArtifactLocation parsed = converter.convert(
- Joiner.on(',').join("", "test.java")
- );
- assertThat(parsed)
- .isEqualTo(
- ArtifactLocation.newBuilder()
- .setRelativePath(Paths.get("test.java").toString())
- .setIsSource(true)
- .build());
- }
-
- @Test
- public void testConverterDerivedArtifact() throws Exception {
- ArtifactLocation parsed = converter.convert(
- Joiner.on(',').join("bin", "java/com/test.java")
- );
- assertThat(parsed)
- .isEqualTo(
- ArtifactLocation.newBuilder()
- .setRootExecutionPathFragment(Paths.get("bin").toString())
- .setRelativePath(Paths.get("java/com/test.java").toString())
- .setIsSource(false)
- .build());
- }
-
- @Test
- public void testConverterExternal() throws Exception {
- ArtifactLocation externalArtifact =
- converter.convert(Joiner.on(',').join("", "test.java", "1"));
- assertThat(externalArtifact)
- .isEqualTo(
- ArtifactLocation.newBuilder()
- .setRelativePath(Paths.get("test.java").toString())
- .setIsSource(true)
- .setIsExternal(true)
- .build());
- ArtifactLocation nonExternalArtifact =
- converter.convert(Joiner.on(',').join("", "test.java", "0"));
- assertThat(nonExternalArtifact)
- .isEqualTo(
- ArtifactLocation.newBuilder()
- .setRelativePath(Paths.get("test.java").toString())
- .setIsSource(true)
- .setIsExternal(false)
- .build());
- }
-
- @Test
- public void testInvalidFormatFails() throws Exception {
- assertFails("/root", ArtifactLocationConverter.INVALID_FORMAT);
- assertFails("/root,exec,rel,extra", ArtifactLocationConverter.INVALID_FORMAT);
- }
-
- private void assertFails(String input, String expectedError) {
- try {
- new ArtifactLocationConverter().convert(input);
- fail();
- } catch (OptionsParsingException e) {
- assertThat(e).hasMessage(expectedError);
- }
- }
-}
-
diff --git a/src/test/java/com/google/devtools/build/android/ideinfo/BUILD b/src/test/java/com/google/devtools/build/android/ideinfo/BUILD
deleted file mode 100644
index 924ec5f28b..0000000000
--- a/src/test/java/com/google/devtools/build/android/ideinfo/BUILD
+++ /dev/null
@@ -1,52 +0,0 @@
-filegroup(
- name = "srcs",
- srcs = glob(["**"]),
- visibility = ["//src/test/java/com/google/devtools/build/android:__pkg__"],
-)
-
-java_test(
- name = "JarFilterTest",
- size = "small",
- srcs = ["JarFilterTest.java"],
- deps = [
- "//src/main/java/com/google/devtools/common/options",
- "//src/main/protobuf:package_manifest_java_proto",
- "//src/tools/android/java/com/google/devtools/build/android/ideinfo:jar_filter_lib",
- "//third_party:guava",
- "//third_party:jsr305",
- "//third_party:junit4",
- "//third_party:truth",
- "//third_party/protobuf:protobuf_java",
- ],
-)
-
-java_test(
- name = "PackageParserTest",
- size = "small",
- srcs = ["PackageParserTest.java"],
- deps = [
- "//src/main/java/com/google/devtools/common/options",
- "//src/main/protobuf:package_manifest_java_proto",
- "//src/tools/android/java/com/google/devtools/build/android/ideinfo:package_parser_lib",
- "//third_party:guava",
- "//third_party:jsr305",
- "//third_party:junit4",
- "//third_party:truth",
- "//third_party/protobuf:protobuf_java",
- ],
-)
-
-java_test(
- name = "ArtifactLocationConverterTest",
- size = "small",
- srcs = ["ArtifactLocationConverterTest.java"],
- deps = [
- "//src/main/java/com/google/devtools/common/options",
- "//src/main/protobuf:package_manifest_java_proto",
- "//src/tools/android/java/com/google/devtools/build/android/ideinfo:package_parser_lib",
- "//third_party:guava",
- "//third_party:junit4",
- "//third_party:truth",
- "//third_party/protobuf:protobuf_java",
- ],
-)
diff --git a/src/test/java/com/google/devtools/build/android/ideinfo/JarFilterTest.java b/src/test/java/com/google/devtools/build/android/ideinfo/JarFilterTest.java
deleted file mode 100644
index 2bb779f088..0000000000
--- a/src/test/java/com/google/devtools/build/android/ideinfo/JarFilterTest.java
+++ /dev/null
@@ -1,255 +0,0 @@
-// Copyright 2015 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.android.ideinfo;
-
-import static com.google.common.truth.Truth.assertThat;
-import static java.nio.charset.StandardCharsets.UTF_8;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Lists;
-import com.google.common.io.Files;
-import com.google.devtools.build.android.ideinfo.JarFilter.JarFilterOptions;
-import com.google.devtools.build.lib.ideinfo.androidstudio.PackageManifestOuterClass.ArtifactLocation;
-import com.google.devtools.build.lib.ideinfo.androidstudio.PackageManifestOuterClass.JavaSourcePackage;
-import com.google.devtools.build.lib.ideinfo.androidstudio.PackageManifestOuterClass.PackageManifest;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipFile;
-import java.util.zip.ZipOutputStream;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-/** Unit tests for {@link JarFilter} */
-@RunWith(JUnit4.class)
-public class JarFilterTest {
-
- @Rule public TemporaryFolder folder = new TemporaryFolder();
-
- @Test
- public void testFilterMethod() throws Exception {
- List<String> prefixes =
- ImmutableList.of("com/google/foo/Foo", "com/google/bar/Bar", "com/google/baz/Baz");
- assertThat(JarFilter.shouldKeepClass(prefixes, "com/google/foo/Foo.class")).isTrue();
- assertThat(JarFilter.shouldKeepClass(prefixes, "com/google/foo/Foo$Inner.class")).isTrue();
- assertThat(JarFilter.shouldKeepClass(prefixes, "com/google/bar/Bar.class")).isTrue();
- assertThat(JarFilter.shouldKeepClass(prefixes, "com/google/foo/Foo/NotFoo.class")).isFalse();
- assertThat(JarFilter.shouldKeepClass(prefixes, "wrong/com/google/foo/Foo.class")).isFalse();
- }
-
- @Test
- public void legacyIntegrationTest() throws Exception {
- PackageManifest packageManifest =
- PackageManifest.newBuilder()
- .addSources(
- JavaSourcePackage.newBuilder()
- .setArtifactLocation(
- ArtifactLocation.newBuilder()
- .setIsSource(true)
- .setRelativePath("com/google/foo/Foo.java"))
- .setPackageString("com.google.foo"))
- .addSources(
- JavaSourcePackage.newBuilder()
- .setArtifactLocation(
- ArtifactLocation.newBuilder()
- .setIsSource(true)
- .setRelativePath("com/google/bar/Bar.java"))
- .setPackageString("com.google.bar"))
- .addSources(
- JavaSourcePackage.newBuilder()
- .setArtifactLocation(
- ArtifactLocation.newBuilder()
- .setIsSource(true)
- .setRelativePath("some/path/Test.java"))
- .setPackageString("com.google.test"))
- .build();
- assertThat(JarFilter.parsePackageManifest(packageManifest))
- .containsExactly("com/google/foo/Foo", "com/google/bar/Bar", "com/google/test/Test");
- File manifest = folder.newFile("foo.manifest");
- try (FileOutputStream outputStream = new FileOutputStream(manifest)) {
- packageManifest.writeTo(outputStream);
- }
-
- File filterJar = folder.newFile("foo.jar");
- try (ZipOutputStream zo = new ZipOutputStream(new FileOutputStream(filterJar))) {
- zo.putNextEntry(new ZipEntry("com/google/foo/Foo.class"));
- zo.closeEntry();
- zo.putNextEntry(new ZipEntry("com/google/foo/Foo$Inner.class"));
- zo.closeEntry();
- zo.putNextEntry(new ZipEntry("com/google/bar/Bar.class"));
- zo.closeEntry();
- zo.putNextEntry(new ZipEntry("com/google/test/Test.class"));
- zo.closeEntry();
- zo.putNextEntry(new ZipEntry("com/google/foo/Foo2.class"));
- zo.closeEntry();
- }
-
- File outputJar = folder.newFile("foo-filtered-gen.jar");
-
- String[] args =
- new String[] {
- "--jar",
- filterJar.getPath(),
- "--output",
- outputJar.getPath(),
- "--manifest",
- manifest.getPath()
- };
- JarFilter.JarFilterOptions options = JarFilter.parseArgs(args);
- JarFilter.main(options);
-
- List<String> filteredJarNames = Lists.newArrayList();
- try (ZipFile zipFile = new ZipFile(outputJar)) {
- Enumeration<? extends ZipEntry> entries = zipFile.entries();
- while (entries.hasMoreElements()) {
- ZipEntry zipEntry = entries.nextElement();
- filteredJarNames.add(zipEntry.getName());
- }
- }
-
- assertThat(filteredJarNames)
- .containsExactly(
- "com/google/foo/Foo.class",
- "com/google/foo/Foo$Inner.class",
- "com/google/bar/Bar.class",
- "com/google/test/Test.class");
- }
-
- @Test
- public void fullIntegrationTest() throws Exception {
- File fooJava = folder.newFile("Foo.java");
- Files.write("package com.google.foo; class Foo { class Inner {} }".getBytes(UTF_8), fooJava);
-
- File barJava = folder.newFile("Bar.java");
- Files.write("package com.google.foo.bar; class Bar {}".getBytes(UTF_8), barJava);
-
- File srcJar = folder.newFile("gen.srcjar");
- try (ZipOutputStream zo = new ZipOutputStream(new FileOutputStream(srcJar))) {
- zo.putNextEntry(new ZipEntry("com/google/foo/gen/Gen.java"));
- zo.write("package gen; class Gen {}".getBytes(UTF_8));
- zo.closeEntry();
- zo.putNextEntry(new ZipEntry("com/google/foo/gen/Gen2.java"));
- zo.write("package gen; class Gen2 {}".getBytes(UTF_8));
- zo.closeEntry();
- }
-
- File src3Jar = folder.newFile("gen3.srcjar");
- try (ZipOutputStream zo = new ZipOutputStream(new FileOutputStream(src3Jar))) {
- zo.putNextEntry(new ZipEntry("com/google/foo/gen/Gen3.java"));
- zo.write("package gen; class Gen3 {}".getBytes(UTF_8));
- zo.closeEntry();
- }
-
- File filterJar = folder.newFile("foo.jar");
- try (ZipOutputStream zo = new ZipOutputStream(new FileOutputStream(filterJar))) {
- zo.putNextEntry(new ZipEntry("com/google/foo/Foo.class"));
- zo.closeEntry();
- zo.putNextEntry(new ZipEntry("com/google/foo/Foo$Inner.class"));
- zo.closeEntry();
- zo.putNextEntry(new ZipEntry("com/google/foo/bar/Bar.class"));
- zo.closeEntry();
- zo.putNextEntry(new ZipEntry("gen/Gen.class"));
- zo.closeEntry();
- zo.putNextEntry(new ZipEntry("gen/Gen2.class"));
- zo.closeEntry();
- zo.putNextEntry(new ZipEntry("gen/Gen3.class"));
- zo.closeEntry();
- zo.putNextEntry(new ZipEntry("com/google/foo/Foo2.class"));
- zo.closeEntry();
- }
- File filterSrcJar = folder.newFile("foo-src.jar");
- try (ZipOutputStream zo = new ZipOutputStream(new FileOutputStream(filterSrcJar))) {
- zo.putNextEntry(new ZipEntry("com/google/foo/Foo.java"));
- zo.closeEntry();
- zo.putNextEntry(new ZipEntry("com/google/foo/bar/Bar.java"));
- zo.closeEntry();
- zo.putNextEntry(new ZipEntry("gen/Gen.java"));
- zo.closeEntry();
- zo.putNextEntry(new ZipEntry("gen/Gen2.java"));
- zo.closeEntry();
- zo.putNextEntry(new ZipEntry("gen/Gen3.java"));
- zo.closeEntry();
- zo.putNextEntry(new ZipEntry("com/google/foo/Foo2.java"));
- zo.closeEntry();
- zo.putNextEntry(new ZipEntry("com/google/foo/bar/Bar2.java"));
- zo.closeEntry();
- }
-
- File filteredJar = folder.newFile("foo-filtered-gen.jar");
- File filteredSourceJar = folder.newFile("foo-filtered-gen-src.jar");
-
- String[] args =
- new String[] {
- "--keep_java_file",
- fooJava.getPath(),
- "--keep_java_file",
- barJava.getPath(),
- "--keep_source_jar",
- srcJar.getPath(),
- "--keep_source_jar",
- src3Jar.getPath(),
- "--filter_jar",
- filterJar.getPath(),
- "--filter_source_jar",
- filterSrcJar.getPath(),
- "--filtered_jar",
- filteredJar.getPath(),
- "--filtered_source_jar",
- filteredSourceJar.getPath()
- };
- JarFilterOptions options = JarFilter.parseArgs(args);
- JarFilter.main(options);
-
- List<String> filteredJarNames = Lists.newArrayList();
- try (ZipFile zipFile = new ZipFile(filteredJar)) {
- Enumeration<? extends ZipEntry> entries = zipFile.entries();
- while (entries.hasMoreElements()) {
- ZipEntry zipEntry = entries.nextElement();
- filteredJarNames.add(zipEntry.getName());
- }
- }
-
- List<String> filteredSourceJarNames = Lists.newArrayList();
- try (ZipFile zipFile = new ZipFile(filteredSourceJar)) {
- Enumeration<? extends ZipEntry> entries = zipFile.entries();
- while (entries.hasMoreElements()) {
- ZipEntry zipEntry = entries.nextElement();
- filteredSourceJarNames.add(zipEntry.getName());
- }
- }
-
- assertThat(filteredJarNames)
- .containsExactly(
- "com/google/foo/Foo.class",
- "com/google/foo/Foo$Inner.class",
- "com/google/foo/bar/Bar.class",
- "gen/Gen.class",
- "gen/Gen2.class",
- "gen/Gen3.class");
-
- assertThat(filteredSourceJarNames)
- .containsExactly(
- "com/google/foo/Foo.java",
- "com/google/foo/bar/Bar.java",
- "gen/Gen.java",
- "gen/Gen2.java",
- "gen/Gen3.java");
- }
-}
diff --git a/src/test/java/com/google/devtools/build/android/ideinfo/PackageParserTest.java b/src/test/java/com/google/devtools/build/android/ideinfo/PackageParserTest.java
deleted file mode 100644
index e775ca36c7..0000000000
--- a/src/test/java/com/google/devtools/build/android/ideinfo/PackageParserTest.java
+++ /dev/null
@@ -1,281 +0,0 @@
-// Copyright 2015 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.android.ideinfo;
-
-import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.fail;
-
-import com.google.common.base.Joiner;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.devtools.build.lib.ideinfo.androidstudio.PackageManifestOuterClass.ArtifactLocation;
-import com.google.protobuf.MessageLite;
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.StringWriter;
-import java.io.UnsupportedEncodingException;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.InvalidPathException;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.List;
-import java.util.Map;
-import javax.annotation.Nonnull;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-/**
- * Unit tests for {@link PackageParser}
- */
-@RunWith(JUnit4.class)
-public class PackageParserTest {
-
- private static class MockPackageParserIoProvider extends PackageParserIoProvider {
- private final Map<Path, InputStream> sources = Maps.newHashMap();
- private final List<ArtifactLocation> sourceLocations = Lists.newArrayList();
- private StringWriter writer = new StringWriter();
-
- public MockPackageParserIoProvider addSource(ArtifactLocation source, String javaSrc) {
- try {
- Path path = Paths.get(source.getRootExecutionPathFragment(), source.getRelativePath());
- sources.put(path, new ByteArrayInputStream(javaSrc.getBytes("UTF-8")));
- sourceLocations.add(source);
-
- } catch (UnsupportedEncodingException | InvalidPathException e) {
- fail(e.getMessage());
- }
- return this;
- }
-
- public void reset() {
- sources.clear();
- sourceLocations.clear();
- writer = new StringWriter();
- }
-
- public List<ArtifactLocation> getSourceLocations() {
- return Lists.newArrayList(sourceLocations);
- }
-
- @Nonnull
- @Override
- public BufferedReader getReader(Path file) throws IOException {
- InputStream input = sources.get(file);
- return new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8));
- }
-
- @Override
- public void writeProto(@Nonnull MessageLite message, @Nonnull Path file) throws IOException {
- writer.write(message.toString());
- }
- }
-
- private static final ArtifactLocation DUMMY_SOURCE_ARTIFACT =
- ArtifactLocation.newBuilder()
- .setRelativePath("java/com/google/Foo.java")
- .setIsSource(true)
- .build();
-
- private static final ArtifactLocation DUMMY_DERIVED_ARTIFACT =
- ArtifactLocation.newBuilder()
- .setRootExecutionPathFragment("bin")
- .setRelativePath("java/com/google/Bla.java")
- .setIsSource(false)
- .build();
-
- private static final ArtifactLocation DUMMY_SCALA_SOURCE_ARTIFACT =
- ArtifactLocation.newBuilder()
- .setRelativePath("scala/com/google/Foo.scala")
- .setIsSource(true)
- .build();
-
- private static final ArtifactLocation DUMMY_SCALA_DERIVED_ARTIFACT =
- ArtifactLocation.newBuilder()
- .setRootExecutionPathFragment("bin")
- .setRelativePath("scala/com/google/Bla.scala")
- .setIsSource(false)
- .build();
-
- private MockPackageParserIoProvider mockIoProvider;
- private PackageParser parser;
-
- @Before
- public void setUp() {
- mockIoProvider = new MockPackageParserIoProvider();
- parser = new PackageParser(mockIoProvider);
- }
-
- private Map<ArtifactLocation, String> parsePackageStrings() throws Exception {
- List<ArtifactLocation> sources = mockIoProvider.getSourceLocations();
- return parser.parsePackageStrings(sources);
- }
-
- @Test
- public void testParseCommandLineArguments() throws Exception {
- String[] args = new String[] {
- "--output_manifest",
- "/tmp/out.manifest",
- "--sources",
- Joiner.on(':').join(
- ",java/com/google/Foo.java",
- "bin/out,java/com/google/Bla.java")
- };
- PackageParser.PackageParserOptions options = PackageParser.parseArgs(args);
- assertThat(options.outputManifest.toString())
- .isEqualTo(Paths.get("/tmp/out.manifest").toString());
- assertThat(options.sources).hasSize(2);
- assertThat(options.sources.get(0))
- .isEqualTo(
- ArtifactLocation.newBuilder()
- .setRelativePath(Paths.get("java/com/google/Foo.java").toString())
- .setIsSource(true)
- .build());
- assertThat(options.sources.get(1))
- .isEqualTo(
- ArtifactLocation.newBuilder()
- .setRootExecutionPathFragment(Paths.get("bin/out").toString())
- .setRelativePath(Paths.get("java/com/google/Bla.java").toString())
- .setIsSource(false)
- .build());
- }
-
- @Test
- public void testReadNoSources() throws Exception {
- Map<ArtifactLocation, String> map = parsePackageStrings();
- assertThat(map).isEmpty();
- }
-
- @Test
- public void testSingleRead() throws Exception {
- mockIoProvider
- .addSource(
- DUMMY_SOURCE_ARTIFACT,
- "package com.google;\n public class Bla {}\"");
- Map<ArtifactLocation, String> map = parsePackageStrings();
- assertThat(map).hasSize(1);
- assertThat(map).containsEntry(
- DUMMY_SOURCE_ARTIFACT,
- "com.google");
- }
-
- @Test
- public void testMultiRead() throws Exception {
- mockIoProvider
- .addSource(DUMMY_SOURCE_ARTIFACT, "package com.test;\n public class Foo {}\"")
- .addSource(DUMMY_DERIVED_ARTIFACT, "package com.other;\n public class Bla {}\"");
- Map<ArtifactLocation, String> map = parsePackageStrings();
- assertThat(map).hasSize(2);
- assertThat(map).containsEntry(DUMMY_SOURCE_ARTIFACT, "com.test");
- assertThat(map).containsEntry(DUMMY_DERIVED_ARTIFACT, "com.other");
- }
-
- @Test
- public void testReadSomeInvalid() throws Exception {
- mockIoProvider
- .addSource(DUMMY_SOURCE_ARTIFACT, "package %com.test;\n public class Foo {}\"")
- .addSource(DUMMY_DERIVED_ARTIFACT, "package com.other;\n public class Bla {}\"");
- Map<ArtifactLocation, String> map = parsePackageStrings();
- assertThat(map).hasSize(1);
- assertThat(map).containsEntry(DUMMY_DERIVED_ARTIFACT, "com.other");
- }
-
- @Test
- public void testReadAllInvalid() throws Exception {
- mockIoProvider
- .addSource(DUMMY_SOURCE_ARTIFACT, "#package com.test;\n public class Foo {}\"")
- .addSource(DUMMY_DERIVED_ARTIFACT, "package %com.other\n public class Bla {}\"");
- Map<ArtifactLocation, String> map = parsePackageStrings();
- assertThat(map).isEmpty();
- }
-
- @Test
- public void testReadScala() throws Exception {
- mockIoProvider
- .addSource(DUMMY_SCALA_SOURCE_ARTIFACT, "package com.test\n class Foo {}\"")
- .addSource(DUMMY_SCALA_DERIVED_ARTIFACT, "package com.other {}\n object Bla {}\"");
- Map<ArtifactLocation, String> map = parsePackageStrings();
- assertThat(map).containsEntry(DUMMY_SCALA_SOURCE_ARTIFACT, "com.test");
- assertThat(map).containsEntry(DUMMY_SCALA_DERIVED_ARTIFACT, "com.other");
- }
-
- @Test
- public void testWriteEmptyMap() throws Exception {
- parser.writeManifest(
- Maps.<ArtifactLocation, String> newHashMap(),
- Paths.get("/java/com/google/test.manifest"));
- assertThat(mockIoProvider.writer.toString()).isEmpty();
- }
-
- @Test
- public void testWriteMap() throws Exception {
- Map<ArtifactLocation, String> map = ImmutableMap.of(
- DUMMY_SOURCE_ARTIFACT,
- "com.google",
- DUMMY_DERIVED_ARTIFACT,
- "com.other"
- );
- parser.writeManifest(map, Paths.get("/java/com/google/test.manifest"));
-
- String writtenString = mockIoProvider.writer.toString();
- assertThat(writtenString).contains(String.format(
- "relative_path: \"%s\"",
- DUMMY_SOURCE_ARTIFACT.getRelativePath()));
- assertThat(writtenString).contains("package_string: \"com.google\"");
-
- assertThat(writtenString).contains(String.format(
- "root_execution_path_fragment: \"%s\"",
- DUMMY_DERIVED_ARTIFACT.getRootExecutionPathFragment()));
- assertThat(writtenString).contains(String.format(
- "relative_path: \"%s\"",
- DUMMY_DERIVED_ARTIFACT.getRelativePath()));
- assertThat(writtenString).contains("package_string: \"com.other\"");
- }
-
- @Test
- public void testHandlesOldFormat() throws Exception {
- String[] args = new String[] {
- "--output_manifest",
- "/tmp/out.manifest",
- "--sources",
- Joiner.on(':').join(
- ",java/com/google/Foo.java,/usr/local/google/code",
- "bin,java/com/google/Bla.java,/usr/local/_tmp/code/bin"
- )};
- PackageParser.PackageParserOptions options = PackageParser.parseArgs(args);
- assertThat(options.outputManifest.toString())
- .isEqualTo(Paths.get("/tmp/out.manifest").toString());
- assertThat(options.sources).hasSize(2);
- assertThat(options.sources.get(0))
- .isEqualTo(
- ArtifactLocation.newBuilder()
- .setRelativePath(Paths.get("java/com/google/Foo.java").toString())
- .setIsSource(true)
- .build());
- assertThat(options.sources.get(1))
- .isEqualTo(
- ArtifactLocation.newBuilder()
- .setRootExecutionPathFragment(Paths.get("bin").toString())
- .setRelativePath(Paths.get("java/com/google/Bla.java").toString())
- .setIsSource(false)
- .build());
- }
-
-}
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java b/src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java
index a8aaa9735d..55cc5e2045 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java
@@ -211,16 +211,6 @@ public final class BazelAnalysisMock extends AnalysisMock {
.add("sh_binary(name = 'strip_resources', srcs = ['empty.sh'])")
.add("sh_binary(name = 'build_incremental_dexmanifest', srcs = ['empty.sh'])")
.add("sh_binary(name = 'incremental_install', srcs = ['empty.sh'])")
- .add("java_binary(name = 'JarFilter',")
- .add(" runtime_deps = [ ':JarFilter_import'],")
- .add(" main_class = 'com.google.devtools.build.android.ideinfo.JarFilter')")
- .add("java_import(name = 'JarFilter_import',")
- .add(" jars = [ 'jar_filter_deploy.jar' ])")
- .add("java_binary(name = 'PackageParser',")
- .add(" runtime_deps = [ ':PackageParser_import'],")
- .add(" main_class = 'com.google.devtools.build.android.ideinfo.PackageParser')")
- .add("java_import(name = 'PackageParser_import',")
- .add(" jars = [ 'package_parser_deploy.jar' ])")
.add("java_binary(name = 'IdlClass',")
.add(" runtime_deps = [ ':idlclass_import' ],")
.add(" main_class = 'com.google.devtools.build.android.idlclass.IdlClass')")