Java 类org.gradle.api.tasks.bundling.War 实例源码

项目:Reer    文件:JettyPlugin.java   
private void configureAbstractJettyTask(final Project project, final JettyPluginConvention jettyConvention, AbstractJettyRunTask jettyTask) {
    jettyTask.setDaemon(false);
    jettyTask.setReload(RELOAD_AUTOMATIC);
    jettyTask.setScanIntervalSeconds(0);
    jettyTask.getConventionMapping().map("contextPath", new Callable<Object>() {
        public Object call() throws Exception {
            return ((War) project.getTasks().getByName(WarPlugin.WAR_TASK_NAME)).getBaseName();
        }
    });
    jettyTask.getConventionMapping().map("httpPort", new Callable<Object>() {
        public Object call() throws Exception {
            return jettyConvention.getHttpPort();
        }
    });
    jettyTask.getConventionMapping().map("stopPort", new Callable<Object>() {
        public Object call() throws Exception {
            return jettyConvention.getStopPort();
        }
    });
    jettyTask.getConventionMapping().map("stopKey", new Callable<Object>() {
        public Object call() throws Exception {
            return jettyConvention.getStopKey();
        }
    });
}
项目:jsass-gradle-plugin    文件:JSassWarPlugin.java   
@Override
public void apply(Project project) {

    jSassBasePlugin = project.getPlugins().apply(JSassBasePlugin.class);
    project.getPlugins().apply(WarPlugin.class);

    SassCompile compileWebappSass = project.getTasks().create("compileWebappSass", SassCompile.class);
    compileWebappSass.setGroup(BasePlugin.BUILD_GROUP);
    compileWebappSass.setDescription("Compile sass and scss files for the webapp");

    WarPluginConvention warPluginConvention = project.getConvention().getPlugin(WarPluginConvention.class);
    compileWebappSass.setSourceDir(warPluginConvention.getWebAppDir());

    project.afterEvaluate(p -> {
        War war = (War) p.getTasks().getByName(WarPlugin.WAR_TASK_NAME);
        if (jSassBasePlugin.getExtension().isInplace()) {
            compileWebappSass.setDestinationDir(warPluginConvention.getWebAppDir());
        } else {
            compileWebappSass.setDestinationDir(new File(p.getBuildDir(), "generated/webappCss"));
            war.from(compileWebappSass.getDestinationDir());
        }
        war.dependsOn(compileWebappSass);
    });
}
项目:gradle-plugins    文件:WarOverlayPlugin.java   
@Override
public void apply(Project project) {
    this.project = project;
    project.getPluginManager().apply(WarPlugin.class);

    project.getTasks().withType(War.class, warTask -> {

        NamedDomainObjectContainer<WarOverlay> warOverlays = project.container(WarOverlay.class, name -> new WarOverlay(name, warTask));
        warTask.getExtensions().add("overlays", warOverlays);

        project.afterEvaluate(p -> warOverlays.all(overlay -> {

            if (overlay.isEnabled()) {
                configureOverlay(overlay);
            } else {
                Collection<CopySpecInternal> children = (Collection<CopySpecInternal>) overlay.getWarTask().getRootSpec().getChildren();
                children.remove(overlay.getWarCopySpec());
            }

        }));
    });

}
项目:gradle-plugins    文件:WarAttachClassesPlugin.java   
@Override
public void apply(Project project) {
    project.getPlugins().apply(WarPlugin.class);

    WarAttachClassesConvention attachClassesConvention = new WarAttachClassesConvention();

    War war = (War) project.getTasks().getByName(WarPlugin.WAR_TASK_NAME);
    war.getConvention().getPlugins().put("attachClasses", attachClassesConvention);

    project.afterEvaluate(p -> {
        if (attachClassesConvention.isAttachClasses()) {
            Jar jar = (Jar) project.getTasks().getByName(JavaPlugin.JAR_TASK_NAME);
            jar.setClassifier(attachClassesConvention.getClassesClassifier());

            project.getArtifacts().add(Dependency.ARCHIVES_CONFIGURATION, jar);
        }
    });
}
项目:app-gradle-plugin    文件:AppEngineFlexiblePluginTest.java   
@Test
public void testDefaultConfiguration() throws IOException {
  Project p = new TestProject(testProjectDir.getRoot()).applyFlexibleWarProjectBuilder();

  ExtensionAware ext = (ExtensionAware) p.getExtensions().getByName("appengine");
  DeployExtension deployExt = new ExtensionUtil(ext).get("deploy");
  StageFlexibleExtension stageExt = new ExtensionUtil(ext).get("stage");

  assertEquals(new File(p.getBuildDir(), "staged-app"), stageExt.getStagingDirectory());
  assertEquals(
      testProjectDir.getRoot().toPath().toRealPath().resolve("src/main/appengine"),
      stageExt.getAppEngineDirectory().toPath());
  assertEquals(
      testProjectDir.getRoot().toPath().toRealPath().resolve("src/main/appengine"),
      deployExt.getAppEngineDirectory().toPath());
  assertEquals((((War) p.getProperties().get("war")).getArchivePath()), stageExt.getArtifact());
  assertFalse(new File(testProjectDir.getRoot(), "src/main/docker").exists());
  assertEquals(
      Collections.singletonList(new File(p.getBuildDir(), "staged-app/app.yaml")),
      deployExt.getDeployables());
}
项目:gradle-plugins    文件:WarOverlayPlugin.java   
@Override
public void apply(Project project) {
    this.project = project;
    project.getPluginManager().apply(WarPlugin.class);

    project.getTasks().withType(War.class, warTask -> {

        NamedDomainObjectContainer<WarOverlay> warOverlays = project.container(WarOverlay.class, name -> new WarOverlay(name, warTask));
        warTask.getExtensions().add("overlays", warOverlays);

        project.afterEvaluate(p -> warOverlays.all(overlay -> {

            if (overlay.isEnabled()) {
                configureOverlay(overlay);
            } else {
                Collection<CopySpecInternal> children = (Collection<CopySpecInternal>) overlay.getWarTask().getRootSpec().getChildren();
                children.remove(overlay.getWarCopySpec());
            }

        }));
    });

}
项目:gradle-plugins    文件:WarAttachClassesPlugin.java   
@Override
public void apply(Project project) {
    project.getPlugins().apply(WarPlugin.class);

    WarAttachClassesConvention attachClassesConvention = new WarAttachClassesConvention();

    War war = (War) project.getTasks().getByName(WarPlugin.WAR_TASK_NAME);
    war.getConvention().getPlugins().put("attachClasses", attachClassesConvention);

    project.afterEvaluate(p -> {
        if (attachClassesConvention.isAttachClasses()) {
            Jar jar = (Jar) project.getTasks().getByName(JavaPlugin.JAR_TASK_NAME);
            jar.setClassifier(attachClassesConvention.getClassesClassifier());

            project.getArtifacts().add(Dependency.ARCHIVES_CONFIGURATION, jar);
        }
    });
}
项目:putnami-gradle-plugin    文件:PwtPlugin.java   
private void createCompileTask(final Project project) {
    project.getTasks().create(GwtCompileTask.NAME, GwtCompileTask.class);
    final PutnamiExtension extension = project.getExtensions().getByType(PutnamiExtension.class);
    final War warTask = project.getTasks().withType(War.class).getByName("war");
    warTask.dependsOn(GwtCompileTask.NAME);
    project.getTasks().withType(GwtCompileTask.class, new Action<GwtCompileTask>() {
        @Override
        public void execute(final GwtCompileTask task) {
            task.configure(project, extension);
            warTask.from(extension.getCompile().getWar());
        }
    });

    ConfigurationContainer configurationContainer = project.getConfigurations();
    //      Configuration gwtConfig = configurationContainer.getByName(PwtLibPlugin.CONF_GWT_SDM);
    //      FileCollection warClasspath = warTask.getClasspath().minus(gwtConfig);
    //      warTask.setClasspath(warClasspath);
}
项目:Pushjet-Android    文件:JettyPlugin.java   
private void configureAbstractJettyTask(final Project project, final JettyPluginConvention jettyConvention, AbstractJettyRunTask jettyTask) {
    jettyTask.setDaemon(false);
    jettyTask.setReload(RELOAD_AUTOMATIC);
    jettyTask.setScanIntervalSeconds(0);
    jettyTask.getConventionMapping().map("contextPath", new Callable<Object>() {
        public Object call() throws Exception {
            return ((War) project.getTasks().getByName(WarPlugin.WAR_TASK_NAME)).getBaseName();
        }
    });
    jettyTask.getConventionMapping().map("httpPort", new Callable<Object>() {
        public Object call() throws Exception {
            return jettyConvention.getHttpPort();
        }
    });
    jettyTask.getConventionMapping().map("stopPort", new Callable<Object>() {
        public Object call() throws Exception {
            return jettyConvention.getStopPort();
        }
    });
    jettyTask.getConventionMapping().map("stopKey", new Callable<Object>() {
        public Object call() throws Exception {
            return jettyConvention.getStopKey();
        }
    });
}
项目:Pushjet-Android    文件:JettyPlugin.java   
private void configureAbstractJettyTask(final Project project, final JettyPluginConvention jettyConvention, AbstractJettyRunTask jettyTask) {
    jettyTask.setDaemon(false);
    jettyTask.setReload(RELOAD_AUTOMATIC);
    jettyTask.setScanIntervalSeconds(0);
    jettyTask.getConventionMapping().map("contextPath", new Callable<Object>() {
        public Object call() throws Exception {
            return ((War) project.getTasks().getByName(WarPlugin.WAR_TASK_NAME)).getBaseName();
        }
    });
    jettyTask.getConventionMapping().map("httpPort", new Callable<Object>() {
        public Object call() throws Exception {
            return jettyConvention.getHttpPort();
        }
    });
    jettyTask.getConventionMapping().map("stopPort", new Callable<Object>() {
        public Object call() throws Exception {
            return jettyConvention.getStopPort();
        }
    });
    jettyTask.getConventionMapping().map("stopKey", new Callable<Object>() {
        public Object call() throws Exception {
            return jettyConvention.getStopKey();
        }
    });
}
项目:Reer    文件:PublishArtifactToFileBuildOutcomeTransformer.java   
private String getTypeIdentifier(PublishArtifact artifact) {
    if (artifact instanceof ArchivePublishArtifact) {
        ArchivePublishArtifact publishArtifact = (ArchivePublishArtifact) artifact;
        AbstractArchiveTask task = publishArtifact.getArchiveTask();

        // There is an inheritance hierarchy in play here, so the order
        // of the clauses is very important.

        if (task instanceof War) {
            return WAR_ARTIFACT.getTypeIdentifier();
        } else if (task instanceof Ear) {
            return EAR_ARTIFACT.getTypeIdentifier();
        } else if (task instanceof Jar) {
            return JAR_ARTIFACT.getTypeIdentifier();
        } else if (task instanceof Zip) {
            return ZIP_ARTIFACT.getTypeIdentifier();
        } else if (task instanceof Tar) {
            return TAR_ARTIFACT.getTypeIdentifier();
        } else {
            // we don't know about this kind of archive task
            return ARCHIVE_ARTIFACT.getTypeIdentifier();
        }
    } else {
        // This could very well be a zip (or something else we understand), but we can't know for sure.
        // The client may try to infer from the file extension.
        return UNKNOWN_ARTIFACT.getTypeIdentifier();
    }
}
项目:Reer    文件:WarPlugin.java   
public void apply(final Project project) {
    project.getPluginManager().apply(JavaPlugin.class);
    final WarPluginConvention pluginConvention = new WarPluginConvention(project);
    project.getConvention().getPlugins().put("war", pluginConvention);

    project.getTasks().withType(War.class, new Action<War>() {
        public void execute(War task) {
            task.from(new Callable() {
                public Object call() throws Exception {
                    return pluginConvention.getWebAppDir();
                }
            });
            task.dependsOn(new Callable() {
                public Object call() throws Exception {
                    return project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().getByName(
                            SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath();
                }
            });
            task.classpath(new Object[] {new Callable() {
                public Object call() throws Exception {
                    FileCollection runtimeClasspath = project.getConvention().getPlugin(JavaPluginConvention.class)
                            .getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath();
                    Configuration providedRuntime = project.getConfigurations().getByName(
                            PROVIDED_RUNTIME_CONFIGURATION_NAME);
                    return runtimeClasspath.minus(providedRuntime);
                }
            }});
        }
    });

    War war = project.getTasks().create(WAR_TASK_NAME, War.class);
    war.setDescription("Generates a war archive with all the compiled classes, the web-app content and the libraries.");
    war.setGroup(BasePlugin.BUILD_GROUP);
    ArchivePublishArtifact warArtifact = new ArchivePublishArtifact(war);
    project.getExtensions().getByType(DefaultArtifactPublicationSet.class).addCandidate(warArtifact);
    configureConfigurations(project.getConfigurations());
    configureComponent(project, warArtifact);
}
项目:gradle-plugins    文件:WarOverlayPlugin.java   
private void configureOverlay(WarOverlay overlay, Project otherProject) {
    project.evaluationDependsOn(otherProject.getPath());

    War otherWar = (War) otherProject.getTasks().getByName(WAR_TASK_NAME);

    configureOverlay(overlay, otherWar);

    if (overlay.isEnableCompilation()) {
        project.getDependencies().add(COMPILE_CLASSPATH_CONFIGURATION_NAME, otherProject);
        project.getDependencies().add(TEST_COMPILE_CLASSPATH_CONFIGURATION_NAME, otherProject);
    }
}
项目:gradle-plugins    文件:WarOverlay.java   
public WarOverlay(String name, War warTask) {
    this.name = name;
    this.warTask = warTask;
    this.warCopySpec = warTask.getRootSpec().addChild();

    warCopySpec.setDuplicatesStrategy(DuplicatesStrategy.EXCLUDE);
    exclude("META-INF/maven/**");
    exclude("META-INF/MANIFEST.MF");
}
项目:gradle-plugins    文件:WarArchiveClassesPlugin.java   
@Override
public void apply(Project project) {

    project.getTasks().withType(War.class, war -> {

        WarArchiveClassesConvention archiveClassesConvention = new WarArchiveClassesConvention();

        war.getConvention().getPlugins().put("archiveClasses", archiveClassesConvention);

        Jar warClassesJar = project.getTasks().create(war.getName() + "ClassesJar", Jar.class);
        warClassesJar.getConventionMapping().map("baseName", war::getBaseName);
        warClassesJar.getConventionMapping().map("appendix", war::getAppendix);
        warClassesJar.getConventionMapping().map("version", war::getVersion);
        warClassesJar.getConventionMapping().map("classifier", war::getClassifier);

        project.afterEvaluate(p -> {

            warClassesJar.setEnabled(archiveClassesConvention.isArchiveClasses());

            if (archiveClassesConvention.isArchiveClasses()) {
                FileCollection warClasspath = war.getClasspath();

                warClassesJar.from(warClasspath != null ? warClasspath.filter(File::isDirectory) : Collections.emptyList());

                war.setClasspath(warClasspath == null ? null : warClasspath.filter(File::isFile).plus(project.files(warClassesJar)));
            }
        });
    });
}
项目:gradle-plugins    文件:WarArchiveClassesPluginTest.java   
@Test
public void testArchiveClassesProperty() {
    project.getPlugins().apply(WarPlugin.class);
    project.getPlugins().apply(WarArchiveClassesPlugin.class);

    War warTask = (War) project.getTasks().getByName(WarPlugin.WAR_TASK_NAME);

    assertThat(warTask.hasProperty("archiveClasses")).isTrue();
    assertThat(warTask.property("archiveClasses")).isInstanceOf(Boolean.class);
}
项目:gradle-plugins    文件:WarAttachClassesPluginTest.java   
@Test
public void testProperties() {
    project.getPlugins().apply(WarPlugin.class);
    project.getPlugins().apply(WarAttachClassesPlugin.class);

    War warTask = (War) project.getTasks().getByName(WarPlugin.WAR_TASK_NAME);

    assertThat(warTask.hasProperty("attachClasses")).isTrue();
    assertThat(warTask.property("attachClasses")).isInstanceOf(Boolean.class);

    assertThat(warTask.hasProperty("classesClassifier")).isTrue();
    assertThat(warTask.property("classesClassifier")).isInstanceOf(String.class);
}
项目:gradle-plugins    文件:WarOverlayPlugin.java   
private void configureOverlay(WarOverlay overlay, Project otherProject) {
    project.evaluationDependsOn(otherProject.getPath());

    War otherWar = (War) otherProject.getTasks().getByName(WAR_TASK_NAME);

    configureOverlay(overlay, otherWar);

    if (overlay.isEnableCompilation()) {
        project.getDependencies().add(COMPILE_CLASSPATH_CONFIGURATION_NAME, otherProject);
        project.getDependencies().add(TEST_COMPILE_CLASSPATH_CONFIGURATION_NAME, otherProject);
    }
}
项目:gradle-plugins    文件:WarOverlay.java   
public WarOverlay(String name, War warTask) {
    this.name = name;
    this.warTask = warTask;
    this.warCopySpec = warTask.getRootSpec().addChild();

    warCopySpec.setDuplicatesStrategy(DuplicatesStrategy.EXCLUDE);
    exclude("META-INF/maven/**");
    exclude("META-INF/MANIFEST.MF");
}
项目:gradle-plugins    文件:WarArchiveClassesPlugin.java   
@Override
public void apply(Project project) {

    project.getTasks().withType(War.class, war -> {

        WarArchiveClassesConvention archiveClassesConvention = new WarArchiveClassesConvention();

        war.getConvention().getPlugins().put("archiveClasses", archiveClassesConvention);

        Jar warClassesJar = project.getTasks().create(war.getName() + "ClassesJar", Jar.class);
        warClassesJar.getConventionMapping().map("baseName", war::getBaseName);
        warClassesJar.getConventionMapping().map("appendix", war::getAppendix);
        warClassesJar.getConventionMapping().map("version", war::getVersion);
        warClassesJar.getConventionMapping().map("classifier", war::getClassifier);

        project.afterEvaluate(p -> {

            warClassesJar.setEnabled(archiveClassesConvention.isArchiveClasses());

            if (archiveClassesConvention.isArchiveClasses()) {
                FileCollection warClasspath = war.getClasspath();

                warClassesJar.from(warClasspath != null ? warClasspath.filter(File::isDirectory) : Collections.emptyList());

                war.setClasspath(warClasspath == null ? null : warClasspath.filter(File::isFile).plus(project.files(warClassesJar)));
            }
        });
    });
}
项目:gradle-plugins    文件:WarArchiveClassesPluginTest.java   
@Test
public void testArchiveClassesProperty() {
    project.getPlugins().apply(WarPlugin.class);
    project.getPlugins().apply(WarArchiveClassesPlugin.class);

    War warTask = (War) project.getTasks().getByName(WarPlugin.WAR_TASK_NAME);

    assertThat(warTask.hasProperty("archiveClasses")).isTrue();
    assertThat(warTask.property("archiveClasses")).isInstanceOf(Boolean.class);
}
项目:gradle-plugins    文件:WarAttachClassesPluginTest.java   
@Test
public void testProperties() {
    project.getPlugins().apply(WarPlugin.class);
    project.getPlugins().apply(WarAttachClassesPlugin.class);

    War warTask = (War) project.getTasks().getByName(WarPlugin.WAR_TASK_NAME);

    assertThat(warTask.hasProperty("attachClasses")).isTrue();
    assertThat(warTask.property("attachClasses")).isInstanceOf(Boolean.class);

    assertThat(warTask.hasProperty("classesClassifier")).isTrue();
    assertThat(warTask.property("classesClassifier")).isInstanceOf(String.class);
}
项目:putnami-gradle-plugin    文件:GwtRunTask.java   
@TaskAction
public void exec() throws Exception {
    War warTask = (War) getProject().getTasks().getByName("war");
    jettyConf = new File(getProject().getBuildDir(), "putnami/conf/jetty-run-conf.xml");
    Map<String, String> model = new ImmutableMap.Builder<String, String>()
                .put("__WAR_FILE__", warTask.getArchivePath().getAbsolutePath())
                .build();
    ResourceUtils.copy("/stub.jetty-conf.xml", jettyConf, model);
    JavaAction jetty = execJetty();
    jetty.join();
}
项目:Pushjet-Android    文件:JettyPlugin.java   
private Object getWebXml(Project project) {
    War war = (War) project.getTasks().getByName(WarPlugin.WAR_TASK_NAME);
    File webXml;
    if (war.getWebXml() != null) {
        webXml = war.getWebXml();
    } else {
        webXml = new File(getWarConvention(project).getWebAppDir(), "WEB-INF/web.xml");
    }
    return webXml;
}
项目:Pushjet-Android    文件:WarPlugin.java   
public void apply(final Project project) {
    project.getPlugins().apply(JavaPlugin.class);
    final WarPluginConvention pluginConvention = new WarPluginConvention(project);
    project.getConvention().getPlugins().put("war", pluginConvention);

    project.getTasks().withType(War.class, new Action<War>() {
        public void execute(War task) {
            task.from(new Callable() {
                public Object call() throws Exception {
                    return pluginConvention.getWebAppDir();
                }
            });
            task.dependsOn(new Callable() {
                public Object call() throws Exception {
                    return project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().getByName(
                            SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath();
                }
            });
            task.classpath(new Object[] {new Callable() {
                public Object call() throws Exception {
                    FileCollection runtimeClasspath = project.getConvention().getPlugin(JavaPluginConvention.class)
                            .getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath();
                    Configuration providedRuntime = project.getConfigurations().getByName(
                            PROVIDED_RUNTIME_CONFIGURATION_NAME);
                    return runtimeClasspath.minus(providedRuntime);
                }
            }});
        }
    });

    War war = project.getTasks().create(WAR_TASK_NAME, War.class);
    war.setDescription("Generates a war archive with all the compiled classes, the web-app content and the libraries.");
    war.setGroup(BasePlugin.BUILD_GROUP);
    ArchivePublishArtifact warArtifact = new ArchivePublishArtifact(war);
    project.getExtensions().getByType(DefaultArtifactPublicationSet.class).addCandidate(warArtifact);
    configureConfigurations(project.getConfigurations());
    configureComponent(project, warArtifact);
}
项目:Pushjet-Android    文件:JettyPlugin.java   
private Object getWebXml(Project project) {
    War war = (War) project.getTasks().getByName(WarPlugin.WAR_TASK_NAME);
    File webXml;
    if (war.getWebXml() != null) {
        webXml = war.getWebXml();
    } else {
        webXml = new File(getWarConvention(project).getWebAppDir(), "WEB-INF/web.xml");
    }
    return webXml;
}
项目:Pushjet-Android    文件:WarPlugin.java   
public void apply(final Project project) {
    project.getPlugins().apply(JavaPlugin.class);
    final WarPluginConvention pluginConvention = new WarPluginConvention(project);
    project.getConvention().getPlugins().put("war", pluginConvention);

    project.getTasks().withType(War.class, new Action<War>() {
        public void execute(War task) {
            task.from(new Callable() {
                public Object call() throws Exception {
                    return pluginConvention.getWebAppDir();
                }
            });
            task.dependsOn(new Callable() {
                public Object call() throws Exception {
                    return project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().getByName(
                            SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath();
                }
            });
            task.classpath(new Object[] {new Callable() {
                public Object call() throws Exception {
                    FileCollection runtimeClasspath = project.getConvention().getPlugin(JavaPluginConvention.class)
                            .getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath();
                    Configuration providedRuntime = project.getConfigurations().getByName(
                            PROVIDED_RUNTIME_CONFIGURATION_NAME);
                    return runtimeClasspath.minus(providedRuntime);
                }
            }});
        }
    });

    War war = project.getTasks().create(WAR_TASK_NAME, War.class);
    war.setDescription("Generates a war archive with all the compiled classes, the web-app content and the libraries.");
    war.setGroup(BasePlugin.BUILD_GROUP);
    ArchivePublishArtifact warArtifact = new ArchivePublishArtifact(war);
    project.getExtensions().getByType(DefaultArtifactPublicationSet.class).addCandidate(warArtifact);
    configureConfigurations(project.getConfigurations());
    configureComponent(project, warArtifact);
}
项目:gradle-plugins    文件:WarOverlayPlugin.java   
private void configureOverlay(WarOverlay overlay, ExternalDependency dependency) {

        War warTask = overlay.getWarTask();

        String capitalizedWarTaskName = StringGroovyMethods.capitalize((CharSequence) warTask.getName());
        String capitalizedOverlayName = StringGroovyMethods.capitalize((CharSequence) overlay.getName());

        dependency.setTransitive(false);

        Configuration configuration = project.getConfigurations().create(overlay.getConfigurationName());
        configuration.setDescription(String.format("Contents of the overlay '%s' for the task '%s'.", overlay.getName(), warTask.getName()));
        configuration.getDependencies().add(dependency);

        File destinationDir = new File(project.getBuildDir(), String.format("overlays/%s/%s", warTask.getName(), overlay.getName()));
        Action<CopySpec> extractOverlay = copySpec -> {
            copySpec.into(destinationDir);
            copySpec.from((Callable<FileTree>) () -> project.zipTree(configuration.getSingleFile()));
        };

        Sync extractOverlayTask = project.getTasks().create(String.format("extract%s%sOverlay", capitalizedOverlayName, capitalizedWarTaskName), Sync.class, extractOverlay);

        overlay.getWarCopySpec().from(extractOverlayTask);

        if (overlay.isEnableCompilation()) {

            project.sync(extractOverlay);

            project.getTasks().getByName(CLEAN_TASK_NAME).finalizedBy(extractOverlayTask);

            ConfigurableFileCollection classes = project.files(new File(destinationDir, "WEB-INF/classes"))
                    .builtBy(extractOverlayTask);

            project.getDependencies().add(COMPILE_CLASSPATH_CONFIGURATION_NAME, classes);
            project.getDependencies().add(TEST_COMPILE_CLASSPATH_CONFIGURATION_NAME, classes);

            FileTree libs = project.files(extractOverlayTask).builtBy(extractOverlayTask).getAsFileTree()
                    .matching(patternFilterable -> patternFilterable.include("WEB-INF/lib/**"));

            project.getDependencies().add(COMPILE_CLASSPATH_CONFIGURATION_NAME, libs);
            project.getDependencies().add(TEST_COMPILE_CLASSPATH_CONFIGURATION_NAME, libs);
        }
    }
项目:gradle-plugins    文件:WarOverlayPlugin.java   
private void configureOverlay(WarOverlay overlay, ExternalDependency dependency) {

        War warTask = overlay.getWarTask();

        String capitalizedWarTaskName = StringGroovyMethods.capitalize((CharSequence) warTask.getName());
        String capitalizedOverlayName = StringGroovyMethods.capitalize((CharSequence) overlay.getName());

        dependency.setTransitive(false);

        Configuration configuration = project.getConfigurations().create(overlay.getConfigurationName());
        configuration.setDescription(String.format("Contents of the overlay '%s' for the task '%s'.", overlay.getName(), warTask.getName()));
        configuration.getDependencies().add(dependency);

        File destinationDir = new File(project.getBuildDir(), String.format("overlays/%s/%s", warTask.getName(), overlay.getName()));
        Action<CopySpec> extractOverlay = copySpec -> {
            copySpec.into(destinationDir);
            copySpec.from((Callable<FileTree>) () -> project.zipTree(configuration.getSingleFile()));
        };

        Sync extractOverlayTask = project.getTasks().create(String.format("extract%s%sOverlay", capitalizedOverlayName, capitalizedWarTaskName), Sync.class, extractOverlay);

        overlay.getWarCopySpec().from(extractOverlayTask);

        if (overlay.isEnableCompilation()) {

            project.sync(extractOverlay);

            project.getTasks().getByName(CLEAN_TASK_NAME).finalizedBy(extractOverlayTask);

            ConfigurableFileCollection classes = project.files(new File(destinationDir, "WEB-INF/classes"))
                    .builtBy(extractOverlayTask);

            project.getDependencies().add(COMPILE_CLASSPATH_CONFIGURATION_NAME, classes);
            project.getDependencies().add(TEST_COMPILE_CLASSPATH_CONFIGURATION_NAME, classes);

            FileTree libs = project.files(extractOverlayTask).builtBy(extractOverlayTask).getAsFileTree()
                    .matching(patternFilterable -> patternFilterable.include("WEB-INF/lib/**"));

            project.getDependencies().add(COMPILE_CLASSPATH_CONFIGURATION_NAME, libs);
            project.getDependencies().add(TEST_COMPILE_CLASSPATH_CONFIGURATION_NAME, libs);
        }
    }