use of org.gradle.api.internal.plugins.DslObject in project gradle by gradle.
the class AsmBackedClassGeneratorTest method honorsPublicType.
@Test
public void honorsPublicType() throws Exception {
DslObject dslObject = new DslObject(newInstance(BeanWithPublicType.class));
assertEquals(typeOf(Bean.class), dslObject.getPublicType());
}
use of org.gradle.api.internal.plugins.DslObject in project gradle by gradle.
the class AsmBackedClassGeneratorTest method canAddDynamicPropertiesAndMethodsToJavaObject.
@Test
public void canAddDynamicPropertiesAndMethodsToJavaObject() throws Exception {
Bean bean = newInstance(Bean.class);
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.
@SuppressWarnings("deprecation")
@Override
public void apply(final Project project) {
project.getPluginManager().apply(JavaLibraryPlugin.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.");
((DeprecatableConfiguration) antlrConfiguration).deprecateForConsumption(deprecation -> deprecation.willBecomeAnErrorInGradle8().withUpgradeGuideSection(7, "plugin_configuration_consumption"));
antlrConfiguration.defaultDependencies(dependencies -> dependencies.add(project.getDependencies().create("antlr:antlr:2.7.7@jar")));
Configuration apiConfiguration = project.getConfigurations().getByName(JavaPlugin.API_CONFIGURATION_NAME);
apiConfiguration.extendsFrom(antlrConfiguration);
// Wire the antlr configuration into all antlr tasks
project.getTasks().withType(AntlrTask.class).configureEach(antlrTask -> antlrTask.getConventionMapping().map("antlrClasspath", () -> project.getConfigurations().getByName(ANTLR_CONFIGURATION_NAME)));
project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets().all(new Action<SourceSet>() {
@Override
public void execute(final SourceSet sourceSet) {
// for each source set we will:
// 1) Add a new 'antlr' virtual directory mapping
org.gradle.api.plugins.antlr.internal.AntlrSourceVirtualDirectoryImpl antlrDirectoryDelegate = new org.gradle.api.plugins.antlr.internal.AntlrSourceVirtualDirectoryImpl(((DefaultSourceSet) sourceSet).getDisplayName(), objectFactory);
new DslObject(sourceSet).getConvention().getPlugins().put(AntlrSourceVirtualDirectory.NAME, antlrDirectoryDelegate);
sourceSet.getExtensions().add(AntlrSourceDirectorySet.class, AntlrSourceVirtualDirectory.NAME, antlrDirectoryDelegate.getAntlr());
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");
// 3) 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);
sourceSet.getJava().srcDir(outputDirectory);
project.getTasks().register(taskName, AntlrTask.class, new Action<AntlrTask>() {
@Override
public void execute(AntlrTask antlrTask) {
antlrTask.setDescription("Processes the " + sourceSet.getName() + " Antlr grammars.");
// 4) set up convention mapping for default sources (allows user to not have to specify)
antlrTask.setSource(antlrDirectoryDelegate.getAntlr());
antlrTask.setOutputDirectory(outputDirectory);
}
});
// 5) register fact that antlr should be run before compiling
project.getTasks().named(sourceSet.getCompileJavaTaskName(), new Action<Task>() {
@Override
public void execute(Task task) {
task.dependsOn(taskName);
}
});
}
});
}
use of org.gradle.api.internal.plugins.DslObject in project webpieces by deanhiller.
the class TemplateCompilerPlugin method configureSourceSetDefaults.
private void configureSourceSetDefaults(Project project) {
log.debug("setup configure source set defaults");
JavaPluginExtension javaPluginExtension = javaPluginExtension();
// SourceSetContainer sourceSets = javaPluginExtension.getSourceSets();
// SourceSet main = sourceSets.findByName(SourceSet.MAIN_SOURCE_SET_NAME);
// SourceSet test = sourceSets.findByName(SourceSet.TEST_SOURCE_SET_NAME);
//
// test.setRuntimeClasspath(project.getObjects().fileCollection().from(test.getOutput(), main.getOutput(), project.getConfigurations().getByName(JavaPlugin.TEST_RUNTIME_CLASSPATH_CONFIGURATION_NAME)));
// // Register the project's source set output directories
// sourceSets.all(sourceSet ->
// buildOutputCleanupRegistry.registerOutputs(sourceSet.getOutput())
// );
javaPluginExtension.getSourceSets().all(sourceSet -> {
String name = "templates";
final DefaultTemplateSourceSet groovySourceSet = new DefaultTemplateSourceSet(name, ((DefaultSourceSet) sourceSet).getDisplayName(), objectFactory);
(new DslObject(sourceSet)).getConvention().getPlugins().put("templates", groovySourceSet);
// copied from JavaBasePlugin
processCopyTemplateResources(project, sourceSet);
// sourceSet.getExtensions().add(GroovySourceDirectorySet.class, "groovy", groovySourceSet.getGroovy()); //We do not need this one
SourceDirectorySet groovySource = groovySourceSet.getTemplateDirSet();
groovySource.srcDir("src/" + sourceSet.getName() + "/java");
sourceSet.getResources().getFilter().exclude(SerializableLambdas.spec((element) -> {
return groovySource.contains(element.getFile());
}));
sourceSet.getAllJava().source(groovySource);
sourceSet.getAllSource().source(groovySource);
// copy over but comment as I think no longer needed anymore
// NEEDED?: configureOutputDirectoryForSourceSet(sourceSet, groovySourceSet.getTemplateDirSet(), project);
final TaskProvider<TemplateCompile> compileTask = project.getTasks().register(sourceSet.getCompileTaskName("templates"), TemplateCompile.class, compile -> {
JvmPluginsHelper.configureForSourceSet(sourceSet, groovySource, compile, compile.getOptions(), project);
// copy over but comment as I think no longer needed anymore
// NEEDED?: compile.dependsOn(sourceSet.getCompileJavaTaskName());
compile.setDescription("Compiles the " + sourceSet.getName() + " Webpieces Templates.");
compile.setSource(groovySource);
// copy over but comment as I think no longer needed anymore
// NEEDED?: compile.setDestinationDir(new File(project.getBuildDir(), "classes/" + groovySourceSet.getTemplateDirSet().getName() + "/" + sourceSet.getName()));
// we do not support different versions of java from gradle right now...
// compile.getJavaLauncher().convention(getToolchainTool(project, JavaToolchainService::launcherFor));
});
JvmPluginsHelper.configureOutputDirectoryForSourceSet(sourceSet, groovySource, this.project, compileTask, compileTask.map(TemplateCompile::getOptions));
this.jvmPluginServices.useDefaultTargetPlatformInference(this.project.getConfigurations().getByName(sourceSet.getCompileClasspathConfigurationName()), compileTask);
this.jvmPluginServices.useDefaultTargetPlatformInference(this.project.getConfigurations().getByName(sourceSet.getRuntimeClasspathConfigurationName()), compileTask);
this.project.getTasks().named(sourceSet.getClassesTaskName(), (task) -> {
task.dependsOn(new Object[] { compileTask });
});
// Ties resources to be done first or something but we don't need this
// this.project.getConfigurations().getByName(sourceSet.getCompileClasspathConfigurationName()).attributes((attrs) -> {
// attrs.attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, (LibraryElements)this.project.getObjects().named(LibraryElements.class, "classes+resources"));
// });
});
// this.project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(new ConfigureAction(this.project, objectFactory));
}
use of org.gradle.api.internal.plugins.DslObject in project gradle-apt-plugin by tbroyer.
the class AptPlugin34to42 method configureCompileTaskForSourceSet.
@Override
protected void configureCompileTaskForSourceSet(Project project, final SourceSet sourceSet, AbstractCompile task, CompileOptions compileOptions) {
if (!(task instanceof JavaCompile)) {
prevImpl.configureCompileTaskForSourceSet(project, sourceSet, task, compileOptions);
return;
}
compileOptions.setAnnotationProcessorPath(project.files(new Callable<FileCollection>() {
@Override
public FileCollection call() {
return new DslObject(sourceSet).getConvention().getPlugin(AptPlugin.AptSourceSetConvention.class).getAnnotationProcessorPath();
}
}));
task.getConvention().getPlugin(AptPlugin.AptConvention.class).setGeneratedSourcesDestinationDir(new Callable<File>() {
@Override
public File call() {
return new DslObject(sourceSet.getOutput()).getConvention().getPlugin(AptPlugin.AptSourceSetOutputConvention.class).getGeneratedSourcesDir();
}
});
}
Aggregations