use of org.gradle.api.file.FileVisitor in project gradle by gradle.
the class CompositeFileTreeTest method visitsEachTreeWithClosure.
@Test
public void visitsEachTreeWithClosure() {
final Closure visitor = TestUtil.TEST_CLOSURE;
final FileVisitor closureAsVisitor = DefaultGroovyMethods.asType(visitor, FileVisitor.class);
context.checking(new Expectations() {
{
oneOf(source1).visit(closureAsVisitor);
oneOf(source2).visit(closureAsVisitor);
}
});
tree.visit(visitor);
}
use of org.gradle.api.file.FileVisitor in project gradle by gradle.
the class CompositeFileTreeTest method visitsEachTreeWithVisitor.
@Test
public void visitsEachTreeWithVisitor() {
final FileVisitor visitor = context.mock(FileVisitor.class);
context.checking(new Expectations() {
{
oneOf(source1).visit(visitor);
oneOf(source2).visit(visitor);
}
});
tree.visit(visitor);
}
use of org.gradle.api.file.FileVisitor in project gradle by gradle.
the class SerializableCoffeeScriptCompileSpec method toRelativeFiles.
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()));
}
});
}
use of org.gradle.api.file.FileVisitor in project gradle by gradle.
the class TarTaskOutputPacker method storeDirectoryProperty.
private void storeDirectoryProperty(String propertyPath, File directory, final TarOutputStream outputStream) throws IOException {
if (!directory.isDirectory()) {
throw new IllegalArgumentException(String.format("Expected '%s' to be a directory", directory));
}
final String propertyRoot = propertyPath + "/";
outputStream.putNextEntry(new TarEntry(propertyRoot));
outputStream.closeEntry();
FileVisitor visitor = new FileVisitor() {
@Override
public void visitDir(FileVisitDetails dirDetails) {
try {
storeDirectoryEntry(dirDetails, propertyRoot, outputStream);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
@Override
public void visitFile(FileVisitDetails fileDetails) {
try {
String path = propertyRoot + fileDetails.getRelativePath().getPathString();
storeFileEntry(fileDetails.getFile(), path, fileDetails.getLastModified(), fileDetails.getSize(), fileDetails.getMode(), outputStream);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
};
directoryWalkerFactory.create().walkDir(directory, RelativePath.EMPTY_ROOT, visitor, Specs.satisfyAll(), new AtomicBoolean(), false);
}
use of org.gradle.api.file.FileVisitor in project gradle by gradle.
the class RuntimeShadedJarCreator method processDirectory.
private void processDirectory(final ZipOutputStream outputStream, File file, final byte[] buffer, final HashSet<String> seenPaths, final Map<String, List<String>> services) {
final List<FileVisitDetails> fileVisitDetails = new ArrayList<FileVisitDetails>();
directoryFileTreeFactory.create(file).visit(new FileVisitor() {
@Override
public void visitDir(FileVisitDetails dirDetails) {
fileVisitDetails.add(dirDetails);
}
@Override
public void visitFile(FileVisitDetails fileDetails) {
fileVisitDetails.add(fileDetails);
}
});
// We need to sort here since the file order obtained from the filesystem
// can change between machines and we always want to have the same shaded jars.
Collections.sort(fileVisitDetails, new Comparator<FileVisitDetails>() {
@Override
public int compare(FileVisitDetails o1, FileVisitDetails o2) {
return o1.getPath().compareTo(o2.getPath());
}
});
for (FileVisitDetails details : fileVisitDetails) {
try {
if (details.isDirectory()) {
ZipEntry zipEntry = newZipEntryWithFixedTime(details.getPath() + "/");
processEntry(outputStream, null, zipEntry, buffer, seenPaths, services);
} else {
ZipEntry zipEntry = newZipEntryWithFixedTime(details.getPath());
InputStream inputStream = details.open();
try {
processEntry(outputStream, inputStream, zipEntry, buffer, seenPaths, services);
} finally {
inputStream.close();
}
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}
Aggregations