Search in sources :

Example 1 with Archive

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

the class WarLauncherTests method explodedWarHasOnlyWebInfClassesAndContentsOfWebInfLibOnClasspath.

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

Example 2 with Archive

use of org.springframework.boot.loader.archive.Archive 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 3 with Archive

use of org.springframework.boot.loader.archive.Archive 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 4 with Archive

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

the class PropertiesLauncher method getClassPathArchives.

@Override
protected List<Archive> getClassPathArchives() throws Exception {
    List<Archive> lib = new ArrayList<>();
    for (String path : this.paths) {
        for (Archive archive : getClassPathArchives(path)) {
            if (archive instanceof ExplodedArchive) {
                List<Archive> nested = new ArrayList<>(archive.getNestedArchives(new ArchiveEntryFilter()));
                nested.add(0, archive);
                lib.addAll(nested);
            } else {
                lib.add(archive);
            }
        }
    }
    addNestedEntries(lib);
    return lib;
}
Also used : ExplodedArchive(org.springframework.boot.loader.archive.ExplodedArchive) JarFileArchive(org.springframework.boot.loader.archive.JarFileArchive) Archive(org.springframework.boot.loader.archive.Archive) ExplodedArchive(org.springframework.boot.loader.archive.ExplodedArchive) ArrayList(java.util.ArrayList)

Example 5 with Archive

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

the class PropertiesLauncher method getClassPathArchives.

private List<Archive> getClassPathArchives(String path) throws Exception {
    String root = cleanupPath(stripFileUrlPrefix(path));
    List<Archive> lib = new ArrayList<>();
    File file = new File(root);
    if (!isAbsolutePath(root)) {
        file = new File(this.home, root);
    }
    if (file.isDirectory()) {
        debug("Adding classpath entries from " + file);
        Archive archive = new ExplodedArchive(file, false);
        lib.add(archive);
    }
    Archive archive = getArchive(file);
    if (archive != null) {
        debug("Adding classpath entries from archive " + archive.getUrl() + root);
        lib.add(archive);
    }
    List<Archive> nestedArchives = getNestedArchives(root);
    if (nestedArchives != null) {
        debug("Adding classpath entries from nested " + root);
        lib.addAll(nestedArchives);
    }
    return lib;
}
Also used : ExplodedArchive(org.springframework.boot.loader.archive.ExplodedArchive) JarFileArchive(org.springframework.boot.loader.archive.JarFileArchive) Archive(org.springframework.boot.loader.archive.Archive) ExplodedArchive(org.springframework.boot.loader.archive.ExplodedArchive) ArrayList(java.util.ArrayList) File(java.io.File)

Aggregations

Archive (org.springframework.boot.loader.archive.Archive)7 ExplodedArchive (org.springframework.boot.loader.archive.ExplodedArchive)7 JarFileArchive (org.springframework.boot.loader.archive.JarFileArchive)7 File (java.io.File)6 URL (java.net.URL)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)2 EntryFilter (org.springframework.boot.loader.archive.Archive.EntryFilter)1