From 4e866bee2de3e8cf4bdcc16c272222f7d1c12155 Mon Sep 17 00:00:00 2001 From: Finn Carroll Date: Fri, 20 Dec 2024 10:47:13 -0800 Subject: [PATCH] ThirdPartyAudit append counter to duplicate files on unzip. Signed-off-by: Finn Carroll --- .../gradle/precommit/ThirdPartyAuditTask.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/buildSrc/src/main/java/org/opensearch/gradle/precommit/ThirdPartyAuditTask.java b/buildSrc/src/main/java/org/opensearch/gradle/precommit/ThirdPartyAuditTask.java index a74781ac44720..06d574bc6d8f9 100644 --- a/buildSrc/src/main/java/org/opensearch/gradle/precommit/ThirdPartyAuditTask.java +++ b/buildSrc/src/main/java/org/opensearch/gradle/precommit/ThirdPartyAuditTask.java @@ -309,6 +309,25 @@ private void extractJars(Set jars) { jars.forEach(jar -> { FileTree jarFiles = getProject().zipTree(jar); getProject().copy(spec -> { + spec.eachFile(details -> { + File targetFile = new File(jarExpandDir, details.getPath()); + if (targetFile.exists()) { + if ((targetFile.isDirectory() && !details.isDirectory()) || (details.isDirectory() && targetFile.isFile())) { + + // Windows duplicate handling. dup.txt-1, dup.txt-2, ... + int counter = 1; + String basePath = details.getPath(); + String newPath; + do { + newPath = basePath + "-" + counter++; + targetFile = new File(jarExpandDir, newPath); + } while (targetFile.exists()); + + details.setPath(newPath); + } + } + }); + spec.from(jarFiles); spec.into(jarExpandDir); // exclude classes from multi release jars