From 9332c518070d4131de26b1e6d6052d37e7dd6999 Mon Sep 17 00:00:00 2001 From: Finn Carroll Date: Thu, 19 Dec 2024 14:32:27 -0800 Subject: [PATCH] Add failing ThirdPartyAuditIT which mocks file collision. Signed-off-by: Finn Carroll --- .../precommit/ThirdPartyAuditTaskIT.java | 10 ++++++ .../thirdPartyAudit/sample_jars/build.gradle | 35 ++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/buildSrc/src/integTest/java/org/opensearch/gradle/precommit/ThirdPartyAuditTaskIT.java b/buildSrc/src/integTest/java/org/opensearch/gradle/precommit/ThirdPartyAuditTaskIT.java index 4e5bbfd409f90..b2d5e4fb7d7cf 100644 --- a/buildSrc/src/integTest/java/org/opensearch/gradle/precommit/ThirdPartyAuditTaskIT.java +++ b/buildSrc/src/integTest/java/org/opensearch/gradle/precommit/ThirdPartyAuditTaskIT.java @@ -48,6 +48,16 @@ public void setUp() throws Exception { setupJarJdkClasspath(getProjectDir("thirdPartyAudit")); } + public void testJarMetadataUnpackCollision() { + BuildResult result = getGradleRunner("thirdPartyAudit").withArguments( + ":clean", + ":empty", + "-s", + "-PcompileGroup=other.gradle:force-collision", + "-PcompileVersion=0.0.1" + ).build(); + } + public void testOpenSearchIgnored() { BuildResult result = getGradleRunner("thirdPartyAudit").withArguments( ":clean", diff --git a/buildSrc/src/testKit/thirdPartyAudit/sample_jars/build.gradle b/buildSrc/src/testKit/thirdPartyAudit/sample_jars/build.gradle index 3db2a6e7c2733..e83d128542c9c 100644 --- a/buildSrc/src/testKit/thirdPartyAudit/sample_jars/build.gradle +++ b/buildSrc/src/testKit/thirdPartyAudit/sample_jars/build.gradle @@ -51,6 +51,38 @@ dependencies { } } +// Must configure a single task for these test jars to ensure they are unzipped to the same directory +tasks.register("force-collision", Jar) { + destinationDirectory = file("${buildDir}/testrepo/org/other/gradle/collision-test/0.0.1/") + + doFirst { + def destDir = destinationDirectory.get().asFile + def shareDir = new File(temporaryDir, "jar1") + shareDir.mkdirs() + + def jarFile1 = new File(destDir, "dummy-license-file.jar") + def jarFile2 = new File(destDir, "dummy-license-dir.jar") + + // dummy-license-file.jar unpacks a META-INF/LICENSE file + def metaInf1 = new File(shareDir, "META-INF") + metaInf1.mkdirs() + new File(metaInf1, "LICENSE").text = "Test License Content" + + // dummy-license-dir.jar unpacks a META-INF/LICENSE/content.txt file + def licenseDir = new File(shareDir, "META-INF/LICENSE") + licenseDir.mkdirs() + new File(licenseDir, "content.txt").text = "Test Content" + + ant.jar(destfile: jarFile1) { + fileset(dir: shareDir) + } + + ant.jar(destfile: jarFile2) { + fileset(dir: shareDir) + } + } +} + tasks.register("jarhellJdk", Jar) { destinationDirectory = file("${buildDir}/testrepo/org/other/gradle/jarhellJdk/0.0.1/") archiveFileName = "jarhellJdk-0.0.1.jar" @@ -58,4 +90,5 @@ tasks.register("jarhellJdk", Jar) { include "**/String.class" into "java/lang" } -build.dependsOn("jarhellJdk") + +build.dependsOn("jarhellJdk", "force-collision")