Skip to content

Commit

Permalink
Adjust folder resolution.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Sep 23, 2024
1 parent 2c9ebed commit c85d85a
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,21 +173,26 @@ protected Iterable<File> discoverySet() {
*/
@TaskAction
public void apply() throws IOException {
if (!getSource().equals(getTarget()) && deleteRecursively(getTarget())) {
File source = getSource().getAbsoluteFile(), target = getTarget().getAbsoluteFile();
if (!source.equals(getTarget()) && deleteRecursively(getTarget())) {
getLogger().debug("Deleted target directory {}", getTarget());
}
Queue<File> queue = QueueFactory.make(Collections.singletonList(getSource()));
Queue<File> queue = QueueFactory.make(Collections.singletonList(source));
while (!queue.isEmpty()) {
File candidate = queue.remove();
File[] file = candidate.listFiles();
if (file != null) {
queue.addAll(Arrays.asList(file));
} else {
Path relative = getSource().toPath().relativize(candidate.toPath());
File targetCandidate = getTarget().toPath().resolve(relative).toFile();
getLogger().debug("Created dir " + targetCandidate.getParent() + ": " + targetCandidate.getParentFile().mkdirs());
getLogger().debug("Created file " + targetCandidate + ": " + targetCandidate.createNewFile());
doApply(new Plugin.Engine.Source.ForJarFile(candidate), new Plugin.Engine.Target.ForJarFile(targetCandidate));
if (!candidate.getAbsoluteFile().toString().startsWith(source.toString())) {
throw new IllegalStateException(candidate + " is not a subdirectory of " + source);
}
File resolved = new File(target, candidate.toString().substring(source.toString().length()));
if (resolved.getParentFile().mkdirs()) {
getLogger().debug("Created host directory for {}", resolved);
}
getLogger().debug("Transforming {} to {}", candidate, resolved);
doApply(new Plugin.Engine.Source.ForJarFile(candidate), new Plugin.Engine.Target.ForJarFile(resolved));
}
}
}
Expand Down

0 comments on commit c85d85a

Please sign in to comment.