Java Code Examples for org.gradle.api.file.FileTree

The following examples show how to use org.gradle.api.file.FileTree. These examples are extracted from open source projects. 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
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 Project: javaccPlugin   Author: johnmartel   File: JavaccCompilerInputOutputConfigurationTest.java    License: 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
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 Project: Pushjet-Android   Author: Pushjet   File: CompositeFileCollection.java    License: 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 Project: javaccPlugin   Author: johnmartel   File: JavaccSourceFileCompiler.java    License: 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 Project: clojurephant   Author: clojurephant   File: Namespaces.java    License: 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 Project: Pushjet-Android   Author: Pushjet   File: SourceTask.java    License: 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 Project: javaccPlugin   Author: johnmartel   File: JavaccSourceFileCompilerTest.java    License: 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 Project: pushfish-android   Author: PushFish   File: ClassSetAnalysisUpdater.java    License: 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
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 Project: pushfish-android   Author: PushFish   File: SourceTask.java    License: 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 Project: Pushjet-Android   Author: Pushjet   File: CompositeFileTree.java    License: 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 Project: pushfish-android   Author: PushFish   File: UnionFileTree.java    License: 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 Project: pushfish-android   Author: PushFish   File: LazilyInitializedFileTree.java    License: 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 Project: javaide   Author: tranleduy2000   File: AidlCompile.java    License: 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 Project: pushfish-android   Author: PushFish   File: AbstractFileCollection.java    License: 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 Project: javaide   Author: tranleduy2000   File: PackageApplication.java    License: 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
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 Project: gradle-plugins   Author: freefair   File: AspectjCompile.java    License: MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
@InputFiles
@SkipWhenEmpty
@PathSensitive(PathSensitivity.RELATIVE)
public FileTree getSource() {
    return super.getSource();
}
 
Example #20
Source Project: javaccPlugin   Author: johnmartel   File: CompiledJavaccFile.java    License: 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
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 Project: javaccPlugin   Author: johnmartel   File: CompiledJavaccFilesDirectoryFactory.java    License: 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
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
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 Project: pushfish-android   Author: PushFish   File: Compile.java    License: 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 Project: gradle-plugins   Author: freefair   File: CompressFileOperationsImpl.java    License: 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 Project: Pushjet-Android   Author: Pushjet   File: DelegatingFileCollection.java    License: BSD 2-Clause "Simplified" License 4 votes vote down vote up
public FileTree getAsFileTree() {
    return getDelegate().getAsFileTree();
}
 
Example #28
Source Project: Pushjet-Android   Author: Pushjet   File: DefaultScript.java    License: BSD 2-Clause "Simplified" License 4 votes vote down vote up
public FileTree tarTree(Object tarPath) {
    return fileOperations.tarTree(tarPath);
}
 
Example #29
Source Project: pushfish-android   Author: PushFish   File: AbstractProject.java    License: BSD 2-Clause "Simplified" License 4 votes vote down vote up
public FileTree zipTree(Object zipPath) {
    return getFileOperations().zipTree(zipPath);
}
 
Example #30
Source Project: pushfish-android   Author: PushFish   File: AbstractProject.java    License: BSD 2-Clause "Simplified" License 4 votes vote down vote up
public FileTree tarTree(Object tarPath) {
    return getFileOperations().tarTree(tarPath);
}