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)));
}
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();
}
}
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);
}
}
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")));
}
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);
}
Aggregations