use of com.google.devtools.build.lib.ideinfo.androidstudio.PackageManifestOuterClass.PackageManifest in project bazel by bazelbuild.
the class JarFilterTest method legacyIntegrationTest.
@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[] { "--jars", 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");
}
Aggregations