From 09bdf6dc0a0d85b5098fb391bc503b6aa68c9df3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Kohlschu=CC=88tter?= Date: Wed, 13 Dec 2023 15:33:35 +0100 Subject: [PATCH] maven-plugin: Create directories under META-INF/jacline/scripts ... to further reduce the chance of duplicate names. --- .../jacline/mavenplugin/JaclineCompileMojo.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/jacline-maven-plugin/src/main/java/com/kohlschutter/jacline/mavenplugin/JaclineCompileMojo.java b/jacline-maven-plugin/src/main/java/com/kohlschutter/jacline/mavenplugin/JaclineCompileMojo.java index b44c4802..fadf6fe2 100644 --- a/jacline-maven-plugin/src/main/java/com/kohlschutter/jacline/mavenplugin/JaclineCompileMojo.java +++ b/jacline-maven-plugin/src/main/java/com/kohlschutter/jacline/mavenplugin/JaclineCompileMojo.java @@ -364,10 +364,14 @@ private void copyJavaScriptFiles(List roots, List entryPointsLis if (entryPointPaths.contains(f)) { continue; } - String simpleName = f.getName(f.getNameCount() - 1).toString(); - AtomicInteger ai = sameFileMap.computeIfAbsent(sameFileMapKeyForName(simpleName), ( - k) -> new AtomicInteger(0)); + Path relativePath = rp.relativize(f); + Path relativeParent = relativePath.getParent(); + + String simpleName = relativePath.getName(relativePath.getNameCount() - 1).toString(); + + AtomicInteger ai = sameFileMap.computeIfAbsent(sameFileMapKeyForName(relativePath + .toString()), (k) -> new AtomicInteger(0)); if (ai.get() != 0) { Matcher matcher = FILE_DEDUP_SUFFIX.matcher(simpleName); if (!matcher.find()) { @@ -377,13 +381,16 @@ private void copyJavaScriptFiles(List roots, List entryPointsLis String baseName = matcher.replaceFirst(""); // strip .js suffix do { simpleName = baseName + "-" + ai.incrementAndGet() + suffix; - } while (sameFileMap.containsKey(sameFileMapKeyForName(simpleName))); + relativePath = relativeParent.resolve(simpleName); + } while (sameFileMap.containsKey(sameFileMapKeyForName(relativePath.toString()))); sameFileMap.put(simpleName, new AtomicInteger(0)); } else { ai.incrementAndGet(); } - Files.copy(f, outDir.resolve(simpleName), StandardCopyOption.REPLACE_EXISTING); + Path targetPath = outDir.resolve(relativePath.toString()); + Files.createDirectories(targetPath.getParent()); + Files.copy(f, targetPath, StandardCopyOption.REPLACE_EXISTING); } } }