Search in sources :

Example 6 with PatternSet

use of org.gradle.api.tasks.util.PatternSet 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.setCompilerArgs(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 7 with PatternSet

use of org.gradle.api.tasks.util.PatternSet in project gradle by gradle.

the class DirectoryFileTree method filter.

public DirectoryFileTree filter(PatternFilterable patterns) {
    PatternSet patternSet = this.patternSet.intersect();
    patternSet.copyFrom(patterns);
    return new DirectoryFileTree(dir, patternSet, directoryWalkerFactory, fileSystem, postfix);
}
Also used : PatternSet(org.gradle.api.tasks.util.PatternSet)

Example 8 with PatternSet

use of org.gradle.api.tasks.util.PatternSet in project gradle by gradle.

the class IncrementalCompilationInitializer method initializeCompilation.

public void initializeCompilation(JavaCompileSpec spec, Collection<String> staleClasses) {
    if (staleClasses.isEmpty()) {
        spec.setSource(new SimpleFileCollection());
        //do nothing. No classes need recompilation.
        return;
    }
    Factory<PatternSet> patternSetFactory = fileOperations.getFileResolver().getPatternSetFactory();
    PatternSet classesToDelete = patternSetFactory.create();
    PatternSet sourceToCompile = patternSetFactory.create();
    preparePatterns(staleClasses, classesToDelete, sourceToCompile);
    //selectively configure the source
    spec.setSource(spec.getSource().getAsFileTree().matching(sourceToCompile));
    //since we're compiling selectively we need to include the classes compiled previously
    List<File> classpath = Lists.newArrayList(spec.getCompileClasspath());
    classpath.add(spec.getDestinationDir());
    spec.setCompileClasspath(classpath);
    //get rid of stale files
    FileTree deleteMe = fileOperations.fileTree(spec.getDestinationDir()).matching(classesToDelete);
    fileOperations.delete(deleteMe);
}
Also used : SimpleFileCollection(org.gradle.api.internal.file.collections.SimpleFileCollection) FileTree(org.gradle.api.file.FileTree) PatternSet(org.gradle.api.tasks.util.PatternSet) File(java.io.File)

Example 9 with PatternSet

use of org.gradle.api.tasks.util.PatternSet in project gradle by gradle.

the class DefaultScalaJavaJointCompiler method execute.

public WorkResult execute(ScalaJavaJointCompileSpec spec) {
    scalaCompiler.execute(spec);
    PatternFilterable patternSet = new PatternSet();
    patternSet.include("**/*.java");
    FileTree javaSource = spec.getSource().getAsFileTree().matching(patternSet);
    if (!javaSource.isEmpty()) {
        spec.setSource(javaSource);
        javaCompiler.execute(spec);
    }
    return new WorkResult() {

        public boolean getDidWork() {
            return true;
        }
    };
}
Also used : FileTree(org.gradle.api.file.FileTree) WorkResult(org.gradle.api.tasks.WorkResult) PatternSet(org.gradle.api.tasks.util.PatternSet) PatternFilterable(org.gradle.api.tasks.util.PatternFilterable)

Example 10 with PatternSet

use of org.gradle.api.tasks.util.PatternSet in project gradle by gradle.

the class DefaultFileSystemSnapshotter method snapshotDirectoryTree.

/*
     * For simplicity this only caches trees without includes/excludes. However, if it is asked
     * to snapshot a filtered tree, it will try to find a snapshot for the underlying
     * tree and filter it in memory instead of walking the file system again. This covers the
     * majority of cases, because all task outputs are put into the cache without filters
     * before any downstream task uses them.
     */
@Override
public FileTreeSnapshot snapshotDirectoryTree(final DirectoryFileTree dirTree) {
    // Could potentially coordinate with a thread that is snapshotting an overlapping directory tree
    final String path = dirTree.getDir().getAbsolutePath();
    final PatternSet patterns = dirTree.getPatterns();
    FileTreeSnapshot snapshot = fileSystemMirror.getDirectoryTree(path);
    if (snapshot != null) {
        return filterSnapshot(snapshot, patterns);
    }
    if (!patterns.isEmpty()) {
        return snapshotWithoutCaching(dirTree);
    }
    return producingTrees.guardByKey(path, new Factory<FileTreeSnapshot>() {

        @Override
        public FileTreeSnapshot create() {
            FileTreeSnapshot snapshot = fileSystemMirror.getDirectoryTree(path);
            if (snapshot == null) {
                return snapshotAndCache(dirTree);
            } else {
                return snapshot;
            }
        }
    });
}
Also used : PatternSet(org.gradle.api.tasks.util.PatternSet)

Aggregations

PatternSet (org.gradle.api.tasks.util.PatternSet)14 File (java.io.File)7 Project (org.gradle.api.Project)4 FileTree (org.gradle.api.file.FileTree)4 SimpleFileCollection (org.gradle.api.internal.file.collections.SimpleFileCollection)3 LinkedHashSet (java.util.LinkedHashSet)2 FileCollectionFactory (org.gradle.api.internal.file.FileCollectionFactory)2 MinimalFileSet (org.gradle.api.internal.file.collections.MinimalFileSet)2 ObjectFile (org.gradle.nativeplatform.ObjectFile)2 NativeToolChainInternal (org.gradle.nativeplatform.toolchain.internal.NativeToolChainInternal)2 PlatformToolProvider (org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider)2 PreCompiledHeader (org.gradle.nativeplatform.toolchain.internal.PreCompiledHeader)2 GradleException (org.gradle.api.GradleException)1 FileCollection (org.gradle.api.file.FileCollection)1 RelativePath (org.gradle.api.file.RelativePath)1 PatternStep (org.gradle.api.internal.file.pattern.PatternStep)1 Spec (org.gradle.api.specs.Spec)1 WorkResult (org.gradle.api.tasks.WorkResult)1 IncrementalCompileOptions (org.gradle.api.tasks.scala.IncrementalCompileOptions)1 Test (org.gradle.api.tasks.testing.Test)1