From bdf421147305f8d9b9c12c7bc24367dfcbece089 Mon Sep 17 00:00:00 2001 From: Gabriele Cardosi Date: Mon, 24 Jun 2024 17:18:07 +0200 Subject: [PATCH] [incubator-kie-issues#1347] Enforce reproducible build (#6001) * [incubator-kie-issues#1347] Enforce reproducible build * [incubator-kie-issues#1347] Enforce reproducible build - using custom property * [incubator-kie-issues#1347] Enforce reproducible build - fix broken test on reproducible build --------- Co-authored-by: Gabriele-Cardosi --- .github/workflows/pr-drools.yml | 2 +- ...ultKieSessionFromByteArrayExampleTest.java | 18 +++++++--- pom.xml | 36 +++++++++++++++++++ 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/.github/workflows/pr-drools.yml b/.github/workflows/pr-drools.yml index a9f23db1ff0..d1f5f77b4f7 100644 --- a/.github/workflows/pr-drools.yml +++ b/.github/workflows/pr-drools.yml @@ -61,7 +61,7 @@ jobs: - name: Build Chain uses: apache/incubator-kie-kogito-pipelines/.ci/actions/build-chain@main env: - BUILD_MVN_OPTS_CURRENT: -Dfull + BUILD_MVN_OPTS_CURRENT: '-Dfull -Dreproducible' MAVEN_OPTS: "-Dfile.encoding=UTF-8" with: definition-file: https://raw.githubusercontent.com/${GROUP:apache}/incubator-kie-kogito-pipelines/${BRANCH:main}/.ci/pull-request-config.yaml 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 d43598a218a..76093b9989c 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 @@ -21,8 +21,10 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; +import java.io.FilenameFilter; import java.io.InputStream; import java.io.PrintStream; +import java.util.Arrays; import org.junit.Test; import org.kie.api.KieServices; @@ -120,11 +122,19 @@ public static File getFile(String exampleName) { 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")) { - return new File(targetFolder, str); - } + FilenameFilter expectedJArFilter = (d, str ) -> str.startsWith(exampleName) && + str.endsWith(".jar") && + !str.endsWith("-sources.jar") && + !str.endsWith("-tests.jar") && + !str.endsWith("-javadoc.jar"); + String[] foundFile = targetFolder.list(expectedJArFilter); + if (foundFile == null || foundFile.length == 0) { + throw new RuntimeException("The target jar does not exist, please build project " + exampleName + " first"); + } else if (foundFile.length > 1) { + String errorFiles = Arrays.toString(foundFile); + throw new RuntimeException("Multiple matching files exists: " + errorFiles + "; please check!"); } + return new File(targetFolder, foundFile[0]); } throw new RuntimeException("The target jar does not exist, please build project " + exampleName + " first"); diff --git a/pom.xml b/pom.xml index fcab554d20f..c23c483f355 100644 --- a/pom.xml +++ b/pom.xml @@ -239,6 +239,42 @@ drools-distribution + + reproducible-build + + + reproducible + + + + + + org.apache.maven.plugins + maven-artifact-plugin + + + check-buildplan + + check-buildplan + + + validate + + + compare + + compare + + + install + + + + + + rewrite