@Override protected WebResourceSet createMainResourceSet() { final Path docBase = config.docBase(); assert docBase.isAbsolute(); final String docBaseStr = docBase.toString(); getContext().setDocBase(docBaseStr); if (Files.isDirectory(docBase)) { return new DirResourceSet(this, "/", docBaseStr, "/"); } final Optional<String> jarRootOpt = config.jarRoot(); if (jarRootOpt.isPresent()) { // If docBase is a JAR file final String jarRoot = jarRootOpt.get(); if ("/".equals(jarRoot)) { return new JarResourceSet(this, "/", docBaseStr, "/"); } else { return new JarSubsetResourceSet(this, "/", docBaseStr, "/", jarRoot); } } throw new IllegalArgumentException(sm.getString("standardRoot.startInvalidMain", docBaseStr)); }
@Override public void setResources(final WebResourceRoot resources) { this.resources = resources; if (StandardRoot.class.isInstance(resources)) { final List<WebResourceSet> jars = (List<WebResourceSet>) Reflections.get(resources, "jarResources"); if (jars != null && !jars.isEmpty()) { final Iterator<WebResourceSet> jarIt = jars.iterator(); while (jarIt.hasNext()) { final WebResourceSet set = jarIt.next(); if (set.getBaseUrl() == null) { continue; } final File file = URLs.toFile(set.getBaseUrl()); try { if (file.exists() && (!TomEEClassLoaderEnricher.validateJarFile(file) || !jarIsAccepted(file))) { // need to remove this resource LOGGER.warning("Removing " + file.getAbsolutePath() + " since it is offending"); jarIt.remove(); } } catch (final IOException e) { // ignore } } } } }
private JarWarResourceSet getFirstJarWarResourceSetAtJarResources(WebResourceRoot resources) { JarWarResourceSet result = null; for (WebResourceSet resourceSet :resources.getJarResources()) { if (resourceSet instanceof JarWarResourceSet) { result = (JarWarResourceSet) resourceSet; break; } } return result; }
private URL mainFile(WebResourceRoot resources) { URL result = null; for (WebResourceSet resourceSet :resources.getJarResources()) { if (resourceSet instanceof JarWarResourceSet) { result = resourceSet.getBaseUrl(); break; } } return result; }
@Override public void addJarResources(WebResourceSet webResourceSet) { if (this.jarResources == null) { this.jarResources = new ArrayList<>(); } this.jarResources.add(webResourceSet); }
@Override public void addPreResources(WebResourceSet webResourceSet) { throw new UnsupportedOperationException(NOT_SUPPORTED_YET); }
@Override public WebResourceSet[] getPreResources() { throw new UnsupportedOperationException(NOT_SUPPORTED_YET); }
@Override public WebResourceSet[] getJarResources() { return this.jarResources.toArray(new WebResourceSet[this.jarResources.size()]); }
@Override public void addPostResources(WebResourceSet webResourceSet) { throw new UnsupportedOperationException(NOT_SUPPORTED_YET); }
@Override public WebResourceSet[] getPostResources() { throw new UnsupportedOperationException(NOT_SUPPORTED_YET); }
public void init(WebResourceSet... webResourcesSet) throws LifecycleException { for (WebResourceSet webResourceSet : webResourcesSet) { this.webResourceRoot.addJarResources(webResourceSet); } }
@Override public WebResourceSet[] getPreResources() { return new WebResourceSet[0]; }
@Override public WebResourceSet[] getJarResources() { return new WebResourceSet[0]; }
@Override public WebResourceSet[] getPostResources() { return new WebResourceSet[0]; }
@Override public void addPreResources(final WebResourceSet webResourceSet) { delegate.addPreResources(webResourceSet); }
@Override public WebResourceSet[] getPreResources() { return delegate.getPreResources(); }
@Override public void addJarResources(final WebResourceSet webResourceSet) { delegate.addJarResources(webResourceSet); }
@Override public WebResourceSet[] getJarResources() { return delegate.getJarResources(); }
@Override public void addPostResources(final WebResourceSet webResourceSet) { delegate.addPostResources(webResourceSet); }
@Override public WebResourceSet[] getPostResources() { return delegate.getPostResources(); }
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 /*for now doesnt make sense, todo: configure*/); } } return null; }
@Override public void addPreResources(WebResourceSet webResourceSet) { }
@Override public void addJarResources(WebResourceSet webResourceSet) { }
@Override public void addPostResources(WebResourceSet webResourceSet) { }