Search in sources :

Example 1 with PackageManifest

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");
}
Also used : JarFilterOptions(com.google.devtools.build.android.ideinfo.JarFilter.JarFilterOptions) ZipFile(java.util.zip.ZipFile) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) ZipEntry(java.util.zip.ZipEntry) PackageManifest(com.google.devtools.build.lib.ideinfo.androidstudio.PackageManifestOuterClass.PackageManifest) File(java.io.File) ZipFile(java.util.zip.ZipFile) Test(org.junit.Test)

Aggregations

JarFilterOptions (com.google.devtools.build.android.ideinfo.JarFilter.JarFilterOptions)1 PackageManifest (com.google.devtools.build.lib.ideinfo.androidstudio.PackageManifestOuterClass.PackageManifest)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 ZipEntry (java.util.zip.ZipEntry)1 ZipFile (java.util.zip.ZipFile)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 Test (org.junit.Test)1