Search in sources :

Example 21 with FileTree

use of org.gradle.api.file.FileTree in project gradle by gradle.

the class IncrementalCompilationInitializer method deleteStaleFilesIn.

private void deleteStaleFilesIn(PatternSet classesToDelete, File destinationDir) {
    if (destinationDir == null) {
        return;
    }
    FileTree deleteMe = fileOperations.fileTree(destinationDir).matching(classesToDelete);
    fileOperations.delete(deleteMe);
}
Also used : FileTree(org.gradle.api.file.FileTree)

Example 22 with FileTree

use of org.gradle.api.file.FileTree in project gradle by gradle.

the class JdkCacheDirectory method unpack.

private File unpack(File jdkArchive) {
    final FileTree fileTree = asFileTree(jdkArchive);
    final String rootName = getRootDirectory(fileTree);
    String installRootName = getNameWithoutExtension(jdkArchive);
    final File installLocation = new File(jdkDirectory, installRootName);
    if (!installLocation.exists()) {
        operations.copy(spec -> {
            spec.from(fileTree);
            spec.into(jdkDirectory);
            spec.exclude(FileTreeElement::isDirectory);
            spec.eachFile(fileCopyDetails -> {
                String path = fileCopyDetails.getPath();
                if (path.startsWith(rootName)) {
                    // root names can be weird, regexp based replacement won't work
                    String newPath = installRootName + path.substring(rootName.length());
                    fileCopyDetails.setPath(newPath);
                }
            });
        });
        LOGGER.info("Installed {} into {}", jdkArchive.getName(), installLocation);
    }
    return installLocation;
}
Also used : FileTreeElement(org.gradle.api.file.FileTreeElement) FileTree(org.gradle.api.file.FileTree) File(java.io.File)

Example 23 with FileTree

use of org.gradle.api.file.FileTree in project gradle by gradle.

the class TemplateFactory method whenNoSourcesAvailable.

public TemplateOperation whenNoSourcesAvailable(String subproject, List<TemplateOperation> operations) {
    return new ConditionalTemplateOperation(() -> {
        FileTree mainFiles = initSettings.getTarget().dir(subproject + "/src/main/" + language.getName()).getAsFileTree();
        FileTree testFiles = initSettings.getTarget().dir(subproject + "/src/test/" + language.getName()).getAsFileTree();
        return mainFiles.isEmpty() || testFiles.isEmpty();
    }, operations);
}
Also used : FileTree(org.gradle.api.file.FileTree)

Example 24 with FileTree

use of org.gradle.api.file.FileTree in project rest.li by linkedin.

the class PublishRestModelTask method copy.

@Override
public void copy() {
    if (getSource().isEmpty()) {
        getProject().getLogger().error("No interface file is found. Skip publishing interface.");
        return;
    }
    getProject().getLogger().lifecycle("Publishing rest model to API project ...");
    FileTree apiRestModelFiles = getSuffixedFiles(getProject(), getDestinationDir(), _suffix);
    int apiRestModelFileCount = apiRestModelFiles.getFiles().size();
    super.copy();
    // FileTree is lazily evaluated, so that it scans for files only when the contents of the file tree are queried
    if (apiRestModelFileCount != 0 && apiRestModelFileCount != apiRestModelFiles.getFiles().size()) {
        getProject().getLogger().warn("{} files count changed after publish. You may have duplicate files with different names.", _suffix);
    }
}
Also used : FileTree(org.gradle.api.file.FileTree)

Aggregations

FileTree (org.gradle.api.file.FileTree)24 File (java.io.File)8 Test (org.junit.Test)6 GradleException (org.gradle.api.GradleException)5 Expectations (org.jmock.Expectations)5 IOException (java.io.IOException)4 FileCollection (org.gradle.api.file.FileCollection)4 TaskAction (org.gradle.api.tasks.TaskAction)4 PatternSet (org.gradle.api.tasks.util.PatternSet)4 Project (org.gradle.api.Project)2 DirectoryFileTree (org.gradle.api.internal.file.collections.DirectoryFileTree)2 MinimalFileSet (org.gradle.api.internal.file.collections.MinimalFileSet)2 TestClassProcessor (org.gradle.api.internal.tasks.testing.TestClassProcessor)2 TestFramework (org.gradle.api.internal.tasks.testing.TestFramework)2 WorkerTestClassProcessorFactory (org.gradle.api.internal.tasks.testing.WorkerTestClassProcessorFactory)2 MaxNParallelTestClassProcessor (org.gradle.api.internal.tasks.testing.processors.MaxNParallelTestClassProcessor)2 RestartEveryNTestClassProcessor (org.gradle.api.internal.tasks.testing.processors.RestartEveryNTestClassProcessor)2 TestMainAction (org.gradle.api.internal.tasks.testing.processors.TestMainAction)2 ForkingTestClassProcessor (org.gradle.api.internal.tasks.testing.worker.ForkingTestClassProcessor)2 SourceSet (org.gradle.api.tasks.SourceSet)2