use of org.gradle.api.internal.ConventionMapping in project gradle by gradle.
the class PlayIdeaPlugin method configureIdeaModule.
@Mutate
public void configureIdeaModule(@Path("tasks.ideaModule") GenerateIdeaModule ideaModule, @Path("binaries.playBinary") final PlayApplicationBinarySpec playApplicationBinarySpec, @Path("buildDir") final File buildDir, ConfigurationContainer configurations, final FileResolver fileResolver) {
IdeaModule module = ideaModule.getModule();
module.setScopes(buildScopes(configurations));
ConventionMapping conventionMapping = conventionMappingFor(module);
conventionMapping.map("sourceDirs", new Callable<Set<File>>() {
@Override
public Set<File> call() throws Exception {
// TODO: Assets should probably be a source set too
Set<File> sourceDirs = Sets.newHashSet(playApplicationBinarySpec.getAssets().getAssetDirs());
return CollectionUtils.inject(sourceDirs, playApplicationBinarySpec.getInputs(), new Action<CollectionUtils.InjectionStep<Set<File>, LanguageSourceSet>>() {
@Override
public void execute(CollectionUtils.InjectionStep<Set<File>, LanguageSourceSet> step) {
step.getTarget().addAll(step.getItem().getSource().getSrcDirs());
}
});
}
});
conventionMapping.map("testSourceDirs", new Callable<Set<File>>() {
@Override
public Set<File> call() throws Exception {
// TODO: This should be modeled as a source set
return Collections.singleton(fileResolver.resolve("test"));
}
});
conventionMapping.map("singleEntryLibraries", new Callable<Map<String, Iterable<File>>>() {
@Override
public Map<String, Iterable<File>> call() throws Exception {
return ImmutableMap.<String, Iterable<File>>builder().put("COMPILE", Collections.singleton(playApplicationBinarySpec.getClasses().getClassesDir())).put("RUNTIME", playApplicationBinarySpec.getClasses().getResourceDirs()).put("TEST", Collections.singleton(new File(buildDir, "playBinary/testClasses"))).build();
}
});
module.setScalaPlatform(playApplicationBinarySpec.getTargetPlatform().getScalaPlatform());
conventionMapping.map("targetBytecodeVersion", new Callable<JavaVersion>() {
@Override
public JavaVersion call() throws Exception {
return getTargetJavaVersion(playApplicationBinarySpec);
}
});
conventionMapping.map("languageLevel", new Callable<IdeaLanguageLevel>() {
@Override
public IdeaLanguageLevel call() throws Exception {
return new IdeaLanguageLevel(getTargetJavaVersion(playApplicationBinarySpec));
}
});
ideaModule.dependsOn(playApplicationBinarySpec.getInputs());
ideaModule.dependsOn(playApplicationBinarySpec.getAssets());
}
use of org.gradle.api.internal.ConventionMapping in project gradle by gradle.
the class EclipsePlugin method configureEclipseProject.
private void configureEclipseProject(final Project project, final EclipseModel model) {
maybeAddTask(project, this, ECLIPSE_PROJECT_TASK_NAME, GenerateEclipseProject.class, new Action<GenerateEclipseProject>() {
@Override
public void execute(GenerateEclipseProject task) {
final EclipseProject projectModel = task.getProjectModel();
//task properties:
task.setDescription("Generates the Eclipse project file.");
task.setInputFile(project.file(".project"));
task.setOutputFile(project.file(".project"));
//model:
model.setProject(projectModel);
projectModel.setName(project.getName());
final ConventionMapping convention = ((IConventionAware) projectModel).getConventionMapping();
convention.map("comment", new Callable<String>() {
@Override
public String call() {
return project.getDescription();
}
});
project.getPlugins().withType(JavaBasePlugin.class, new Action<JavaBasePlugin>() {
@Override
public void execute(JavaBasePlugin javaBasePlugin) {
if (!project.getPlugins().hasPlugin(EarPlugin.class)) {
projectModel.buildCommand("org.eclipse.jdt.core.javabuilder");
}
projectModel.natures("org.eclipse.jdt.core.javanature");
convention.map("linkedResources", new Callable<Set<Link>>() {
@Override
public Set<Link> call() {
return new LinkedResourcesCreator().links(project);
}
});
}
});
project.getPlugins().withType(GroovyBasePlugin.class, new Action<GroovyBasePlugin>() {
@Override
public void execute(GroovyBasePlugin groovyBasePlugin) {
projectModel.getNatures().add(projectModel.getNatures().indexOf("org.eclipse.jdt.core.javanature"), "org.eclipse.jdt.groovy.core.groovyNature");
}
});
project.getPlugins().withType(ScalaBasePlugin.class, new Action<ScalaBasePlugin>() {
@Override
public void execute(ScalaBasePlugin scalaBasePlugin) {
projectModel.getBuildCommands().set(Iterables.indexOf(projectModel.getBuildCommands(), new Predicate<BuildCommand>() {
@Override
public boolean apply(BuildCommand buildCommand) {
return buildCommand.getName().equals("org.eclipse.jdt.core.javabuilder");
}
}), new BuildCommand("org.scala-ide.sdt.core.scalabuilder"));
projectModel.getNatures().add(projectModel.getNatures().indexOf("org.eclipse.jdt.core.javanature"), "org.scala-ide.sdt.core.scalanature");
}
});
}
});
}
use of org.gradle.api.internal.ConventionMapping in project gradle by gradle.
the class PmdPlugin method configureTaskConventionMapping.
private void configureTaskConventionMapping(Configuration configuration, Pmd task) {
ConventionMapping taskMapping = task.getConventionMapping();
taskMapping.map("pmdClasspath", Callables.returning(configuration));
taskMapping.map("ruleSets", new Callable<List<String>>() {
@Override
public List<String> call() {
return extension.getRuleSets();
}
});
taskMapping.map("ruleSetConfig", new Callable<TextResource>() {
@Override
public TextResource call() {
return extension.getRuleSetConfig();
}
});
taskMapping.map("ruleSetFiles", new Callable<FileCollection>() {
@Override
public FileCollection call() {
return extension.getRuleSetFiles();
}
});
taskMapping.map("ignoreFailures", new Callable<Boolean>() {
@Override
public Boolean call() {
return extension.isIgnoreFailures();
}
});
taskMapping.map("rulePriority", new Callable<Integer>() {
@Override
public Integer call() {
return extension.getRulePriority();
}
});
taskMapping.map("consoleOutput", new Callable<Boolean>() {
@Override
public Boolean call() {
return extension.isConsoleOutput();
}
});
taskMapping.map("targetJdk", new Callable<TargetJdk>() {
@Override
public TargetJdk call() {
return extension.getTargetJdk();
}
});
}
use of org.gradle.api.internal.ConventionMapping in project gradle by gradle.
the class EclipsePlugin method configureEclipseJdt.
private void configureEclipseJdt(final Project project, final EclipseModel model) {
final EclipsePlugin eclipsePlugin = this;
project.getPlugins().withType(JavaBasePlugin.class, new Action<JavaBasePlugin>() {
@Override
public void execute(JavaBasePlugin javaBasePlugin) {
maybeAddTask(project, eclipsePlugin, ECLIPSE_JDT_TASK_NAME, GenerateEclipseJdt.class, new Action<GenerateEclipseJdt>() {
@Override
public void execute(GenerateEclipseJdt task) {
// task properties:
task.setDescription("Generates the Eclipse JDT settings file.");
task.setOutputFile(project.file(".settings/org.eclipse.jdt.core.prefs"));
task.setInputFile(project.file(".settings/org.eclipse.jdt.core.prefs"));
// model properties:
EclipseJdt jdt = task.getJdt();
model.setJdt(jdt);
ConventionMapping conventionMapping = ((IConventionAware) jdt).getConventionMapping();
conventionMapping.map("sourceCompatibility", new Callable<JavaVersion>() {
@Override
public JavaVersion call() {
return project.getConvention().getPlugin(JavaPluginConvention.class).getSourceCompatibility();
}
});
conventionMapping.map("targetCompatibility", new Callable<JavaVersion>() {
@Override
public JavaVersion call() {
return project.getConvention().getPlugin(JavaPluginConvention.class).getTargetCompatibility();
}
});
conventionMapping.map("javaRuntimeName", new Callable<String>() {
@Override
public String call() {
return eclipseJavaRuntimeNameFor(project.getConvention().getPlugin(JavaPluginConvention.class).getTargetCompatibility());
}
});
}
});
}
});
}
use of org.gradle.api.internal.ConventionMapping in project gradle by gradle.
the class EclipseWtpPlugin method configureEclipseWtpComponent.
private void configureEclipseWtpComponent(final Project project, final EclipseModel model) {
maybeAddTask(project, this, ECLIPSE_WTP_COMPONENT_TASK_NAME, GenerateEclipseWtpComponent.class, new Action<GenerateEclipseWtpComponent>() {
@Override
public void execute(final GenerateEclipseWtpComponent task) {
// task properties:
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"));
// model properties:
model.getWtp().setComponent(task.getComponent());
((IConventionAware) task.getComponent()).getConventionMapping().map("deployName", new Callable<String>() {
@Override
public String call() throws Exception {
return model.getProject().getName();
}
});
final Set<Configuration> libConfigurations = task.getComponent().getLibConfigurations();
final Set<Configuration> rootConfigurations = task.getComponent().getRootConfigurations();
final Set<Configuration> minusConfigurations = task.getComponent().getMinusConfigurations();
project.getPlugins().withType(JavaPlugin.class, new Action<JavaPlugin>() {
@Override
public void execute(JavaPlugin javaPlugin) {
if (hasWarOrEarPlugin(project)) {
return;
}
libConfigurations.add(project.getConfigurations().getByName("runtime"));
task.getComponent().setClassesDeployPath("/");
((IConventionAware) task.getComponent()).getConventionMapping().map("libDeployPath", new Callable<String>() {
@Override
public String call() throws Exception {
return "../";
}
});
((IConventionAware) task.getComponent()).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) {
libConfigurations.add(project.getConfigurations().getByName("runtime"));
minusConfigurations.add(project.getConfigurations().getByName("providedRuntime"));
task.getComponent().setClassesDeployPath("/WEB-INF/classes");
ConventionMapping convention = ((IConventionAware) task.getComponent()).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")).getBaseName();
}
});
convention.map("resources", new Callable<List<WbResource>>() {
@Override
public List<WbResource> call() throws Exception {
return Lists.newArrayList(new WbResource("/", project.getConvention().getPlugin(WarPluginConvention.class).getWebAppDirName()));
}
});
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) {
rootConfigurations.clear();
rootConfigurations.add(project.getConfigurations().getByName("deploy"));
libConfigurations.clear();
libConfigurations.add(project.getConfigurations().getByName("earlib"));
task.getComponent().setClassesDeployPath("/");
final ConventionMapping convention = ((IConventionAware) task.getComponent()).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 project.files(project.getConvention().getPlugin(EarPluginConvention.class).getAppDirName()).getFiles();
}
});
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