Search in sources :

Example 76 with JarFile

use of java.util.jar.JarFile in project spring-boot by spring-projects.

the class RepackagerTests method metaInfIndexListIsRemovedFromRepackagedJar.

@Test
public void metaInfIndexListIsRemovedFromRepackagedJar() throws Exception {
    this.testJarFile.addClass("A.class", ClassWithMainMethod.class);
    this.testJarFile.addFile("META-INF/INDEX.LIST", this.temporaryFolder.newFile("INDEX.LIST"));
    File source = this.testJarFile.getFile();
    File dest = this.temporaryFolder.newFile("dest.jar");
    Repackager repackager = new Repackager(source);
    repackager.repackage(dest, NO_LIBRARIES);
    JarFile jarFile = new JarFile(dest);
    try {
        assertThat(jarFile.getEntry("META-INF/INDEX.LIST")).isNull();
    } finally {
        jarFile.close();
    }
}
Also used : JarFile(java.util.jar.JarFile) JarFile(java.util.jar.JarFile) File(java.io.File) Test(org.junit.Test)

Example 77 with JarFile

use of java.util.jar.JarFile in project spring-boot by spring-projects.

the class RepackagerTests method dontRecompressZips.

@Test
public void dontRecompressZips() throws Exception {
    TestJarFile nested = new TestJarFile(this.temporaryFolder);
    nested.addClass("a/b/C.class", ClassWithoutMainMethod.class);
    final File nestedFile = nested.getFile();
    this.testJarFile.addFile("test/nested.jar", nestedFile);
    this.testJarFile.addClass("A.class", ClassWithMainMethod.class);
    File file = this.testJarFile.getFile();
    Repackager repackager = new Repackager(file);
    repackager.repackage(new Libraries() {

        @Override
        public void doWithLibraries(LibraryCallback callback) throws IOException {
            callback.library(new Library(nestedFile, LibraryScope.COMPILE));
        }
    });
    JarFile jarFile = new JarFile(file);
    try {
        assertThat(jarFile.getEntry("BOOT-INF/lib/" + nestedFile.getName()).getMethod()).isEqualTo(ZipEntry.STORED);
        assertThat(jarFile.getEntry("BOOT-INF/classes/test/nested.jar").getMethod()).isEqualTo(ZipEntry.STORED);
    } finally {
        jarFile.close();
    }
}
Also used : IOException(java.io.IOException) JarFile(java.util.jar.JarFile) JarFile(java.util.jar.JarFile) File(java.io.File) Test(org.junit.Test)

Example 78 with JarFile

use of java.util.jar.JarFile in project spring-boot by spring-projects.

the class RepackagerTests method customLayoutFactoryWithLayout.

@Test
public void customLayoutFactoryWithLayout() throws Exception {
    this.testJarFile.addClass("a/b/C.class", ClassWithMainMethod.class);
    File source = this.testJarFile.getFile();
    Repackager repackager = new Repackager(source, new TestLayoutFactory());
    repackager.setLayout(new Layouts.Jar());
    repackager.repackage(NO_LIBRARIES);
    JarFile jarFile = new JarFile(source);
    assertThat(jarFile.getEntry("test")).isNull();
    jarFile.close();
}
Also used : JarFile(java.util.jar.JarFile) JarFile(java.util.jar.JarFile) File(java.io.File) Test(org.junit.Test)

Example 79 with JarFile

use of java.util.jar.JarFile in project spring-boot by spring-projects.

the class RepackagerTests method customLayoutFactoryWithoutLayout.

@Test
public void customLayoutFactoryWithoutLayout() throws Exception {
    this.testJarFile.addClass("a/b/C.class", ClassWithMainMethod.class);
    File source = this.testJarFile.getFile();
    Repackager repackager = new Repackager(source, new TestLayoutFactory());
    repackager.repackage(NO_LIBRARIES);
    JarFile jarFile = new JarFile(source);
    assertThat(jarFile.getEntry("test")).isNotNull();
    jarFile.close();
}
Also used : JarFile(java.util.jar.JarFile) JarFile(java.util.jar.JarFile) File(java.io.File) Test(org.junit.Test)

Example 80 with JarFile

use of java.util.jar.JarFile in project spring-boot by spring-projects.

the class RepackagerTests method existingSourceEntriesTakePrecedenceOverStandardLibraries.

@Test
public void existingSourceEntriesTakePrecedenceOverStandardLibraries() throws Exception {
    TestJarFile nested = new TestJarFile(this.temporaryFolder);
    nested.addClass("a/b/C.class", ClassWithoutMainMethod.class);
    final File nestedFile = nested.getFile();
    this.testJarFile.addFile("BOOT-INF/lib/" + nestedFile.getName(), nested.getFile());
    this.testJarFile.addClass("A.class", ClassWithMainMethod.class);
    File file = this.testJarFile.getFile();
    Repackager repackager = new Repackager(file);
    long sourceLength = nestedFile.length();
    repackager.repackage(new Libraries() {

        @Override
        public void doWithLibraries(LibraryCallback callback) throws IOException {
            nestedFile.delete();
            File toZip = RepackagerTests.this.temporaryFolder.newFile();
            ZipUtil.packEntry(toZip, nestedFile);
            callback.library(new Library(nestedFile, LibraryScope.COMPILE));
        }
    });
    JarFile jarFile = new JarFile(file);
    try {
        assertThat(jarFile.getEntry("BOOT-INF/lib/" + nestedFile.getName()).getSize()).isEqualTo(sourceLength);
    } finally {
        jarFile.close();
    }
}
Also used : IOException(java.io.IOException) JarFile(java.util.jar.JarFile) JarFile(java.util.jar.JarFile) File(java.io.File) Test(org.junit.Test)

Aggregations

JarFile (java.util.jar.JarFile)509 File (java.io.File)289 JarEntry (java.util.jar.JarEntry)230 IOException (java.io.IOException)212 URL (java.net.URL)92 ZipEntry (java.util.zip.ZipEntry)92 InputStream (java.io.InputStream)90 Manifest (java.util.jar.Manifest)81 ZipFile (java.util.zip.ZipFile)74 FileOutputStream (java.io.FileOutputStream)71 Test (org.junit.Test)66 ArrayList (java.util.ArrayList)54 JarURLConnection (java.net.JarURLConnection)48 Attributes (java.util.jar.Attributes)43 JarOutputStream (java.util.jar.JarOutputStream)41 MalformedURLException (java.net.MalformedURLException)31 FileInputStream (java.io.FileInputStream)30 Support_PlatformFile (tests.support.Support_PlatformFile)26 Enumeration (java.util.Enumeration)24 HashSet (java.util.HashSet)20