Search in sources :

Example 1 with PatternSet

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

the class CompositeFileTreeTest method matchingWithPatternSetReturnsUnionOfFilteredSets.

@Test
public void matchingWithPatternSetReturnsUnionOfFilteredSets() {
    final PatternSet patternSet = new PatternSet();
    final FileTreeInternal filtered1 = context.mock(FileTreeInternal.class);
    final FileTreeInternal filtered2 = context.mock(FileTreeInternal.class);
    context.checking(new Expectations() {

        {
            oneOf(source1).matching(patternSet);
            will(returnValue(filtered1));
            oneOf(source2).matching(patternSet);
            will(returnValue(filtered2));
        }
    });
    FileTree filtered = tree.matching(patternSet);
    assertThat(filtered, instanceOf(CompositeFileTree.class));
    CompositeFileTree filteredCompositeSet = (CompositeFileTree) filtered;
    assertThat(toList(filteredCompositeSet.getSourceCollections()), equalTo(toList(filtered1, filtered2)));
}
Also used : Expectations(org.jmock.Expectations) FileTree(org.gradle.api.file.FileTree) PatternSet(org.gradle.api.tasks.util.PatternSet) Test(org.junit.Test)

Example 2 with PatternSet

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

the class SingleIncludePatternFileTree method doVisit.

private void doVisit(FileVisitor visitor, File file, LinkedList<String> relativePath, int segmentIndex, AtomicBoolean stopFlag) {
    if (stopFlag.get()) {
        return;
    }
    String segment = patternSegments.get(segmentIndex);
    if (segment.contains("**")) {
        PatternSet patternSet = new PatternSet();
        patternSet.include(includePattern);
        patternSet.exclude(excludeSpec);
        DirectoryFileTree fileTree = new DirectoryFileTree(baseDir, patternSet);
        fileTree.visitFrom(visitor, file, new RelativePath(file.isFile(), relativePath.toArray(new String[relativePath.size()])));
    } else if (segment.contains("*") || segment.contains("?")) {
        PatternStep step = PatternStepFactory.getStep(segment, false);
        File[] children = file.listFiles();
        if (children == null) {
            if (!file.canRead()) {
                throw new GradleException(String.format("Could not list contents of directory '%s' as it is not readable.", file));
            }
            // else, might be a link which points to nothing, or has been removed while we're visiting, or ...
            throw new GradleException(String.format("Could not list contents of '%s'.", file));
        }
        for (File child : children) {
            if (stopFlag.get()) {
                break;
            }
            String childName = child.getName();
            if (step.matches(childName)) {
                relativePath.addLast(childName);
                doVisitDirOrFile(visitor, child, relativePath, segmentIndex + 1, stopFlag);
                relativePath.removeLast();
            }
        }
    } else {
        relativePath.addLast(segment);
        doVisitDirOrFile(visitor, new File(file, segment), relativePath, segmentIndex + 1, stopFlag);
        relativePath.removeLast();
    }
}
Also used : RelativePath(org.gradle.api.file.RelativePath) PatternStep(org.gradle.api.internal.file.pattern.PatternStep) GradleException(org.gradle.api.GradleException) PatternSet(org.gradle.api.tasks.util.PatternSet) File(java.io.File)

Example 3 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.setToolChain(binary.getToolChain());
    task.setTargetPlatform(binary.getTargetPlatform());
    task.includes(sourceSet.getExportedHeaders().getSourceDirectories());
    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 : Project(org.gradle.api.Project) LanguageSourceSetInternal(org.gradle.language.base.internal.LanguageSourceSetInternal) PreprocessingTool(org.gradle.nativeplatform.PreprocessingTool) FileTree(org.gradle.api.file.FileTree) StaticLibraryBinarySpecInternal(org.gradle.nativeplatform.internal.StaticLibraryBinarySpecInternal) File(java.io.File) PatternSet(org.gradle.api.tasks.util.PatternSet)

Example 4 with PatternSet

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

the class AssembleTaskConfig method configureAssembleTask.

private void configureAssembleTask(Assemble task, final NativeBinarySpecInternal binary, final LanguageSourceSetInternal sourceSet) {
    task.setDescription("Assembles the " + sourceSet + " of " + binary);
    task.setToolChain(binary.getToolChain());
    task.setTargetPlatform(binary.getTargetPlatform());
    task.source(sourceSet.getSource());
    final Project project = task.getProject();
    task.setObjectFileDir(new File(binary.getNamingScheme().getOutputDirectory(project.getBuildDir(), "objs"), sourceSet.getProjectScopedName()));
    Tool assemblerTool = binary.getToolByName("assembler");
    task.setAssemblerArgs(assemblerTool.getArgs());
    binary.binaryInputs(task.getOutputs().getFiles().getAsFileTree().matching(new PatternSet().include("**/*.obj", "**/*.o")));
}
Also used : Project(org.gradle.api.Project) File(java.io.File) PatternSet(org.gradle.api.tasks.util.PatternSet) Tool(org.gradle.nativeplatform.Tool)

Example 5 with PatternSet

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

the class PCHCompileTaskConfig method configureCompileTask.

@Override
protected void configureCompileTask(AbstractNativeCompileTask task, final NativeBinarySpecInternal binary, final LanguageSourceSetInternal languageSourceSet) {
    // Note that the sourceSet is the sourceSet this pre-compiled header will be used with - it's not an
    // input sourceSet to the compile task.
    final DependentSourceSetInternal sourceSet = (DependentSourceSetInternal) languageSourceSet;
    task.setDescription("Compiles a pre-compiled header for the " + sourceSet + " of " + binary);
    // Add the source of the source set to the include paths to resolve any headers that may be in source directories
    task.includes(sourceSet.getSource().getSourceDirectories());
    final Project project = task.getProject();
    task.source(sourceSet.getPrefixHeaderFile());
    task.setObjectFileDir(new File(binary.getNamingScheme().getOutputDirectory(project.getBuildDir(), "objs"), languageSourceSet.getProjectScopedName() + "PCH"));
    task.dependsOn(project.getTasks().withType(PrefixHeaderFileGenerateTask.class).matching(new Spec<PrefixHeaderFileGenerateTask>() {

        @Override
        public boolean isSatisfiedBy(PrefixHeaderFileGenerateTask prefixHeaderFileGenerateTask) {
            return prefixHeaderFileGenerateTask.getPrefixHeaderFile().equals(sourceSet.getPrefixHeaderFile());
        }
    }));
    // This is so that VisualCpp has the object file of the generated source file available at link time
    binary.binaryInputs(task.getOutputs().getFiles().getAsFileTree().matching(new PatternSet().include("**/*.obj", "**/*.o")));
    PreCompiledHeader pch = binary.getPrefixFileToPCH().get(sourceSet.getPrefixHeaderFile());
    pch.setPchObjects(task.getOutputs().getFiles().getAsFileTree().matching(new PatternSet().include("**/*.pch", "**/*.gch")));
    pch.builtBy(task);
}
Also used : Project(org.gradle.api.Project) PrefixHeaderFileGenerateTask(org.gradle.nativeplatform.tasks.PrefixHeaderFileGenerateTask) PreCompiledHeader(org.gradle.nativeplatform.toolchain.internal.PreCompiledHeader) Spec(org.gradle.api.specs.Spec) ObjectFile(org.gradle.nativeplatform.ObjectFile) File(java.io.File) PatternSet(org.gradle.api.tasks.util.PatternSet)

Aggregations

PatternSet (org.gradle.api.tasks.util.PatternSet)11 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)2 ObjectFile (org.gradle.nativeplatform.ObjectFile)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 PatternFilterable (org.gradle.api.tasks.util.PatternFilterable)1 LanguageSourceSetInternal (org.gradle.language.base.internal.LanguageSourceSetInternal)1 AbstractNativeSourceCompileTask (org.gradle.language.nativeplatform.tasks.AbstractNativeSourceCompileTask)1 PlatformScalaCompile (org.gradle.language.scala.tasks.PlatformScalaCompile)1 Mutate (org.gradle.model.Mutate)1