Search in sources :

Example 11 with FileTree

use of org.gradle.api.file.FileTree in project gradle by gradle.

the class CopySpecActionImpl method execute.

@Override
public void execute(final CopySpecResolver specResolver) {
    FileTree source = specResolver.getSource();
    source.visit(new CopyFileVisitorImpl(specResolver, action, instantiator, objectFactory, fileSystem, reproducibleFileOrder));
}
Also used : FileTree(org.gradle.api.file.FileTree)

Example 12 with FileTree

use of org.gradle.api.file.FileTree in project gradle by gradle.

the class WindowsResourcesCompileTaskConfig method configureResourceCompileTask.

private void configureResourceCompileTask(WindowsResourceCompile task, final NativeBinarySpecInternal binary, final WindowsResourceSet sourceSet) {
    task.setDescription("Compiles resources of the " + sourceSet + " of " + binary);
    task.getToolChain().set(binary.getToolChain());
    task.getTargetPlatform().set(binary.getTargetPlatform());
    task.includes(sourceSet.getExportedHeaders().getSourceDirectories());
    FileCollectionFactory fileCollectionFactory = ((ProjectInternal) task.getProject()).getServices().get(FileCollectionFactory.class);
    task.includes(fileCollectionFactory.create(new MinimalFileSet() {

        @Override
        public Set<File> getFiles() {
            PlatformToolProvider platformToolProvider = ((NativeToolChainInternal) binary.getToolChain()).select((NativePlatformInternal) binary.getTargetPlatform());
            return new LinkedHashSet<File>(platformToolProvider.getSystemLibraries(ToolType.WINDOW_RESOURCES_COMPILER).getIncludeDirs());
        }

        @Override
        public String getDisplayName() {
            return "System includes for " + binary.getToolChain().getDisplayName();
        }
    }));
    task.source(sourceSet.getSource());
    final Project project = task.getProject();
    task.setOutputDir(new File(binary.getNamingScheme().getOutputDirectory(project.getBuildDir(), "objs"), ((LanguageSourceSetInternal) sourceSet).getProjectScopedName()));
    PreprocessingTool rcCompiler = (PreprocessingTool) binary.getToolByName("rcCompiler");
    task.setMacros(rcCompiler.getMacros());
    task.getCompilerArgs().set(rcCompiler.getArgs());
    FileTree resourceOutputs = task.getOutputs().getFiles().getAsFileTree().matching(new PatternSet().include("**/*.res"));
    binary.binaryInputs(resourceOutputs);
    if (binary instanceof StaticLibraryBinarySpecInternal) {
        ((StaticLibraryBinarySpecInternal) binary).additionalLinkFiles(resourceOutputs);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) NativeToolChainInternal(org.gradle.nativeplatform.toolchain.internal.NativeToolChainInternal) Project(org.gradle.api.Project) LanguageSourceSetInternal(org.gradle.language.base.internal.LanguageSourceSetInternal) PlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider) PreprocessingTool(org.gradle.nativeplatform.PreprocessingTool) FileTree(org.gradle.api.file.FileTree) StaticLibraryBinarySpecInternal(org.gradle.nativeplatform.internal.StaticLibraryBinarySpecInternal) MinimalFileSet(org.gradle.api.internal.file.collections.MinimalFileSet) File(java.io.File) PatternSet(org.gradle.api.tasks.util.PatternSet) FileCollectionFactory(org.gradle.api.internal.file.FileCollectionFactory)

Example 13 with FileTree

use of org.gradle.api.file.FileTree 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 14 with FileTree

use of org.gradle.api.file.FileTree in project gradle by gradle.

the class DefaultTestExecuter method execute.

@Override
public void execute(final JvmTestExecutionSpec testExecutionSpec, TestResultProcessor testResultProcessor) {
    final TestFramework testFramework = testExecutionSpec.getTestFramework();
    final WorkerTestClassProcessorFactory testInstanceFactory = testFramework.getProcessorFactory();
    final Set<File> classpath = ImmutableSet.copyOf(testExecutionSpec.getClasspath());
    final Set<File> modulePath = ImmutableSet.copyOf(testExecutionSpec.getModulePath());
    final List<String> testWorkerImplementationModules = testFramework.getTestWorkerImplementationModules();
    final Factory<TestClassProcessor> forkingProcessorFactory = new Factory<TestClassProcessor>() {

        @Override
        public TestClassProcessor create() {
            return new ForkingTestClassProcessor(workerLeaseService, workerFactory, testInstanceFactory, testExecutionSpec.getJavaForkOptions(), classpath, modulePath, testWorkerImplementationModules, testFramework.getWorkerConfigurationAction(), moduleRegistry, documentationRegistry);
        }
    };
    final Factory<TestClassProcessor> reforkingProcessorFactory = new Factory<TestClassProcessor>() {

        @Override
        public TestClassProcessor create() {
            return new RestartEveryNTestClassProcessor(forkingProcessorFactory, testExecutionSpec.getForkEvery());
        }
    };
    processor = new PatternMatchTestClassProcessor(testFilter, new RunPreviousFailedFirstTestClassProcessor(testExecutionSpec.getPreviousFailedTestClasses(), new MaxNParallelTestClassProcessor(getMaxParallelForks(testExecutionSpec), reforkingProcessorFactory, actorFactory)));
    final FileTree testClassFiles = testExecutionSpec.getCandidateClassFiles();
    Runnable detector;
    if (testExecutionSpec.isScanForTestClasses() && testFramework.getDetector() != null) {
        TestFrameworkDetector testFrameworkDetector = testFramework.getDetector();
        testFrameworkDetector.setTestClasses(testExecutionSpec.getTestClassesDirs().getFiles());
        testFrameworkDetector.setTestClasspath(classpath);
        detector = new DefaultTestClassScanner(testClassFiles, testFrameworkDetector, processor);
    } else {
        detector = new DefaultTestClassScanner(testClassFiles, null, processor);
    }
    new TestMainAction(detector, processor, testResultProcessor, workerLeaseService, clock, testExecutionSpec.getPath(), "Gradle Test Run " + testExecutionSpec.getIdentityPath()).run();
}
Also used : WorkerTestClassProcessorFactory(org.gradle.api.internal.tasks.testing.WorkerTestClassProcessorFactory) RunPreviousFailedFirstTestClassProcessor(org.gradle.api.internal.tasks.testing.processors.RunPreviousFailedFirstTestClassProcessor) ActorFactory(org.gradle.internal.actor.ActorFactory) WorkerProcessFactory(org.gradle.process.internal.worker.WorkerProcessFactory) Factory(org.gradle.internal.Factory) WorkerTestClassProcessorFactory(org.gradle.api.internal.tasks.testing.WorkerTestClassProcessorFactory) TestMainAction(org.gradle.api.internal.tasks.testing.processors.TestMainAction) ForkingTestClassProcessor(org.gradle.api.internal.tasks.testing.worker.ForkingTestClassProcessor) MaxNParallelTestClassProcessor(org.gradle.api.internal.tasks.testing.processors.MaxNParallelTestClassProcessor) TestClassProcessor(org.gradle.api.internal.tasks.testing.TestClassProcessor) RunPreviousFailedFirstTestClassProcessor(org.gradle.api.internal.tasks.testing.processors.RunPreviousFailedFirstTestClassProcessor) RestartEveryNTestClassProcessor(org.gradle.api.internal.tasks.testing.processors.RestartEveryNTestClassProcessor) PatternMatchTestClassProcessor(org.gradle.api.internal.tasks.testing.processors.PatternMatchTestClassProcessor) RestartEveryNTestClassProcessor(org.gradle.api.internal.tasks.testing.processors.RestartEveryNTestClassProcessor) PatternMatchTestClassProcessor(org.gradle.api.internal.tasks.testing.processors.PatternMatchTestClassProcessor) TestFramework(org.gradle.api.internal.tasks.testing.TestFramework) MaxNParallelTestClassProcessor(org.gradle.api.internal.tasks.testing.processors.MaxNParallelTestClassProcessor) ForkingTestClassProcessor(org.gradle.api.internal.tasks.testing.worker.ForkingTestClassProcessor) FileTree(org.gradle.api.file.FileTree) File(java.io.File)

Example 15 with FileTree

use of org.gradle.api.file.FileTree in project gradle by gradle.

the class CompositeFileCollectionTest method getAsFileTreeDelegatesToEachSet.

@Test
public void getAsFileTreeDelegatesToEachSet() {
    final File file1 = new File("dir1");
    final File file2 = new File("dir2");
    FileTree fileTree = collection.getAsFileTree();
    assertThat(fileTree, instanceOf(CompositeFileTree.class));
    context.checking(new Expectations() {

        {
            oneOf(source1).getFiles();
            will(returnValue(toSet(file1)));
            oneOf(source2).getFiles();
            will(returnValue(toSet(file2)));
        }
    });
    ((CompositeFileTree) fileTree).getSourceCollections();
}
Also used : Expectations(org.jmock.Expectations) FileTree(org.gradle.api.file.FileTree) DirectoryFileTree(org.gradle.api.internal.file.collections.DirectoryFileTree) File(java.io.File) Test(org.junit.Test)

Aggregations

FileTree (org.gradle.api.file.FileTree)24 File (java.io.File)8 Test (org.junit.Test)6 GradleException (org.gradle.api.GradleException)5 Expectations (org.jmock.Expectations)5 IOException (java.io.IOException)4 FileCollection (org.gradle.api.file.FileCollection)4 TaskAction (org.gradle.api.tasks.TaskAction)4 PatternSet (org.gradle.api.tasks.util.PatternSet)4 Project (org.gradle.api.Project)2 DirectoryFileTree (org.gradle.api.internal.file.collections.DirectoryFileTree)2 MinimalFileSet (org.gradle.api.internal.file.collections.MinimalFileSet)2 TestClassProcessor (org.gradle.api.internal.tasks.testing.TestClassProcessor)2 TestFramework (org.gradle.api.internal.tasks.testing.TestFramework)2 WorkerTestClassProcessorFactory (org.gradle.api.internal.tasks.testing.WorkerTestClassProcessorFactory)2 MaxNParallelTestClassProcessor (org.gradle.api.internal.tasks.testing.processors.MaxNParallelTestClassProcessor)2 RestartEveryNTestClassProcessor (org.gradle.api.internal.tasks.testing.processors.RestartEveryNTestClassProcessor)2 TestMainAction (org.gradle.api.internal.tasks.testing.processors.TestMainAction)2 ForkingTestClassProcessor (org.gradle.api.internal.tasks.testing.worker.ForkingTestClassProcessor)2 SourceSet (org.gradle.api.tasks.SourceSet)2