@Override public boolean isDirectory() { return this.delegate.isDirectory(); }
/** * Get class dirs from WebAppContext.getExtraClasspath as resources * * @param context the context to look for extra classpaths in * @return the list of Resources to the extra classpath * @throws Exception if unable to find the extra classpaths */ protected List<Resource> findExtraClasspathDirs(WebAppContext context) throws Exception { if (context == null || context.getExtraClasspath() == null) return null; List<Resource> dirResources = new ArrayList<Resource>(); StringTokenizer tokenizer = new StringTokenizer(context.getExtraClasspath(), ",;"); while (tokenizer.hasMoreTokens()) { Resource resource = context.newResource(tokenizer.nextToken().trim()); if (resource.exists() && resource.isDirectory()) dirResources.add(resource); } return dirResources; }
/** * Add in fragment descriptors that have already been discovered by MetaInfConfiguration * * @param context the web app context to look in * @param metaData the metadata to populate with fragments * * @throws Exception if unable to find web fragments */ public void addWebFragments (final WebAppContext context, final MetaData metaData) throws Exception { @SuppressWarnings("unchecked") Map<Resource, Resource> frags = (Map<Resource,Resource>)context.getAttribute(FRAGMENT_RESOURCES); if (frags!=null) { for (Resource key : frags.keySet()) { if (key.isDirectory()) //tolerate the case where the library is a directory, not a jar. useful for OSGi for example { metaData.addFragment(key, frags.get(key)); } else //the standard case: a jar most likely inside WEB-INF/lib { metaData.addFragment(key, frags.get(key)); } } } } }
public Resource getWebInf() throws IOException { if (super.getBaseResource() == null) return null; // Iw there a WEB-INF directory? Resource web_inf= super.getBaseResource().addPath("WEB-INF/"); if (!web_inf.exists() || !web_inf.isDirectory()) return null; return web_inf; }
/** * Get <code>WEB-INF/classes</code> dir * * @param context the context to look for the <code>WEB-INF/classes</code> directory * @return the Resource for the <code>WEB-INF/classes</code> directory * @throws Exception if unable to find the <code>WEB-INF/classes</code> directory */ protected Resource findWebInfClassesDir (WebAppContext context) throws Exception { if (context == null) return null; Resource web_inf = context.getWebInf(); // Find WEB-INF/classes if (web_inf != null && web_inf.isDirectory()) { // Look for classes directory Resource classes= web_inf.addPath("classes/"); if (classes.exists()) return classes; } return null; }
@Override public URL getResource(String path) throws MalformedURLException { Resource resource=WebAppContext.this.getResource(path); if (resource==null || !resource.exists()) return null; // Should we go to the original war? if (resource.isDirectory() && resource instanceof ResourceCollection && !WebAppContext.this.isExtractWAR()) { Resource[] resources = ((ResourceCollection)resource).getResources(); for (int i=resources.length;i-->0;) { if (resources[i].getName().startsWith("jar:file")) return resources[i].getURI().toURL(); } } return resource.getURI().toURL(); }
if (web_inf_lib.exists() && web_inf_lib.isDirectory())
if (resource.isDirectory() && resource instanceof ResourceCollection) addClassPath(resource); else addURL(url); else if (resource.isDirectory())
private void configureDocumentRoot(WebAppContext handler) { File root = getValidDocumentRoot(); File docBase = (root != null) ? root : createTempDir("jetty-docbase"); try { List<Resource> resources = new ArrayList<>(); Resource rootResource = (docBase.isDirectory() ? Resource.newResource(docBase.getCanonicalFile()) : JarResource.newJarResource(Resource.newResource(docBase))); resources.add((root != null) ? new LoaderHidingResource(rootResource) : rootResource); for (URL resourceJarUrl : this.getUrlsOfJarsWithMetaInfResources()) { Resource resource = createResource(resourceJarUrl); if (resource.exists() && resource.isDirectory()) { resources.add(resource); } } handler.setBaseResource( new ResourceCollection(resources.toArray(new Resource[0]))); } catch (Exception ex) { throw new IllegalStateException(ex); } }
protected Resource findWebXml(WebAppContext context) throws IOException, MalformedURLException { String descriptor = context.getDescriptor(); if (descriptor != null) { Resource web = context.newResource(descriptor); if (web.exists() && !web.isDirectory()) return web; } Resource web_inf = context.getWebInf(); if (web_inf != null && web_inf.isDirectory()) { // do web.xml file Resource web = web_inf.addPath("web.xml"); if (web.exists()) return web; if (LOG.isDebugEnabled()) LOG.debug("No WEB-INF/web.xml in " + context.getWar() + ". Serving files and default/dynamic servlets only"); } return null; }
LOG.debug("Try webapp=" + web_app + ", exists=" + web_app.exists() + ", directory=" + web_app.isDirectory()+" file="+(web_app.getFile())); if (web_app.exists() && !web_app.isDirectory() && !web_app.toString().startsWith("jar:")) if (jarWebApp.exists() && jarWebApp.isDirectory()) web_app= jarWebApp; (context.isExtractWAR() && web_app.getFile() != null && !web_app.getFile().isDirectory()) || (context.isExtractWAR() && web_app.getFile() == null) || !web_app.isDirectory()) if (!web_app.exists() || !web_app.isDirectory())
if (lib.exists() && lib.isDirectory())
if (jar.isDirectory()) webFrag = Resource.newResource(uriJarPrefix(uri,"!/META-INF/web-fragment.xml")); if (!webFrag.exists() || webFrag.isDirectory())
if (target.isDirectory()) if (!resourcesDir.exists() || !resourcesDir.isDirectory())
if (web_inf != null && web_inf.isDirectory() && context.getClassLoader() instanceof WebAppClassLoader) if (lib.exists() || lib.isDirectory()) ((WebAppClassLoader)context.getClassLoader()).addJars(lib);
if(web_inf!=null&&web_inf.isDirectory())
/** * Instantiates a new resource collection. * * @param resources the resources to be added to collection */ public ResourceCollection(Resource... resources) { List<Resource> list = new ArrayList<Resource>(); for (Resource r : resources) { if (r==null) continue; if (r instanceof ResourceCollection) { for (Resource r2 : ((ResourceCollection)r).getResources()) list.add(r2); } else list.add(r); } _resources = list.toArray(new Resource[list.size()]); for(Resource r : _resources) { if(!r.exists() || !r.isDirectory()) throw new IllegalArgumentException(r + " is not an existing directory."); } }
/** * Instantiates a new resource collection. * * @param resources the resource strings to be added to collection */ public ResourceCollection(String[] resources) { _resources = new Resource[resources.length]; try { for(int i=0; i<resources.length; i++) { _resources[i] = Resource.newResource(resources[i]); if(!_resources[i].exists() || !_resources[i].isDirectory()) throw new IllegalArgumentException(_resources[i] + " is not an existing directory."); } } catch(IllegalArgumentException e) { throw e; } catch(Exception e) { throw new RuntimeException(e); } }
public Collection<Resource> getAllResources() { try { ArrayList<Resource> deep=new ArrayList<>(); { String[] list=list(); if (list!=null) { for (String i:list) { Resource r=addPath(i); if (r.isDirectory()) deep.addAll(r.getAllResources()); else deep.add(r); } } } return deep; } catch(Exception e) { throw new IllegalStateException(e); } }