use of org.gradle.api.file.RelativePath in project gradle by gradle.
the class SyncCopyActionDecorator method execute.
@Override
public WorkResult execute(final CopyActionProcessingStream stream) {
final Set<RelativePath> visited = new HashSet<>();
WorkResult didWork = delegate.execute(action -> stream.process(details -> {
visited.add(details.getRelativePath());
action.processFile(details);
}));
SyncCopyActionDecoratorFileVisitor fileVisitor = new SyncCopyActionDecoratorFileVisitor(visited, preserveSpec, deleter);
MinimalFileTree walker = directoryFileTreeFactory.create(baseDestDir).postfix();
walker.visit(fileVisitor);
visited.clear();
return WorkResults.didWork(didWork.getDidWork() || fileVisitor.didWork);
}
use of org.gradle.api.file.RelativePath in project gradle by gradle.
the class DefaultFileCopyDetails method getRelativePath.
@Override
public RelativePath getRelativePath() {
if (relativePath == null) {
RelativePath path = fileDetails.getRelativePath();
relativePath = specResolver.getDestPath().append(path.isFile(), path.getSegments());
}
return relativePath;
}
use of org.gradle.api.file.RelativePath in project gradle by gradle.
the class InstrumentingClasspathFileTransformer method visitEntries.
private void visitEntries(File source, ClasspathBuilder.EntryBuilder builder) throws IOException, FileException {
classpathWalker.visit(source, entry -> {
try {
if (entry.getName().endsWith(".class")) {
ClassReader reader = new ClassReader(entry.getContent());
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS);
Pair<RelativePath, ClassVisitor> chain = transform.apply(entry, classWriter);
reader.accept(chain.right, 0);
byte[] bytes = classWriter.toByteArray();
builder.put(chain.left.getPathString(), bytes);
} else {
builder.put(entry.getName(), entry.getContent());
}
} catch (Throwable e) {
throw new IOException("Failed to process the entry '" + entry.getName() + "' from '" + source + "'", e);
}
});
}
use of org.gradle.api.file.RelativePath in project gradle by gradle.
the class DirectoryTrees method contains.
public static boolean contains(FileSystem fileSystem, DirectoryTree tree, File file) {
String prefix = tree.getDir().getAbsolutePath() + File.separator;
if (!file.getAbsolutePath().startsWith(prefix)) {
return false;
}
RelativePath path = RelativePath.parse(true, file.getAbsolutePath().substring(prefix.length()));
return tree.getPatterns().getAsSpec().isSatisfiedBy(new DefaultFileTreeElement(file, path, fileSystem, fileSystem));
}
use of org.gradle.api.file.RelativePath in project gradle by gradle.
the class SingleIncludePatternFileTree method doVisit.
private void doVisit(FileVisitor visitor, File file, LinkedList<String> relativePath, int segmentIndex, AtomicBoolean stopFlag) {
if (stopFlag.get()) {
return;
}
String segment = patternSegments.get(segmentIndex);
if (segment.contains("**")) {
PatternSet patternSet = new PatternSet();
patternSet.include(includePattern);
patternSet.exclude(excludeSpec);
DirectoryFileTree fileTree = new DirectoryFileTree(baseDir, patternSet, fileSystem);
fileTree.visitFrom(visitor, file, new RelativePath(file.isFile(), relativePath.toArray(new String[relativePath.size()])));
} else if (segment.contains("*") || segment.contains("?")) {
PatternStep step = PatternStepFactory.getStep(segment, false);
File[] children = file.listFiles();
if (children == null) {
if (!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));
}
for (File child : children) {
if (stopFlag.get()) {
break;
}
String childName = child.getName();
if (step.matches(childName)) {
relativePath.addLast(childName);
doVisitDirOrFile(visitor, child, relativePath, segmentIndex + 1, stopFlag);
relativePath.removeLast();
}
}
} else {
relativePath.addLast(segment);
doVisitDirOrFile(visitor, new File(file, segment), relativePath, segmentIndex + 1, stopFlag);
relativePath.removeLast();
}
}
Aggregations