/** * Run wsimport */ @TaskAction protected void wsimport() { Objects.requireNonNull(getWsdls()).visit(new EmptyFileVisitor() { /** * @see org.gradle.api.file.EmptyFileVisitor#visitFile(org.gradle.api.file.FileVisitDetails) */ @Override public void visitFile(FileVisitDetails file) { Path relativeWsdlFile = Paths.get(file.getPath()); Path absoluteWsdlFile = file.getFile().toPath(); if (relativeWsdlFile.isAbsolute() || !absoluteWsdlFile.isAbsolute()) { throw new IllegalArgumentException(String.format("Illegal file visit details %s", file)); } Path baseDir = Objects.requireNonNull(absoluteWsdlFile.getRoot()).resolve( absoluteWsdlFile.subpath(0, absoluteWsdlFile.getNameCount() - relativeWsdlFile.getNameCount())); runWsimport(baseDir, relativeWsdlFile); } }); }
private void processDirectory(File file, final Trie.Builder builder) { new DirectoryFileTree(file).visit(new FileVisitor() { @Override public void visitDir(FileVisitDetails dirDetails) { } @Override public void visitFile(FileVisitDetails fileDetails) { try { ZipEntry zipEntry = new ZipEntry(fileDetails.getPath()); InputStream inputStream = fileDetails.open(); try { processEntry(zipEntry, builder); } finally { inputStream.close(); } } catch (IOException e) { throw new UncheckedIOException(e); } } }); }
JarSnapshot createSnapshot(HashCode hash, FileTree classes, final ClassFilesAnalyzer analyzer) { final Map<String, HashCode> hashes = Maps.newHashMap(); classes.visit(new FileVisitor() { public void visitDir(FileVisitDetails dirDetails) { } public void visitFile(FileVisitDetails fileDetails) { analyzer.visitFile(fileDetails); String className = fileDetails.getPath().replaceAll("/", ".").replaceAll("\\.class$", ""); HashCode classHash = hasher.hash(fileDetails.getFile()); hashes.put(className, classHash); } }); return new JarSnapshot(new JarSnapshotData(hash, hashes, analyzer.getAnalysis())); }
protected void handleDiscoveredInputs(T spec, IncrementalCompilation compilation, final DiscoveredInputRecorder discoveredInputRecorder) { for (File includeFile : compilation.getDiscoveredInputs()) { discoveredInputRecorder.newInput(includeFile); } if (sourceFilesUseMacroIncludes(spec.getSourceFiles(), compilation.getFinalState())) { LOGGER.info("After parsing the source files, Gradle cannot calculate the exact set of include files for {}. Every file in the include search path will be considered an input.", task.getName()); for (final File includeRoot : spec.getIncludeRoots()) { LOGGER.info("adding files in {} to discovered inputs for {}", includeRoot, task.getName()); directoryFileTreeFactory.create(includeRoot).visit(new EmptyFileVisitor() { @Override public void visitFile(FileVisitDetails fileDetails) { discoveredInputRecorder.newInput(fileDetails.getFile()); } }); } } }
@Override public void visitTreeOrBackingFile(final FileVisitor visitor) { File backingFile = getBackingFile(); if (backingFile!=null) { new SingletonFileTree(backingFile).visit(visitor); } else { // We need to wrap the visitor so that the file seen by the visitor has already // been extracted from the archive and we do not try to extract it again. // It's unsafe to keep the FileVisitDetails provided by TarFileTree directly // because we do not expect to visit the same paths again (after extracting everything). visit(new FileVisitor() { @Override public void visitDir(FileVisitDetails dirDetails) { visitor.visitDir(new DefaultFileVisitDetails(dirDetails.getFile(), chmod, stat)); } @Override public void visitFile(FileVisitDetails fileDetails) { visitor.visitFile(new DefaultFileVisitDetails(fileDetails.getFile(), chmod, stat)); } }); } }
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; }
@Override public void visitFile(final FileVisitDetails fileDetails) { final File outputFileDir = new File(destinationDir, fileDetails.getRelativePath().getParent().getPathString()); // Copy the raw form FileOperations fileOperations = (ProjectInternal) getProject(); fileOperations.copy(new Action<CopySpec>() { @Override public void execute(CopySpec copySpec) { copySpec.from(fileDetails.getFile()).into(outputFileDir); } }); // Capture the relative file relativeFiles.add(new RelativeFile(fileDetails.getFile(), fileDetails.getRelativePath())); }
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())); }
private Collection<String> accumulatePackages() { final Collection<String> result = new HashSet<>(); compileSourceRoots.getAsFileTree().visit(new FileVisitor() { @Override public void visitDir(FileVisitDetails dirDetails) { final String packageName = dirDetails.getRelativePath().getPathString().replace(File.separatorChar, '.'); if (logger.isDebugEnabled()) { logger.debug("Packages: " + packageName); } result.add(packageName); } @Override public void visitFile(FileVisitDetails fileDetails) { // ignore } }); return result; }
@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)); }
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())); } }); }
@Override public void visitFile(FileVisitDetails fileDetails) { File file = fileDetails.getFile(); if (!hasExtension(file, ".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()); }
private void detectionScan() { testFrameworkDetector.startDetection(testClassProcessor); candidateClassFiles.visit(new ClassFileVisitor() { public void visitClassFile(FileVisitDetails fileDetails) { testFrameworkDetector.processTestClass(fileDetails.getFile()); } }); }
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); } }); }
@Override public void visitFile(FileVisitDetails fileDetails) { final File file = fileDetails.getFile(); if (file.getAbsolutePath().endsWith(".class")) { visitClassFile(fileDetails); } }
private void storeDirectoryEntry(FileVisitDetails dirDetails, String propertyRoot, TarOutputStream outputStream) throws IOException { String path = dirDetails.getRelativePath().getPathString(); TarEntry entry = new TarEntry(propertyRoot + path + "/"); storeModificationTime(entry, dirDetails.getLastModified()); entry.setMode(UnixStat.DIR_FLAG | dirDetails.getMode()); outputStream.putNextEntry(entry); outputStream.closeEntry(); }
@Override public FileTree visit(Action<? super FileVisitDetails> visitor) { for (FileTree tree : getSourceCollections()) { tree.visit(visitor); } return this; }
@Override public void walkDir(File file, RelativePath path, FileVisitor visitor, Spec<? super FileTreeElement> spec, AtomicBoolean stopFlag, boolean postfix) { File[] children = file.listFiles(); if (children == null) { if (file.isDirectory() && !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)); } List<FileVisitDetails> dirs = new ArrayList<FileVisitDetails>(); for (int i = 0; !stopFlag.get() && i < children.length; i++) { File child = children[i]; boolean isFile = child.isFile(); RelativePath childPath = path.append(isFile, child.getName()); FileVisitDetails details = new DefaultFileVisitDetails(child, childPath, stopFlag, fileSystem, fileSystem, !isFile); if (DirectoryFileTree.isAllowed(details, spec)) { if (isFile) { visitor.visitFile(details); } else { dirs.add(details); } } } // now handle dirs for (int i = 0; !stopFlag.get() && i < dirs.size(); i++) { FileVisitDetails dir = dirs.get(i); if (postfix) { walkDir(dir.getFile(), dir.getRelativePath(), visitor, spec, stopFlag, postfix); visitor.visitDir(dir); } else { visitor.visitDir(dir); walkDir(dir.getFile(), dir.getRelativePath(), visitor, spec, stopFlag, postfix); } } }
private void processSingleFile(File file, FileVisitor visitor, Spec<FileTreeElement> spec, AtomicBoolean stopFlag) { RelativePath path = new RelativePath(true, file.getName()); FileVisitDetails details = new DefaultFileVisitDetails(file, path, stopFlag, fileSystem, fileSystem, false); if (isAllowed(details, spec)) { visitor.visitFile(details); } }
public DefaultFileCopyDetails(FileVisitDetails fileDetails, CopySpecResolver specResolver, Chmod chmod) { super(chmod); this.filterChain = new FilterChain(specResolver.getFilteringCharset()); this.fileDetails = fileDetails; this.specResolver = specResolver; this.duplicatesStrategy = specResolver.getDuplicatesStrategy(); }
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); }
private void maybeDelete(FileVisitDetails fileDetails, boolean isDir) { RelativePath path = fileDetails.getRelativePath(); if (!visited.contains(path)) { if (preserveSet.isEmpty() || !preserveSpec.isSatisfiedBy(fileDetails)) { if (isDir) { GFileUtils.deleteDirectory(fileDetails.getFile()); } else { GFileUtils.deleteQuietly(fileDetails.getFile()); } didWork = true; } } }
@Override public void run() { this.candidateClassFiles.visit(new ClassFileVisitor() { @Override public void visitClassFile(FileVisitDetails fileDetails) { String className = fileDetails.getRelativePath().getPathString().replaceAll("\\.class", "").replace('/', '.'); TestClassRunInfo testClass = new DefaultTestClassRunInfo(className); EclipsePluginTestClassScanner.this.testClassProcessor.processTestClass(testClass); } }); }
@Override public void visitFile(FileVisitDetails fileDetails) { final File file = fileDetails.getFile(); if (isValidTestClassFile(file)) { visitClassFile(fileDetails); } }
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()); }
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; } }
public void visitFile(FileVisitDetails fileDetails) { final File file = fileDetails.getFile(); if (file.getAbsolutePath().endsWith(".class")) { visitClassFile(fileDetails); } }
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); }
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); }
private static Set<String> classesInJar(FileTree jarContents) { final Set<String> out = new HashSet<String>(); jarContents.visit(new FileVisitor() { public void visitDir(FileVisitDetails dirDetails) {} public void visitFile(FileVisitDetails fileDetails) { out.add(fileDetails.getPath().replaceAll("/", ".").replaceAll("\\.class$", "")); } }); return out; }