From e892d71dec3e5de790fee8b31f55f26668aa16f3 Mon Sep 17 00:00:00 2001 From: Mario Fusco Date: Fri, 21 Jun 2024 10:25:46 +0200 Subject: [PATCH] [KIE-1339] fix Drools reproducible build also when running the complete test-suite (#5999) --- .../drools/core/util/KeyStoreHelperTest.java | 12 ++++++++++++ .../DefaultKieSessionFromFileExample.java | 14 ++++++-------- ...aultKieSessionFromByteArrayExampleTest.java | 18 ++++++++---------- .../KieModuleFromMultipleFilesExample.java | 14 ++++++-------- .../kiemodulemodel/KieModuleModelExample.java | 14 ++++++-------- .../NamedKieSessionFromFileExample.java | 14 ++++++-------- 6 files changed, 44 insertions(+), 42 deletions(-) diff --git a/drools-core/src/test/java/org/drools/core/util/KeyStoreHelperTest.java b/drools-core/src/test/java/org/drools/core/util/KeyStoreHelperTest.java index aa8b95b33a7..50868fc9997 100755 --- a/drools-core/src/test/java/org/drools/core/util/KeyStoreHelperTest.java +++ b/drools-core/src/test/java/org/drools/core/util/KeyStoreHelperTest.java @@ -18,6 +18,7 @@ */ package org.drools.core.util; +import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.UnsupportedEncodingException; @@ -35,6 +36,7 @@ import javax.crypto.SecretKeyFactory; import javax.crypto.spec.DESKeySpec; +import org.junit.AfterClass; import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -52,6 +54,16 @@ public class KeyStoreHelperTest { private static final String KEY_PASSWORD = "keypwd"; private static final String KEY_PHRASE = "secretkey"; + @AfterClass + public static void cleanup() { + try { + new File(KEYSTORE_JCEKS_FILENAME).delete(); + } catch (Exception e) { + // ignore + } + + } + @Test public void testSignDataWithPrivateKey() throws UnsupportedEncodingException, UnrecoverableKeyException, diff --git a/drools-examples-api/default-kiesession-from-file/src/main/java/org/drools/example/api/defaultkiesessionfromfile/DefaultKieSessionFromFileExample.java b/drools-examples-api/default-kiesession-from-file/src/main/java/org/drools/example/api/defaultkiesessionfromfile/DefaultKieSessionFromFileExample.java index 4022a96c58a..f2466e388dc 100644 --- a/drools-examples-api/default-kiesession-from-file/src/main/java/org/drools/example/api/defaultkiesessionfromfile/DefaultKieSessionFromFileExample.java +++ b/drools-examples-api/default-kiesession-from-file/src/main/java/org/drools/example/api/defaultkiesessionfromfile/DefaultKieSessionFromFileExample.java @@ -18,6 +18,9 @@ */ package org.drools.example.api.defaultkiesessionfromfile; +import java.io.File; +import java.io.PrintStream; + import org.kie.api.KieServices; import org.kie.api.builder.KieModule; import org.kie.api.builder.KieRepository; @@ -26,9 +29,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; -import java.io.PrintStream; - public class DefaultKieSessionFromFileExample { @@ -69,8 +69,7 @@ public static File getFile(String exampleName) { File folder = new File("drools-examples-api").getAbsoluteFile(); File exampleFolder = null; while (folder != null) { - exampleFolder = new File(folder, - exampleName); + exampleFolder = new File(folder, exampleName); if (exampleFolder.exists()) { break; } @@ -80,14 +79,13 @@ public static File getFile(String exampleName) { if (exampleFolder != null) { - File targetFolder = new File(exampleFolder, - "target"); + File targetFolder = new File(exampleFolder, "target"); if (!targetFolder.exists()) { throw new RuntimeException("The target folder does not exist, please build project " + exampleName + " first"); } for (String str : targetFolder.list()) { - if (str.startsWith(exampleName) && !str.endsWith("-sources.jar") && !str.endsWith("-tests.jar") && !str.endsWith("-javadoc.jar")) { + if (str.startsWith(exampleName) && str.endsWith(".jar") && !str.endsWith("-sources.jar") && !str.endsWith("-tests.jar") && !str.endsWith("-javadoc.jar")) { return new File(targetFolder, str); } } diff --git a/drools-examples-api/default-kiesession-from-file/src/test/java/org/drools/example/api/defaultkiesessionfromfile/DefaultKieSessionFromByteArrayExampleTest.java b/drools-examples-api/default-kiesession-from-file/src/test/java/org/drools/example/api/defaultkiesessionfromfile/DefaultKieSessionFromByteArrayExampleTest.java index 60c732e59a7..d43598a218a 100644 --- a/drools-examples-api/default-kiesession-from-file/src/test/java/org/drools/example/api/defaultkiesessionfromfile/DefaultKieSessionFromByteArrayExampleTest.java +++ b/drools-examples-api/default-kiesession-from-file/src/test/java/org/drools/example/api/defaultkiesessionfromfile/DefaultKieSessionFromByteArrayExampleTest.java @@ -18,6 +18,12 @@ */ package org.drools.example.api.defaultkiesessionfromfile; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.io.PrintStream; + import org.junit.Test; import org.kie.api.KieServices; import org.kie.api.builder.KieModule; @@ -25,12 +31,6 @@ import org.kie.api.runtime.KieContainer; import org.kie.api.runtime.KieSession; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStream; -import java.io.PrintStream; - import static org.junit.Assert.assertEquals; public class DefaultKieSessionFromByteArrayExampleTest { @@ -105,8 +105,7 @@ public static File getFile(String exampleName) { File folder = new File("drools-examples-api").getAbsoluteFile(); File exampleFolder = null; while (folder != null) { - exampleFolder = new File(folder, - exampleName); + exampleFolder = new File(folder, exampleName); if (exampleFolder.exists()) { break; } @@ -116,8 +115,7 @@ public static File getFile(String exampleName) { if (exampleFolder != null) { - File targetFolder = new File(exampleFolder, - "target"); + File targetFolder = new File(exampleFolder, "target"); if (!targetFolder.exists()) { throw new RuntimeException("The target folder does not exist, please build project " + exampleName + " first"); } diff --git a/drools-examples-api/kie-module-from-multiple-files/src/main/java/org/drools/example/api/kiemodulefrommultiplefiles/KieModuleFromMultipleFilesExample.java b/drools-examples-api/kie-module-from-multiple-files/src/main/java/org/drools/example/api/kiemodulefrommultiplefiles/KieModuleFromMultipleFilesExample.java index c058e3a3842..19ac711b914 100644 --- a/drools-examples-api/kie-module-from-multiple-files/src/main/java/org/drools/example/api/kiemodulefrommultiplefiles/KieModuleFromMultipleFilesExample.java +++ b/drools-examples-api/kie-module-from-multiple-files/src/main/java/org/drools/example/api/kiemodulefrommultiplefiles/KieModuleFromMultipleFilesExample.java @@ -18,6 +18,9 @@ */ package org.drools.example.api.kiemodulefrommultiplefiles; +import java.io.File; +import java.io.PrintStream; + import org.kie.api.KieServices; import org.kie.api.builder.KieModule; import org.kie.api.builder.KieRepository; @@ -27,9 +30,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; -import java.io.PrintStream; - public class KieModuleFromMultipleFilesExample { @@ -76,8 +76,7 @@ public static File getFile(String exampleName) { File folder = new File( KieModuleFromMultipleFilesExample.class.getProtectionDomain().getCodeSource().getLocation().getPath() ); File exampleFolder = null; while (folder != null) { - exampleFolder = new File(folder, - exampleName); + exampleFolder = new File(folder, exampleName); if (exampleFolder.exists()) { break; } @@ -87,14 +86,13 @@ public static File getFile(String exampleName) { if (exampleFolder != null) { - File targetFolder = new File(exampleFolder, - "target"); + File targetFolder = new File(exampleFolder, "target"); if (!targetFolder.exists()) { throw new RuntimeException("The target folder does not exist, please build project " + exampleName + " first"); } for (String str : targetFolder.list()) { - if (str.startsWith(exampleName) && !str.endsWith("-sources.jar") && !str.endsWith("-tests.jar") && !str.endsWith("-javadoc.jar")) { + if (str.startsWith(exampleName) && str.endsWith(".jar") && !str.endsWith("-sources.jar") && !str.endsWith("-tests.jar") && !str.endsWith("-javadoc.jar")) { return new File(targetFolder, str); } } diff --git a/drools-examples-api/kiemodulemodel-example/src/main/java/org/drools/example/api/kiemodulemodel/KieModuleModelExample.java b/drools-examples-api/kiemodulemodel-example/src/main/java/org/drools/example/api/kiemodulemodel/KieModuleModelExample.java index fc6c1c158ed..363d426c9de 100644 --- a/drools-examples-api/kiemodulemodel-example/src/main/java/org/drools/example/api/kiemodulemodel/KieModuleModelExample.java +++ b/drools-examples-api/kiemodulemodel-example/src/main/java/org/drools/example/api/kiemodulemodel/KieModuleModelExample.java @@ -18,6 +18,9 @@ */ package org.drools.example.api.kiemodulemodel; +import java.io.File; +import java.io.PrintStream; + import org.drools.base.util.Drools; import org.kie.api.KieServices; import org.kie.api.builder.KieBuilder; @@ -31,9 +34,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; -import java.io.PrintStream; - public class KieModuleModelExample { private static final Logger LOG = LoggerFactory.getLogger(KieModuleModelExample.class); @@ -115,8 +115,7 @@ public static File getFile(String exampleName) { File folder = new File("drools-examples-api").getAbsoluteFile(); File exampleFolder = null; while (folder != null) { - exampleFolder = new File(folder, - exampleName); + exampleFolder = new File(folder, exampleName); if (exampleFolder.exists()) { break; } @@ -126,14 +125,13 @@ public static File getFile(String exampleName) { if (exampleFolder != null) { - File targetFolder = new File(exampleFolder, - "target"); + File targetFolder = new File(exampleFolder, "target"); if (!targetFolder.exists()) { throw new RuntimeException("The target folder does not exist, please build project " + exampleName + " first"); } for (String str : targetFolder.list()) { - if (str.startsWith(exampleName) && !str.endsWith("-sources.jar") && !str.endsWith("-tests.jar") && !str.endsWith("-javadoc.jar")) { + if (str.startsWith(exampleName) && str.endsWith(".jar") && !str.endsWith("-sources.jar") && !str.endsWith("-tests.jar") && !str.endsWith("-javadoc.jar")) { return new File(targetFolder, str); } } diff --git a/drools-examples-api/named-kiesession-from-file/src/main/java/org/drools/example/api/namedkiesessionfromfile/NamedKieSessionFromFileExample.java b/drools-examples-api/named-kiesession-from-file/src/main/java/org/drools/example/api/namedkiesessionfromfile/NamedKieSessionFromFileExample.java index 330b4e4afd9..56784896361 100644 --- a/drools-examples-api/named-kiesession-from-file/src/main/java/org/drools/example/api/namedkiesessionfromfile/NamedKieSessionFromFileExample.java +++ b/drools-examples-api/named-kiesession-from-file/src/main/java/org/drools/example/api/namedkiesessionfromfile/NamedKieSessionFromFileExample.java @@ -18,6 +18,9 @@ */ package org.drools.example.api.namedkiesessionfromfile; +import java.io.File; +import java.io.PrintStream; + import org.kie.api.KieServices; import org.kie.api.builder.KieModule; import org.kie.api.builder.KieRepository; @@ -26,9 +29,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; -import java.io.PrintStream; - public class NamedKieSessionFromFileExample { @@ -69,8 +69,7 @@ public static File getFile(String exampleName) { File folder = new File("drools-examples-api").getAbsoluteFile(); File exampleFolder = null; while (folder != null) { - exampleFolder = new File(folder, - exampleName); + exampleFolder = new File(folder, exampleName); if (exampleFolder.exists()) { break; } @@ -80,14 +79,13 @@ public static File getFile(String exampleName) { if (exampleFolder != null) { - File targetFolder = new File(exampleFolder, - "target"); + File targetFolder = new File(exampleFolder, "target"); if (!targetFolder.exists()) { throw new RuntimeException("The target folder does not exist, please build project " + exampleName + " first"); } for (String str : targetFolder.list()) { - if (str.startsWith(exampleName) && !str.endsWith("-sources.jar") && !str.endsWith("-tests.jar") && !str.endsWith("-javadoc.jar")) { + if (str.startsWith(exampleName) && str.endsWith(".jar") && !str.endsWith("-sources.jar") && !str.endsWith("-tests.jar") && !str.endsWith("-javadoc.jar")) { return new File(targetFolder, str); } }