Search in sources :

Example 1 with JarFileArchive

use of org.springframework.boot.loader.archive.JarFileArchive in project spring-boot by spring-projects.

the class WarLauncherTests method archivedWarHasOnlyWebInfClassesAndContentsOWebInfLibOnClasspath.

@Test
public void archivedWarHasOnlyWebInfClassesAndContentsOWebInfLibOnClasspath() throws Exception {
    File jarRoot = createJarArchive("archive.war", "WEB-INF");
    WarLauncher launcher = new WarLauncher(new JarFileArchive(jarRoot));
    List<Archive> archives = launcher.getClassPathArchives();
    assertThat(archives).hasSize(2);
    assertThat(getUrls(archives)).containsOnly(new URL("jar:" + jarRoot.toURI().toURL() + "!/WEB-INF/classes!/"), new URL("jar:" + jarRoot.toURI().toURL() + "!/WEB-INF/lib/foo.jar!/"));
}
Also used : JarFileArchive(org.springframework.boot.loader.archive.JarFileArchive) ExplodedArchive(org.springframework.boot.loader.archive.ExplodedArchive) Archive(org.springframework.boot.loader.archive.Archive) JarFileArchive(org.springframework.boot.loader.archive.JarFileArchive) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Example 2 with JarFileArchive

use of org.springframework.boot.loader.archive.JarFileArchive in project spring-boot by spring-projects.

the class PropertiesLauncher method getNestedArchives.

private List<Archive> getNestedArchives(String root) throws Exception {
    if (root.startsWith("/") || this.parent.getUrl().equals(this.home.toURI().toURL())) {
        // If home dir is same as parent archive, no need to add it twice.
        return null;
    }
    Archive parent = this.parent;
    if (root.startsWith("jar:file:") && root.contains("!")) {
        int index = root.indexOf("!");
        String file = root.substring("jar:file:".length(), index);
        parent = new JarFileArchive(new File(file));
        root = root.substring(index + 1, root.length());
        while (root.startsWith("/")) {
            root = root.substring(1);
        }
    }
    EntryFilter filter = new PrefixMatchingArchiveFilter(root);
    return parent.getNestedArchives(filter);
}
Also used : EntryFilter(org.springframework.boot.loader.archive.Archive.EntryFilter) JarFileArchive(org.springframework.boot.loader.archive.JarFileArchive) Archive(org.springframework.boot.loader.archive.Archive) ExplodedArchive(org.springframework.boot.loader.archive.ExplodedArchive) JarFileArchive(org.springframework.boot.loader.archive.JarFileArchive) File(java.io.File)

Example 3 with JarFileArchive

use of org.springframework.boot.loader.archive.JarFileArchive in project spring-boot by spring-projects.

the class Launcher method createArchive.

protected final Archive createArchive() throws Exception {
    ProtectionDomain protectionDomain = getClass().getProtectionDomain();
    CodeSource codeSource = protectionDomain.getCodeSource();
    URI location = (codeSource == null ? null : codeSource.getLocation().toURI());
    String path = (location == null ? null : location.getSchemeSpecificPart());
    if (path == null) {
        throw new IllegalStateException("Unable to determine code source archive");
    }
    File root = new File(path);
    if (!root.exists()) {
        throw new IllegalStateException("Unable to determine code source archive from " + root);
    }
    return (root.isDirectory() ? new ExplodedArchive(root) : new JarFileArchive(root));
}
Also used : ExplodedArchive(org.springframework.boot.loader.archive.ExplodedArchive) ProtectionDomain(java.security.ProtectionDomain) JarFileArchive(org.springframework.boot.loader.archive.JarFileArchive) CodeSource(java.security.CodeSource) URI(java.net.URI) JarFile(org.springframework.boot.loader.jar.JarFile) File(java.io.File)

Example 4 with JarFileArchive

use of org.springframework.boot.loader.archive.JarFileArchive in project spring-boot by spring-projects.

the class JarLauncherTests method archivedJarHasOnlyBootInfClassesAndContentsOfBootInfLibOnClasspath.

@Test
public void archivedJarHasOnlyBootInfClassesAndContentsOfBootInfLibOnClasspath() throws Exception {
    File jarRoot = createJarArchive("archive.jar", "BOOT-INF");
    JarLauncher launcher = new JarLauncher(new JarFileArchive(jarRoot));
    List<Archive> archives = launcher.getClassPathArchives();
    assertThat(archives).hasSize(2);
    assertThat(getUrls(archives)).containsOnly(new URL("jar:" + jarRoot.toURI().toURL() + "!/BOOT-INF/classes!/"), new URL("jar:" + jarRoot.toURI().toURL() + "!/BOOT-INF/lib/foo.jar!/"));
}
Also used : JarFileArchive(org.springframework.boot.loader.archive.JarFileArchive) ExplodedArchive(org.springframework.boot.loader.archive.ExplodedArchive) Archive(org.springframework.boot.loader.archive.Archive) JarFileArchive(org.springframework.boot.loader.archive.JarFileArchive) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Aggregations

File (java.io.File)4 ExplodedArchive (org.springframework.boot.loader.archive.ExplodedArchive)4 JarFileArchive (org.springframework.boot.loader.archive.JarFileArchive)4 Archive (org.springframework.boot.loader.archive.Archive)3 URL (java.net.URL)2 Test (org.junit.Test)2 URI (java.net.URI)1 CodeSource (java.security.CodeSource)1 ProtectionDomain (java.security.ProtectionDomain)1 EntryFilter (org.springframework.boot.loader.archive.Archive.EntryFilter)1 JarFile (org.springframework.boot.loader.jar.JarFile)1