Search in sources :

Example 1 with ExplodedArchive

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

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

the class PropertiesLauncher method getProperty.

private String getProperty(String propertyKey, String manifestKey, String defaultValue) throws Exception {
    if (manifestKey == null) {
        manifestKey = propertyKey.replace('.', '-');
        manifestKey = toCamelCase(manifestKey);
    }
    String property = SystemPropertyUtils.getProperty(propertyKey);
    if (property != null) {
        String value = SystemPropertyUtils.resolvePlaceholders(this.properties, property);
        debug("Property '" + propertyKey + "' from environment: " + value);
        return value;
    }
    if (this.properties.containsKey(propertyKey)) {
        String value = SystemPropertyUtils.resolvePlaceholders(this.properties, this.properties.getProperty(propertyKey));
        debug("Property '" + propertyKey + "' from properties: " + value);
        return value;
    }
    try {
        if (this.home != null) {
            // Prefer home dir for MANIFEST if there is one
            Manifest manifest = new ExplodedArchive(this.home, false).getManifest();
            if (manifest != null) {
                String value = manifest.getMainAttributes().getValue(manifestKey);
                if (value != null) {
                    debug("Property '" + manifestKey + "' from home directory manifest: " + value);
                    return SystemPropertyUtils.resolvePlaceholders(this.properties, value);
                }
            }
        }
    } catch (IllegalStateException ex) {
    // Ignore
    }
    // Otherwise try the parent archive
    Manifest manifest = createArchive().getManifest();
    if (manifest != null) {
        String value = manifest.getMainAttributes().getValue(manifestKey);
        if (value != null) {
            debug("Property '" + manifestKey + "' from archive manifest: " + value);
            return SystemPropertyUtils.resolvePlaceholders(this.properties, value);
        }
    }
    return defaultValue == null ? defaultValue : SystemPropertyUtils.resolvePlaceholders(this.properties, defaultValue);
}
Also used : ExplodedArchive(org.springframework.boot.loader.archive.ExplodedArchive) Manifest(java.util.jar.Manifest)

Example 3 with ExplodedArchive

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

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

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

ExplodedArchive (org.springframework.boot.loader.archive.ExplodedArchive)6 JarFileArchive (org.springframework.boot.loader.archive.JarFileArchive)5 File (java.io.File)4 Archive (org.springframework.boot.loader.archive.Archive)4 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 URI (java.net.URI)1 CodeSource (java.security.CodeSource)1 ProtectionDomain (java.security.ProtectionDomain)1 Manifest (java.util.jar.Manifest)1 JarFile (org.springframework.boot.loader.jar.JarFile)1