Skip to content

Commit

Permalink
Perform testing using module-path
Browse files Browse the repository at this point in the history
* Upgrade testing
* Test as classpath-only, module-classpath and module-whitebox
* Use Maven workarounds to achieve module-whitebox
* Workaround tested on Maven 3.9.9
  • Loading branch information
jodastephen committed Sep 26, 2024
1 parent 9807e37 commit d1d42be
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 29 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -46,7 +46,7 @@ jobs:

- name: Maven build
run: |
mvn install site
mvn -X install site
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
Expand Down
110 changes: 83 additions & 27 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,33 +123,89 @@
</execution>
</executions>
</plugin>
<!-- Hack to extract dependencies for Surefire plugin -->
<!-- Aim of this config is to test the project three times. -->
<!-- First, with both main and test code on the classpath (test lifecycle phase). -->
<!-- Then, with main code on the modulepath and test code on the classpath (test lifecycle phase). -->
<!-- Then, with both main and test code on the modulepath (integration-test lifecycle phase). -->
<!-- The last of these is achieved by a Maven workaround/hack. -->
<!-- When maven-compiler-plugin testCompile runs with two module-info.java files with the same module name -->
<!-- the code in both src/test/java and src/main/java is compiled into target/test-classes. -->
<!-- This is a bug, but we can use it to our advantage - all we have to do is patch in src/main/resources -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<!-- test with both main and test code on the classpath -->
<execution>
<id>default-test</id>
<configuration>
<useModulePath>false</useModulePath>
</configuration>
</execution>
<!-- test with main code on the modulepath and test code on the classpath -->
<execution>
<id>test-module-classpath</id>
<goals>
<goal>test</goal>
</goals>
<phase>test</phase>
<configuration>
<useModulePath>true</useModulePath>
</configuration>
</execution>
<!-- test with both main and test code on the modulepath (as a single patched module using src/test/java/module-info.java) -->
<!-- by this point, target/test-classes contains the complied form of src/test/java and src/main/java -->
<!-- patch-module ise used to add the missing src/main/resources without copying it -->
<execution>
<id>copy-dependencies</id>
<phase>compile</phase>
<id>test-module-whitebox</id>
<goals>
<goal>copy-dependencies</goal>
<goal>test</goal>
</goals>
<phase>integration-test</phase>
<configuration>
<outputDirectory>${project.build.directory}/dependencies</outputDirectory>
<overWriteReleases>true</overWriteReleases>
<overWriteIfNewer>true</overWriteIfNewer>
<argLine>--patch-module org.joda.money=src/main/resources</argLine>
</configuration>
</execution>
</executions>
</plugin>
<!-- Surefire plugin is broken, https://issues.apache.org/jira/browse/SUREFIRE-1501 -->
<!-- Avoid issues with IntelliJ and Eclipse by adding the module-info dynamically -->
<!-- Tests in either IDE will operate as classpath tests -->
<!-- Tests in Maven will operate as whitebox tests -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.6.0</version>
<executions>
<execution>
<id>add-source</id>
<goals>
<goal>add-test-source</goal>
</goals>
<phase>pre-integration-test</phase>
<configuration>
<sources>
<source>src/modtest/java/</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<!-- An additional testCompile step. -->
<!-- This recompiles the test code after src/test/java/module-info.java has been added as a test source by build-helper -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>--add-modules org.joda.convert --module-path ${project.build.directory}/dependencies ${argLine}</argLine>
</configuration>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>test-module-whitebox</id>
<goals>
<goal>testCompile</goal>
</goals>
<phase>pre-integration-test</phase>
</execution>
</executions>
</plugin>

<!-- Setup OSGi bundle data -->
<plugin>
<groupId>org.apache.felix</groupId>
Expand Down Expand Up @@ -777,32 +833,32 @@
<maven-checkstyle-plugin.version>3.4.0</maven-checkstyle-plugin.version>
<maven-clean-plugin.version>3.4.0</maven-clean-plugin.version>
<maven-compiler-plugin.version>3.13.0</maven-compiler-plugin.version>
<maven-deploy-plugin.version>3.1.2</maven-deploy-plugin.version>
<maven-dependency-plugin.version>3.7.1</maven-dependency-plugin.version>
<maven-deploy-plugin.version>3.1.3</maven-deploy-plugin.version>
<maven-dependency-plugin.version>3.8.0</maven-dependency-plugin.version>
<maven-enforcer-plugin.version>3.5.0</maven-enforcer-plugin.version>
<maven-gpg-plugin.version>3.2.5</maven-gpg-plugin.version>
<maven-install-plugin.version>3.1.2</maven-install-plugin.version>
<maven-gpg-plugin.version>3.2.6</maven-gpg-plugin.version>
<maven-install-plugin.version>3.1.3</maven-install-plugin.version>
<maven-jar-plugin.version>3.4.2</maven-jar-plugin.version>
<maven-javadoc-plugin.version>3.8.0</maven-javadoc-plugin.version>
<maven-jxr-plugin.version>3.4.0</maven-jxr-plugin.version>
<maven-plugin-plugin.version>3.13.1</maven-plugin-plugin.version>
<maven-pmd-plugin.version>3.24.0</maven-pmd-plugin.version>
<maven-project-info-reports-plugin.version>3.6.2</maven-project-info-reports-plugin.version>
<maven-javadoc-plugin.version>3.10.0</maven-javadoc-plugin.version>
<maven-jxr-plugin.version>3.5.0</maven-jxr-plugin.version>
<maven-plugin-plugin.version>3.15.0</maven-plugin-plugin.version>
<maven-pmd-plugin.version>3.25.0</maven-pmd-plugin.version>
<maven-project-info-reports-plugin.version>3.7.0</maven-project-info-reports-plugin.version>
<maven-release-plugin.version>3.1.1</maven-release-plugin.version>
<maven-repository-plugin.version>2.4</maven-repository-plugin.version>
<maven-resources-plugin.version>3.3.1</maven-resources-plugin.version>
<maven-site-plugin.version>3.12.1</maven-site-plugin.version>
<maven-site-plugin.version>3.20.0</maven-site-plugin.version>
<maven-source-plugin.version>3.3.1</maven-source-plugin.version>
<maven-surefire-plugin.version>3.3.1</maven-surefire-plugin.version>
<maven-surefire-report-plugin.version>3.3.1</maven-surefire-report-plugin.version>
<maven-surefire-plugin.version>3.5.0</maven-surefire-plugin.version>
<maven-surefire-report-plugin.version>3.5.0</maven-surefire-report-plugin.version>
<maven-toolchains-plugin.version>3.2.0</maven-toolchains-plugin.version>
<github-api.version>1.323</github-api.version>
<github-api.version>1.326</github-api.version>
<github-release-plugin.version>1.6.0</github-release-plugin.version>
<jacoco-maven-plugin.version>0.8.12</jacoco-maven-plugin.version>
<nexus-staging-maven-plugin.version>1.6.13</nexus-staging-maven-plugin.version>
<revapi-maven-plugin.version>0.11.1</revapi-maven-plugin.version>
<revapi-java.version>0.15.1</revapi-java.version>
<spotbugs-maven-plugin.version>4.8.6.2</spotbugs-maven-plugin.version>
<spotbugs-maven-plugin.version>4.8.6.4</spotbugs-maven-plugin.version>

<!-- Properties for maven-compiler-plugin -->
<maven.compiler.source>21</maven.compiler.source>
Expand Down
33 changes: 33 additions & 0 deletions src/modtest/java/module-info.java
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit d1d42be

Please sign in to comment.