@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 } } } } }
@Override protected void startInternal() throws LifecycleException { String docBase = context.getDocBase(); File f = new File(docBase); if (!f.isAbsolute()) { f = new File(((Host) context.getParent()).getAppBaseFile(), f.getName()); } if (f.isDirectory()) { main = new DirResourceSet(this, f.getAbsolutePath(), "", ""); } else if (f.isFile() && docBase.endsWith(".war")) { main = new JarResourceSet(this, f.getAbsolutePath(), "", ""); } else { throw new IllegalArgumentException(sm.getString("standardRoot.startInvalidMain")); } mainResources.clear(); mainResources.add(main); for (ArrayList<WebResourceSet> list : allResources) { for (WebResourceSet webResourceSet : list) { webResourceSet.start(); } } setState(LifecycleState.STARTING); }
private boolean preResourceExists(String path) { for (WebResourceSet webResourceSet : preResources) { WebResource webResource = webResourceSet.getResource(path); if (webResource.exists()) { return true; } } return false; }
@Override protected void destroyInternal() throws LifecycleException { for (ArrayList<WebResourceSet> list : allResources) { for (WebResourceSet webResourceSet : list) { webResourceSet.destroy(); } } super.destroyInternal(); }
@Override protected void stopInternal() throws LifecycleException { for (ArrayList<WebResourceSet> list : allResources) { for (WebResourceSet webResourceSet : list) { webResourceSet.stop(); } } mainResources.clear(); jarResources.clear(); setState(LifecycleState.STOPPING); }
@Override protected void initInternal() throws LifecycleException { super.initInternal(); if (context == null) { throw new IllegalStateException(sm.getString("standardRoot.noContext")); } for (ArrayList<WebResourceSet> list : allResources) { for (WebResourceSet webResourceSet : list) { webResourceSet.init(); } } }
@Override public String[] list(String path) { checkState(); // Set because we don't want duplicates HashSet<String> result = new HashSet<>(); for (ArrayList<WebResourceSet> list : allResources) { for (WebResourceSet webResourceSet : list) { String[] entries = webResourceSet.list(path); for (String entry : entries) { result.add(entry); } } } return result.toArray(new String[result.size()]); }
protected WebResource getResourceInternal(String path) { checkState(); WebResource result = null; for (ArrayList<WebResourceSet> list : allResources) { for (WebResourceSet webResourceSet : list) { result = webResourceSet.getResource(path); if (result.exists()) { return result; } } } // Default is empty resource in main resources return new EmptyResource(this, path); }
@Override public Set<String> listWebAppPaths(String path) { checkState(); // Set because we don't want duplicates HashSet<String> result = new HashSet<>(); for (ArrayList<WebResourceSet> list : allResources) { for (WebResourceSet webResourceSet : list) { result.addAll(webResourceSet.listWebAppPaths(path)); } } if (result.size() == 0) { return null; } return result; }
@Override public boolean write(String path, InputStream is, boolean overwrite) { checkState(); if (!overwrite && preResourceExists(path)) { return false; } return main.write(path, is, overwrite); }
@Override public boolean mkdir(String path) { checkState(); if (preResourceExists(path)) { return false; } return main.mkdir(path); }
@Override public WebResource[] getResources(String path) { checkState(); ArrayList<WebResource> result = new ArrayList<>(); for (ArrayList<WebResourceSet> list : allResources) { for (WebResourceSet webResourceSet : list) { WebResource webResource = webResourceSet.getResource(path); if (webResource.exists()) { result.add(webResource); } } } if (result.size() == 0) { result.add(main.getResource(path)); } return result.toArray(new WebResource[result.size()]); }
@Override public void addPostResources(WebResourceSet webResourceSet) { webResourceSet.setRoot(this); postResources.add(webResourceSet); }
@Override public void addJarResources(WebResourceSet webResourceSet) { webResourceSet.setRoot(this); jarResources.add(webResourceSet); }