use of org.gradle.api.internal.plugins.DslObject in project gradle by gradle.
the class AsmBackedClassGeneratorTest method generatesDslObjectCompatibleObject.
@Test
public void generatesDslObjectCompatibleObject() throws Exception {
DslObject dslObject = new DslObject(generator.generate(Bean.class).newInstance());
assertEquals(Bean.class, dslObject.getDeclaredType());
assertNotNull(dslObject.getConventionMapping());
assertNotNull(dslObject.getConvention());
assertNotNull(dslObject.getExtensions());
assertNotNull(dslObject.getAsDynamicObject());
}
use of org.gradle.api.internal.plugins.DslObject in project gradle by gradle.
the class AsmBackedClassGeneratorTest method canAddDynamicPropertiesAndMethodsToGroovyObject.
@Test
public void canAddDynamicPropertiesAndMethodsToGroovyObject() throws Exception {
TestDecoratedGroovyBean bean = generator.generate(TestDecoratedGroovyBean.class).newInstance();
DynamicObjectAware dynamicObjectAware = (DynamicObjectAware) bean;
ConventionObject conventionObject = new ConventionObject();
new DslObject(dynamicObjectAware).getConvention().getPlugins().put("plugin", conventionObject);
call("{ it.conventionProperty = 'value' }", bean);
assertThat(conventionObject.getConventionProperty(), equalTo("value"));
assertThat(call("{ it.hasProperty('conventionProperty') }", bean), notNullValue());
assertThat(call("{ it.conventionProperty }", bean), equalTo((Object) "value"));
assertThat(call("{ it.conventionMethod('value') }", bean), equalTo((Object) "[value]"));
assertThat(call("{ it.invokeMethod('conventionMethod', 'value') }", bean), equalTo((Object) "[value]"));
}
use of org.gradle.api.internal.plugins.DslObject in project gradle by gradle.
the class AntlrPlugin method apply.
public void apply(final Project project) {
project.getPluginManager().apply(JavaPlugin.class);
// set up a configuration named 'antlr' for the user to specify the antlr libs to use in case
// they want a specific version etc.
final Configuration antlrConfiguration = project.getConfigurations().create(ANTLR_CONFIGURATION_NAME).setVisible(false).setDescription("The Antlr libraries to be used for this project.");
antlrConfiguration.defaultDependencies(new Action<DependencySet>() {
@Override
public void execute(DependencySet dependencies) {
dependencies.add(project.getDependencies().create("antlr:antlr:2.7.7@jar"));
}
});
project.getConfigurations().getByName(COMPILE_CONFIGURATION_NAME).extendsFrom(antlrConfiguration);
// Wire the antlr configuration into all antlr tasks
project.getTasks().withType(AntlrTask.class, new Action<AntlrTask>() {
public void execute(AntlrTask antlrTask) {
antlrTask.getConventionMapping().map("antlrClasspath", new Callable<Object>() {
public Object call() throws Exception {
return project.getConfigurations().getByName(ANTLR_CONFIGURATION_NAME);
}
});
}
});
project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(new Action<SourceSet>() {
public void execute(SourceSet sourceSet) {
// for each source set we will:
// 1) Add a new 'antlr' virtual directory mapping
final AntlrSourceVirtualDirectoryImpl antlrDirectoryDelegate = new AntlrSourceVirtualDirectoryImpl(((DefaultSourceSet) sourceSet).getDisplayName(), sourceDirectorySetFactory);
new DslObject(sourceSet).getConvention().getPlugins().put(AntlrSourceVirtualDirectory.NAME, antlrDirectoryDelegate);
final String srcDir = "src/" + sourceSet.getName() + "/antlr";
antlrDirectoryDelegate.getAntlr().srcDir(srcDir);
sourceSet.getAllSource().source(antlrDirectoryDelegate.getAntlr());
// 2) create an AntlrTask for this sourceSet following the gradle
// naming conventions via call to sourceSet.getTaskName()
final String taskName = sourceSet.getTaskName("generate", "GrammarSource");
AntlrTask antlrTask = project.getTasks().create(taskName, AntlrTask.class);
antlrTask.setDescription("Processes the " + sourceSet.getName() + " Antlr grammars.");
// 3) set up convention mapping for default sources (allows user to not have to specify)
antlrTask.setSource(antlrDirectoryDelegate.getAntlr());
// 4) Set up the Antlr output directory (adding to javac inputs!)
final String outputDirectoryName = project.getBuildDir() + "/generated-src/antlr/" + sourceSet.getName();
final File outputDirectory = new File(outputDirectoryName);
antlrTask.setOutputDirectory(outputDirectory);
sourceSet.getJava().srcDir(outputDirectory);
// 6) register fact that antlr should be run before compiling
project.getTasks().getByName(sourceSet.getCompileJavaTaskName()).dependsOn(taskName);
}
});
}
use of org.gradle.api.internal.plugins.DslObject in project gradle by gradle.
the class BuildDashboardPlugin method apply.
public void apply(final Project project) {
project.getPluginManager().apply(ReportingBasePlugin.class);
final GenerateBuildDashboard buildDashboardTask = project.getTasks().create(BUILD_DASHBOARD_TASK_NAME, GenerateBuildDashboard.class);
buildDashboardTask.setDescription("Generates a dashboard of all the reports produced by this build.");
buildDashboardTask.setGroup("reporting");
DirectoryReport htmlReport = buildDashboardTask.getReports().getHtml();
ConventionMapping htmlReportConventionMapping = new DslObject(htmlReport).getConventionMapping();
htmlReportConventionMapping.map("destination", new Callable<Object>() {
public Object call() throws Exception {
return project.getExtensions().getByType(ReportingExtension.class).file("buildDashboard");
}
});
Action<Task> captureReportingTasks = new Action<Task>() {
public void execute(Task task) {
if (!(task instanceof Reporting)) {
return;
}
Reporting reporting = (Reporting) task;
buildDashboardTask.aggregate(reporting);
if (!task.equals(buildDashboardTask)) {
task.finalizedBy(buildDashboardTask);
}
}
};
for (Project aProject : project.getAllprojects()) {
aProject.getTasks().all(captureReportingTasks);
}
}
Aggregations