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

The following examples show how to use org.gradle.api.file.FileVisitDetails. 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
JarSnapshot createSnapshot(byte[] hash, FileTree classes, final ClassFilesAnalyzer analyzer) {
    final Map<String, byte[]> hashes = new HashMap<String, byte[]>();
    classes.visit(new FileVisitor() {
        public void visitDir(FileVisitDetails dirDetails) {
        }

        public void visitFile(FileVisitDetails fileDetails) {
            analyzer.visitFile(fileDetails);
            String className = fileDetails.getPath().replaceAll("/", ".").replaceAll("\\.class$", "");
            byte[] classHash = hasher.hash(fileDetails.getFile());
            hashes.put(className, classHash);
        }
    });

    return new JarSnapshot(new JarSnapshotData(hash, hashes, analyzer.getAnalysis()));
}
 
Example 2
public Set<? extends LocallyAvailableResource> search(String pattern) {
    if (!getBaseDir().exists()) {
        return Collections.emptySet();
    }

    final Set<LocallyAvailableResource> entries = new HashSet<LocallyAvailableResource>();
    findFiles(pattern).visit(new EmptyFileVisitor() {
        public void visitFile(FileVisitDetails fileDetails) {
            final File file = fileDetails.getFile();
            // We cannot clean in progress markers, or in progress files here because
            // the file system visitor stuff can't handle the file system mutating while visiting
            if (!isInProgressMarkerFile(file) && !isInProgressFile(file)) {
                entries.add(entryAt(file));
            }
        }
    });

    return entries;
}
 
Example 3
public Set<? extends LocallyAvailableResource> search(String pattern) {
    if (!getBaseDir().exists()) {
        return Collections.emptySet();
    }

    final Set<LocallyAvailableResource> entries = new HashSet<LocallyAvailableResource>();
    findFiles(pattern).visit(new EmptyFileVisitor() {
        public void visitFile(FileVisitDetails fileDetails) {
            final File file = fileDetails.getFile();
            // We cannot clean in progress markers, or in progress files here because
            // the file system visitor stuff can't handle the file system mutating while visiting
            if (!isInProgressMarkerFile(file) && !isInProgressFile(file)) {
                entries.add(entryAt(file));
            }
        }
    });

    return entries;
}
 
Example 4
Source Project: javaccPlugin   Source File: NonJavaccSourceFileVisitorTest.java    License: MIT License 6 votes vote down vote up
@Test
public void givenATextInputFileInSubDirectoryWhenVisitFileThenFileIsCopiedToTaskOutputDirectory() {
    inputDirectory = new File(getClass().getResource("/javacc/inputWithNonJavaccFilesInSubDirectory").getFile());
    when(compiler.getInputDirectory()).thenReturn(inputDirectory);

    FileVisitDetails fileDetails = mock(FileVisitDetails.class);
    when(fileDetails.getFile()).thenReturn(new File(inputDirectory, TEXT_INPUT_IN_SUBFOLDER_FILENAME));
    when(fileDetails.getName()).thenReturn(TEXT_INPUT_IN_SUBFOLDER_FILENAME);

    sourceVisitor.visitFile(fileDetails);

    assertEquals(1, outputDirectory.list().length);
    assertTrue(Arrays.asList(outputDirectory.list()).contains("sub"));

    final File outputSubDirectory = new File(outputDirectory, "sub");
    assertEquals(1, outputSubDirectory.list().length);
    assertTrue(Arrays.asList(outputSubDirectory.list()).contains(TEXT_INPUT_FILENAME));
}
 
Example 5
JarSnapshot createSnapshot(byte[] hash, FileTree classes, final ClassFilesAnalyzer analyzer) {
    final Map<String, byte[]> hashes = new HashMap<String, byte[]>();
    classes.visit(new FileVisitor() {
        public void visitDir(FileVisitDetails dirDetails) {
        }

        public void visitFile(FileVisitDetails fileDetails) {
            analyzer.visitFile(fileDetails);
            String className = fileDetails.getPath().replaceAll("/", ".").replaceAll("\\.class$", "");
            byte[] classHash = hasher.hash(fileDetails.getFile());
            hashes.put(className, classHash);
        }
    });

    return new JarSnapshot(new JarSnapshotData(hash, hashes, analyzer.getAnalysis()));
}
 
Example 6
public Set<? extends LocallyAvailableResource> search(String pattern) {
    if (!getBaseDir().exists()) {
        return Collections.emptySet();
    }

    final Set<LocallyAvailableResource> entries = new HashSet<LocallyAvailableResource>();
    findFiles(pattern).visit(new EmptyFileVisitor() {
        public void visitFile(FileVisitDetails fileDetails) {
            final File file = fileDetails.getFile();
            // We cannot clean in progress markers, or in progress files here because
            // the file system visitor stuff can't handle the file system mutating while visiting
            if (!isInProgressMarkerFile(file) && !isInProgressFile(file)) {
                entries.add(entryAt(file));
            }
        }
    });

    return entries;
}
 
Example 7
public Set<? extends LocallyAvailableResource> search(String pattern) {
    if (!getBaseDir().exists()) {
        return Collections.emptySet();
    }

    final Set<LocallyAvailableResource> entries = new HashSet<LocallyAvailableResource>();
    findFiles(pattern).visit(new EmptyFileVisitor() {
        public void visitFile(FileVisitDetails fileDetails) {
            final File file = fileDetails.getFile();
            // We cannot clean in progress markers, or in progress files here because
            // the file system visitor stuff can't handle the file system mutating while visiting
            if (!isInProgressMarkerFile(file) && !isInProgressFile(file)) {
                entries.add(entryAt(file));
            }
        }
    });

    return entries;
}
 
Example 8
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 9
public void visitFile(FileVisitDetails fileDetails) {
    File file = fileDetails.getFile();
    if (!file.getName().endsWith(".class")) {
        return;
    }
    String className = fileDetails.getPath().replaceAll("/", ".").replaceAll("\\.class$", "");
    if (!className.startsWith(packagePrefix)) {
        return;
    }

    ClassAnalysis analysis = analyzer.getClassAnalysis(className, file);
    accumulator.addClass(className, analysis.isDependencyToAll(), analysis.getClassDependencies());
}
 
Example 10
private void processFile(FileVisitDetails visitDetails) {
    DefaultFileCopyDetails details = createDefaultFileCopyDetails(visitDetails);
    for (Action<? super FileCopyDetails> action : copySpecResolver.getAllCopyActions()) {
        action.execute(details);
        if (details.isExcluded()) {
            return;
        }
    }
    action.processFile(details);
}
 
Example 11
Source Project: javaccPlugin   Source File: NonJavaccSourceFileVisitorTest.java    License: MIT License 5 votes vote down vote up
@Test
public void givenAJavaccInputFileWhenVisitFileThenFileIsNotCopiedToTaskOutputDirectory() {
    FileVisitDetails fileDetails = mock(FileVisitDetails.class);
    when(fileDetails.getFile()).thenReturn(new File(inputDirectory, JAVACC_INPUT_FILENAME));
    when(fileDetails.getName()).thenReturn(JAVACC_INPUT_FILENAME);

    sourceVisitor.visitFile(fileDetails);

    assertEquals(0, outputDirectory.list().length);
}
 
Example 12
private void maybeDelete(FileVisitDetails fileDetails, boolean isDir) {
    RelativePath path = fileDetails.getRelativePath();
    if (!visited.contains(path)) {
        if (isDir) {
            GFileUtils.deleteDirectory(fileDetails.getFile());
        } else {
            GFileUtils.deleteQuietly(fileDetails.getFile());
        }
        didWork = true;
    }
}
 
Example 13
private void detectionScan() {
    testFrameworkDetector.startDetection(testClassProcessor);
    candidateClassFiles.visit(new ClassFileVisitor() {
        public void visitClassFile(FileVisitDetails fileDetails) {
            testFrameworkDetector.processTestClass(fileDetails.getFile());
        }
    });
}
 
Example 14
private void filenameScan() {
    candidateClassFiles.visit(new ClassFileVisitor() {
        public void visitClassFile(FileVisitDetails fileDetails) {
            String className = fileDetails.getRelativePath().getPathString().replaceAll("\\.class", "").replace('/', '.');
            TestClassRunInfo testClass = new DefaultTestClassRunInfo(className);
            testClassProcessor.processTestClass(testClass);
        }
    });
}
 
Example 15
public void visitFile(FileVisitDetails fileDetails) {
    final File file = fileDetails.getFile();

    if (file.getAbsolutePath().endsWith(".class")) {
        visitClassFile(fileDetails);
    }
}
 
Example 16
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 17
private void processFile(FileVisitDetails visitDetails) {
    DefaultFileCopyDetails details = createDefaultFileCopyDetails(visitDetails);
    for (Action<? super FileCopyDetails> action : spec.getAllCopyActions()) {
        action.execute(details);
        if (details.isExcluded()) {
            return;
        }
    }
    action.processFile(details);
}
 
Example 18
Source Project: javaccPlugin   Source File: JavaccSourceFileVisitorTest.java    License: MIT License 5 votes vote down vote up
@Test
public void givenAJavaSourceFileWhenVisitFileThenDoesNotDelegateToTaskCompile() {
    FileVisitDetails fileDetails = mock(FileVisitDetails.class);
    File fileToVisit = new File(JAVA_SOURCE_FILE);
    when(fileDetails.getFile()).thenReturn(fileToVisit);
    when(fileDetails.getName()).thenReturn(JAVA_SOURCE_FILE);
    when(fileDetails.getPath()).thenReturn(JAVA_SOURCE_FILE);

    sourceVisitor.visitFile(fileDetails);

    verify(compiler, never()).compile(any(File.class), any(RelativePath.class));
    verify(logger).debug(anyString(), eq(fileToVisit.getAbsolutePath()), eq("JavaCC"));
}
 
Example 19
private void maybeDelete(FileVisitDetails fileDetails, boolean isDir) {
    RelativePath path = fileDetails.getRelativePath();
    if (!visited.contains(path)) {
        if (isDir) {
            GFileUtils.deleteDirectory(fileDetails.getFile());
        } else {
            GFileUtils.deleteQuietly(fileDetails.getFile());
        }
        didWork = true;
    }
}
 
Example 20
JarSnapshot createSnapshot(FileTree archivedClasses) {
    final Map<String, byte[]> hashes = new HashMap<String, byte[]>();
    archivedClasses.visit(new FileVisitor() {
        public void visitDir(FileVisitDetails dirDetails) {
        }

        public void visitFile(FileVisitDetails fileDetails) {
            hashes.put(fileDetails.getPath().replaceAll("/", ".").replaceAll("\\.class$", ""), hasher.hash(fileDetails.getFile()));
        }
    });
    return new JarSnapshot(hashes);
}
 
Example 21
private void detectionScan() {
    testFrameworkDetector.startDetection(testClassProcessor);
    candidateClassFiles.visit(new ClassFileVisitor() {
        public void visitClassFile(FileVisitDetails fileDetails) {
            testFrameworkDetector.processTestClass(fileDetails.getFile());
        }
    });
}
 
Example 22
private void filenameScan() {
    candidateClassFiles.visit(new ClassFileVisitor() {
        public void visitClassFile(FileVisitDetails fileDetails) {
            String className = fileDetails.getRelativePath().getPathString().replaceAll("\\.class", "").replace('/', '.');
            TestClassRunInfo testClass = new DefaultTestClassRunInfo(className);
            testClassProcessor.processTestClass(testClass);
        }
    });
}
 
Example 23
public void visitFile(FileVisitDetails fileDetails) {
    final File file = fileDetails.getFile();

    if (file.getAbsolutePath().endsWith(".class")) {
        visitClassFile(fileDetails);
    }
}
 
Example 24
Source Project: playframework   Source File: JavaScriptMinify.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void visitFile(final FileVisitDetails fileDetails) {
    final File outputFileDir = new File(destinationDir.get().getAsFile(), fileDetails.getRelativePath().getParent().getPathString());

    // Copy the raw form
    FileOperations fileOperations = ((ProjectInternal) getProject()).getFileOperations();
    fileOperations.copy(copySpec -> copySpec.from(fileDetails.getFile()).into(outputFileDir));

    // Capture the relative file
    relativeFiles.add(new RelativeFile(fileDetails.getFile(), fileDetails.getRelativePath()));
}
 
Example 25
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 26
public void visitFile(FileVisitDetails fileDetails) {
    File file = fileDetails.getFile();
    if (!file.getName().endsWith(".class")) {
        return;
    }
    String className = fileDetails.getPath().replaceAll("/", ".").replaceAll("\\.class$", "");
    if (!className.startsWith(packagePrefix)) {
        return;
    }

    ClassAnalysis analysis = analyzer.getClassAnalysis(className, file);
    accumulator.addClass(className, analysis.isDependencyToAll(), analysis.getClassDependencies());
}
 
Example 27
private void processFile(FileVisitDetails visitDetails) {
    DefaultFileCopyDetails details = createDefaultFileCopyDetails(visitDetails);
    for (Action<? super FileCopyDetails> action : copySpecResolver.getAllCopyActions()) {
        action.execute(details);
        if (details.isExcluded()) {
            return;
        }
    }
    action.processFile(details);
}
 
Example 28
Source Project: javaccPlugin   Source File: NonJavaccSourceFileVisitorTest.java    License: MIT License 5 votes vote down vote up
@Test
public void givenATextInputFileWhenVisitFileThenFileIsCopiedToTaskOutputDirectory() {
    FileVisitDetails fileDetails = mock(FileVisitDetails.class);
    when(fileDetails.getFile()).thenReturn(new File(inputDirectory, TEXT_INPUT_FILENAME));
    when(fileDetails.getName()).thenReturn(TEXT_INPUT_FILENAME);

    sourceVisitor.visitFile(fileDetails);

    assertEquals(1, outputDirectory.list().length);
    assertTrue(Arrays.asList(outputDirectory.list()).contains(TEXT_INPUT_FILENAME));
}
 
Example 29
Source Project: javaccPlugin   Source File: NonJavaccSourceFileVisitorTest.java    License: MIT License 5 votes vote down vote up
@Test(expected = JavaccTaskException.class)
public void givenAnUnexistingTextInputFileWhenVisitFileThenExceptionIsThrown() {
    FileVisitDetails fileDetails = mock(FileVisitDetails.class);
    when(fileDetails.getFile()).thenReturn(new File(UNEXISTING_INPUT_FILENAME));
    when(fileDetails.getName()).thenReturn(UNEXISTING_INPUT_FILENAME);

    sourceVisitor.visitFile(fileDetails);
}
 
Example 30
private void detectionScan() {
    testFrameworkDetector.startDetection(testClassProcessor);
    candidateClassFiles.visit(new ClassFileVisitor() {
        public void visitClassFile(FileVisitDetails fileDetails) {
            testFrameworkDetector.processTestClass(fileDetails.getFile());
        }
    });
}