Search in sources :

Example 1 with SourceDirectorySet

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DirectoryTree(org.gradle.api.file.DirectoryTree) InvalidUserDataException(org.gradle.api.InvalidUserDataException) SourceDirectorySet(org.gradle.api.file.SourceDirectorySet) File(java.io.File)

Example 2 with SourceDirectorySet

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));
}
Also used : JavaCompile(org.gradle.api.tasks.compile.JavaCompile) StringUtils(org.apache.commons.lang.StringUtils) Action(org.gradle.api.Action) SourceDirectorySet(org.gradle.api.file.SourceDirectorySet) JvmPluginsHelper(org.gradle.api.plugins.internal.JvmPluginsHelper) JavaPlugin(org.gradle.api.plugins.JavaPlugin) HasCompileOptions(org.gradle.api.internal.tasks.compile.HasCompileOptions) Cast(org.gradle.internal.Cast) Function(java.util.function.Function) SourceSet(org.gradle.api.tasks.SourceSet) Inject(javax.inject.Inject) Task(org.gradle.api.Task) TaskProvider(org.gradle.api.tasks.TaskProvider) DirectoryProperty(org.gradle.api.file.DirectoryProperty) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) HasCompileOptions(org.gradle.api.internal.tasks.compile.HasCompileOptions) SourceDirectorySet(org.gradle.api.file.SourceDirectorySet)

Example 3 with SourceDirectorySet

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);
        }
    }
}
Also used : SourceDirectorySet(org.gradle.api.file.SourceDirectorySet) File(java.io.File)

Example 4 with SourceDirectorySet

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));
}
Also used : CORE_PLUGIN_PREFIX(org.gradle.api.internal.plugins.DefaultPluginManager.CORE_PLUGIN_PREFIX) Project(org.gradle.api.Project) JavaGradlePluginPlugin(org.gradle.plugin.devel.plugins.JavaGradlePluginPlugin) SourceDirectorySet(org.gradle.api.file.SourceDirectorySet) CORE_PLUGIN_NAMESPACE(org.gradle.api.internal.plugins.DefaultPluginManager.CORE_PLUGIN_NAMESPACE) TextFileResourceLoader(org.gradle.internal.resource.TextFileResourceLoader) GradlePluginDevelopmentExtension(org.gradle.plugin.devel.GradlePluginDevelopmentExtension) Collectors(java.util.stream.Collectors) SourceSet(org.gradle.api.tasks.SourceSet) Inject(javax.inject.Inject) List(java.util.List) GroovyBasePlugin(org.gradle.api.plugins.GroovyBasePlugin) GroovySourceDirectorySet(org.gradle.api.tasks.GroovySourceDirectorySet) TaskContainer(org.gradle.api.tasks.TaskContainer) GradleException(org.gradle.api.GradleException) FileTree(org.gradle.api.file.FileTree) TaskProvider(org.gradle.api.tasks.TaskProvider) DirectoryProperty(org.gradle.api.file.DirectoryProperty) Documentation(org.gradle.internal.deprecation.Documentation) Plugin(org.gradle.api.Plugin) SourceSet(org.gradle.api.tasks.SourceSet) DirectoryProperty(org.gradle.api.file.DirectoryProperty) TaskContainer(org.gradle.api.tasks.TaskContainer) GradlePluginDevelopmentExtension(org.gradle.plugin.devel.GradlePluginDevelopmentExtension) FileTree(org.gradle.api.file.FileTree) SourceDirectorySet(org.gradle.api.file.SourceDirectorySet) GroovySourceDirectorySet(org.gradle.api.tasks.GroovySourceDirectorySet)

Example 5 with SourceDirectorySet

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)));
    });
}
Also used : ConfigurableFileCollection(org.gradle.api.file.ConfigurableFileCollection) DefaultSourceSet(org.gradle.api.internal.tasks.DefaultSourceSet) Groovydoc(org.gradle.api.tasks.javadoc.Groovydoc) BiFunction(java.util.function.BiFunction) JavaToolchainService(org.gradle.jvm.toolchain.JavaToolchainService) FileCollection(org.gradle.api.file.FileCollection) LibraryElements(org.gradle.api.attributes.LibraryElements) DslObject(org.gradle.api.internal.plugins.DslObject) Inject(javax.inject.Inject) Provider(org.gradle.api.provider.Provider) GroovySourceDirectorySet(org.gradle.api.tasks.GroovySourceDirectorySet) TaskProvider(org.gradle.api.tasks.TaskProvider) ModuleRegistry(org.gradle.api.internal.classpath.ModuleRegistry) GroovyRuntime(org.gradle.api.tasks.GroovyRuntime) ReportingExtension(org.gradle.api.reporting.ReportingExtension) Project(org.gradle.api.Project) SourceDirectorySet(org.gradle.api.file.SourceDirectorySet) JvmPluginsHelper(org.gradle.api.plugins.internal.JvmPluginsHelper) DefaultGroovySourceSet(org.gradle.api.internal.tasks.DefaultGroovySourceSet) Sets(com.google.common.collect.Sets) JavaToolchainSpec(org.gradle.jvm.toolchain.JavaToolchainSpec) JvmEcosystemUtilities(org.gradle.api.plugins.jvm.internal.JvmEcosystemUtilities) ObjectFactory(org.gradle.api.model.ObjectFactory) SerializableLambdas.spec(org.gradle.api.internal.lambdas.SerializableLambdas.spec) GroovyCompile(org.gradle.api.tasks.compile.GroovyCompile) Plugin(org.gradle.api.Plugin) JvmPluginServices(org.gradle.api.plugins.jvm.internal.JvmPluginServices) GroovyCompile(org.gradle.api.tasks.compile.GroovyCompile) DefaultGroovySourceSet(org.gradle.api.internal.tasks.DefaultGroovySourceSet) GroovySourceDirectorySet(org.gradle.api.tasks.GroovySourceDirectorySet) SourceDirectorySet(org.gradle.api.file.SourceDirectorySet) ConfigurableFileCollection(org.gradle.api.file.ConfigurableFileCollection) FileCollection(org.gradle.api.file.FileCollection)

Aggregations

SourceDirectorySet (org.gradle.api.file.SourceDirectorySet)13 SourceSet (org.gradle.api.tasks.SourceSet)6 File (java.io.File)5 Inject (javax.inject.Inject)4 Plugin (org.gradle.api.Plugin)4 FileCollection (org.gradle.api.file.FileCollection)4 GroovySourceDirectorySet (org.gradle.api.tasks.GroovySourceDirectorySet)4 Project (org.gradle.api.Project)3 Configuration (org.gradle.api.artifacts.Configuration)3 DirectoryProperty (org.gradle.api.file.DirectoryProperty)3 TaskProvider (org.gradle.api.tasks.TaskProvider)3 EtaOptions (com.typelead.gradle.eta.api.EtaOptions)2 DefaultEtaSourceSet (com.typelead.gradle.eta.internal.DefaultEtaSourceSet)2 EtaCompile (com.typelead.gradle.eta.tasks.EtaCompile)2 EtaInstallDependencies (com.typelead.gradle.eta.tasks.EtaInstallDependencies)2 EtaResolveDependencies (com.typelead.gradle.eta.tasks.EtaResolveDependencies)2 Action (org.gradle.api.Action)2 Task (org.gradle.api.Task)2 LibraryElements (org.gradle.api.attributes.LibraryElements)2 Directory (org.gradle.api.file.Directory)2