Search in sources :

Example 1 with Resource

use of org.mortbay.resource.Resource in project gradle by gradle.

the class JettyRun method getDependencyFiles.

@Internal
private Set<File> getDependencyFiles() {
    List<Resource> overlays = new ArrayList<Resource>();
    Set<File> dependencies = getClasspath().getFiles();
    LOGGER.debug("Adding dependencies {} for WEB-INF/lib ", dependencies);
    //            }
    if (!overlays.isEmpty()) {
        try {
            Resource resource = getWebAppConfig().getBaseResource();
            ResourceCollection rc = new ResourceCollection();
            if (resource == null) {
                // nothing configured, so we automagically enable the overlays
                int size = overlays.size() + 1;
                Resource[] resources = new Resource[size];
                resources[0] = Resource.newResource(getWebAppSourceDirectory().toURI().toURL());
                for (int i = 1; i < size; i++) {
                    resources[i] = overlays.get(i - 1);
                    LOGGER.info("Adding overlay: " + resources[i]);
                }
                rc.setResources(resources);
            } else {
                if (resource instanceof ResourceCollection) {
                    // there was a preconfigured ResourceCollection ... append the artifact wars
                    Resource[] old = ((ResourceCollection) resource).getResources();
                    int size = old.length + overlays.size();
                    Resource[] resources = new Resource[size];
                    System.arraycopy(old, 0, resources, 0, old.length);
                    for (int i = old.length; i < size; i++) {
                        resources[i] = overlays.get(i - old.length);
                        LOGGER.info("Adding overlay: " + resources[i]);
                    }
                    rc.setResources(resources);
                } else {
                    // baseResource was already configured w/c could be src/main/webapp
                    if (!resource.isDirectory() && String.valueOf(resource.getFile()).endsWith(".war")) {
                        // its a war
                        resource = Resource.newResource("jar:" + resource.getURL().toString() + "!/");
                    }
                    int size = overlays.size() + 1;
                    Resource[] resources = new Resource[size];
                    resources[0] = resource;
                    for (int i = 1; i < size; i++) {
                        resources[i] = overlays.get(i - 1);
                        LOGGER.info("Adding overlay: " + resources[i]);
                    }
                    rc.setResources(resources);
                }
            }
            getWebAppConfig().setBaseResource(rc);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    return dependencies;
}
Also used : ArrayList(java.util.ArrayList) Resource(org.mortbay.resource.Resource) File(java.io.File) InputFile(org.gradle.api.tasks.InputFile) IOException(java.io.IOException) InvalidUserDataException(org.gradle.api.InvalidUserDataException) ResourceCollection(org.mortbay.resource.ResourceCollection) Internal(org.gradle.api.tasks.Internal)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 InvalidUserDataException (org.gradle.api.InvalidUserDataException)1 InputFile (org.gradle.api.tasks.InputFile)1 Internal (org.gradle.api.tasks.Internal)1 Resource (org.mortbay.resource.Resource)1 ResourceCollection (org.mortbay.resource.ResourceCollection)1