Search in sources :

Example 21 with Resource

use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.

the class MavenWebInfConfiguration method findClassDirs.

/** 
     * Add in the classes dirs from test/classes and target/classes
     * @see org.eclipse.jetty.webapp.WebInfConfiguration#findClassDirs(org.eclipse.jetty.webapp.WebAppContext)
     */
@Override
protected List<Resource> findClassDirs(WebAppContext context) throws Exception {
    List<Resource> list = new ArrayList<Resource>();
    JettyWebAppContext jwac = (JettyWebAppContext) context;
    if (jwac.getClassPathFiles() != null) {
        for (File f : jwac.getClassPathFiles()) {
            if (f.exists() && f.isDirectory()) {
                try {
                    list.add(Resource.newResource(f.toURI()));
                } catch (Exception e) {
                    LOG.warn("Bad url ", e);
                }
            }
        }
    }
    List<Resource> classesDirs = super.findClassDirs(context);
    if (classesDirs != null)
        list.addAll(classesDirs);
    return list;
}
Also used : ArrayList(java.util.ArrayList) Resource(org.eclipse.jetty.util.resource.Resource) File(java.io.File) IOException(java.io.IOException)

Example 22 with Resource

use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.

the class MavenWebInfConfiguration method unpack.

/** 
     * @see org.eclipse.jetty.webapp.WebInfConfiguration#unpack(org.eclipse.jetty.webapp.WebAppContext)
     */
@Override
public void unpack(WebAppContext context) throws IOException {
    //Unpack and find base resource as normal
    super.unpack(context);
    //Get the base resource for the "virtual" webapp
    _originalResourceBase = context.getBaseResource();
    JettyWebAppContext jwac = (JettyWebAppContext) context;
    //determine sequencing of overlays
    _unpackedOverlayResources = new ArrayList<Resource>();
    if (jwac.getOverlays() != null && !jwac.getOverlays().isEmpty()) {
        List<Resource> resourceBaseCollection = new ArrayList<Resource>();
        for (Overlay o : jwac.getOverlays()) {
            //can refer to the current project in list of overlays for ordering purposes
            if (o.getConfig() != null && o.getConfig().isCurrentProject() && _originalResourceBase.exists()) {
                resourceBaseCollection.add(_originalResourceBase);
                LOG.debug("Adding virtual project to resource base list");
                continue;
            }
            Resource unpacked = unpackOverlay(jwac, o);
            //remember the unpacked overlays for later so we can delete the tmp files
            _unpackedOverlayResources.add(unpacked);
            //add in the selectively unpacked overlay in the correct order to the webapps resource base
            resourceBaseCollection.add(unpacked);
            LOG.debug("Adding " + unpacked + " to resource base list");
        }
        if (!resourceBaseCollection.contains(_originalResourceBase) && _originalResourceBase.exists()) {
            if (jwac.getBaseAppFirst()) {
                LOG.debug("Adding virtual project first in resource base list");
                resourceBaseCollection.add(0, _originalResourceBase);
            } else {
                LOG.debug("Adding virtual project last in resource base list");
                resourceBaseCollection.add(_originalResourceBase);
            }
        }
        jwac.setBaseResource(new ResourceCollection(resourceBaseCollection.toArray(new Resource[resourceBaseCollection.size()])));
    }
    jwac.setAttribute(RESOURCE_BASES_POST_OVERLAY, jwac.getBaseResource());
}
Also used : Resource(org.eclipse.jetty.util.resource.Resource) ArrayList(java.util.ArrayList) ResourceCollection(org.eclipse.jetty.util.resource.ResourceCollection)

Example 23 with Resource

use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.

the class MavenWebInfConfiguration method findJars.

/**
     * Get the jars to examine from the files from which we have
     * synthesized the classpath. Note that the classpath is not
     * set at this point, so we cannot get them from the classpath.
     * @param context the web app context
     * @return the list of jars found
     */
@Override
protected List<Resource> findJars(WebAppContext context) throws Exception {
    List<Resource> list = new ArrayList<Resource>();
    JettyWebAppContext jwac = (JettyWebAppContext) context;
    if (jwac.getClassPathFiles() != null) {
        for (File f : jwac.getClassPathFiles()) {
            if (f.getName().toLowerCase(Locale.ENGLISH).endsWith(".jar")) {
                try {
                    list.add(Resource.newResource(f.toURI()));
                } catch (Exception e) {
                    LOG.warn("Bad url ", e);
                }
            }
        }
    }
    List<Resource> superList = super.findJars(context);
    if (superList != null)
        list.addAll(superList);
    return list;
}
Also used : ArrayList(java.util.ArrayList) Resource(org.eclipse.jetty.util.resource.Resource) File(java.io.File) IOException(java.io.IOException)

Example 24 with Resource

use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.

the class AnnotationConfiguration method parseBundle.

protected void parseBundle(WebAppContext context, AnnotationParser parser, Bundle webbundle, Bundle bundle) throws Exception {
    Resource bundleRes = parser.getResource(bundle);
    Set<Handler> handlers = new HashSet<Handler>();
    handlers.addAll(_discoverableAnnotationHandlers);
    if (_classInheritanceHandler != null)
        handlers.add(_classInheritanceHandler);
    handlers.addAll(_containerInitializerAnnotationHandlers);
    if (_parserTasks != null) {
        BundleParserTask task = new BundleParserTask(parser, handlers, bundleRes);
        _parserTasks.add(task);
        if (LOG.isDebugEnabled())
            task.setStatistic(new TimeStatistic());
    }
}
Also used : Resource(org.eclipse.jetty.util.resource.Resource) Handler(org.eclipse.jetty.annotations.AnnotationParser.Handler) HashSet(java.util.HashSet)

Example 25 with Resource

use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.

the class AnnotationParser method indexBundle.

/**
     * Keep track of a jetty URI Resource and its associated OSGi bundle.
     * 
     * @param bundle the bundle to index
     * @return the resource for the bundle
     * @throws Exception if unable to create the resource reference
     */
protected Resource indexBundle(Bundle bundle) throws Exception {
    File bundleFile = BundleFileLocatorHelperFactory.getFactory().getHelper().getBundleInstallLocation(bundle);
    Resource resource = Resource.newResource(bundleFile.toURI());
    URI uri = resource.getURI();
    _uriToBundle.putIfAbsent(uri, bundle);
    _bundleToUri.putIfAbsent(bundle, uri);
    _bundleToResource.putIfAbsent(bundle, resource);
    _resourceToBundle.putIfAbsent(resource, bundle);
    return resource;
}
Also used : Resource(org.eclipse.jetty.util.resource.Resource) File(java.io.File) URI(java.net.URI)

Aggregations

Resource (org.eclipse.jetty.util.resource.Resource)196 Test (org.junit.Test)79 File (java.io.File)46 URL (java.net.URL)39 ArrayList (java.util.ArrayList)38 Matchers.containsString (org.hamcrest.Matchers.containsString)31 IOException (java.io.IOException)28 ResourceCollection (org.eclipse.jetty.util.resource.ResourceCollection)18 JarResource (org.eclipse.jetty.util.resource.JarResource)16 XmlConfiguration (org.eclipse.jetty.xml.XmlConfiguration)16 Server (org.eclipse.jetty.server.Server)13 HashSet (java.util.HashSet)12 InputStream (java.io.InputStream)9 HashMap (java.util.HashMap)9 URI (java.net.URI)8 MalformedURLException (java.net.MalformedURLException)7 StringTokenizer (java.util.StringTokenizer)7 URISyntaxException (java.net.URISyntaxException)6 Properties (java.util.Properties)6 Set (java.util.Set)6