use of org.gradle.api.plugins.Convention in project gradle by gradle.
the class ExtensibleDynamicObjectTest method canGetAndSetPropertyDefinedByConventionObject.
@Test
public void canGetAndSetPropertyDefinedByConventionObject() {
Bean bean = new Bean();
Convention convention = bean.extensibleDynamicObject.getConvention();
ConventionBean conventionBean = new ConventionBean();
convention.getPlugins().put("test", conventionBean);
conventionBean.setConventionProperty("value");
assertThat(bean.getProperty("conventionProperty"), equalTo((Object) "value"));
bean.setProperty("conventionProperty", "new value");
assertThat(bean.getProperty("conventionProperty"), equalTo((Object) "new value"));
assertThat(conventionBean.getConventionProperty(), equalTo((Object) "new value"));
}
use of org.gradle.api.plugins.Convention in project gradle by gradle.
the class ScalaBasePlugin method configureScalaCompile.
private static void configureScalaCompile(final Project project, JavaBasePlugin javaPlugin, final SourceSet sourceSet) {
String taskName = sourceSet.getCompileTaskName("scala");
final ScalaCompile scalaCompile = project.getTasks().create(taskName, ScalaCompile.class);
scalaCompile.dependsOn(sourceSet.getCompileJavaTaskName());
javaPlugin.configureForSourceSet(sourceSet, scalaCompile);
Convention scalaConvention = (Convention) InvokerHelper.getProperty(sourceSet, "convention");
ScalaSourceSet scalaSourceSet = scalaConvention.findPlugin(ScalaSourceSet.class);
scalaCompile.setDescription("Compiles the " + scalaSourceSet.getScala() + ".");
scalaCompile.setSource(scalaSourceSet.getScala());
project.getTasks().getByName(sourceSet.getClassesTaskName()).dependsOn(taskName);
// cannot use convention mapping because the resulting object won't be serializable
// cannot compute at task execution time because we need association with source set
project.getGradle().addBuildListener(new BuildAdapter() {
@Override
public void projectsEvaluated(Gradle gradle) {
IncrementalCompileOptions incrementalOptions = scalaCompile.getScalaCompileOptions().getIncrementalOptions();
if (incrementalOptions.getAnalysisFile() == null) {
String analysisFilePath = project.getBuildDir().getPath() + "/tmp/scala/compilerAnalysis/" + scalaCompile.getName() + ".analysis";
incrementalOptions.setAnalysisFile(new File(analysisFilePath));
}
if (incrementalOptions.getPublishedCode() == null) {
Jar jarTask = (Jar) project.getTasks().findByName(sourceSet.getJarTaskName());
incrementalOptions.setPublishedCode(jarTask == null ? null : jarTask.getArchivePath());
}
}
});
}
use of org.gradle.api.plugins.Convention in project gradle by gradle.
the class ScalaBasePlugin method configureSourceSetDefaults.
private static void configureSourceSetDefaults(final Project project, final SourceDirectorySetFactory sourceDirectorySetFactory) {
final JavaBasePlugin javaPlugin = project.getPlugins().getPlugin(JavaBasePlugin.class);
project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(new Action<SourceSet>() {
@Override
public void execute(final SourceSet sourceSet) {
String displayName = (String) InvokerHelper.invokeMethod(sourceSet, "getDisplayName", null);
Convention sourceSetConvention = (Convention) InvokerHelper.getProperty(sourceSet, "convention");
DefaultScalaSourceSet scalaSourceSet = new DefaultScalaSourceSet(displayName, sourceDirectorySetFactory);
sourceSetConvention.getPlugins().put("scala", scalaSourceSet);
final SourceDirectorySet scalaDirectorySet = scalaSourceSet.getScala();
scalaDirectorySet.srcDir(new Callable<File>() {
@Override
public File call() throws Exception {
return project.file("src/" + sourceSet.getName() + "/scala");
}
});
sourceSet.getAllJava().source(scalaDirectorySet);
sourceSet.getAllSource().source(scalaDirectorySet);
sourceSet.getResources().getFilter().exclude(new Spec<FileTreeElement>() {
@Override
public boolean isSatisfiedBy(FileTreeElement element) {
return scalaDirectorySet.contains(element.getFile());
}
});
configureScalaCompile(project, javaPlugin, sourceSet);
}
});
}
Aggregations