From c85d85af0e1e1161252e181df4c37137a82d4086 Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Mon, 23 Sep 2024 22:39:47 +0200 Subject: [PATCH] Adjust folder resolution. --- .../build/gradle/ByteBuddyJarsTask.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/byte-buddy-gradle-plugin/src/main/java/net/bytebuddy/build/gradle/ByteBuddyJarsTask.java b/byte-buddy-gradle-plugin/src/main/java/net/bytebuddy/build/gradle/ByteBuddyJarsTask.java index f5beb4ca65..9520e98a4e 100644 --- a/byte-buddy-gradle-plugin/src/main/java/net/bytebuddy/build/gradle/ByteBuddyJarsTask.java +++ b/byte-buddy-gradle-plugin/src/main/java/net/bytebuddy/build/gradle/ByteBuddyJarsTask.java @@ -173,21 +173,26 @@ protected Iterable 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 queue = QueueFactory.make(Collections.singletonList(getSource())); + Queue 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)); } } }