use of org.gradle.api.file.SourceDirectorySet in project gradle by gradle.
the class DefaultSourceDirectorySet method doGetSrcDirTrees.
private Set<DirectoryTree> doGetSrcDirTrees() {
Set<DirectoryTree> result = new LinkedHashSet<DirectoryTree>();
for (Object path : source) {
if (path instanceof SourceDirectorySet) {
SourceDirectorySet nested = (SourceDirectorySet) path;
result.addAll(nested.getSrcDirTrees());
} else {
for (File srcDir : fileResolver.resolveFiles(path)) {
if (srcDir.exists() && !srcDir.isDirectory()) {
throw new InvalidUserDataException(String.format("Source directory '%s' is not a directory.", srcDir));
}
result.add(directoryFileTreeFactory.create(srcDir, patterns));
}
}
}
return result;
}
use of org.gradle.api.file.SourceDirectorySet in project gradle by gradle.
the class DefaultJvmLanguageSourceDirectoryBuilder method build.
void build() {
if (taskBuilder == null) {
throw new IllegalStateException("You must specify the task which will contribute classes from this source directory");
}
SourceDirectorySet langSrcDir = project.getObjects().sourceDirectorySet(name, description == null ? "Sources for " + name : description);
langSrcDir.srcDir("src/" + sourceSet.getName() + "/" + name);
DefaultCompileTaskDetails details = createTaskDetails(langSrcDir);
JvmPluginsHelper.configureOutputDirectoryForSourceSet(sourceSet, langSrcDir, project, details.task, details.task.map(task -> {
if (task instanceof HasCompileOptions) {
return ((HasCompileOptions) task).getOptions();
}
throw new UnsupportedOperationException("Unsupported compile task " + task.getClass().getName());
}), Cast.uncheckedCast(details.mapping));
if (includeInAllJava) {
sourceSet.getAllJava().source(langSrcDir);
}
sourceSet.getAllSource().source(langSrcDir);
project.getTasks().named(JavaPlugin.CLASSES_TASK_NAME).configure(classes -> classes.dependsOn(details.task));
}
use of org.gradle.api.file.SourceDirectorySet in project gradle by gradle.
the class SourceSetRenderer method renderSourceSetDirectories.
private void renderSourceSetDirectories(LanguageSourceSet sourceSet, TextReportBuilder builder) {
Set<File> srcDirs = sourceSet.getSource().getSrcDirs();
if (srcDirs.isEmpty()) {
builder.item("No source directories");
} else {
for (File file : srcDirs) {
builder.item("srcDir", file);
}
SourceDirectorySet source = sourceSet.getSource();
Set<String> includes = source.getIncludes();
if (!includes.isEmpty()) {
builder.item("includes", includes);
}
Set<String> excludes = source.getExcludes();
if (!excludes.isEmpty()) {
builder.item("excludes", excludes);
}
Set<String> filterIncludes = source.getFilter().getIncludes();
if (!filterIncludes.isEmpty()) {
builder.item("limit to", filterIncludes);
}
}
}
use of org.gradle.api.file.SourceDirectorySet in project gradle by gradle.
the class PrecompiledGroovyPluginsPlugin method exposeScriptsAsPlugins.
private void exposeScriptsAsPlugins(Project project) {
GradlePluginDevelopmentExtension pluginExtension = project.getExtensions().getByType(GradlePluginDevelopmentExtension.class);
SourceSet pluginSourceSet = pluginExtension.getPluginSourceSet();
FileTree scriptPluginFiles = pluginSourceSet.getAllSource().matching(PrecompiledGroovyScript::filterPluginFiles);
List<PrecompiledGroovyScript> scriptPlugins = scriptPluginFiles.getFiles().stream().map(file -> new PrecompiledGroovyScript(file, getTextFileResourceLoader())).peek(scriptPlugin -> validateScriptPlugin(project, scriptPlugin)).collect(Collectors.toList());
declarePluginMetadata(pluginExtension, scriptPlugins);
DirectoryProperty buildDir = project.getLayout().getBuildDirectory();
TaskContainer tasks = project.getTasks();
TaskProvider<ExtractPluginRequestsTask> extractPluginRequests = tasks.register("extractPluginRequests", ExtractPluginRequestsTask.class, task -> {
task.getScriptPlugins().convention(scriptPlugins);
task.getScriptFiles().from(scriptPluginFiles.getFiles());
task.getExtractedPluginRequestsClassesDirectory().convention(buildDir.dir("groovy-dsl-plugins/output/plugin-requests"));
task.getExtractedPluginRequestsClassesStagingDirectory().convention(buildDir.dir("groovy-dsl-plugins/output/plugin-requests-staging"));
});
TaskProvider<GeneratePluginAdaptersTask> generatePluginAdapters = tasks.register("generatePluginAdapters", GeneratePluginAdaptersTask.class, task -> {
task.getScriptPlugins().convention(scriptPlugins);
task.getExtractedPluginRequestsClassesDirectory().convention(extractPluginRequests.flatMap(ExtractPluginRequestsTask::getExtractedPluginRequestsClassesDirectory));
task.getPluginAdapterSourcesOutputDirectory().convention(buildDir.dir("groovy-dsl-plugins/output/adapter-src"));
});
TaskProvider<CompileGroovyScriptPluginsTask> precompilePlugins = tasks.register("compileGroovyPlugins", CompileGroovyScriptPluginsTask.class, task -> {
task.getScriptPlugins().convention(scriptPlugins);
task.getScriptFiles().from(scriptPluginFiles.getFiles());
task.getPrecompiledGroovyScriptsOutputDirectory().convention(buildDir.dir("groovy-dsl-plugins/output/plugin-classes"));
SourceDirectorySet javaSource = pluginSourceSet.getJava();
SourceDirectorySet groovySource = pluginSourceSet.getExtensions().getByType(GroovySourceDirectorySet.class);
task.getClasspath().from(pluginSourceSet.getCompileClasspath(), javaSource.getClassesDirectory(), groovySource.getClassesDirectory());
});
pluginSourceSet.getJava().srcDir(generatePluginAdapters.flatMap(GeneratePluginAdaptersTask::getPluginAdapterSourcesOutputDirectory));
pluginSourceSet.getOutput().dir(precompilePlugins.flatMap(CompileGroovyScriptPluginsTask::getPrecompiledGroovyScriptsOutputDirectory));
pluginSourceSet.getOutput().dir(extractPluginRequests.flatMap(ExtractPluginRequestsTask::getExtractedPluginRequestsClassesStagingDirectory));
}
use of org.gradle.api.file.SourceDirectorySet in project gradle by gradle.
the class GroovyBasePlugin method configureSourceSetDefaults.
@SuppressWarnings("deprecation")
private void configureSourceSetDefaults() {
javaPluginExtension().getSourceSets().all(sourceSet -> {
final DefaultGroovySourceSet groovySourceSet = new DefaultGroovySourceSet("groovy", ((DefaultSourceSet) sourceSet).getDisplayName(), objectFactory);
addSourceSetExtension(sourceSet, groovySourceSet);
final SourceDirectorySet groovySource = groovySourceSet.getGroovy();
groovySource.srcDir("src/" + sourceSet.getName() + "/groovy");
// Explicitly capture only a FileCollection in the lambda below for compatibility with configuration-cache.
@SuppressWarnings("UnnecessaryLocalVariable") final FileCollection groovySourceFiles = groovySource;
sourceSet.getResources().getFilter().exclude(spec(element -> groovySourceFiles.contains(element.getFile())));
sourceSet.getAllJava().source(groovySource);
sourceSet.getAllSource().source(groovySource);
final TaskProvider<GroovyCompile> compileTask = project.getTasks().register(sourceSet.getCompileTaskName("groovy"), GroovyCompile.class, compile -> {
JvmPluginsHelper.configureForSourceSet(sourceSet, groovySource, compile, compile.getOptions(), project);
compile.setDescription("Compiles the " + sourceSet.getName() + " Groovy source.");
compile.setSource(groovySource);
compile.getJavaLauncher().convention(getToolchainTool(project, JavaToolchainService::launcherFor));
compile.getGroovyOptions().getDisabledGlobalASTTransformations().convention(Sets.newHashSet("groovy.grape.GrabAnnotationTransformation"));
});
String compileClasspathConfigurationName = sourceSet.getCompileClasspathConfigurationName();
JvmPluginsHelper.configureOutputDirectoryForSourceSet(sourceSet, groovySource, project, compileTask, compileTask.map(GroovyCompile::getOptions));
useDefaultTargetPlatformInference(compileTask, compileClasspathConfigurationName);
useDefaultTargetPlatformInference(compileTask, sourceSet.getRuntimeClasspathConfigurationName());
// TODO: `classes` should be a little more tied to the classesDirs for a SourceSet so every plugin
// doesn't need to do this.
project.getTasks().named(sourceSet.getClassesTaskName(), task -> task.dependsOn(compileTask));
// Explain that Groovy, for compile, also needs the resources (#9872)
project.getConfigurations().getByName(compileClasspathConfigurationName).attributes(attrs -> attrs.attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, project.getObjects().named(LibraryElements.class, LibraryElements.CLASSES_AND_RESOURCES)));
});
}
Aggregations