use of org.gradle.api.tasks.bundling.War in project gradle by gradle.
the class PublishArtifactToFileBuildOutcomeTransformer method getTypeIdentifier.
private String getTypeIdentifier(PublishArtifact artifact) {
if (artifact instanceof ArchivePublishArtifact) {
ArchivePublishArtifact publishArtifact = (ArchivePublishArtifact) artifact;
AbstractArchiveTask task = publishArtifact.getArchiveTask();
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 {
// The client may try to infer from the file extension.
return UNKNOWN_ARTIFACT.getTypeIdentifier();
}
}
use of org.gradle.api.tasks.bundling.War in project spring-boot by spring-projects.
the class WarPluginAction method configureBootWarTask.
private TaskProvider<BootWar> configureBootWarTask(Project project) {
Configuration developmentOnly = project.getConfigurations().getByName(SpringBootPlugin.DEVELOPMENT_ONLY_CONFIGURATION_NAME);
Configuration productionRuntimeClasspath = project.getConfigurations().getByName(SpringBootPlugin.PRODUCTION_RUNTIME_CLASSPATH_CONFIGURATION_NAME);
Callable<FileCollection> classpath = () -> project.getExtensions().getByType(SourceSetContainer.class).getByName(SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath().minus(providedRuntimeConfiguration(project)).minus((developmentOnly.minus(productionRuntimeClasspath))).filter(new JarTypeFileSpec());
TaskProvider<ResolveMainClassName> resolveMainClassName = ResolveMainClassName.registerForTask(SpringBootPlugin.BOOT_WAR_TASK_NAME, project, classpath);
TaskProvider<BootWar> bootWarProvider = project.getTasks().register(SpringBootPlugin.BOOT_WAR_TASK_NAME, BootWar.class, (bootWar) -> {
bootWar.setGroup(BasePlugin.BUILD_GROUP);
bootWar.setDescription("Assembles an executable war archive containing webapp" + " content, and the main classes and their dependencies.");
bootWar.providedClasspath(providedRuntimeConfiguration(project));
bootWar.setClasspath(classpath);
Provider<String> manifestStartClass = project.provider(() -> (String) bootWar.getManifest().getAttributes().get("Start-Class"));
bootWar.getMainClass().convention(resolveMainClassName.flatMap((resolver) -> manifestStartClass.isPresent() ? manifestStartClass : resolveMainClassName.get().readMainClassName()));
});
bootWarProvider.map((bootWar) -> bootWar.getClasspath());
return bootWarProvider;
}
use of org.gradle.api.tasks.bundling.War in project gradle by gradle.
the class WarPlugin method apply.
@Override
public void apply(final Project project) {
project.getPluginManager().apply(JavaPlugin.class);
final WarPluginConvention pluginConvention = new DefaultWarPluginConvention(project);
project.getConvention().getPlugins().put("war", pluginConvention);
project.getTasks().withType(War.class).configureEach(task -> {
task.getWebAppDirectory().convention(project.getLayout().dir(project.provider(() -> pluginConvention.getWebAppDir())));
task.from(task.getWebAppDirectory());
task.dependsOn((Callable) () -> project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath());
task.classpath((Callable) () -> {
FileCollection runtimeClasspath = project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath();
Configuration providedRuntime = project.getConfigurations().getByName(PROVIDED_RUNTIME_CONFIGURATION_NAME);
return runtimeClasspath.minus(providedRuntime);
});
});
TaskProvider<War> war = project.getTasks().register(WAR_TASK_NAME, War.class, warTask -> {
warTask.setDescription("Generates a war archive with all the compiled classes, the web-app content and the libraries.");
warTask.setGroup(BasePlugin.BUILD_GROUP);
});
PublishArtifact warArtifact = new LazyPublishArtifact(war, ((ProjectInternal) project).getFileResolver());
project.getExtensions().getByType(DefaultArtifactPublicationSet.class).addCandidate(warArtifact);
configureConfigurations(project.getConfigurations());
configureComponent(project, warArtifact);
}
use of org.gradle.api.tasks.bundling.War in project gradle by gradle.
the class JettyPlugin method getWebXml.
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;
}
use of org.gradle.api.tasks.bundling.War in project gradle by gradle.
the class EclipseWtpPlugin method configureEclipseWtpComponent.
private void configureEclipseWtpComponent(final Project project, final EclipseModel model) {
XmlTransformer xmlTransformer = new XmlTransformer();
xmlTransformer.setIndentation("\t");
final EclipseWtpComponent component = project.getObjects().newInstance(EclipseWtpComponent.class, project, new XmlFileContentMerger(xmlTransformer));
model.getWtp().setComponent(component);
TaskProvider<GenerateEclipseWtpComponent> task = project.getTasks().register(ECLIPSE_WTP_COMPONENT_TASK_NAME, GenerateEclipseWtpComponent.class, component);
task.configure(new Action<GenerateEclipseWtpComponent>() {
@Override
public void execute(final GenerateEclipseWtpComponent task) {
task.setDescription("Generates the Eclipse WTP component settings file.");
task.setInputFile(project.file(".settings/org.eclipse.wst.common.component"));
task.setOutputFile(project.file(".settings/org.eclipse.wst.common.component"));
}
});
addWorker(task, ECLIPSE_WTP_COMPONENT_TASK_NAME);
((IConventionAware) component).getConventionMapping().map("deployName", new Callable<String>() {
@Override
public String call() throws Exception {
return model.getProject().getName();
}
});
project.getPlugins().withType(JavaPlugin.class, new Action<JavaPlugin>() {
@Override
public void execute(JavaPlugin javaPlugin) {
if (hasWarOrEarPlugin(project)) {
return;
}
Set<Configuration> libConfigurations = component.getLibConfigurations();
libConfigurations.add(project.getConfigurations().getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME));
component.setClassesDeployPath("/");
((IConventionAware) component).getConventionMapping().map("libDeployPath", new Callable<String>() {
@Override
public String call() throws Exception {
return "../";
}
});
((IConventionAware) component).getConventionMapping().map("sourceDirs", new Callable<Set<File>>() {
@Override
public Set<File> call() throws Exception {
return getMainSourceDirs(project);
}
});
}
});
project.getPlugins().withType(WarPlugin.class, new Action<WarPlugin>() {
@Override
public void execute(WarPlugin warPlugin) {
Set<Configuration> libConfigurations = component.getLibConfigurations();
Set<Configuration> minusConfigurations = component.getMinusConfigurations();
libConfigurations.add(project.getConfigurations().getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME));
minusConfigurations.add(project.getConfigurations().getByName("providedRuntime"));
component.setClassesDeployPath("/WEB-INF/classes");
ConventionMapping convention = ((IConventionAware) component).getConventionMapping();
convention.map("libDeployPath", new Callable<String>() {
@Override
public String call() throws Exception {
return "/WEB-INF/lib";
}
});
convention.map("contextPath", new Callable<String>() {
@Override
public String call() throws Exception {
return ((War) project.getTasks().getByName("war")).getArchiveBaseName().getOrNull();
}
});
convention.map("resources", new Callable<List<WbResource>>() {
@Override
public List<WbResource> call() throws Exception {
File projectDir = project.getProjectDir();
File webAppDir = ((War) project.getTasks().getByName("war")).getWebAppDirectory().get().getAsFile();
String webAppDirName = RelativePathUtil.relativePath(projectDir, webAppDir);
return Lists.newArrayList(new WbResource("/", webAppDirName));
}
});
convention.map("sourceDirs", new Callable<Set<File>>() {
@Override
public Set<File> call() throws Exception {
return getMainSourceDirs(project);
}
});
}
});
project.getPlugins().withType(EarPlugin.class, new Action<EarPlugin>() {
@Override
public void execute(EarPlugin earPlugin) {
Set<Configuration> libConfigurations = component.getLibConfigurations();
Set<Configuration> rootConfigurations = component.getRootConfigurations();
rootConfigurations.clear();
rootConfigurations.add(project.getConfigurations().getByName("deploy"));
libConfigurations.clear();
libConfigurations.add(project.getConfigurations().getByName("earlib"));
component.setClassesDeployPath("/");
final ConventionMapping convention = ((IConventionAware) component).getConventionMapping();
convention.map("libDeployPath", new Callable<String>() {
@Override
public String call() throws Exception {
String deployPath = ((Ear) project.getTasks().findByName(EarPlugin.EAR_TASK_NAME)).getLibDirName();
if (!deployPath.startsWith("/")) {
deployPath = "/" + deployPath;
}
return deployPath;
}
});
convention.map("sourceDirs", new Callable<Set<File>>() {
@Override
public Set<File> call() throws Exception {
return WrapUtil.toSet(((Ear) project.getTasks().findByName(EarPlugin.EAR_TASK_NAME)).getAppDirectory().get().getAsFile());
}
});
project.getPlugins().withType(JavaPlugin.class, new Action<JavaPlugin>() {
@Override
public void execute(JavaPlugin javaPlugin) {
convention.map("sourceDirs", new Callable<Set<File>>() {
@Override
public Set<File> call() throws Exception {
return getMainSourceDirs(project);
}
});
}
});
}
});
}
Aggregations