From 1ea4ef339d76fd05e700fa49a732264ca0edd466 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Tue, 1 Oct 2024 22:23:24 +0100 Subject: [PATCH] Perform testing using module-path (#143) * Upgrade testing * Test as classpath-only, module-classpath and module-whitebox * Use Maven workarounds to achieve module-whitebox * Tested on Maven 3.8.8 and 3.9.9 --- .github/workflows/build.yml | 2 +- .gitignore | 3 +- pom.xml | 182 ++++++++++++------ src/test-whitebox/module-info.java | 33 ++++ .../java/org/joda/money/TestModulepath.java | 56 ++++++ 5 files changed, 210 insertions(+), 66 deletions(-) create mode 100644 src/test-whitebox/module-info.java create mode 100644 src/test/java/org/joda/money/TestModulepath.java diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b87736d..b25a45e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -35,7 +35,7 @@ jobs: - name: Maven version run: | mkdir -p ./.mvn - echo '-e -B -DtrimStackTrace=false' > ./.mvn/maven.config + echo '-e -B -ntp -DtrimStackTrace=false' > ./.mvn/maven.config mvn --version mkdir -p target diff --git a/.gitignore b/.gitignore index eb7b4b0..44a5e40 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,5 @@ /nbproject/ .idea *.iml -/test-output/ \ No newline at end of file +/test-output/ +/src/test/java/module-info.java diff --git a/pom.xml b/pom.xml index 921c406..1f84463 100644 --- a/pom.xml +++ b/pom.xml @@ -123,33 +123,103 @@ - + + + + + + + + org.apache.maven.plugins - maven-dependency-plugin + maven-surefire-plugin + + + default-test + + test + + + false + + + + + test-module-classpath + + test + + test + + true + + + + + + + test-module-whitebox + + test + + integration-test + + --patch-module org.joda.money=src/main/resources + + + + + + + + + + com.coderplus.maven.plugins + copy-rename-maven-plugin + ${copy-rename-maven-plugin.version} + + + activate-module-info + pre-integration-test + + copy + + + src/test-whitebox/module-info.java + src/test/java/module-info.java + + - copy-dependencies - compile + deactivate-module-info + post-integration-test - copy-dependencies + rename - ${project.build.directory}/dependencies - true - true + src/test/java/module-info.java + src/test-whitebox/module-info.java - + + org.apache.maven.plugins - maven-surefire-plugin - - --add-modules org.joda.convert --module-path ${project.build.directory}/dependencies ${argLine} - + maven-compiler-plugin + + + test-module-whitebox + + testCompile + + pre-integration-test + + + org.apache.felix @@ -168,6 +238,7 @@ ${joda.osgi.packages} ${joda.osgi.require.capability} + true @@ -438,44 +509,6 @@ - - - org.eclipse.m2e - lifecycle-mapping - 1.0.0 - - - - - - org.apache.felix - maven-bundle-plugin - [2.5.4,) - - manifest - - - - - - - - - org.apache.maven.plugins - maven-dependency-plugin - [3.1.1,) - - copy-dependencies - - - - - - - - - - @@ -631,6 +664,26 @@ + + + intellij-idea + + + idea.maven.embedder.version + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + --add-modules org.joda.convert + + + + + compat @@ -777,32 +830,33 @@ 3.4.0 3.4.0 3.13.0 - 3.1.2 - 3.7.1 + 3.1.3 + 3.8.0 3.5.0 - 3.2.5 - 3.1.2 + 3.2.6 + 3.1.3 3.4.2 - 3.8.0 - 3.4.0 - 3.13.1 - 3.24.0 - 3.6.2 + 3.10.0 + 3.5.0 + 3.15.0 + 3.25.0 + 3.7.0 3.1.1 2.4 3.3.1 3.12.1 3.3.1 - 3.3.1 - 3.3.1 + 3.5.0 + 3.5.0 3.2.0 - 1.323 + 1.0 + 1.326 1.6.0 0.8.12 1.6.13 0.11.1 0.15.1 - 4.8.6.2 + 4.8.6.4 21 diff --git a/src/test-whitebox/module-info.java b/src/test-whitebox/module-info.java new file mode 100644 index 0000000..de04614 --- /dev/null +++ b/src/test-whitebox/module-info.java @@ -0,0 +1,33 @@ +/* + * Copyright 2009-present, Stephen Colebourne + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Joda-Money test module. + */ +open module org.joda.money { + + // mandatory for testing + requires org.joda.convert; + + // all packages are exported + exports org.joda.money; + exports org.joda.money.format; + + requires transitive org.junit.jupiter.api; + requires transitive org.junit.jupiter.engine; + requires transitive org.junit.jupiter.params; + requires transitive org.assertj.core; +} diff --git a/src/test/java/org/joda/money/TestModulepath.java b/src/test/java/org/joda/money/TestModulepath.java new file mode 100644 index 0000000..6e769d8 --- /dev/null +++ b/src/test/java/org/joda/money/TestModulepath.java @@ -0,0 +1,56 @@ +/* + * Copyright 2009-present, Stephen Colebourne + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.joda.money; + +import static java.util.stream.Collectors.joining; + +import java.util.ArrayList; + +import org.junit.jupiter.api.Test; + +/** + * Test that the classpath/modulepath is correctly set. + */ +class TestModulepath { + + @Test + void dumpPaths() { + var classpath = System.getProperty("java.class.path", ""); + var modulepath = System.getProperty("jdk.module.path", ""); + System.out.println("Classpath: " + describePath(classpath)); + System.out.println("Modulepath: " + describePath(modulepath)); + } + + private static String describePath(String path) { + if (path.isEmpty()) { + return ""; + } + var list = new ArrayList(); + if (path.contains("target/classes") || path.contains("target\\classes")) { + list.add("target/classes"); + } + if (path.contains("target/test-classes") || path.contains("target\\test-classes")) { + list.add("target/test-classes"); + } + if (path.contains("joda-convert")) { + list.add("joda-convert"); + } + if (path.contains("junit-jupiter")) { + list.add("junit-jupiter"); + } + return list.isEmpty() ? path : list.stream().collect(joining(" ")); + } +}