Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Gradle Wrapper and build against Java 18 #651

Merged
merged 31 commits into from Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
2f77469
Upgrade from Gradle Wrapper 7.4 to 7.5
beatngu13 Jul 14, 2022
a3c8760
Upgrade Java version(s)
beatngu13 Jul 14, 2022
12edd78
Include JUnit Jupiter 5.9.0-RC1
beatngu13 Jul 14, 2022
18270b5
Revert "Include JUnit Jupiter 5.9.0-RC1"
beatngu13 Jul 14, 2022
17121f3
Disable envvar demo on Java 17+
beatngu13 Jul 15, 2022
3d03a6f
Replace archived sormuras/download-jdk with oracle-actions/setup-java
beatngu13 Jul 15, 2022
5fee5f0
Use 18 as experimental Java version
beatngu13 Aug 17, 2022
8ad21fb
Disable mixed abstract entry-based tests on Java 17+
beatngu13 Aug 17, 2022
c751e56
Use --add-opens JVM instead of disabling tests on Java 17+
beatngu13 Aug 17, 2022
976832a
Fix documentation for --add-opens
beatngu13 Aug 17, 2022
2789d03
Refactor
beatngu13 Aug 17, 2022
9601940
Sync Javadoc with SetEnvironmentVariable
beatngu13 Aug 17, 2022
d80f22f
Modify JVM args for test and demo
beatngu13 Aug 27, 2022
d383e2c
Add missing module-info directives
beatngu13 Aug 28, 2022
fc2c373
Do whitebox testing with module patching
beatngu13 Aug 28, 2022
b8f47c7
Merge branch 'main' into issue/613-upgrade-gradle-and-pipeline
beatngu13 Aug 28, 2022
d34d55e
Fix Xlint on non-modular builds
beatngu13 Aug 28, 2022
798eb0a
Add Xlint key missing-explicit-ctor only on Java 16+
beatngu13 Aug 28, 2022
30234f8
Add missing provides declarative to test module-info.java
beatngu13 Sep 5, 2022
ae1332e
Replace extractingResultOf with extracting
beatngu13 Sep 5, 2022
8554f9e
Update --add-opens in docs
beatngu13 Sep 5, 2022
2a5f48a
Allow setting SecurityManager on Java 12+
beatngu13 Sep 5, 2022
e68e91d
Changing the java version for gradle for experimental build
aepfli Sep 6, 2022
5973312
Improve description of experimental job
beatngu13 Sep 6, 2022
be7295d
Bump experimental build to 19
Sep 14, 2022
84e6ca8
Add comments to suppressed deprecation warnings
Sep 14, 2022
11e2005
Add comments for our build script quirks
beatngu13 Sep 18, 2022
dd2e5ad
Untangle patching and linting
beatngu13 Sep 18, 2022
ff5cfe4
Improve value extraction
beatngu13 Sep 18, 2022
1c605bd
Set Javadoc language level to 17+
beatngu13 Sep 18, 2022
922cba0
Try without exclude of internal package
beatngu13 Sep 18, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 9 additions & 11 deletions .github/workflows/build.yml
Expand Up @@ -117,7 +117,7 @@ jobs:
timeout-minutes: 15
strategy:
matrix:
java: [ 11, 17 ]
java: [ 11, 17, 18 ]
junit-version: [ '5.9.0' ]
modular: [true, false]
os: [ubuntu, macos, windows]
Expand Down Expand Up @@ -151,23 +151,21 @@ jobs:
modular: [true, false]
os: [ubuntu, macos, windows]
name: Experimental build with newest JDK early-access build and Gradle release candidate
# Gradle doesn't work with JDK EA builds, so we start it with a supported Java version,
# but execute the build on the experimental version
# Gradle doesn't work with JDK EA builds, so we launch it with a supported Java version,
# but set the Gradle toolchain to use the experimental version.
steps:
- name: Check out repo
uses: actions/checkout@v2
- uses: sormuras/download-jdk@v1
- name: Set up experimental Java
uses: oracle-actions/setup-java@v1
beatngu13 marked this conversation as resolved.
Show resolved Hide resolved
with:
feature: ${{ env.EXPERIMENTAL_JAVA }}
- uses: actions/setup-java@v2
with:
java-version: ${{ env.JDK_VERSION }}
distribution: jdkfile
jdkFile: ${{ env.JDK_FILE }}
website: jdk.java.net
release: ${{ env.EXPERIMENTAL_JAVA }}
- name: Prepare JDK_EXPERIMENTAL env var
shell: bash
run: echo "JDK_EXPERIMENTAL=$JAVA_HOME" >> $GITHUB_ENV
- uses: actions/setup-java@v2
- name: Set up supported Java
uses: actions/setup-java@v2
with:
java-version: 17
distribution: temurin
Expand Down
59 changes: 45 additions & 14 deletions build.gradle.kts
Expand Up @@ -198,6 +198,10 @@ tasks {
if (modularBuild.toBoolean())
java.srcDir("src/main/module")
}
test {
if (modularBuild.toBoolean())
java.srcDir("src/test/module")
}
create("demo") {
java {
srcDir("src/demo/java")
Expand All @@ -223,10 +227,29 @@ tasks {
options.compilerArgs.add("-Xlint:all,-exports")
}

// Prepares test-related JVM args
val moduleName = "org.junitpioneer"
val targetModule = if (modularBuild.toBoolean()) moduleName else "ALL-UNNAMED"
val patchModuleArg = "--patch-module=$moduleName=${compileJava.get().destinationDirectory.asFile.get().path}"
beatngu13 marked this conversation as resolved.
Show resolved Hide resolved
val testJvmArgs = listOf(
"-XX:+IgnoreUnrecognizedVMOptions",
"--add-opens=java.base/java.util=$targetModule",
beatngu13 marked this conversation as resolved.
Show resolved Hide resolved
"--add-opens=java.base/java.lang=$targetModule",
patchModuleArg
)

compileTestJava {
options.encoding = "UTF-8"
options.compilerArgs.add("-Werror")
options.compilerArgs.add("-Xlint:all")
var xlintArg = "-Xlint:all"
if (modularBuild.toBoolean()) {
options.compilerArgs.add(patchModuleArg)
beatngu13 marked this conversation as resolved.
Show resolved Hide resolved
xlintArg += ",-exports,-requires-automatic"
if (JavaVersion.current() >= JavaVersion.VERSION_16) {
xlintArg += ",-missing-explicit-ctor"
}
beatngu13 marked this conversation as resolved.
Show resolved Hide resolved
}
options.compilerArgs.add(xlintArg)
}

test {
Expand All @@ -241,19 +264,17 @@ tasks {
includeTestsMatching("*Tests")
}
systemProperty("java.util.logging.manager", "org.apache.logging.log4j.jul.LogManager")
// `EnvironmentVariableExtension` uses reflection to change environment variables;
// this prevents the corresponding warning (and keeps working on Java 8)
// IF YOU ADD MORE OPTIONS; CONSIDER REPLACING `-XX:+IgnoreUnrecognizedVMOptions WITH A CONDITIONAL
jvmArgs(
"-XX:+IgnoreUnrecognizedVMOptions",
"--add-opens=java.base/java.util=ALL-UNNAMED")
if (JavaVersion.current() >= JavaVersion.VERSION_12)
systemProperty("java.security.manager", "allow")
beatngu13 marked this conversation as resolved.
Show resolved Hide resolved
jvmArgs(testJvmArgs)
}

testing {
suites {
val test by getting(JvmTestSuite::class) {
useJUnitJupiter()
}

val demoTests by registering(JvmTestSuite::class) {
dependencies {
implementation(project)
Expand All @@ -262,15 +283,25 @@ tasks {
}

sources {
java { srcDir("src/demo/java") }
resources { srcDir("src/demo/resources") }
java {
srcDir("src/demo/java")
}
resources {
srcDir("src/demo/resources")
}
}
targets { all { testTask.configure {
shouldRunAfter(test)
filter {
includeTestsMatching("*Demo")

targets {
all {
testTask.configure {
shouldRunAfter(test)
filter {
includeTestsMatching("*Demo")
}
jvmArgs(testJvmArgs)
}
}
} } }
}
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion docs/environment-variables.adoc
Expand Up @@ -66,8 +66,15 @@ module java.base does not "opens java.lang" to unnamed module [...]
----

The best way to prevent these warnings/errors, is to change the code under test, so this extension is no longer needed.
The next best thing is to allow access to that specific package with `--add-opens=java.base/java.util=ALL-UNNAMED` (if you place JUnit Pioneer on the class path) or `--add-opens=java.base/java.util=org.junitpioneer` (if you place it on the module path).
The next best thing is to allow access to that specific package:

[source]
----
--add-opens java.base/java.util=$TARGET_MODULE
beatngu13 marked this conversation as resolved.
Show resolved Hide resolved
--add-opens java.base/java.lang=$TARGET_MODULE
----

Where `$TARGET_MODULE` equals `ALL-UNNAMED` if you place JUnit Pioneer on the class path, or `org.junitpioneer` if you place JUnit Pioneer on the module path.
These command line options need to be added to the JVM that executes the tests:

* https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html[Gradle]
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
6 changes: 6 additions & 0 deletions gradlew
Expand Up @@ -205,6 +205,12 @@ set -- \
org.gradle.wrapper.GradleWrapperMain \
"$@"

# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi

# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
Expand Down
14 changes: 8 additions & 6 deletions gradlew.bat
Expand Up @@ -14,7 +14,7 @@
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
Expand All @@ -25,7 +25,7 @@
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
if "%DIRNAME%"=="" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

Expand All @@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Expand Down Expand Up @@ -75,13 +75,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
if %ERRORLEVEL% equ 0 goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%

:mainEnd
if "%OS%"=="Windows_NT" endlocal
Expand Down
Expand Up @@ -35,9 +35,9 @@
* uses reflection to change them. This requires that the {@link SecurityManager}
* allows modifications and can potentially break on different operating systems and
* Java versions. Be aware that this is a fragile solution and consider finding a
* better one for your specific situation. If you're running on Java 9 or later, you
* may have to add {@code --add-opens=java.base/java.util=ALL-UNNAMED} to your test
* execution to prevent warnings or even errors.</p>
* better one for your specific situation. If you're running on Java 9 or later and
* are encountering warnings or errors, check
* <a href="https://junit-pioneer.org/docs/environment-variables/#warnings-for-reflective-access">the documentation</a>.</p>
*
* <p>During
* <a href="https://junit.org/junit5/docs/current/user-guide/#writing-tests-parallel-execution" target="_top">parallel test execution</a>,
Expand Down
3 changes: 3 additions & 0 deletions src/main/module/module-info.java
Expand Up @@ -22,11 +22,14 @@
exports org.junitpioneer.jupiter;
exports org.junitpioneer.jupiter.cartesian;
exports org.junitpioneer.jupiter.params;
exports org.junitpioneer.jupiter.json;

opens org.junitpioneer.vintage to org.junit.platform.commons;
opens org.junitpioneer.jupiter to org.junit.platform.commons;
opens org.junitpioneer.jupiter.cartesian to org.junit.platform.commons;
opens org.junitpioneer.jupiter.issue to org.junit.platform.commons;
opens org.junitpioneer.jupiter.params to org.junit.platform.commons;
opens org.junitpioneer.jupiter.json to org.junit.platform.commons, com.fasterxml.jackson.databind;

provides org.junit.platform.launcher.TestExecutionListener
with org.junitpioneer.jupiter.issue.IssueExtensionExecutionListener;
Expand Down
Expand Up @@ -506,7 +506,7 @@ void onMethods() throws NoSuchMethodException {
.allSatisfy(annotation -> assertThat(annotation)
.isInstanceOfAny(RepeatableTestAnnotation.class, NonRepeatableTestAnnotation.class,
MetaAnnotatedTestAnnotation.class))
.extractingResultOf("value")
.extracting(this::extractingResultOfValue)
.containsExactlyInAnyOrder("Inherited 4", "Inherited 5", "Inherited 6",
"Annotated with repeatable 2");
}
Expand All @@ -523,7 +523,7 @@ void onClassNotRepeated() {
.allSatisfy(annotation -> assertThat(annotation)
.isInstanceOfAny(RepeatableTestAnnotation.class, NonRepeatableTestAnnotation.class,
MetaAnnotatedTestAnnotation.class))
.extractingResultOf("value")
.extracting(this::extractingResultOfValue)
.containsExactlyInAnyOrder("Inherited 1", "Inherited 2", "Inherited 3",
"Annotated with repeatable 1");
}
Expand All @@ -539,7 +539,7 @@ void onMethodRepeated() throws NoSuchMethodException {
assertThat(result)
.hasSize(1)
.allSatisfy(annotation -> assertThat(annotation).isInstanceOf(MetaAnnotatedTestAnnotation.class))
.extractingResultOf("value")
.extracting(this::extractingResultOfValue)
.containsExactlyInAnyOrder("Annotated with repeatable 2");
}

Expand All @@ -553,10 +553,23 @@ void onClassRepeated() {
assertThat(result)
.hasSize(1)
.allSatisfy(annotation -> assertThat(annotation).isInstanceOf(MetaAnnotatedTestAnnotation.class))
.extractingResultOf("value")
.extracting(this::extractingResultOfValue)
.containsExactlyInAnyOrder("Annotated with repeatable 1");
}

// see https://github.com/assertj/assertj/issues/2760
String extractingResultOfValue(Annotation annotation) {
if (annotation instanceof MetaAnnotatedTestAnnotation) {
return ((MetaAnnotatedTestAnnotation) annotation).value();
} else if (annotation instanceof NonRepeatableTestAnnotation) {
return ((NonRepeatableTestAnnotation) annotation).value();
} else if (annotation instanceof RepeatableTestAnnotation) {
return ((RepeatableTestAnnotation) annotation).value();
} else {
return null;
}
beatngu13 marked this conversation as resolved.
Show resolved Hide resolved
}

}

}
Expand Up @@ -28,12 +28,9 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.condition.EnabledForJreRange;
import org.junit.jupiter.api.condition.JRE;
import org.junit.jupiter.api.extension.ExtensionConfigurationException;
import org.junitpioneer.testkit.ExecutionResults;

@EnabledForJreRange(max = JRE.JAVA_16, disabledReason = "See: https://github.com/junit-pioneer/junit-pioneer/issues/509")
@DisplayName("EnvironmentVariable extension")
class EnvironmentVariableExtensionTests {

Expand Down
Expand Up @@ -21,10 +21,7 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledForJreRange;
import org.junit.jupiter.api.condition.JRE;

@EnabledForJreRange(max = JRE.JAVA_16, disabledReason = "See: https://github.com/junit-pioneer/junit-pioneer/issues/509")
@DisplayName("JUnitPioneer system environment utilities")
@WritesEnvironmentVariable
class EnvironmentVariableUtilsTests {
Expand Down
53 changes: 53 additions & 0 deletions src/test/module/module-info.java
@@ -0,0 +1,53 @@
/**
* JUnit Pioneer provides extensions for <a href="https://github.com/junit-team/junit5/">JUnit 5</a>
* and its Jupiter API.
*
* <p>Pioneer does not limit itself to proven ideas with wide application but is purposely open to
* experiments. It aims to spin off successful and cohesive portions into sibling projects or back
* into the JUnit 5 code base.
*
* <p>The dependencies on Jupiter modules could be marked as <code>transitive</code> but that would
* allow users who depend on this module to not `require` org.junit.*, which would be backwards.
*/
module org.junitpioneer {
// see Javadoc for why these aren't transitive
requires org.junit.jupiter.api;
requires org.junit.jupiter.params;
requires org.junit.platform.launcher;

requires static com.fasterxml.jackson.core;
requires static com.fasterxml.jackson.databind;

exports org.junitpioneer.vintage;
exports org.junitpioneer.jupiter;
exports org.junitpioneer.jupiter.cartesian;
exports org.junitpioneer.jupiter.params;
exports org.junitpioneer.jupiter.json;

opens org.junitpioneer.vintage to org.junit.platform.commons;
opens org.junitpioneer.jupiter to org.junit.platform.commons, nl.jqno.equalsverifier;
opens org.junitpioneer.jupiter.cartesian to org.junit.platform.commons;
opens org.junitpioneer.jupiter.issue to org.junit.platform.commons;
opens org.junitpioneer.jupiter.params to org.junit.platform.commons;
opens org.junitpioneer.jupiter.json to org.junit.platform.commons, com.fasterxml.jackson.databind;

provides org.junit.platform.launcher.TestExecutionListener
with org.junitpioneer.jupiter.issue.IssueExtensionExecutionListener;
provides org.junitpioneer.jupiter.IssueProcessor
with org.junitpioneer.jupiter.issue.StoringIssueProcessor;
uses org.junitpioneer.jupiter.IssueProcessor;

requires org.junit.platform.testkit;
requires org.mockito;
requires org.assertj.core;
requires nl.jqno.equalsverifier;

// via org.assertj.core
requires java.instrument;
requires jdk.unsupported;
// via nl.jqno.equalsverifier
requires java.sql;

opens org.junitpioneer.internal to org.junit.platform.commons;
opens org.junitpioneer.testkit to org.junit.platform.commons;
}