From 1888af0f92eeb92363bd298aa4b4e27504968440 Mon Sep 17 00:00:00 2001 From: sebthom Date: Sat, 7 Sep 2024 14:05:13 +0200 Subject: [PATCH] test: add test project --- .ci/build.sh | 20 +---- .ci/maven-toolchains.xml | 14 +++- .github/workflows/build.yml | 33 ++++---- pom.xml | 22 ++++-- src/test/project/pom.xml | 46 +++++++++++ .../com/vegardit/maven/parent/test/Shape.java | 77 +++++++++++++++++++ .../parent/test/RuntimeJavaVersionTest.java | 26 +++++++ .../maven/parent/test/ShapeTests.java | 35 +++++++++ 8 files changed, 231 insertions(+), 42 deletions(-) create mode 100644 src/test/project/pom.xml create mode 100644 src/test/project/src/main/java/com/vegardit/maven/parent/test/Shape.java create mode 100644 src/test/project/src/test/java/com/vegardit/maven/parent/test/RuntimeJavaVersionTest.java create mode 100644 src/test/project/src/test/java/com/vegardit/maven/parent/test/ShapeTests.java diff --git a/.ci/build.sh b/.ci/build.sh index cdb2ef10..eedc67a6 100644 --- a/.ci/build.sh +++ b/.ci/build.sh @@ -37,25 +37,7 @@ echo "###################################################" echo "# Determining GIT branch...... #" echo "###################################################" GIT_BRANCH=$(git branch --show-current) -echo " -> GIT Branch: $GIT_BRANCH"; echo - - -echo -echo "###################################################" -echo "# Configuring JDK Class Data Sharing... #" -echo "###################################################" -java_version=$(java -version 2>&1) -echo "$java_version" -# https://docs.oracle.com/javase/8/docs/technotes/guides/vm/class-data-sharing.html -jdk_version_checksum=$(echo "$java_version" | md5sum | cut -f1 -d" ") -if [[ ! -f $HOME/.xshare/$jdk_version_checksum ]]; then - echo " -> Generating shared class data archive..." - mkdir -p $HOME/.xshare - java -Xshare:dump -XX:+UnlockDiagnosticVMOptions -XX:SharedArchiveFile=$HOME/.xshare/$jdk_version_checksum -else - echo " -> Reusing shared class data archive..." -fi -export JAVA_TOOL_OPTIONS="${JAVA_TOOL_OPTIONS:-} -Xshare:on -XX:+UnlockDiagnosticVMOptions -XX:SharedArchiveFile=$HOME/.xshare/$jdk_version_checksum" +echo " -> GIT Branch: $GIT_BRANCH" echo diff --git a/.ci/maven-toolchains.xml b/.ci/maven-toolchains.xml index 39c6084c..1d079ddc 100644 --- a/.ci/maven-toolchains.xml +++ b/.ci/maven-toolchains.xml @@ -4,11 +4,21 @@ jdk - ${env.JAVA_VERSION} + 17 default - ${env.JAVA_HOME} + ${env.JAVA17_HOME} + + + + jdk + + 21 + default + + + ${env.JAVA21_HOME} diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ee0c12ed..b1a045f1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -97,25 +97,26 @@ jobs: uses: actions/checkout@v4 # https://github.com/actions/checkout - - name: "Install: JDK ${{ env.JAVA_VERSION }} ☕" + - name: "Install: JDK 21 ☕" # to run example unit tests uses: actions/setup-java@v4 # https://github.com/actions/setup-java + id: setup-java-21 with: distribution: temurin - java-version: ${{ env.JAVA_VERSION }} - - - # reusing CDS archives of the same JVM randomly fails in GitHub Actions with - # "An error has occurred while processing the shared archive file. shared class paths mismatch" - #- name: Calculate Java version checksum - # id: java-version-checksum - # run: | - # echo "md5sum=$(java -version 2>&1 | md5sum | cut -f1 -d" ")" >> $GITHUB_OUTPUT - #- name: Cache Java CDS archive - # uses: actions/cache@v3 - # with: - # path: | - # ~/.xshare/${{ steps.java-version-checksum.outputs.md5sum }} - # key: ${{ runner.os }}-xshare-${{ steps.java-version-checksum.outputs.md5sum }} + java-version: 21 + + + - name: "Install: JDK 17 ☕" # to run Maven and plugins and compile test project + uses: actions/setup-java@v4 # https://github.com/actions/setup-java + id: setup-java-17 + with: + distribution: temurin + java-version: 17 + + + - name: Set JAVA_HOME env vars + run: | + echo "JAVA17_HOME=${{ steps.setup-java-17.outputs.path }}" >> $GITHUB_ENV + echo "JAVA21_HOME=${{ steps.setup-java-21.outputs.path }}" >> $GITHUB_ENV - name: "Cache: Maven Binary" diff --git a/pom.xml b/pom.xml index bab718ca..27e86eb1 100644 --- a/pom.xml +++ b/pom.xml @@ -68,6 +68,9 @@ https://github.com/vegardit/vegardit-maven-parent/actions + + src/test/project + -1 ? javaVersion.substring(0, javaVersion.indexOf(".")) : javaVersion); - def ecjVersion = javaMajorVersion < 17 ? "3.33.0" : project.properties["eclipse-java-compiler.version"]; def ecjArtifactMeta = artifactFactory.createArtifactWithClassifier("org.eclipse.jdt", "ecj", ecjVersion, "jar", null); def ecjArtifact = artifactResolver.resolve(new org.apache.maven.artifact.resolver.ArtifactResolutionRequest() + def ecjVersion = javaMajorVersion < 17 ? "3.33.0" : project.properties["eclipse-java-compiler.version"]; + def ecjArtifactMeta = artifactFactory.createArtifactWithClassifier("org.eclipse.jdt", "ecj", ecjVersion, "jar", null); + def ecjArtifact = artifactResolver.resolve(new org.apache.maven.artifact.resolver.ArtifactResolutionRequest() .setArtifact(ecjArtifactMeta) .setLocalRepository(session.localRepository) .setRemoteRepositories(project.remoteArtifactRepositories) @@ -359,12 +366,16 @@ } + /* in Maven 4: session.topLevelProject.basedir https://github.com/apache/maven/pull/1061 */ + topdir = project.properties['maven.multiModuleProjectDirectory'] + + /* * loading/locating checkstyle config */ if(!project.properties.containsKey("checkstyle.config.path")) { - if(new File("src/etc/checkstyle.xml").exists()) { - setProjectProp("checkstyle.config.path", "src/etc/checkstyle.xml"); + if(new File("$topdir/src/etc/checkstyle.xml").exists()) { + setProjectProp("checkstyle.config.path", "$topdir/src/etc/checkstyle.xml"); } else { def checkstyleConfigArtifactMeta = null; if(project.properties.containsKey("checkstyle.config.artifact")) { @@ -397,8 +408,8 @@ * loading eclipse formatter config */ if(!project.properties.containsKey("eclipse-formatter.config.path")) { - if(new File("src/etc/eclipse-formatter.xml").exists()) { - setProjectProp("eclipse-formatter.config.path", "src/etc/eclipse-formatter.xml"); + if(new File("$topdir/src/etc/eclipse-formatter.xml").exists()) { + setProjectProp("eclipse-formatter.config.path", "$topdir/src/etc/eclipse-formatter.xml"); } else { def eclipseFormatterConfigArtifactMeta = null; if(project.properties.containsKey("eclipse-formatter.config.artifact")) { @@ -1960,6 +1971,7 @@ execute + ${github.site.skip}