use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.
the class MetaData method getJarForFragment.
public Resource getJarForFragment(String name) {
FragmentDescriptor f = getFragment(name);
if (f == null)
return null;
Resource jar = null;
for (Resource r : _webFragmentResourceMap.keySet()) {
if (_webFragmentResourceMap.get(r).equals(f))
jar = r;
}
return jar;
}
use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.
the class MetaInfConfiguration method scanForResources.
/**
* Scan for META-INF/resources dir in the given jar.
*
* @param context the context for the scan
* @param target the target resource to scan for
* @param cache the resource cache
* @throws Exception if unable to scan for resources
*/
public void scanForResources(WebAppContext context, Resource target, ConcurrentHashMap<Resource, Resource> cache) throws Exception {
Resource resourcesDir = null;
if (cache != null && cache.containsKey(target)) {
resourcesDir = cache.get(target);
if (resourcesDir == EmptyResource.INSTANCE) {
if (LOG.isDebugEnabled())
LOG.debug(target + " cached as containing no META-INF/resources");
return;
} else if (LOG.isDebugEnabled())
LOG.debug(target + " META-INF/resources found in cache ");
} else {
//not using caches or not in the cache so check for the resources dir
if (LOG.isDebugEnabled())
LOG.debug(target + " META-INF/resources checked");
if (target.isDirectory()) {
//TODO think how to handle an unpacked jar file (eg for osgi)
resourcesDir = target.addPath("/META-INF/resources");
} else {
//Resource represents a packed jar
URI uri = target.getURI();
resourcesDir = Resource.newResource(uriJarPrefix(uri, "!/META-INF/resources"));
}
if (!resourcesDir.exists() || !resourcesDir.isDirectory()) {
resourcesDir.close();
resourcesDir = EmptyResource.INSTANCE;
}
if (cache != null) {
Resource old = cache.putIfAbsent(target, resourcesDir);
if (old != null)
resourcesDir = old;
else if (LOG.isDebugEnabled())
LOG.debug(target + " META-INF/resources cache updated");
}
if (resourcesDir == EmptyResource.INSTANCE) {
return;
}
}
//add it to the meta inf resources for this context
Set<Resource> dirs = (Set<Resource>) context.getAttribute(METAINF_RESOURCES);
if (dirs == null) {
dirs = new HashSet<Resource>();
context.setAttribute(METAINF_RESOURCES, dirs);
}
if (LOG.isDebugEnabled())
LOG.debug(resourcesDir + " added to context");
dirs.add(resourcesDir);
}
use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.
the class MetaInfConfiguration method scanForFragment.
/**
* Scan for META-INF/web-fragment.xml file in the given jar.
*
* @param context the context for the scan
* @param jar the jar resource to scan for fragements in
* @param cache the resource cache
* @throws Exception if unable to scan for fragments
*/
public void scanForFragment(WebAppContext context, Resource jar, ConcurrentHashMap<Resource, Resource> cache) throws Exception {
Resource webFrag = null;
if (cache != null && cache.containsKey(jar)) {
webFrag = cache.get(jar);
if (webFrag == EmptyResource.INSTANCE) {
if (LOG.isDebugEnabled())
LOG.debug(jar + " cached as containing no META-INF/web-fragment.xml");
return;
} else if (LOG.isDebugEnabled())
LOG.debug(jar + " META-INF/web-fragment.xml found in cache ");
} else {
//not using caches or not in the cache so check for the web-fragment.xml
if (LOG.isDebugEnabled())
LOG.debug(jar + " META-INF/web-fragment.xml checked");
if (jar.isDirectory()) {
//TODO ????
webFrag = jar.addPath("/META-INF/web-fragment.xml");
} else {
URI uri = jar.getURI();
webFrag = Resource.newResource(uriJarPrefix(uri, "!/META-INF/web-fragment.xml"));
}
if (!webFrag.exists() || webFrag.isDirectory()) {
webFrag.close();
webFrag = EmptyResource.INSTANCE;
}
if (cache != null) {
//web-fragment.xml doesn't exist: put token in cache to signal we've seen the jar
Resource old = cache.putIfAbsent(jar, webFrag);
if (old != null)
webFrag = old;
else if (LOG.isDebugEnabled())
LOG.debug(jar + " META-INF/web-fragment.xml cache updated");
}
if (webFrag == EmptyResource.INSTANCE)
return;
}
Map<Resource, Resource> fragments = (Map<Resource, Resource>) context.getAttribute(METAINF_FRAGMENTS);
if (fragments == null) {
fragments = new HashMap<Resource, Resource>();
context.setAttribute(METAINF_FRAGMENTS, fragments);
}
fragments.put(jar, webFrag);
if (LOG.isDebugEnabled())
LOG.debug(webFrag + " added to context");
}
use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.
the class WebInfConfiguration method findExtraClasspathJars.
/**
* Get jars from WebAppContext.getExtraClasspath as resources
*
* @param context the context to find extra classpath jars in
* @return the list of Resources with the extra classpath, or null if not found
* @throws Exception if unable to find the extra classpath jars
*/
protected List<Resource> findExtraClasspathJars(WebAppContext context) throws Exception {
if (context == null || context.getExtraClasspath() == null)
return null;
List<Resource> jarResources = new ArrayList<Resource>();
StringTokenizer tokenizer = new StringTokenizer(context.getExtraClasspath(), ",;");
while (tokenizer.hasMoreTokens()) {
Resource resource = context.newResource(tokenizer.nextToken().trim());
String fnlc = resource.getName().toLowerCase(Locale.ENGLISH);
int dot = fnlc.lastIndexOf('.');
String extension = (dot < 0 ? null : fnlc.substring(dot));
if (extension != null && (extension.equals(".jar") || extension.equals(".zip"))) {
jarResources.add(resource);
}
}
return jarResources;
}
use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.
the class WebInfConfiguration method findClassDirs.
protected List<Resource> findClassDirs(WebAppContext context) throws Exception {
if (context == null)
return null;
List<Resource> classDirs = new ArrayList<Resource>();
Resource webInfClasses = findWebInfClassesDir(context);
if (webInfClasses != null)
classDirs.add(webInfClasses);
List<Resource> extraClassDirs = findExtraClasspathDirs(context);
if (extraClassDirs != null)
classDirs.addAll(extraClassDirs);
return classDirs;
}
Aggregations