use of org.gradle.api.internal.IConventionAware 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.IConventionAware 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();
}
});
project.getPlugins().withType(JavaPlugin.class, new Action<JavaPlugin>() {
@Override
public void execute(JavaPlugin javaPlugin) {
if (hasWarOrEarPlugin(project)) {
return;
}
task.getComponent().setLibConfigurations(Sets.<Configuration>newHashSet(project.getConfigurations().getByName("runtime")));
task.getComponent().setMinusConfigurations(Sets.<Configuration>newHashSet());
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) {
task.getComponent().setLibConfigurations(Sets.<Configuration>newHashSet(project.getConfigurations().getByName("runtime")));
task.getComponent().setMinusConfigurations(Sets.<Configuration>newHashSet(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) {
task.getComponent().setRootConfigurations(Sets.<Configuration>newHashSet(project.getConfigurations().getByName("deploy")));
task.getComponent().setLibConfigurations(Sets.<Configuration>newHashSet(project.getConfigurations().getByName("earlib")));
task.getComponent().setMinusConfigurations(Sets.<Configuration>newHashSet());
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);
}
});
}
});
}
});
}
});
}
use of org.gradle.api.internal.IConventionAware in project gradle by gradle.
the class IdeaPlugin method configureIdeaProject.
private void configureIdeaProject(final Project project) {
if (isRoot(project)) {
final GenerateIdeaProject task = project.getTasks().create("ideaProject", GenerateIdeaProject.class);
task.setDescription("Generates IDEA project file (IPR)");
XmlFileContentMerger ipr = new XmlFileContentMerger(task.getXmlTransformer());
IdeaProject ideaProject = instantiator.newInstance(IdeaProject.class, project, ipr);
task.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() throws Exception {
return JavaVersion.current().toString();
}
});
conventionMapping.map("languageLevel", new Callable<IdeaLanguageLevel>() {
@Override
public IdeaLanguageLevel call() throws Exception {
JavaVersion maxSourceCompatibility = getMaxJavaModuleCompatibilityVersionFor(SOURCE_COMPATIBILITY);
return new IdeaLanguageLevel(maxSourceCompatibility);
}
});
conventionMapping.map("targetBytecodeVersion", new Callable<JavaVersion>() {
@Override
public JavaVersion call() throws Exception {
return getMaxJavaModuleCompatibilityVersionFor(TARGET_COMPATIBILITY);
}
});
ideaProject.setWildcards(Sets.newHashSet("!?*.class", "!?*.scala", "!?*.groovy", "!?*.java"));
conventionMapping.map("modules", new Callable<List<IdeaModule>>() {
@Override
public List<IdeaModule> call() throws Exception {
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() throws Exception {
return new PathFactory().addPathVariable("PROJECT_DIR", task.getOutputFile().getParentFile());
}
});
addWorker(task);
}
}
use of org.gradle.api.internal.IConventionAware 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.IConventionAware in project gradle by gradle.
the class OsgiPluginConvention method createDefaultOsgiManifest.
private OsgiManifest createDefaultOsgiManifest() {
OsgiManifest osgiManifest = project.getServices().get(Instantiator.class).newInstance(DefaultOsgiManifest.class, project.getFileResolver());
ConventionMapping mapping = ((IConventionAware) osgiManifest).getConventionMapping();
final OsgiHelper osgiHelper = new OsgiHelper();
mapping.map("version", new Callable<Object>() {
public Object call() throws Exception {
return osgiHelper.getVersion(project.getVersion().toString());
}
});
mapping.map("name", new Callable<Object>() {
public Object call() throws Exception {
return project.getConvention().getPlugin(BasePluginConvention.class).getArchivesBaseName();
}
});
mapping.map("symbolicName", new Callable<Object>() {
public Object call() throws Exception {
return osgiHelper.getBundleSymbolicName(project);
}
});
return osgiManifest;
}
Aggregations