use of org.gradle.api.internal.ConventionMapping in project gradle by gradle.
the class IdeaPlugin method configureIdeaModuleForJava.
private void configureIdeaModuleForJava(final Project project) {
project.getTasks().withType(GenerateIdeaModule.class, new Action<GenerateIdeaModule>() {
@Override
public void execute(GenerateIdeaModule ideaModule) {
// Defaults
setupScopes(ideaModule);
// Convention
ConventionMapping convention = ((IConventionAware) ideaModule.getModule()).getConventionMapping();
convention.map("sourceDirs", new Callable<Set<File>>() {
@Override
public Set<File> call() {
SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();
return sourceSets.getByName("main").getAllSource().getSrcDirs();
}
});
convention.map("testSourceDirs", new Callable<Set<File>>() {
@Override
public Set<File> call() {
SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();
return sourceSets.getByName("test").getAllSource().getSrcDirs();
}
});
convention.map("singleEntryLibraries", new Callable<Map<String, FileCollection>>() {
@Override
public Map<String, FileCollection> call() {
SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();
LinkedHashMap<String, FileCollection> map = new LinkedHashMap<String, FileCollection>(2);
map.put("RUNTIME", sourceSets.getByName("main").getOutput().getDirs());
map.put("TEST", sourceSets.getByName("test").getOutput().getDirs());
return map;
}
});
convention.map("targetBytecodeVersion", new Callable<JavaVersion>() {
@Override
public JavaVersion call() {
JavaVersion moduleTargetBytecodeLevel = project.getConvention().getPlugin(JavaPluginConvention.class).getTargetCompatibility();
return includeModuleBytecodeLevelOverride(project.getRootProject(), moduleTargetBytecodeLevel) ? moduleTargetBytecodeLevel : null;
}
});
convention.map("languageLevel", new Callable<IdeaLanguageLevel>() {
@Override
public IdeaLanguageLevel call() {
IdeaLanguageLevel moduleLanguageLevel = new IdeaLanguageLevel(project.getConvention().getPlugin(JavaPluginConvention.class).getSourceCompatibility());
return includeModuleLanguageLevelOverride(project.getRootProject(), moduleLanguageLevel) ? moduleLanguageLevel : null;
}
});
// Dependencies
ideaModule.dependsOn(new Callable<FileCollection>() {
@Override
public FileCollection call() {
SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();
return sourceSets.getByName("main").getOutput().getDirs().plus(sourceSets.getByName("test").getOutput().getDirs());
}
});
}
});
}
use of org.gradle.api.internal.ConventionMapping in project gradle by gradle.
the class IdeaPlugin method configureIdeaProject.
private void configureIdeaProject(final Project project) {
if (isRoot()) {
final GenerateIdeaProject projectTask = project.getTasks().create("ideaProject", GenerateIdeaProject.class);
projectTask.setDescription("Generates IDEA project file (IPR)");
XmlFileContentMerger ipr = new XmlFileContentMerger(projectTask.getXmlTransformer());
IdeaProject ideaProject = instantiator.newInstance(IdeaProject.class, project, ipr);
projectTask.setIdeaProject(ideaProject);
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.getOutputFile().getParentFile());
}
});
addWorker(projectTask);
addWorkspace(ideaProject);
}
}
use of org.gradle.api.internal.ConventionMapping in project gradle by gradle.
the class SigningExtension method addSignatureSpecConventions.
/**
* Adds conventions to the given spec, using this settings object's default signatory and signature type as the default signatory and signature type for the spec.
*/
protected void addSignatureSpecConventions(SignatureSpec spec) {
if (!(spec instanceof IConventionAware)) {
throw new InvalidUserDataException("Cannot add conventions to signature spec \'" + String.valueOf(spec) + "\' as it is not convention aware");
}
ConventionMapping conventionMapping = ((IConventionAware) spec).getConventionMapping();
conventionMapping.map("signatory", new Callable<Signatory>() {
public Signatory call() {
return getSignatory();
}
});
conventionMapping.map("signatureType", new Callable<SignatureType>() {
public SignatureType call() {
return getSignatureType();
}
});
conventionMapping.map("required", new Callable<Boolean>() {
public Boolean call() {
return isRequired();
}
});
}
use of org.gradle.api.internal.ConventionMapping in project gradle by gradle.
the class FindBugsPlugin method configureForSourceSet.
@Override
protected void configureForSourceSet(final SourceSet sourceSet, FindBugs task) {
task.setDescription("Run FindBugs analysis for " + sourceSet.getName() + " classes");
task.setSource(sourceSet.getAllJava());
ConventionMapping taskMapping = task.getConventionMapping();
taskMapping.map("classes", new Callable<FileCollection>() {
@Override
public FileCollection call() {
return sourceSet.getOutput().getClassesDirs();
}
});
taskMapping.map("classpath", new Callable<FileCollection>() {
@Override
public FileCollection call() {
return sourceSet.getCompileClasspath();
}
});
}
use of org.gradle.api.internal.ConventionMapping in project gradle by gradle.
the class JavaBasePlugin method configureForSourceSet.
@Deprecated
public void configureForSourceSet(final SourceSet sourceSet, final AbstractCompile compile) {
SingleMessageLogger.nagUserOfDiscontinuedMethod("configureForSourceSet(SourceSet, AbstractCompile)");
ConventionMapping conventionMapping;
compile.setDescription("Compiles the " + sourceSet.getJava() + ".");
conventionMapping = compile.getConventionMapping();
compile.setSource(sourceSet.getJava());
conventionMapping.map("classpath", new Callable<Object>() {
public Object call() throws Exception {
return sourceSet.getCompileClasspath().plus(compile.getProject().files(sourceSet.getJava().getOutputDir()));
}
});
// TODO: This doesn't really work any more, but configureForSourceSet is a public API.
// This should allow builds to continue to work, but it will kill build caching for JavaCompile
conventionMapping.map("destinationDir", new Callable<Object>() {
public Object call() throws Exception {
return sourceSet.getOutput().getClassesDir();
}
});
}
Aggregations