use of org.gradle.internal.xml.XmlTransformer in project gradle by gradle.
the class IdeaPlugin method configureIdeaModule.
private void configureIdeaModule(final ProjectInternal project) {
IdeaModuleIml iml = new IdeaModuleIml(new XmlTransformer(), project.getProjectDir());
final IdeaModule module = instantiator.newInstance(IdeaModule.class, project, iml);
final TaskProvider<GenerateIdeaModule> task = project.getTasks().register(IDEA_MODULE_TASK_NAME, GenerateIdeaModule.class, module);
task.configure(new Action<GenerateIdeaModule>() {
@Override
public void execute(GenerateIdeaModule task) {
task.setDescription("Generates IDEA module files (IML)");
}
});
ideaModel.setModule(module);
final String defaultModuleName = uniqueProjectNameProvider.getUniqueName(project);
module.setName(defaultModuleName);
ConventionMapping conventionMapping = ((IConventionAware) module).getConventionMapping();
Set<File> sourceDirs = Sets.newLinkedHashSet();
conventionMapping.map("sourceDirs", new Callable<Set<File>>() {
@Override
public Set<File> call() {
return sourceDirs;
}
});
conventionMapping.map("contentRoot", new Callable<File>() {
@Override
public File call() {
return project.getProjectDir();
}
});
Set<File> testSourceDirs = Sets.newLinkedHashSet();
conventionMapping.map("testSourceDirs", new Callable<Set<File>>() {
@Override
public Set<File> call() {
return testSourceDirs;
}
});
Set<File> resourceDirs = Sets.newLinkedHashSet();
conventionMapping.map("resourceDirs", new Callable<Set<File>>() {
@Override
public Set<File> call() throws Exception {
return resourceDirs;
}
});
Set<File> testResourceDirs = Sets.newLinkedHashSet();
conventionMapping.map("testResourceDirs", new Callable<Set<File>>() {
@Override
public Set<File> call() throws Exception {
return testResourceDirs;
}
});
Set<File> excludeDirs = Sets.newLinkedHashSet();
conventionMapping.map("excludeDirs", new Callable<Set<File>>() {
@Override
public Set<File> call() {
excludeDirs.add(project.file(".gradle"));
excludeDirs.add(project.getBuildDir());
return excludeDirs;
}
});
conventionMapping.map("pathFactory", new Callable<PathFactory>() {
@Override
public PathFactory call() {
final PathFactory factory = new PathFactory();
factory.addPathVariable("MODULE_DIR", task.get().getOutputFile().getParentFile());
for (Map.Entry<String, File> entry : module.getPathVariables().entrySet()) {
factory.addPathVariable(entry.getKey(), entry.getValue());
}
return factory;
}
});
artifactRegistry.registerIdeProject(new IdeaModuleMetadata(module, task));
addWorker(task, IDEA_MODULE_TASK_NAME);
}
use of org.gradle.internal.xml.XmlTransformer 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);
}
});
}
});
}
});
}
use of org.gradle.internal.xml.XmlTransformer in project gradle by gradle.
the class EclipsePlugin method configureEclipseClasspath.
private void configureEclipseClasspath(final Project project, final EclipseModel model) {
model.setClasspath(project.getObjects().newInstance(EclipseClasspath.class, project));
((IConventionAware) model.getClasspath()).getConventionMapping().map("defaultOutputDir", new Callable<File>() {
@Override
public File call() {
return new File(project.getProjectDir(), EclipsePluginConstants.DEFAULT_PROJECT_OUTPUT_PATH);
}
});
model.getClasspath().getTestSourceSets().convention(testSourceSetsConvention);
model.getClasspath().getTestConfigurations().convention(testConfigurationsConvention);
project.getPlugins().withType(JavaBasePlugin.class, new Action<JavaBasePlugin>() {
@Override
public void execute(JavaBasePlugin javaBasePlugin) {
final TaskProvider<GenerateEclipseClasspath> task = project.getTasks().register(ECLIPSE_CP_TASK_NAME, GenerateEclipseClasspath.class, model.getClasspath());
task.configure(new Action<GenerateEclipseClasspath>() {
@Override
public void execute(final GenerateEclipseClasspath task) {
task.setDescription("Generates the Eclipse classpath file.");
task.setInputFile(project.file(".classpath"));
task.setOutputFile(project.file(".classpath"));
}
});
addWorker(task, ECLIPSE_CP_TASK_NAME);
XmlTransformer xmlTransformer = new XmlTransformer();
xmlTransformer.setIndentation("\t");
model.getClasspath().setFile(new XmlFileContentMerger(xmlTransformer));
model.getClasspath().setSourceSets(project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets());
AfterEvaluateHelper.afterEvaluateOrExecute(project, new Action<Project>() {
@Override
public void execute(Project p) {
// keep the ordering we had in earlier gradle versions
Set<String> containers = Sets.newLinkedHashSet();
containers.add("org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/" + model.getJdt().getJavaRuntimeName() + "/");
containers.addAll(model.getClasspath().getContainers());
model.getClasspath().setContainers(containers);
}
});
configureScalaDependencies(project, model);
configureJavaClasspath(project, task, model, testSourceSetsConvention, testConfigurationsConvention);
}
});
}
use of org.gradle.internal.xml.XmlTransformer in project gradle by gradle.
the class IdeaPlugin method configureIdeaProject.
private void configureIdeaProject(final Project project) {
if (isRoot()) {
XmlFileContentMerger ipr = new XmlFileContentMerger(new XmlTransformer());
final IdeaProject ideaProject = instantiator.newInstance(IdeaProject.class, project, ipr);
final TaskProvider<GenerateIdeaProject> projectTask = project.getTasks().register(IDEA_PROJECT_TASK_NAME, GenerateIdeaProject.class, ideaProject);
projectTask.configure(new Action<GenerateIdeaProject>() {
@Override
public void execute(GenerateIdeaProject projectTask) {
projectTask.setDescription("Generates IDEA project file (IPR)");
}
});
ideaModel.setProject(ideaProject);
ideaProject.setOutputFile(new File(project.getProjectDir(), project.getName() + ".ipr"));
ConventionMapping conventionMapping = ((IConventionAware) ideaProject).getConventionMapping();
conventionMapping.map("jdkName", new Callable<String>() {
@Override
public String call() {
return JavaVersion.current().toString();
}
});
conventionMapping.map("languageLevel", new Callable<IdeaLanguageLevel>() {
@Override
public IdeaLanguageLevel call() {
JavaVersion maxSourceCompatibility = getMaxJavaModuleCompatibilityVersionFor(SOURCE_COMPATIBILITY);
return new IdeaLanguageLevel(maxSourceCompatibility);
}
});
conventionMapping.map("targetBytecodeVersion", new Callable<JavaVersion>() {
@Override
public JavaVersion call() {
return getMaxJavaModuleCompatibilityVersionFor(TARGET_COMPATIBILITY);
}
});
ideaProject.getWildcards().addAll(Arrays.asList("!?*.class", "!?*.scala", "!?*.groovy", "!?*.java"));
conventionMapping.map("modules", new Callable<List<IdeaModule>>() {
@Override
public List<IdeaModule> call() {
return Lists.newArrayList(Iterables.transform(Sets.filter(project.getRootProject().getAllprojects(), new Predicate<Project>() {
@Override
public boolean apply(Project p) {
return p.getPlugins().hasPlugin(IdeaPlugin.class);
}
}), new Function<Project, IdeaModule>() {
@Override
public IdeaModule apply(Project p) {
return ideaModelFor(p).getModule();
}
}));
}
});
conventionMapping.map("pathFactory", new Callable<PathFactory>() {
@Override
public PathFactory call() {
return new PathFactory().addPathVariable("PROJECT_DIR", projectTask.get().getOutputFile().getParentFile());
}
});
addWorker(projectTask, IDEA_PROJECT_TASK_NAME);
addWorkspace(ideaProject);
}
}
use of org.gradle.internal.xml.XmlTransformer in project gradle by gradle.
the class IdeaPlugin method configureIdeaWorkspace.
private void configureIdeaWorkspace(final Project project) {
if (isRoot()) {
final IdeaWorkspace workspace = project.getObjects().newInstance(IdeaWorkspace.class);
workspace.setIws(new XmlFileContentMerger(new XmlTransformer()));
ideaModel.setWorkspace(workspace);
final TaskProvider<GenerateIdeaWorkspace> task = project.getTasks().register(IDEA_WORKSPACE_TASK_NAME, GenerateIdeaWorkspace.class, workspace);
task.configure(new Action<GenerateIdeaWorkspace>() {
@Override
public void execute(GenerateIdeaWorkspace task) {
task.setDescription("Generates an IDEA workspace file (IWS)");
task.setOutputFile(new File(project.getProjectDir(), project.getName() + ".iws"));
}
});
addWorker(task, IDEA_WORKSPACE_TASK_NAME, false);
}
}
Aggregations