project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().allObjects(
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(),
projectInternal.getFileResolver());
((DynamicObjectAware) sourceSet).getConvention().getPlugins().put(
AntlrSourceVirtualDirectory.NAME, antlrDirectoryDelegate);
final String srcDir = String.format("src/%s/antlr", sourceSet.getName());
antlrDirectoryDelegate.getAntlr().srcDir(srcDir);
sourceSet.getAllSource().add(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().add(taskName, AntlrTask.class);
antlrTask.setDescription(String.format("Processes the %s Antlr grammars.",
sourceSet.getName()));
// 3) set up convention mapping for default sources (allows user to not have to specify)
antlrTask.conventionMapping("defaultSource", new ConventionValue() {
public Object getValue(Convention convention, IConventionAware conventionAwareObject) {
return antlrDirectoryDelegate.getAntlr();
}
});
// 4) set up convention mapping for handling the 'antlr' dependency configuration
antlrTask.getConventionMapping().map("antlrClasspath", new ConventionValue() {