org.gradle.api.file.FileTree Java Examples

The following examples show how to use org.gradle.api.file.FileTree. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WindowsResourcesCompileTaskConfig.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void configureResourceCompileTask(WindowsResourceCompile task, final NativeBinarySpecInternal binary, final WindowsResourceSet sourceSet) {
    task.setDescription(String.format("Compiles resources of the %s of %s", sourceSet, binary));

    task.setToolChain(binary.getToolChain());
    task.setTargetPlatform(binary.getTargetPlatform());

    task.includes(new Callable<Set<File>>() {
        public Set<File> call() {
            return sourceSet.getExportedHeaders().getSrcDirs();
        }
    });
    task.source(sourceSet.getSource());

    final Project project = task.getProject();
    task.setOutputDir(project.file(String.valueOf(project.getBuildDir()) + "/objs/" + binary.getNamingScheme().getOutputDirectoryBase() + "/" + ((LanguageSourceSetInternal) sourceSet).getFullName()));

    PreprocessingTool rcCompiler = (PreprocessingTool) ((ExtensionAware) binary).getExtensions().getByName("rcCompiler");
    task.setMacros(rcCompiler.getMacros());
    task.setCompilerArgs(rcCompiler.getArgs());

    FileTree resourceOutputs = task.getOutputs().getFiles().getAsFileTree().matching(new PatternSet().include("**/*.res"));
    binary.getTasks().getCreateOrLink().source(resourceOutputs);
    if (binary instanceof StaticLibraryBinarySpecInternal) {
        ((StaticLibraryBinarySpecInternal) binary).additionalLinkFiles(resourceOutputs);
    }
}
 
Example #2
Source File: JavaccCompilerInputOutputConfigurationTest.java    From javaccPlugin with MIT License 6 votes vote down vote up
@Test
public void getJavaSourceTreeExcludesOutputFolder() throws IOException {
    Project project = ProjectBuilder.builder().withProjectDir(testFolder.getRoot()).build();
    File javaFile = addTaskWithSourceFile(project, "compileJava", "input/TestClass.java", JavaCompile.class);
    File outputFile = addTaskWithSourceFile(project, "compileJavaccGenerated", "output/Generated.java", JavaCompile.class);
    CompilerInputOutputConfiguration configuration = builder
        .withInputDirectory(inputDirectory)
        .withOutputDirectory(outputDirectory)
        .withJavaCompileTasks(project.getTasks().withType(JavaCompile.class))
        .build();

    FileTree javaSourceTree = configuration.getJavaSourceTree();

    assertThat(javaSourceTree, contains(javaFile.getCanonicalFile()));
    assertThat(javaSourceTree, not(contains(outputFile.getCanonicalFile())));
}
 
Example #3
Source File: FileCollectionBackedArchiveTextResource.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public FileCollectionBackedArchiveTextResource(final FileOperations fileOperations,
                                               final TemporaryFileProvider tempFileProvider,
                                               final FileCollection fileCollection,
                                               final String path, Charset charset) {
    super(tempFileProvider, new LazilyInitializedFileTree() {
        @Override
        public FileTree createDelegate() {
            File archiveFile = fileCollection.getSingleFile();
            String fileExtension = Files.getFileExtension(archiveFile.getName());
            FileTree archiveContents = fileExtension.equals("jar") || fileExtension.equals("zip")
                    ? fileOperations.zipTree(archiveFile) : fileOperations.tarTree(archiveFile);
            PatternSet patternSet = new PatternSet();
            patternSet.include(path);
            return archiveContents.matching(patternSet);
        }
        public TaskDependency getBuildDependencies() {
            return fileCollection.getBuildDependencies();
        }
    }, charset);
}
 
Example #4
Source File: CompositeFileCollection.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public FileTree getAsFileTree() {
    return new CompositeFileTree() {
        @Override
        public void resolve(FileCollectionResolveContext context) {
            ResolvableFileCollectionResolveContext nested = context.newContext();
            CompositeFileCollection.this.resolve(nested);
            context.add(nested.resolveAsFileTrees());
        }

        @Override
        public String getDisplayName() {
            return CompositeFileCollection.this.getDisplayName();
        }
    };
}
 
Example #5
Source File: JavaccSourceFileCompiler.java    From javaccPlugin with MIT License 6 votes vote down vote up
@Override
public void copyCompiledFilesFromTempOutputDirectoryToOutputDirectory() {
    CompiledJavaccFilesDirectory compiledJavaccFilesDirectory = compiledJavaccFilesDirectoryFactory.getCompiledJavaccFilesDirectory(
        configuration.getTempOutputDirectory(), configuration.getCompleteSourceTree(), getOutputDirectory(), getLogger());

    for (CompiledJavaccFile compiledJavaccFile : compiledJavaccFilesDirectory.listFiles()) {
        FileTree javaSourceTree = configuration.getJavaSourceTree();
        if (compiledJavaccFile.customAstClassExists(javaSourceTree)) {
            compiledJavaccFile.ignoreCompiledFileAndUseCustomAstClassFromJavaSourceTree(javaSourceTree);
        } else if (compiledJavaccFile.customAstClassExists()) {
            compiledJavaccFile.copyCustomAstClassToTargetDirectory(configuration.getCompleteSourceTree());
        } else {
            compiledJavaccFile.copyCompiledFileToTargetDirectory();
        }
    }
}
 
Example #6
Source File: Namespaces.java    From clojurephant with Apache License 2.0 5 votes vote down vote up
public static Set<String> findNamespaces(FileCollection sourceRoots, Set<String> extensions) {
  FileTree source = getSources(sourceRoots, extensions);
  Set<Path> roots = sourceRoots.getFiles().stream()
      .map(File::toPath)
      .map(Path::toAbsolutePath)
      .collect(Collectors.toSet());
  return source.getFiles().stream()
      .map(File::toPath)
      .map(Path::toAbsolutePath)
      .map(path -> findNamespace(path, roots))
      .collect(Collectors.toSet());
}
 
Example #7
Source File: SourceTask.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Returns the source for this task, after the include and exclude patterns have been applied. Ignores source files which do not exist.
 *
 * @return The source.
 */
@InputFiles
@SkipWhenEmpty
public FileTree getSource() {
    FileTree src = getProject().files(new ArrayList<Object>(this.source)).getAsFileTree();
    return src == null ? getProject().files().getAsFileTree() : src.matching(patternSet);
}
 
Example #8
Source File: JavaccSourceFileCompilerTest.java    From javaccPlugin with MIT License 5 votes vote down vote up
private void fileIsCompiledByCompiler(CompiledJavaccFile compiledFile) {
    CompiledJavaccFilesDirectory compiledFilesDirectory = mock(CompiledJavaccFilesDirectory.class);
    when(compiledFilesDirectory.listFiles()).thenReturn(Arrays.asList(compiledFile));

    CompiledJavaccFilesDirectoryFactory factory = mock(CompiledJavaccFilesDirectoryFactory.class);
    when(factory.getCompiledJavaccFilesDirectory(any(File.class), any(FileTree.class), any(File.class), any(Logger.class))).thenReturn(compiledFilesDirectory);

    ((JavaccSourceFileCompiler) compiler).setCompiledJavaccFilesDirectoryFactoryForTest(factory);
}
 
Example #9
Source File: ClassSetAnalysisUpdater.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void updateAnalysis(JavaCompileSpec spec) {
    Clock clock = new Clock();
    FileTree tree = fileOperations.fileTree(spec.getDestinationDir());
    ClassFilesAnalyzer analyzer = new ClassFilesAnalyzer(this.analyzer);
    tree.visit(analyzer);
    ClassSetAnalysisData data = analyzer.getAnalysis();
    stash.put(data);
    LOG.info("Class dependency analysis for incremental compilation took {}.", clock.getTime());
}
 
Example #10
Source File: BuildDependenciesOnlyFileCollectionResolveContext.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void convertInto(Object element, Collection<? super FileTree> result, FileResolver resolver) {
    if (element instanceof DefaultFileCollectionResolveContext) {
        DefaultFileCollectionResolveContext nestedContext = (DefaultFileCollectionResolveContext) element;
        result.addAll(nestedContext.resolveAsFileTrees());
    } else if (element instanceof Buildable) {
        Buildable buildable = (Buildable) element;
        result.add(new FileTreeAdapter(new EmptyFileTree(buildable.getBuildDependencies())));
    } else if (element instanceof TaskDependency) {
        TaskDependency dependency = (TaskDependency) element;
        result.add(new FileTreeAdapter(new EmptyFileTree(dependency)));
    }
}
 
Example #11
Source File: SourceTask.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Returns the source for this task, after the include and exclude patterns have been applied. Ignores source files which do not exist.
 *
 * @return The source.
 */
@InputFiles
@SkipWhenEmpty
public FileTree getSource() {
    FileTree src = getProject().files(new ArrayList<Object>(this.source)).getAsFileTree();
    return src == null ? getProject().files().getAsFileTree() : src.matching(patternSet);
}
 
Example #12
Source File: CompositeFileTree.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void resolve(FileCollectionResolveContext context) {
    ResolvableFileCollectionResolveContext nestedContext = context.newContext();
    CompositeFileTree.this.resolve(nestedContext);
    for (FileTree set : nestedContext.resolveAsFileTrees()) {
        if (closure != null) {
            context.add(set.matching(closure));
        } else {
            context.add(set.matching(patterns));
        }
    }
}
 
Example #13
Source File: UnionFileTree.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public UnionFileTree add(FileCollection source) {
    if (!(source instanceof FileTree)) {
        throw new UnsupportedOperationException(String.format("Can only add FileTree instances to %s.", getDisplayName()));
    }
    
    sourceTrees.add((FileTree) source);
    return this;
}
 
Example #14
Source File: LazilyInitializedFileTree.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public final synchronized FileTree getDelegate() {
    if (delegate == null) {
        delegate = createDelegate();
    }
    return delegate;
}
 
Example #15
Source File: AidlCompile.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
FileTree getSourceFiles() {
    FileTree src = null;
    List<File> sources = getSourceDirs();
    if (!sources.isEmpty()) {
        src = getProject().files(sources).getAsFileTree().matching(PATTERN_SET);
    }
    return src == null ? getProject().files().getAsFileTree() : src;
}
 
Example #16
Source File: AbstractFileCollection.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public FileTree getAsFileTree() {
    return new CompositeFileTree() {
        @Override
        public void resolve(FileCollectionResolveContext context) {
            ResolvableFileCollectionResolveContext nested = context.newContext();
            nested.add(AbstractFileCollection.this);
            context.add(nested.resolveAsFileTrees());
        }

        @Override
        public String getDisplayName() {
            return AbstractFileCollection.this.getDisplayName();
        }
    };
}
 
Example #17
Source File: PackageApplication.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@InputFiles
public FileTree getNativeLibraries() {
    FileTree src = null;
    Set<File> folders = getJniFolders();
    if (!folders.isEmpty()) {
        src = getProject().files(new ArrayList<Object>(folders)).getAsFileTree();
    }

    return src == null ? getProject().files().getAsFileTree() : src;
}
 
Example #18
Source File: SerializableCoffeeScriptCompileSpec.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void toRelativeFiles(final FileCollection source, final List<RelativeFile> targets) {
    FileTree fileTree = source.getAsFileTree();

    fileTree.visit(new FileVisitor() {
        public void visitDir(FileVisitDetails dirDetails) {}

        public void visitFile(FileVisitDetails fileDetails) {
            targets.add(new RelativeFile(fileDetails.getFile(), fileDetails.getRelativePath()));
        }
    });
}
 
Example #19
Source File: AspectjCompile.java    From gradle-plugins with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
@InputFiles
@SkipWhenEmpty
@PathSensitive(PathSensitivity.RELATIVE)
public FileTree getSource() {
    return super.getSource();
}
 
Example #20
Source File: CompiledJavaccFile.java    From javaccPlugin with MIT License 5 votes vote down vote up
CompiledJavaccFile(File file, File outputDirectory, FileTree customAstClassesDirectory, File targetDirectory, Logger logger) {
    this.compiledJavaccFile = file;
    this.outputDirectory = outputDirectory;
    this.customAstClassesDirectory = customAstClassesDirectory;
    this.targetDirectory = targetDirectory;
    this.logger = logger;
}
 
Example #21
Source File: SerializableCoffeeScriptCompileSpec.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void toRelativeFiles(final FileCollection source, final List<RelativeFile> targets) {
    FileTree fileTree = source.getAsFileTree();

    fileTree.visit(new FileVisitor() {
        public void visitDir(FileVisitDetails dirDetails) {}

        public void visitFile(FileVisitDetails fileDetails) {
            targets.add(new RelativeFile(fileDetails.getFile(), fileDetails.getRelativePath()));
        }
    });
}
 
Example #22
Source File: CompiledJavaccFilesDirectoryFactory.java    From javaccPlugin with MIT License 5 votes vote down vote up
public CompiledJavaccFilesDirectory getCompiledJavaccFilesDirectory(File outputDirectory, FileTree customAstClassesDirectory, File targetDirectory, Logger logger) {
    if ((outputDirectory == null) || !outputDirectory.exists() || !outputDirectory.isDirectory()) {
        throw new IllegalArgumentException("outputDirectory [" + outputDirectory + "] must be an existing directory");
    }
    
    if (customAstClassesDirectory == null) {
        throw new IllegalArgumentException("customAstClassesDirectory [" + outputDirectory + "] must not be null");
    }
    
    if ((targetDirectory == null) || !targetDirectory.exists() || !targetDirectory.isDirectory()) {
        throw new IllegalArgumentException("targetDirectory [" + targetDirectory + "] must be an existing directory");
    }
    
    return new CompiledJavaccFilesDirectory(outputDirectory, customAstClassesDirectory, targetDirectory, logger);
}
 
Example #23
Source File: BuildDependenciesOnlyFileCollectionResolveContext.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void convertInto(Object element, Collection<? super FileTree> result, FileResolver resolver) {
    if (element instanceof DefaultFileCollectionResolveContext) {
        DefaultFileCollectionResolveContext nestedContext = (DefaultFileCollectionResolveContext) element;
        result.addAll(nestedContext.resolveAsFileTrees());
    } else if (element instanceof Buildable) {
        Buildable buildable = (Buildable) element;
        result.add(new FileTreeAdapter(new EmptyFileTree(buildable.getBuildDependencies())));
    } else if (element instanceof TaskDependency) {
        TaskDependency dependency = (TaskDependency) element;
        result.add(new FileTreeAdapter(new EmptyFileTree(dependency)));
    }
}
 
Example #24
Source File: BuildDependenciesOnlyFileCollectionResolveContext.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void convertInto(Object element, Collection<? super FileTree> result, FileResolver resolver) {
    if (element instanceof DefaultFileCollectionResolveContext) {
        DefaultFileCollectionResolveContext nestedContext = (DefaultFileCollectionResolveContext) element;
        result.addAll(nestedContext.resolveAsFileTrees());
    } else if (element instanceof Buildable) {
        Buildable buildable = (Buildable) element;
        result.add(new FileTreeAdapter(new EmptyFileTree(buildable.getBuildDependencies())));
    } else if (element instanceof TaskDependency) {
        TaskDependency dependency = (TaskDependency) element;
        result.add(new FileTreeAdapter(new EmptyFileTree(dependency)));
    }
}
 
Example #25
Source File: Compile.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
protected void compile() {
    FileTree source = getSource();
    FileCollection classpath = getClasspath();

    performCompilation(source, classpath, cleaningCompiler);
}
 
Example #26
Source File: CompressFileOperationsImpl.java    From gradle-plugins with MIT License 4 votes vote down vote up
@Override
public FileTree arjTree(Object arjFile) {
    return arjTree(arjFile, f -> new ArjArchiveInputStream(new FileInputStream(f)));
}
 
Example #27
Source File: DelegatingFileCollection.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public FileTree getAsFileTree() {
    return getDelegate().getAsFileTree();
}
 
Example #28
Source File: DefaultScript.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public FileTree tarTree(Object tarPath) {
    return fileOperations.tarTree(tarPath);
}
 
Example #29
Source File: AbstractProject.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public FileTree zipTree(Object zipPath) {
    return getFileOperations().zipTree(zipPath);
}
 
Example #30
Source File: AbstractProject.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public FileTree tarTree(Object tarPath) {
    return getFileOperations().tarTree(tarPath);
}