org.gradle.api.tasks.bundling.War Java Examples

The following examples show how to use org.gradle.api.tasks.bundling.War. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JettyPlugin.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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();
        }
    });
}
 
Example #2
Source File: WarOverlayPlugin.java    From gradle-plugins with MIT License 6 votes vote down vote up
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(getClasspathConfigurationName(overlay), otherProject);

        otherProject.getPlugins().withType(WarOverlayPlugin.class, otherWarOverlayPlugin -> {
            Map<String, String> map = new HashMap<>();
            map.put("path", otherProject.getPath());
            map.put("configuration", otherWarOverlayPlugin.getClasspathConfigurationName(otherWar));

            project.getDependencies().add(
                    getClasspathConfigurationName(overlay),
                    project.getDependencies().project(map)
            );
        });
    }
}
 
Example #3
Source File: AppEngineAppYamlPluginTest.java    From app-gradle-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void testDefaultConfiguration() throws IOException {
  Project p = new TestProject(testProjectDir.getRoot()).applyAppYamlWarProjectBuilder();

  AppEngineAppYamlExtension ext = p.getExtensions().getByType(AppEngineAppYamlExtension.class);
  DeployExtension deployExt = ext.getDeploy();
  StageAppYamlExtension stageExt = ext.getStage();

  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("test-project", deployExt.getProjectId());
  assertEquals("test-version", deployExt.getVersion());
}
 
Example #4
Source File: SourceContextPlugin.java    From app-gradle-plugin with Apache License 2.0 6 votes vote down vote up
private void createSourceContextTask() {
  project
      .getTasks()
      .create(
          "_createSourceContext",
          GenRepoInfoFileTask.class,
          genRepoInfoFile -> {
            genRepoInfoFile.setDescription("_internal");

            project.afterEvaluate(
                project -> {
                  genRepoInfoFile.setConfiguration(extension);
                  genRepoInfoFile.setGcloud(cloudSdkOperations.getGcloud());
                });
          });
  configureArchiveTask(project.getTasks().withType(War.class).findByName("war"));
  configureArchiveTask(project.getTasks().withType(Jar.class).findByName("jar"));
}
 
Example #5
Source File: AppEngineStandardPlugin.java    From app-gradle-plugin with Apache License 2.0 6 votes vote down vote up
private void createExplodedWarTask() {
  project
      .getTasks()
      .create(
          EXPLODE_WAR_TASK_NAME,
          ExplodeWarTask.class,
          explodeWar -> {
            explodeWar.setExplodedAppDirectory(explodedWarDir);
            explodeWar.dependsOn(WarPlugin.WAR_TASK_NAME);
            explodeWar.setGroup(APP_ENGINE_STANDARD_TASK_GROUP);
            explodeWar.setDescription("Explode a war into a directory");

            project.afterEvaluate(
                project ->
                    explodeWar.setWarFile(
                        ((War) project.getTasks().getByPath(WarPlugin.WAR_TASK_NAME))
                            .getArchivePath()));
          });
  project.getTasks().getByName(BasePlugin.ASSEMBLE_TASK_NAME).dependsOn(EXPLODE_WAR_TASK_NAME);
}
 
Example #6
Source File: JSassWarPlugin.java    From gradle-plugins with MIT License 6 votes vote down vote up
@Override
public void apply(Project project) {

    project.getPlugins().apply(JSassWebjarsPlugin.class);
    project.getPlugins().apply(WarPlugin.class);

    TaskProvider<SassCompile> sassCompileTaskProvider = project.getTasks().register("compileWebappSass", SassCompile.class, compileWebappSass -> {
        compileWebappSass.setGroup(BasePlugin.BUILD_GROUP);
        compileWebappSass.setDescription("Compile sass and scss files for the webapp");

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

        compileWebappSass.getDestinationDir().set(new File(project.getBuildDir(), "jsass/webapp"));
    });

    project.getTasks().named(WarPlugin.WAR_TASK_NAME, War.class)
            .configure(war -> war.from(sassCompileTaskProvider));
}
 
Example #7
Source File: WarAttachClassesPlugin.java    From gradle-plugins with MIT License 6 votes vote down vote up
@Override
public void apply(Project project) {
    project.getPlugins().apply(WarPlugin.class);

    WarAttachClassesConvention attachClassesConvention = new WarAttachClassesConvention();

    project.getTasks().named(WarPlugin.WAR_TASK_NAME, War.class, war ->
            war.getConvention().getPlugins().put("attachClasses", attachClassesConvention)
    );

    project.afterEvaluate(p -> {
        if (attachClassesConvention.isAttachClasses()) {
            TaskProvider<Jar> jar = project.getTasks().named(JavaPlugin.JAR_TASK_NAME, Jar.class, j ->
                    j.getArchiveClassifier().convention(attachClassesConvention.getClassesClassifier())
            );

            project.getArtifacts().add(Dependency.ARCHIVES_CONFIGURATION, jar);
        }
    });
}
 
Example #8
Source File: WarAttachClassesPlugin.java    From gradle-plugins with MIT License 6 votes vote down vote up
@Override
public void apply(Project project) {
    project.getPlugins().apply(WarPlugin.class);

    WarAttachClassesConvention attachClassesConvention = new WarAttachClassesConvention();

    project.getTasks().named(WarPlugin.WAR_TASK_NAME, War.class, war ->
            war.getConvention().getPlugins().put("attachClasses", attachClassesConvention)
    );

    project.afterEvaluate(p -> {
        if (attachClassesConvention.isAttachClasses()) {
            TaskProvider<Jar> jar = project.getTasks().named(JavaPlugin.JAR_TASK_NAME, Jar.class, j ->
                    j.getArchiveClassifier().convention(attachClassesConvention.getClassesClassifier())
            );

            project.getArtifacts().add(Dependency.ARCHIVES_CONFIGURATION, jar);
        }
    });
}
 
Example #9
Source File: JSassWarPlugin.java    From gradle-plugins with MIT License 6 votes vote down vote up
@Override
public void apply(Project project) {

    project.getPlugins().apply(JSassWebjarsPlugin.class);
    project.getPlugins().apply(WarPlugin.class);

    TaskProvider<SassCompile> sassCompileTaskProvider = project.getTasks().register("compileWebappSass", SassCompile.class, compileWebappSass -> {
        compileWebappSass.setGroup(BasePlugin.BUILD_GROUP);
        compileWebappSass.setDescription("Compile sass and scss files for the webapp");

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

        compileWebappSass.getDestinationDir().set(new File(project.getBuildDir(), "jsass/webapp"));
    });

    project.getTasks().named(WarPlugin.WAR_TASK_NAME, War.class)
            .configure(war -> war.from(sassCompileTaskProvider));
}
 
Example #10
Source File: PwtPlugin.java    From putnami-gradle-plugin with GNU Lesser General Public License v3.0 6 votes vote down vote up
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);
}
 
Example #11
Source File: WarOverlayPlugin.java    From gradle-plugins with MIT License 6 votes vote down vote up
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(getClasspathConfigurationName(overlay), otherProject);

        otherProject.getPlugins().withType(WarOverlayPlugin.class, otherWarOverlayPlugin -> {
            Map<String, String> map = new HashMap<>();
            map.put("path", otherProject.getPath());
            map.put("configuration", otherWarOverlayPlugin.getClasspathConfigurationName(otherWar));

            project.getDependencies().add(
                    getClasspathConfigurationName(overlay),
                    project.getDependencies().project(map)
            );
        });
    }
}
 
Example #12
Source File: JettyPlugin.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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();
        }
    });
}
 
Example #13
Source File: JettyPlugin.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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();
        }
    });
}
 
Example #14
Source File: JettyPlugin.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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();
        }
    });
}
 
Example #15
Source File: WarAttachClassesPluginTest.java    From gradle-plugins with MIT License 5 votes vote down vote up
@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);
}
 
Example #16
Source File: WarArchiveClassesPluginTest.java    From gradle-plugins with MIT License 5 votes vote down vote up
@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);
}
 
Example #17
Source File: GwtRunTask.java    From putnami-gradle-plugin with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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();
}
 
Example #18
Source File: WarPlugin.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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);
}
 
Example #19
Source File: WarArchiveClassesPlugin.java    From gradle-plugins with MIT License 5 votes vote down vote up
@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.getArchiveBaseName().convention(war.getArchiveBaseName());
        warClassesJar.getArchiveAppendix().convention(war.getArchiveAppendix());
        warClassesJar.getArchiveVersion().convention(war.getArchiveVersion());
        warClassesJar.getArchiveClassifier().convention(war.getArchiveClassifier());

        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)));
            }
        });
    });
}
 
Example #20
Source File: WarOverlay.java    From gradle-plugins with MIT License 5 votes vote down vote up
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");
}
 
Example #21
Source File: WarPlugin.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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);
}
 
Example #22
Source File: WarOverlayPlugin.java    From gradle-plugins with MIT License 5 votes vote down vote up
private void configureOverlay(WarOverlay overlay, Callable<FileTree> warTree) {
    War warTask = overlay.getWarTask();

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

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

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

    overlay.getWarCopySpec().from(extractOverlayTask);

    if (overlay.isEnableCompilation()) {

        if (!destinationDir.exists() || isEmpty(destinationDir)) {
            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(getClasspathConfigurationName(overlay), classes);

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

        project.getDependencies().add(getClasspathConfigurationName(overlay), libs);
    }
}
 
Example #23
Source File: WarOverlayPlugin.java    From gradle-plugins with MIT License 5 votes vote down vote up
private void configureOverlay(WarOverlay overlay, ExternalDependency dependency) {
    War warTask = overlay.getWarTask();

    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);

    configureOverlay(overlay, () -> project.zipTree(configuration.getSingleFile()));
}
 
Example #24
Source File: WarOverlayPlugin.java    From gradle-plugins with MIT License 5 votes vote down vote up
@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);

        Configuration warOverlayClasspath = project.getConfigurations().create(warTask.getName() + "OverlayClasspath");
        warTask.getExtensions().add("overlayClasspath", warOverlayClasspath);

        if (warTask.getName().equals(WarPlugin.WAR_TASK_NAME)) {
            project.getConfigurations().getByName(COMPILE_CLASSPATH_CONFIGURATION_NAME).extendsFrom(warOverlayClasspath);
            project.getConfigurations().getByName(TEST_IMPLEMENTATION_CONFIGURATION_NAME).extendsFrom(warOverlayClasspath);
        }

        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());
            }

        }));
    });

}
 
Example #25
Source File: WarAttachClassesPluginTest.java    From gradle-plugins with MIT License 5 votes vote down vote up
@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);
}
 
Example #26
Source File: WarArchiveClassesPluginTest.java    From gradle-plugins with MIT License 5 votes vote down vote up
@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);
}
 
Example #27
Source File: WarArchiveClassesPlugin.java    From gradle-plugins with MIT License 5 votes vote down vote up
@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.getArchiveBaseName().convention(war.getArchiveBaseName());
        warClassesJar.getArchiveAppendix().convention(war.getArchiveAppendix());
        warClassesJar.getArchiveVersion().convention(war.getArchiveVersion());
        warClassesJar.getArchiveClassifier().convention(war.getArchiveClassifier());

        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)));
            }
        });
    });
}
 
Example #28
Source File: WarOverlay.java    From gradle-plugins with MIT License 5 votes vote down vote up
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");
}
 
Example #29
Source File: WarOverlayPlugin.java    From gradle-plugins with MIT License 5 votes vote down vote up
private void configureOverlay(WarOverlay overlay, Callable<FileTree> warTree) {
    War warTask = overlay.getWarTask();

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

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

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

    overlay.getWarCopySpec().from(extractOverlayTask);

    if (overlay.isEnableCompilation()) {

        if (!destinationDir.exists() || isEmpty(destinationDir)) {
            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(getClasspathConfigurationName(overlay), classes);

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

        project.getDependencies().add(getClasspathConfigurationName(overlay), libs);
    }
}
 
Example #30
Source File: WarOverlayPlugin.java    From gradle-plugins with MIT License 5 votes vote down vote up
private void configureOverlay(WarOverlay overlay, ExternalDependency dependency) {
    War warTask = overlay.getWarTask();

    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);

    configureOverlay(overlay, () -> project.zipTree(configuration.getSingleFile()));
}