Search in sources :

Example 21 with WebResourceSet

use of org.apache.catalina.WebResourceSet in project tomee by apache.

the class TomcatWebAppBuilder method configuredClasspath.

private static DeploymentLoader.ExternalConfiguration configuredClasspath(final StandardContext standardContext) {
    Loader loader = standardContext.getLoader();
    if (loader != null && LazyStopLoader.class.isInstance(loader)) {
        loader = LazyStopLoader.class.cast(loader).getDelegateLoader();
    }
    if (loader != null) {
        final ClassLoader cl = standardContext.getLoader().getClassLoader();
        if (cl == null) {
            return null;
        }
        final Collection<String> cp = new LinkedList<>();
        final WebResourceRoot webResources = standardContext.getResources();
        if (webResources != null) {
            // to enhance
            for (final WebResourceSet[] sets : asList(webResources.getPreResources(), webResources.getPostResources(), webResources.getJarResources())) {
                for (final WebResourceSet wr : sets) {
                    final URL base = wr.getBaseUrl();
                    if (base != null) {
                        final File baseFile = URLs.toFile(base);
                        if (baseFile.isDirectory()) {
                            final String[] libs = wr.list("/WEB-INF/lib/");
                            if (libs != null) {
                                for (final String resource : libs) {
                                    cp.add(new File(baseFile, resource).getAbsolutePath());
                                }
                            }
                            final WebResource classes = wr.getResource("/WEB-INF/classes/");
                            if (classes != null) {
                                final String path = classes.getCanonicalPath();
                                if (path != null) {
                                    cp.add(path);
                                }
                            }
                        } else if (baseFile.exists() && baseFile.getName().endsWith(".jar") && wr.getResource("/WEB-INF/classes/").exists()) {
                            try {
                                cp.add(baseFile.getCanonicalPath());
                            } catch (final IOException e) {
                                throw new IllegalStateException(e);
                            }
                        }
                    }
                }
            }
        }
        if (!cp.isEmpty()) {
            return new DeploymentLoader.ExternalConfiguration(cp.toArray(new String[cp.size()]), null);
        }
    }
    return null;
}
Also used : WebappLoader(org.apache.catalina.loader.WebappLoader) Loader(org.apache.catalina.Loader) DeploymentLoader(org.apache.openejb.config.DeploymentLoader) WebResource(org.apache.catalina.WebResource) IOException(java.io.IOException) LinkedList(java.util.LinkedList) URL(java.net.URL) WebResourceSet(org.apache.catalina.WebResourceSet) File(java.io.File) JarFile(java.util.jar.JarFile) WebResourceRoot(org.apache.catalina.WebResourceRoot)

Aggregations

WebResourceSet (org.apache.catalina.WebResourceSet)21 File (java.io.File)8 IOException (java.io.IOException)3 WebResource (org.apache.catalina.WebResource)3 LinkedList (java.util.LinkedList)2 TrackedWebResource (org.apache.catalina.TrackedWebResource)2 WebResourceRoot (org.apache.catalina.WebResourceRoot)2 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 JarFile (java.util.jar.JarFile)1 Host (org.apache.catalina.Host)1 Loader (org.apache.catalina.Loader)1 WebappLoader (org.apache.catalina.loader.WebappLoader)1 DeploymentLoader (org.apache.openejb.config.DeploymentLoader)1 Test (org.junit.Test)1