diff --git a/.github/actions/setup-test-jdk/action.yml b/.github/actions/setup-test-jdk/action.yml index 2aeb7c4f90f4..0d1099c45967 100644 --- a/.github/actions/setup-test-jdk/action.yml +++ b/.github/actions/setup-test-jdk/action.yml @@ -15,3 +15,10 @@ runs: check-latest: true - shell: bash run: echo "JDK8=$JAVA_HOME" >> $GITHUB_ENV + - uses: actions/setup-java@7a6d8a8234af8eb26422e24e3006232cccaa061b # v4 + with: + distribution: ${{ inputs.distribution }} + java-version: 17 + check-latest: true + - shell: bash + run: echo "JDK17=$JAVA_HOME" >> $GITHUB_ENV diff --git a/documentation/documentation.gradle.kts b/documentation/documentation.gradle.kts index 02c96f3035fc..068168209508 100644 --- a/documentation/documentation.gradle.kts +++ b/documentation/documentation.gradle.kts @@ -26,8 +26,8 @@ val modularProjects: List by rootProject modularProjects.forEach { evaluationDependsOn(it.path) } javaLibrary { - mainJavaVersion = JavaVersion.VERSION_1_8 - testJavaVersion = JavaVersion.VERSION_1_8 + mainJavaVersion = JavaVersion.VERSION_17 + testJavaVersion = JavaVersion.VERSION_17 } val apiReport = configurations.dependencyScope("apiReport") diff --git a/gradle.properties b/gradle.properties index 4f2ab7df9946..f95f4713c831 100644 --- a/gradle.properties +++ b/gradle.properties @@ -20,7 +20,7 @@ org.gradle.jvmargs=-Xmx1g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryEr org.gradle.caching=true org.gradle.parallel=true org.gradle.configuration-cache.parallel=true -org.gradle.java.installations.fromEnv=JDK8,JDK18,JDK19,JDK20,JDK21,JDK22,JDK23,JDK24 +org.gradle.java.installations.fromEnv=JDK8,JDK17,JDK21,JDK23,JDK24,JDK25 org.gradle.kotlin.dsl.allWarningsAsErrors=true # Test Distribution diff --git a/gradle/plugins/common/src/main/kotlin/JavaLibraryExtension.kt b/gradle/plugins/common/src/main/kotlin/JavaLibraryExtension.kt index 64a61da7fb7b..9cc28076bbc4 100644 --- a/gradle/plugins/common/src/main/kotlin/JavaLibraryExtension.kt +++ b/gradle/plugins/common/src/main/kotlin/JavaLibraryExtension.kt @@ -1,7 +1,7 @@ import org.gradle.api.JavaVersion open class JavaLibraryExtension { - var mainJavaVersion: JavaVersion = JavaVersion.VERSION_1_8 + var mainJavaVersion: JavaVersion = JavaVersion.VERSION_17 var testJavaVersion: JavaVersion = JavaVersion.VERSION_21 var configureRelease: Boolean = true } diff --git a/gradle/plugins/common/src/main/kotlin/junitbuild.java-library-conventions.gradle.kts b/gradle/plugins/common/src/main/kotlin/junitbuild.java-library-conventions.gradle.kts index b14973e05474..96b3b1b06bbc 100644 --- a/gradle/plugins/common/src/main/kotlin/junitbuild.java-library-conventions.gradle.kts +++ b/gradle/plugins/common/src/main/kotlin/junitbuild.java-library-conventions.gradle.kts @@ -184,10 +184,8 @@ val compileModule by tasks.registering(JavaCompile::class) { enabled = project in modularProjects source = fileTree(combinedModuleSourceDir).builtBy(prepareModuleSourceDir) destinationDirectory = moduleOutputDir - sourceCompatibility = "9" - targetCompatibility = "9" classpath = files() - options.release = 9 + options.release = 17 options.compilerArgs.addAll(listOf( // Suppress warnings for automatic modules: org.apiguardian.api, org.opentest4j "-Xlint:all,-requires-automatic,-requires-transitive-automatic", @@ -262,17 +260,14 @@ tasks.withType().configureEach { } tasks.compileJava { - // See: https://docs.oracle.com/en/java/javase/12/tools/javac.html options.compilerArgs.addAll(listOf( "-Xlint:all", // Enables all recommended warnings. "-Werror", // Terminates compilation when warnings occur. - // Required for compatibility with Java 8's reflection APIs (see https://github.com/junit-team/junit5/issues/3797). "-parameters", // Generates metadata for reflection on method parameters. )) } tasks.compileTestJava { - // See: https://docs.oracle.com/en/java/javase/12/tools/javac.html options.compilerArgs.addAll(listOf( "-Xlint", // Enables all recommended warnings. "-Xlint:-overrides", // Disables "method overrides" warnings. diff --git a/gradle/plugins/common/src/main/kotlin/junitbuild.java-multi-release-sources.gradle.kts b/gradle/plugins/common/src/main/kotlin/junitbuild.java-multi-release-sources.gradle.kts deleted file mode 100644 index 83b2a8e8e273..000000000000 --- a/gradle/plugins/common/src/main/kotlin/junitbuild.java-multi-release-sources.gradle.kts +++ /dev/null @@ -1,45 +0,0 @@ -import junitbuild.extensions.capitalized - -plugins { - id("junitbuild.java-library-conventions") -} - -val mavenizedProjects: List by rootProject.extra - -listOf(9, 17).forEach { javaVersion -> - val sourceSet = sourceSets.register("mainRelease${javaVersion}") { - compileClasspath += sourceSets.main.get().output - runtimeClasspath += sourceSets.main.get().output - java { - setSrcDirs(setOf("src/main/java${javaVersion}")) - } - } - - configurations.named(sourceSet.get().compileClasspathConfigurationName).configure { - extendsFrom(configurations.compileClasspath.get()) - } - - tasks { - - named("allMainClasses").configure { - dependsOn(sourceSet.get().classesTaskName) - } - - named(sourceSet.get().compileJavaTaskName).configure { - options.release = javaVersion - } - - named("checkstyle${sourceSet.name.capitalized()}").configure { - config = resources.text.fromFile(checkstyle.configDirectory.file("checkstyleMain.xml")) - } - - if (project in mavenizedProjects) { - javadoc { - source(sourceSet.get().allJava) - } - named("sourcesJar").configure { - from(sourceSet.get().allSource) - } - } - } -} diff --git a/junit-platform-commons/junit-platform-commons.gradle.kts b/junit-platform-commons/junit-platform-commons.gradle.kts index 3de45a7edfee..eba72705cce1 100644 --- a/junit-platform-commons/junit-platform-commons.gradle.kts +++ b/junit-platform-commons/junit-platform-commons.gradle.kts @@ -1,8 +1,5 @@ -import junitbuild.java.UpdateJarAction - plugins { id("junitbuild.java-library-conventions") - id("junitbuild.java-multi-release-sources") id("junitbuild.native-image-properties") `java-test-fixtures` } @@ -14,28 +11,3 @@ dependencies { compileOnlyApi(libs.apiguardian) } - -tasks.jar { - val release9ClassesDir = sourceSets.mainRelease9.get().output.classesDirs.singleFile - inputs.dir(release9ClassesDir).withPathSensitivity(PathSensitivity.RELATIVE) - doLast(objects.newInstance(UpdateJarAction::class).apply { - javaLauncher = javaToolchains.launcherFor(java.toolchain) - args.addAll( - "--file", archiveFile.get().asFile.absolutePath, - "--release", "9", - "-C", release9ClassesDir.absolutePath, "." - ) - }) -} - -tasks.codeCoverageClassesJar { - exclude("org/junit/platform/commons/util/ModuleUtils.class") - exclude("org/junit/platform/commons/util/PackageNameUtils.class") - exclude("org/junit/platform/commons/util/ServiceLoaderUtils.class") -} - -eclipse { - classpath { - sourceSets -= project.sourceSets.mainRelease9.get() - } -} diff --git a/junit-platform-commons/src/main/java/org/junit/platform/commons/util/ModuleUtils.java b/junit-platform-commons/src/main/java/org/junit/platform/commons/util/ModuleUtils.java index 980c06394ea2..9f20d964f471 100644 --- a/junit-platform-commons/src/main/java/org/junit/platform/commons/util/ModuleUtils.java +++ b/junit-platform-commons/src/main/java/org/junit/platform/commons/util/ModuleUtils.java @@ -10,18 +10,34 @@ package org.junit.platform.commons.util; -import static java.util.Collections.emptyList; -import static java.util.Collections.emptySet; +import static java.util.function.Predicate.isEqual; +import static java.util.stream.Collectors.toCollection; +import static java.util.stream.Collectors.toSet; import static org.apiguardian.api.API.Status.INTERNAL; +import java.io.IOException; +import java.lang.module.Configuration; +import java.lang.module.ModuleFinder; +import java.lang.module.ModuleReader; +import java.lang.module.ModuleReference; +import java.lang.module.ResolvedModule; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedHashSet; import java.util.List; import java.util.Optional; import java.util.Set; import java.util.function.Predicate; +import java.util.stream.Collectors; +import java.util.stream.Stream; import org.apiguardian.api.API; +import org.junit.platform.commons.JUnitException; import org.junit.platform.commons.logging.Logger; import org.junit.platform.commons.logging.LoggerFactory; +import org.junit.platform.commons.support.DefaultResource; import org.junit.platform.commons.support.Resource; import org.junit.platform.commons.support.scanning.ClassFilter; @@ -49,42 +65,40 @@ public class ModuleUtils { * potentially empty */ public static Set findAllNonSystemBootModuleNames() { - logger.config(() -> "Basic version of findAllNonSystemBootModuleNames() always returns an empty set!"); - return emptySet(); + // @formatter:off + Set systemModules = ModuleFinder.ofSystem().findAll().stream() + .map(reference -> reference.descriptor().name()) + .collect(toSet()); + return streamResolvedModules(name -> !systemModules.contains(name)) + .map(ResolvedModule::name) + .collect(toCollection(LinkedHashSet::new)); + // @formatter:on } /** - * Determine if the current Java runtime supports the Java Platform Module System. + * Java 9+ runtime supports the Java Platform Module System. * - * @return {@code true} if the Java Platform Module System is available, - * otherwise {@code false} + * @return {@code true} */ public static boolean isJavaPlatformModuleSystemAvailable() { - return false; + return true; } - /** - * Return the name of the module that the class or interface is a member of. - * - * @param type class or interface to analyze - * @return the module name; never {@code null} but potentially empty - */ public static Optional getModuleName(Class type) { - return Optional.empty(); + Preconditions.notNull(type, "Class type must not be null"); + + return Optional.ofNullable(type.getModule().getName()); } - /** - * Return the raw version of the module that the class or interface is a member of. - * - * @param type class or interface to analyze - * @return the raw module version; never {@code null} but potentially empty - */ public static Optional getModuleVersion(Class type) { - return Optional.empty(); + Preconditions.notNull(type, "Class type must not be null"); + + Module module = type.getModule(); + return module.isNamed() ? module.getDescriptor().rawVersion() : Optional.empty(); } /** - * Find all classes for the given module name. + * Find all {@linkplain Class classes} for the given module name. * * @param moduleName the name of the module to scan; never {@code null} or * empty @@ -96,12 +110,17 @@ public static List> findAllClassesInModule(String moduleName, ClassFilt Preconditions.notBlank(moduleName, "Module name must not be null or empty"); Preconditions.notNull(filter, "Class filter must not be null"); - logger.config(() -> "Basic version of findAllClassesInModule() always returns an empty list!"); - return emptyList(); + logger.debug(() -> "Looking for classes in module: " + moduleName); + // @formatter:off + Set moduleReferences = streamResolvedModules(isEqual(moduleName)) + .map(ResolvedModule::reference) + .collect(toSet()); + // @formatter:on + return scan(moduleReferences, filter, ModuleUtils.class.getClassLoader()); } /** - * Find all resources for the given module name. + * Find all {@linkplain Resource resources} for the given module name. * * @param moduleName the name of the module to scan; never {@code null} or * empty @@ -115,8 +134,178 @@ public static List findAllResourcesInModule(String moduleName, Predica Preconditions.notBlank(moduleName, "Module name must not be null or empty"); Preconditions.notNull(filter, "Resource filter must not be null"); - logger.config(() -> "Basic version of findAllResourcesInModule() always returns an empty list!"); - return emptyList(); + logger.debug(() -> "Looking for classes in module: " + moduleName); + // @formatter:off + Set moduleReferences = streamResolvedModules(isEqual(moduleName)) + .map(ResolvedModule::reference) + .collect(toSet()); + // @formatter:on + return scan(moduleReferences, filter, ModuleUtils.class.getClassLoader()); + } + + /** + * Stream resolved modules from current (or boot) module layer. + */ + private static Stream streamResolvedModules(Predicate moduleNamePredicate) { + Module module = ModuleUtils.class.getModule(); + ModuleLayer layer = module.getLayer(); + if (layer == null) { + logger.config(() -> ModuleUtils.class + " is a member of " + module + + " - using boot layer returned by ModuleLayer.boot() as fall-back."); + layer = ModuleLayer.boot(); + } + return streamResolvedModules(moduleNamePredicate, layer); + } + + /** + * Stream resolved modules from the supplied layer. + */ + private static Stream streamResolvedModules(Predicate moduleNamePredicate, + ModuleLayer layer) { + logger.debug(() -> "Streaming modules for layer @" + System.identityHashCode(layer) + ": " + layer); + Configuration configuration = layer.configuration(); + logger.debug(() -> "Module layer configuration: " + configuration); + Stream stream = configuration.modules().stream(); + return stream.filter(module -> moduleNamePredicate.test(module.name())); + } + + /** + * Scan for classes using the supplied set of module references, class + * filter, and loader. + */ + private static List> scan(Set references, ClassFilter filter, ClassLoader loader) { + logger.debug(() -> "Scanning " + references.size() + " module references: " + references); + ModuleReferenceClassScanner scanner = new ModuleReferenceClassScanner(filter, loader); + List> classes = new ArrayList<>(); + for (ModuleReference reference : references) { + classes.addAll(scanner.scan(reference)); + } + logger.debug(() -> "Found " + classes.size() + " classes: " + classes); + return Collections.unmodifiableList(classes); + } + + /** + * Scan for classes using the supplied set of module references, class + * filter, and loader. + */ + private static List scan(Set references, Predicate filter, + ClassLoader loader) { + logger.debug(() -> "Scanning " + references.size() + " module references: " + references); + ModuleReferenceResourceScanner scanner = new ModuleReferenceResourceScanner(filter, loader); + List classes = new ArrayList<>(); + for (ModuleReference reference : references) { + classes.addAll(scanner.scan(reference)); + } + logger.debug(() -> "Found " + classes.size() + " classes: " + classes); + return Collections.unmodifiableList(classes); + } + + /** + * {@link ModuleReference} class scanner. + * + * @since 1.1 + */ + static class ModuleReferenceClassScanner { + + private final ClassFilter classFilter; + private final ClassLoader classLoader; + + ModuleReferenceClassScanner(ClassFilter classFilter, ClassLoader classLoader) { + this.classFilter = classFilter; + this.classLoader = classLoader; + } + + /** + * Scan module reference for classes that potentially contain testable methods. + */ + List> scan(ModuleReference reference) { + try (ModuleReader reader = reference.open()) { + try (Stream names = reader.list()) { + // @formatter:off + return names.filter(name -> name.endsWith(".class")) + .map(this::className) + .filter(name -> !name.equals("module-info")) + .filter(classFilter::match) + .map(this::loadClassUnchecked) + .filter(classFilter::match) + .collect(Collectors.toList()); + // @formatter:on + } + } + catch (IOException e) { + throw new JUnitException("Failed to read contents of " + reference + ".", e); + } + } + + /** + * Convert resource name to binary class name. + */ + private String className(String resourceName) { + resourceName = resourceName.substring(0, resourceName.length() - 6); // 6 = ".class".length() + resourceName = resourceName.replace('/', '.'); + return resourceName; + } + + /** + * Load class by its binary name. + * + * @see ClassLoader#loadClass(String) + */ + private Class loadClassUnchecked(String binaryName) { + try { + return classLoader.loadClass(binaryName); + } + catch (ClassNotFoundException e) { + throw new JUnitException("Failed to load class with name '" + binaryName + "'.", e); + } + } + + } + + /** + * {@link ModuleReference} resource class scanner. + * + * @since 1.11 + */ + static class ModuleReferenceResourceScanner { + + private final Predicate resourceFilter; + private final ClassLoader classLoader; + + ModuleReferenceResourceScanner(Predicate resourceFilter, ClassLoader classLoader) { + this.resourceFilter = resourceFilter; + this.classLoader = classLoader; + } + + /** + * Scan module reference for resources that potentially contain testable resources. + */ + List scan(ModuleReference reference) { + try (ModuleReader reader = reference.open()) { + try (Stream names = reader.list()) { + // @formatter:off + return names.filter(name -> !name.endsWith(".class")) + .map(this::loadResourceUnchecked) + .filter(resourceFilter) + .collect(Collectors.toList()); + // @formatter:on + } + } + catch (IOException e) { + throw new JUnitException("Failed to read contents of " + reference + ".", e); + } + } + + private Resource loadResourceUnchecked(String binaryName) { + try { + URI uri = classLoader.getResource(binaryName).toURI(); + return new DefaultResource(binaryName, uri); + } + catch (URISyntaxException e) { + throw new JUnitException("Failed to load resource with name '" + binaryName + "'.", e); + } + } + } } diff --git a/junit-platform-commons/src/main/java/org/junit/platform/commons/util/PackageNameUtils.java b/junit-platform-commons/src/main/java/org/junit/platform/commons/util/PackageNameUtils.java index 2a0094dda4c4..0cb6aec9e8d8 100644 --- a/junit-platform-commons/src/main/java/org/junit/platform/commons/util/PackageNameUtils.java +++ b/junit-platform-commons/src/main/java/org/junit/platform/commons/util/PackageNameUtils.java @@ -10,8 +10,6 @@ package org.junit.platform.commons.util; -import static org.junit.platform.commons.util.PackageUtils.DEFAULT_PACKAGE_NAME; - /** * Collection of utilities for working with package names. * @@ -26,13 +24,7 @@ class PackageNameUtils { static String getPackageName(Class clazz) { - Package p = clazz.getPackage(); - if (p != null) { - return p.getName(); - } - String className = clazz.getName(); - int index = className.lastIndexOf('.'); - return index == -1 ? DEFAULT_PACKAGE_NAME : className.substring(0, index); + return clazz.getPackageName(); } } diff --git a/junit-platform-commons/src/main/java/org/junit/platform/commons/util/ServiceLoaderUtils.java b/junit-platform-commons/src/main/java/org/junit/platform/commons/util/ServiceLoaderUtils.java index ce006d770099..878c62a2c7e7 100644 --- a/junit-platform-commons/src/main/java/org/junit/platform/commons/util/ServiceLoaderUtils.java +++ b/junit-platform-commons/src/main/java/org/junit/platform/commons/util/ServiceLoaderUtils.java @@ -13,9 +13,9 @@ import java.util.ServiceLoader; import java.util.function.Predicate; import java.util.stream.Stream; -import java.util.stream.StreamSupport; import org.apiguardian.api.API; +import org.apiguardian.api.API.Status; /** * Collection of utilities for working with {@link ServiceLoader}. @@ -28,7 +28,7 @@ * * @since 5.11 */ -@API(status = API.Status.INTERNAL, since = "5.11") +@API(status = Status.INTERNAL, since = "5.11") public class ServiceLoaderUtils { private ServiceLoaderUtils() { @@ -45,11 +45,12 @@ private ServiceLoaderUtils() { */ public static Stream filter(ServiceLoader serviceLoader, Predicate> providerPredicate) { - return StreamSupport.stream(serviceLoader.spliterator(), false).filter(it -> { - @SuppressWarnings("unchecked") - Class type = (Class) it.getClass(); - return providerPredicate.test(type); - }); + // @formatter:off + return serviceLoader + .stream() + .filter(provider -> providerPredicate.test(provider.type())) + .map(ServiceLoader.Provider::get); + // @formatter:on } } diff --git a/junit-platform-commons/src/main/java9/org/junit/platform/commons/util/ModuleUtils.java b/junit-platform-commons/src/main/java9/org/junit/platform/commons/util/ModuleUtils.java deleted file mode 100644 index 9f20d964f471..000000000000 --- a/junit-platform-commons/src/main/java9/org/junit/platform/commons/util/ModuleUtils.java +++ /dev/null @@ -1,311 +0,0 @@ -/* - * Copyright 2015-2025 the original author or authors. - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v2.0 which - * accompanies this distribution and is available at - * - * https://www.eclipse.org/legal/epl-v20.html - */ - -package org.junit.platform.commons.util; - -import static java.util.function.Predicate.isEqual; -import static java.util.stream.Collectors.toCollection; -import static java.util.stream.Collectors.toSet; -import static org.apiguardian.api.API.Status.INTERNAL; - -import java.io.IOException; -import java.lang.module.Configuration; -import java.lang.module.ModuleFinder; -import java.lang.module.ModuleReader; -import java.lang.module.ModuleReference; -import java.lang.module.ResolvedModule; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Optional; -import java.util.Set; -import java.util.function.Predicate; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import org.apiguardian.api.API; -import org.junit.platform.commons.JUnitException; -import org.junit.platform.commons.logging.Logger; -import org.junit.platform.commons.logging.LoggerFactory; -import org.junit.platform.commons.support.DefaultResource; -import org.junit.platform.commons.support.Resource; -import org.junit.platform.commons.support.scanning.ClassFilter; - -/** - * Collection of utilities for working with {@code java.lang.Module} - * and friends. - * - *

DISCLAIMER

- * - *

These utilities are intended solely for usage within the JUnit framework - * itself. Any usage by external parties is not supported. - * Use at your own risk! - * - * @since 1.1 - */ -@API(status = INTERNAL, since = "1.1") -public class ModuleUtils { - - private static final Logger logger = LoggerFactory.getLogger(ModuleUtils.class); - - /** - * Find all non-system boot modules names. - * - * @return a set of all such module names; never {@code null} but - * potentially empty - */ - public static Set findAllNonSystemBootModuleNames() { - // @formatter:off - Set systemModules = ModuleFinder.ofSystem().findAll().stream() - .map(reference -> reference.descriptor().name()) - .collect(toSet()); - return streamResolvedModules(name -> !systemModules.contains(name)) - .map(ResolvedModule::name) - .collect(toCollection(LinkedHashSet::new)); - // @formatter:on - } - - /** - * Java 9+ runtime supports the Java Platform Module System. - * - * @return {@code true} - */ - public static boolean isJavaPlatformModuleSystemAvailable() { - return true; - } - - public static Optional getModuleName(Class type) { - Preconditions.notNull(type, "Class type must not be null"); - - return Optional.ofNullable(type.getModule().getName()); - } - - public static Optional getModuleVersion(Class type) { - Preconditions.notNull(type, "Class type must not be null"); - - Module module = type.getModule(); - return module.isNamed() ? module.getDescriptor().rawVersion() : Optional.empty(); - } - - /** - * Find all {@linkplain Class classes} for the given module name. - * - * @param moduleName the name of the module to scan; never {@code null} or - * empty - * @param filter the class filter to apply; never {@code null} - * @return an immutable list of all such classes found; never {@code null} - * but potentially empty - */ - public static List> findAllClassesInModule(String moduleName, ClassFilter filter) { - Preconditions.notBlank(moduleName, "Module name must not be null or empty"); - Preconditions.notNull(filter, "Class filter must not be null"); - - logger.debug(() -> "Looking for classes in module: " + moduleName); - // @formatter:off - Set moduleReferences = streamResolvedModules(isEqual(moduleName)) - .map(ResolvedModule::reference) - .collect(toSet()); - // @formatter:on - return scan(moduleReferences, filter, ModuleUtils.class.getClassLoader()); - } - - /** - * Find all {@linkplain Resource resources} for the given module name. - * - * @param moduleName the name of the module to scan; never {@code null} or - * empty - * @param filter the class filter to apply; never {@code null} - * @return an immutable list of all such resources found; never {@code null} - * but potentially empty - * @since 1.11 - */ - @API(status = INTERNAL, since = "1.11") - public static List findAllResourcesInModule(String moduleName, Predicate filter) { - Preconditions.notBlank(moduleName, "Module name must not be null or empty"); - Preconditions.notNull(filter, "Resource filter must not be null"); - - logger.debug(() -> "Looking for classes in module: " + moduleName); - // @formatter:off - Set moduleReferences = streamResolvedModules(isEqual(moduleName)) - .map(ResolvedModule::reference) - .collect(toSet()); - // @formatter:on - return scan(moduleReferences, filter, ModuleUtils.class.getClassLoader()); - } - - /** - * Stream resolved modules from current (or boot) module layer. - */ - private static Stream streamResolvedModules(Predicate moduleNamePredicate) { - Module module = ModuleUtils.class.getModule(); - ModuleLayer layer = module.getLayer(); - if (layer == null) { - logger.config(() -> ModuleUtils.class + " is a member of " + module - + " - using boot layer returned by ModuleLayer.boot() as fall-back."); - layer = ModuleLayer.boot(); - } - return streamResolvedModules(moduleNamePredicate, layer); - } - - /** - * Stream resolved modules from the supplied layer. - */ - private static Stream streamResolvedModules(Predicate moduleNamePredicate, - ModuleLayer layer) { - logger.debug(() -> "Streaming modules for layer @" + System.identityHashCode(layer) + ": " + layer); - Configuration configuration = layer.configuration(); - logger.debug(() -> "Module layer configuration: " + configuration); - Stream stream = configuration.modules().stream(); - return stream.filter(module -> moduleNamePredicate.test(module.name())); - } - - /** - * Scan for classes using the supplied set of module references, class - * filter, and loader. - */ - private static List> scan(Set references, ClassFilter filter, ClassLoader loader) { - logger.debug(() -> "Scanning " + references.size() + " module references: " + references); - ModuleReferenceClassScanner scanner = new ModuleReferenceClassScanner(filter, loader); - List> classes = new ArrayList<>(); - for (ModuleReference reference : references) { - classes.addAll(scanner.scan(reference)); - } - logger.debug(() -> "Found " + classes.size() + " classes: " + classes); - return Collections.unmodifiableList(classes); - } - - /** - * Scan for classes using the supplied set of module references, class - * filter, and loader. - */ - private static List scan(Set references, Predicate filter, - ClassLoader loader) { - logger.debug(() -> "Scanning " + references.size() + " module references: " + references); - ModuleReferenceResourceScanner scanner = new ModuleReferenceResourceScanner(filter, loader); - List classes = new ArrayList<>(); - for (ModuleReference reference : references) { - classes.addAll(scanner.scan(reference)); - } - logger.debug(() -> "Found " + classes.size() + " classes: " + classes); - return Collections.unmodifiableList(classes); - } - - /** - * {@link ModuleReference} class scanner. - * - * @since 1.1 - */ - static class ModuleReferenceClassScanner { - - private final ClassFilter classFilter; - private final ClassLoader classLoader; - - ModuleReferenceClassScanner(ClassFilter classFilter, ClassLoader classLoader) { - this.classFilter = classFilter; - this.classLoader = classLoader; - } - - /** - * Scan module reference for classes that potentially contain testable methods. - */ - List> scan(ModuleReference reference) { - try (ModuleReader reader = reference.open()) { - try (Stream names = reader.list()) { - // @formatter:off - return names.filter(name -> name.endsWith(".class")) - .map(this::className) - .filter(name -> !name.equals("module-info")) - .filter(classFilter::match) - .map(this::loadClassUnchecked) - .filter(classFilter::match) - .collect(Collectors.toList()); - // @formatter:on - } - } - catch (IOException e) { - throw new JUnitException("Failed to read contents of " + reference + ".", e); - } - } - - /** - * Convert resource name to binary class name. - */ - private String className(String resourceName) { - resourceName = resourceName.substring(0, resourceName.length() - 6); // 6 = ".class".length() - resourceName = resourceName.replace('/', '.'); - return resourceName; - } - - /** - * Load class by its binary name. - * - * @see ClassLoader#loadClass(String) - */ - private Class loadClassUnchecked(String binaryName) { - try { - return classLoader.loadClass(binaryName); - } - catch (ClassNotFoundException e) { - throw new JUnitException("Failed to load class with name '" + binaryName + "'.", e); - } - } - - } - - /** - * {@link ModuleReference} resource class scanner. - * - * @since 1.11 - */ - static class ModuleReferenceResourceScanner { - - private final Predicate resourceFilter; - private final ClassLoader classLoader; - - ModuleReferenceResourceScanner(Predicate resourceFilter, ClassLoader classLoader) { - this.resourceFilter = resourceFilter; - this.classLoader = classLoader; - } - - /** - * Scan module reference for resources that potentially contain testable resources. - */ - List scan(ModuleReference reference) { - try (ModuleReader reader = reference.open()) { - try (Stream names = reader.list()) { - // @formatter:off - return names.filter(name -> !name.endsWith(".class")) - .map(this::loadResourceUnchecked) - .filter(resourceFilter) - .collect(Collectors.toList()); - // @formatter:on - } - } - catch (IOException e) { - throw new JUnitException("Failed to read contents of " + reference + ".", e); - } - } - - private Resource loadResourceUnchecked(String binaryName) { - try { - URI uri = classLoader.getResource(binaryName).toURI(); - return new DefaultResource(binaryName, uri); - } - catch (URISyntaxException e) { - throw new JUnitException("Failed to load resource with name '" + binaryName + "'.", e); - } - } - - } - -} diff --git a/junit-platform-commons/src/main/java9/org/junit/platform/commons/util/PackageNameUtils.java b/junit-platform-commons/src/main/java9/org/junit/platform/commons/util/PackageNameUtils.java deleted file mode 100644 index 0cb6aec9e8d8..000000000000 --- a/junit-platform-commons/src/main/java9/org/junit/platform/commons/util/PackageNameUtils.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2015-2025 the original author or authors. - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v2.0 which - * accompanies this distribution and is available at - * - * https://www.eclipse.org/legal/epl-v20.html - */ - -package org.junit.platform.commons.util; - -/** - * Collection of utilities for working with package names. - * - *

DISCLAIMER

- * - *

These utilities are intended solely for usage within the JUnit framework - * itself. Any usage by external parties is not supported. - * Use at your own risk! - * - * @since 1.11.3 - */ -class PackageNameUtils { - - static String getPackageName(Class clazz) { - return clazz.getPackageName(); - } - -} diff --git a/junit-platform-commons/src/main/java9/org/junit/platform/commons/util/ServiceLoaderUtils.java b/junit-platform-commons/src/main/java9/org/junit/platform/commons/util/ServiceLoaderUtils.java deleted file mode 100644 index 878c62a2c7e7..000000000000 --- a/junit-platform-commons/src/main/java9/org/junit/platform/commons/util/ServiceLoaderUtils.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2015-2025 the original author or authors. - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v2.0 which - * accompanies this distribution and is available at - * - * https://www.eclipse.org/legal/epl-v20.html - */ - -package org.junit.platform.commons.util; - -import java.util.ServiceLoader; -import java.util.function.Predicate; -import java.util.stream.Stream; - -import org.apiguardian.api.API; -import org.apiguardian.api.API.Status; - -/** - * Collection of utilities for working with {@link ServiceLoader}. - * - *

DISCLAIMER

- * - *

These utilities are intended solely for usage within the JUnit framework - * itself. Any usage by external parties is not supported. - * Use at your own risk! - * - * @since 5.11 - */ -@API(status = Status.INTERNAL, since = "5.11") -public class ServiceLoaderUtils { - - private ServiceLoaderUtils() { - /* no-op */ - } - - /** - * Filters the supplied service loader using the supplied predicate. - * - * @param the type of the service - * @param serviceLoader the service loader to be filtered - * @param providerPredicate the predicate to filter the loaded services - * @return a stream of loaded services that match the predicate - */ - public static Stream filter(ServiceLoader serviceLoader, - Predicate> providerPredicate) { - // @formatter:off - return serviceLoader - .stream() - .filter(provider -> providerPredicate.test(provider.type())) - .map(ServiceLoader.Provider::get); - // @formatter:on - } - -} diff --git a/junit-platform-console-standalone/junit-platform-console-standalone.gradle.kts b/junit-platform-console-standalone/junit-platform-console-standalone.gradle.kts index a15f463a4d04..f1859d463a37 100644 --- a/junit-platform-console-standalone/junit-platform-console-standalone.gradle.kts +++ b/junit-platform-console-standalone/junit-platform-console-standalone.gradle.kts @@ -85,12 +85,4 @@ tasks { )) } } - - // This jar contains some Java 9 code - // (org.junit.platform.console.ConsoleLauncherToolProvider which implements - // java.util.spi.ToolProvider which is @since 9). - // So in order to resolve this, it can only run on Java 9 - osgiProperties { - property("-runee", "JavaSE-9") - } } diff --git a/junit-platform-console/junit-platform-console.gradle.kts b/junit-platform-console/junit-platform-console.gradle.kts index cd256959b629..586b30004004 100644 --- a/junit-platform-console/junit-platform-console.gradle.kts +++ b/junit-platform-console/junit-platform-console.gradle.kts @@ -3,7 +3,6 @@ import junitbuild.java.UpdateJarAction plugins { id("junitbuild.java-library-conventions") id("junitbuild.shadow-conventions") - id("junitbuild.java-multi-release-sources") } description = "JUnit Platform Console" @@ -33,22 +32,17 @@ tasks { )) } shadowJar { - val release17ClassesDir = sourceSets.mainRelease17.get().output.classesDirs.singleFile - inputs.dir(release17ClassesDir).withPathSensitivity(PathSensitivity.RELATIVE) exclude("META-INF/versions/9/module-info.class") relocate("picocli", "org.junit.platform.console.shadow.picocli") from(projectDir) { include("LICENSE-picocli.md") into("META-INF") } - from(sourceSets.mainRelease9.get().output.classesDirs) doLast(objects.newInstance(UpdateJarAction::class).apply { javaLauncher = project.javaToolchains.launcherFor(java.toolchain) args.addAll( "--file", archiveFile.get().asFile.absolutePath, "--main-class", "org.junit.platform.console.ConsoleLauncher", - "--release", "17", - "-C", release17ClassesDir.absolutePath, "." ) }) } @@ -60,19 +54,4 @@ tasks { attributes("Main-Class" to "org.junit.platform.console.ConsoleLauncher") } } - - // This jar contains some Java 9 code - // (org.junit.platform.console.ConsoleLauncherToolProvider which implements - // java.util.spi.ToolProvider which is @since 9). - // So in order to resolve this, it can only run on Java 9 - osgiProperties { - property("-runee", "JavaSE-9") - } -} - -eclipse { - classpath { - sourceSets -= project.sourceSets.mainRelease9.get() - sourceSets -= project.sourceSets.mainRelease17.get() - } } diff --git a/junit-platform-console/src/main/java9/org/junit/platform/console/ConsoleLauncherToolProvider.java b/junit-platform-console/src/main/java/org/junit/platform/console/ConsoleLauncherToolProvider.java similarity index 100% rename from junit-platform-console/src/main/java9/org/junit/platform/console/ConsoleLauncherToolProvider.java rename to junit-platform-console/src/main/java/org/junit/platform/console/ConsoleLauncherToolProvider.java diff --git a/junit-platform-console/src/main/java/org/junit/platform/console/options/ConsoleUtils.java b/junit-platform-console/src/main/java/org/junit/platform/console/options/ConsoleUtils.java index ed82e426dca0..145ebed63fd4 100644 --- a/junit-platform-console/src/main/java/org/junit/platform/console/options/ConsoleUtils.java +++ b/junit-platform-console/src/main/java/org/junit/platform/console/options/ConsoleUtils.java @@ -12,6 +12,7 @@ import static org.apiguardian.api.API.Status.INTERNAL; +import java.io.Console; import java.nio.charset.Charset; import org.apiguardian.api.API; @@ -35,6 +36,7 @@ public class ConsoleUtils { * {@return the charset of the console} */ public static Charset charset() { - return Charset.defaultCharset(); + Console console = System.console(); + return console != null ? console.charset() : Charset.defaultCharset(); } } diff --git a/junit-platform-console/src/main/java17/org/junit/platform/console/options/ConsoleUtils.java b/junit-platform-console/src/main/java17/org/junit/platform/console/options/ConsoleUtils.java deleted file mode 100644 index 145ebed63fd4..000000000000 --- a/junit-platform-console/src/main/java17/org/junit/platform/console/options/ConsoleUtils.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2015-2025 the original author or authors. - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v2.0 which - * accompanies this distribution and is available at - * - * https://www.eclipse.org/legal/epl-v20.html - */ - -package org.junit.platform.console.options; - -import static org.apiguardian.api.API.Status.INTERNAL; - -import java.io.Console; -import java.nio.charset.Charset; - -import org.apiguardian.api.API; - -/** - * Collection of utilities for working with {@code java.io.Console} - * and friends. - * - *

DISCLAIMER

- * - *

These utilities are intended solely for usage within the JUnit framework - * itself. Any usage by external parties is not supported. - * Use at your own risk! - * - * @since 1.9 - */ -@API(status = INTERNAL, since = "1.9") -public class ConsoleUtils { - - /** - * {@return the charset of the console} - */ - public static Charset charset() { - Console console = System.console(); - return console != null ? console.charset() : Charset.defaultCharset(); - } -} diff --git a/junit-platform-jfr/junit-platform-jfr.gradle.kts b/junit-platform-jfr/junit-platform-jfr.gradle.kts index 0f03e2b99f86..8d82379addad 100644 --- a/junit-platform-jfr/junit-platform-jfr.gradle.kts +++ b/junit-platform-jfr/junit-platform-jfr.gradle.kts @@ -20,17 +20,7 @@ dependencies { osgiVerification(projects.junitPlatformLauncher) } -javaLibrary { - // --release 8 does not support jdk.jfr even though it was backported - configureRelease = false -} - tasks { - compileJava { - javaCompiler = project.javaToolchains.compilerFor { - languageVersion = JavaLanguageVersion.of(8) - } - } compileModule { options.release = 11 } diff --git a/platform-tooling-support-tests/platform-tooling-support-tests.gradle.kts b/platform-tooling-support-tests/platform-tooling-support-tests.gradle.kts index 9e5b70ba9ef2..780a81075e28 100644 --- a/platform-tooling-support-tests/platform-tooling-support-tests.gradle.kts +++ b/platform-tooling-support-tests/platform-tooling-support-tests.gradle.kts @@ -173,12 +173,12 @@ tasks.test { develocity { testDistribution { - requirements.add("jdk=8") + requirements.add("jdk=17") this as TestDistributionConfigurationInternal preferredMaxDuration = Duration.ofMillis(500) } } - jvmArgumentProviders += JavaHomeDir(project, 8, develocity.testDistribution.enabled) + jvmArgumentProviders += JavaHomeDir(project, 17, develocity.testDistribution.enabled) val gradleJavaVersion = JavaVersion.current().majorVersion.toInt() jvmArgumentProviders += JavaHomeDir(project, gradleJavaVersion, develocity.testDistribution.enabled) diff --git a/platform-tooling-support-tests/projects/gradle-kotlin-extensions/build.gradle.kts b/platform-tooling-support-tests/projects/gradle-kotlin-extensions/build.gradle.kts index 5f343d010524..38fa8f92fdce 100644 --- a/platform-tooling-support-tests/projects/gradle-kotlin-extensions/build.gradle.kts +++ b/platform-tooling-support-tests/projects/gradle-kotlin-extensions/build.gradle.kts @@ -13,20 +13,20 @@ val jupiterVersion: String by project val platformVersion: String by project dependencies { - testImplementation(kotlin("stdlib-jdk8")) + testImplementation(kotlin("stdlib")) testImplementation("org.junit.jupiter:junit-jupiter:$jupiterVersion") testRuntimeOnly("org.junit.platform:junit-platform-launcher:$platformVersion") } java { toolchain { - languageVersion = JavaLanguageVersion.of(8) + languageVersion = JavaLanguageVersion.of(17) } } tasks.withType().configureEach { kotlinOptions { - jvmTarget = "1.8" + jvmTarget = "17" apiVersion = "1.6" languageVersion = "1.6" } diff --git a/platform-tooling-support-tests/projects/gradle-kotlin-extensions/gradle.properties b/platform-tooling-support-tests/projects/gradle-kotlin-extensions/gradle.properties index 79b428ebc70c..bed2250e4577 100644 --- a/platform-tooling-support-tests/projects/gradle-kotlin-extensions/gradle.properties +++ b/platform-tooling-support-tests/projects/gradle-kotlin-extensions/gradle.properties @@ -1 +1 @@ -org.gradle.java.installations.fromEnv=JDK8 +org.gradle.java.installations.fromEnv=JDK17 diff --git a/platform-tooling-support-tests/projects/gradle-missing-engine/build.gradle.kts b/platform-tooling-support-tests/projects/gradle-missing-engine/build.gradle.kts index 50b4e7b2924b..0e7c2e9ac3b3 100644 --- a/platform-tooling-support-tests/projects/gradle-missing-engine/build.gradle.kts +++ b/platform-tooling-support-tests/projects/gradle-missing-engine/build.gradle.kts @@ -18,7 +18,7 @@ dependencies { java { toolchain { - languageVersion = JavaLanguageVersion.of(8) + languageVersion = JavaLanguageVersion.of(17) } } diff --git a/platform-tooling-support-tests/projects/gradle-missing-engine/gradle.properties b/platform-tooling-support-tests/projects/gradle-missing-engine/gradle.properties index 79b428ebc70c..bed2250e4577 100644 --- a/platform-tooling-support-tests/projects/gradle-missing-engine/gradle.properties +++ b/platform-tooling-support-tests/projects/gradle-missing-engine/gradle.properties @@ -1 +1 @@ -org.gradle.java.installations.fromEnv=JDK8 +org.gradle.java.installations.fromEnv=JDK17 diff --git a/platform-tooling-support-tests/projects/gradle-starter/build.gradle.kts b/platform-tooling-support-tests/projects/gradle-starter/build.gradle.kts index 751889da23d0..01738a2c1956 100644 --- a/platform-tooling-support-tests/projects/gradle-starter/build.gradle.kts +++ b/platform-tooling-support-tests/projects/gradle-starter/build.gradle.kts @@ -17,7 +17,7 @@ dependencies { java { toolchain { - languageVersion = JavaLanguageVersion.of(8) + languageVersion = JavaLanguageVersion.of(17) } } diff --git a/platform-tooling-support-tests/projects/gradle-starter/gradle.properties b/platform-tooling-support-tests/projects/gradle-starter/gradle.properties index 79b428ebc70c..bed2250e4577 100644 --- a/platform-tooling-support-tests/projects/gradle-starter/gradle.properties +++ b/platform-tooling-support-tests/projects/gradle-starter/gradle.properties @@ -1 +1 @@ -org.gradle.java.installations.fromEnv=JDK8 +org.gradle.java.installations.fromEnv=JDK17 diff --git a/platform-tooling-support-tests/projects/java-versions/pom.xml b/platform-tooling-support-tests/projects/java-versions/pom.xml deleted file mode 100644 index d9d22bbec6b6..000000000000 --- a/platform-tooling-support-tests/projects/java-versions/pom.xml +++ /dev/null @@ -1,63 +0,0 @@ - - - 4.0.0 - - platform.tooling.support.tests - java-versions - 1.0-SNAPSHOT - - - UTF-8 - - - - - org.junit.jupiter - junit-jupiter-engine - ${junit.jupiter.version} - test - - - org.junit.platform - junit-platform-commons - ${junit.platform.version} - test - - - - - - - - maven-compiler-plugin - 3.13.0 - - 1.8 - 1.8 - - - - maven-surefire-plugin - 3.5.2 - - - - - - - - local-temp - file://${maven.repo} - - true - ignore - - - true - ignore - - - - - diff --git a/platform-tooling-support-tests/projects/java-versions/src/test/java/JUnitPlatformCommonsTests.java b/platform-tooling-support-tests/projects/java-versions/src/test/java/JUnitPlatformCommonsTests.java deleted file mode 100644 index 7e7a888bdd6b..000000000000 --- a/platform-tooling-support-tests/projects/java-versions/src/test/java/JUnitPlatformCommonsTests.java +++ /dev/null @@ -1,37 +0,0 @@ - -/* - * Copyright 2015-2025 the original author or authors. - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v2.0 which - * accompanies this distribution and is available at - * - * https://www.eclipse.org/legal/epl-v20.html - */ -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.DisabledOnJre; -import org.junit.jupiter.api.condition.EnabledOnJre; -import org.junit.jupiter.api.condition.JRE; -import org.junit.platform.commons.util.ModuleUtils; - -class JUnitPlatformCommonsTests { - - @Test - @EnabledOnJre(JRE.JAVA_8) - void onJava8() { - assertFalse(ModuleUtils.isJavaPlatformModuleSystemAvailable()); - assertFalse(ModuleUtils.getModuleName(Object.class).isPresent()); - } - - @Test - @DisabledOnJre(JRE.JAVA_8) - void onJava9OrHigher() { - assertTrue(ModuleUtils.isJavaPlatformModuleSystemAvailable()); - assertEquals("java.base", ModuleUtils.getModuleName(Object.class).orElseThrow(Error::new)); - } - -} diff --git a/platform-tooling-support-tests/projects/maven-starter/pom.xml b/platform-tooling-support-tests/projects/maven-starter/pom.xml index c03e69a3277c..6ec91455e3ca 100644 --- a/platform-tooling-support-tests/projects/maven-starter/pom.xml +++ b/platform-tooling-support-tests/projects/maven-starter/pom.xml @@ -9,8 +9,7 @@ UTF-8 - 1.8 - ${maven.compiler.source} + 17 ${junit.platform.version} diff --git a/platform-tooling-support-tests/projects/maven-surefire-compatibility/pom.xml b/platform-tooling-support-tests/projects/maven-surefire-compatibility/pom.xml index 3ac0876b2d8b..3836c489d6d8 100644 --- a/platform-tooling-support-tests/projects/maven-surefire-compatibility/pom.xml +++ b/platform-tooling-support-tests/projects/maven-surefire-compatibility/pom.xml @@ -9,8 +9,7 @@ UTF-8 - 1.8 - ${maven.compiler.source} + 17 diff --git a/platform-tooling-support-tests/projects/reflection-tests/build.gradle.kts b/platform-tooling-support-tests/projects/reflection-tests/build.gradle.kts index 0dea5aab80a1..88cc4dff4bb4 100644 --- a/platform-tooling-support-tests/projects/reflection-tests/build.gradle.kts +++ b/platform-tooling-support-tests/projects/reflection-tests/build.gradle.kts @@ -18,7 +18,7 @@ dependencies { java { toolchain { - languageVersion = JavaLanguageVersion.of(8) + languageVersion = JavaLanguageVersion.of(17) } } diff --git a/platform-tooling-support-tests/projects/reflection-tests/gradle.properties b/platform-tooling-support-tests/projects/reflection-tests/gradle.properties index 79b428ebc70c..bed2250e4577 100644 --- a/platform-tooling-support-tests/projects/reflection-tests/gradle.properties +++ b/platform-tooling-support-tests/projects/reflection-tests/gradle.properties @@ -1 +1 @@ -org.gradle.java.installations.fromEnv=JDK8 +org.gradle.java.installations.fromEnv=JDK17 diff --git a/platform-tooling-support-tests/projects/vintage/build.gradle.kts b/platform-tooling-support-tests/projects/vintage/build.gradle.kts index 37bab7448d5b..efa61d4ac9c1 100644 --- a/platform-tooling-support-tests/projects/vintage/build.gradle.kts +++ b/platform-tooling-support-tests/projects/vintage/build.gradle.kts @@ -26,7 +26,7 @@ dependencies { java { toolchain { - languageVersion = JavaLanguageVersion.of(8) + languageVersion = JavaLanguageVersion.of(17) } } diff --git a/platform-tooling-support-tests/projects/vintage/gradle.properties b/platform-tooling-support-tests/projects/vintage/gradle.properties index 79b428ebc70c..bed2250e4577 100644 --- a/platform-tooling-support-tests/projects/vintage/gradle.properties +++ b/platform-tooling-support-tests/projects/vintage/gradle.properties @@ -1 +1 @@ -org.gradle.java.installations.fromEnv=JDK8 +org.gradle.java.installations.fromEnv=JDK17 diff --git a/platform-tooling-support-tests/projects/vintage/pom.xml b/platform-tooling-support-tests/projects/vintage/pom.xml index 164570994740..2f652775366b 100644 --- a/platform-tooling-support-tests/projects/vintage/pom.xml +++ b/platform-tooling-support-tests/projects/vintage/pom.xml @@ -9,8 +9,7 @@ UTF-8 - 1.8 - ${maven.compiler.source} + 17 diff --git a/platform-tooling-support-tests/src/test/java/platform/tooling/support/HelperTests.java b/platform-tooling-support-tests/src/test/java/platform/tooling/support/HelperTests.java index 6aaa2b1c29be..2fc8fbfdfbfc 100644 --- a/platform-tooling-support-tests/src/test/java/platform/tooling/support/HelperTests.java +++ b/platform-tooling-support-tests/src/test/java/platform/tooling/support/HelperTests.java @@ -65,7 +65,7 @@ void nonExistingJdkVersionYieldsAnEmptyOptional() { } @ParameterizedTest - @ValueSource(ints = 8) + @ValueSource(ints = 17) void checkJavaHome(int version) { var home = Helper.getJavaHome(String.valueOf(version)); assumeTrue(home.isPresent(), "No 'jdk' element found in Maven toolchain for: " + version); diff --git a/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/GradleKotlinExtensionsTests.java b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/GradleKotlinExtensionsTests.java index 6c05aef99240..54d7db513984 100644 --- a/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/GradleKotlinExtensionsTests.java +++ b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/GradleKotlinExtensionsTests.java @@ -36,7 +36,7 @@ void gradle_wrapper(@TempDir Path workspace, @FilePrefix("gradle") OutputFiles o .workingDir(copyToWorkspace(Projects.GRADLE_KOTLIN_EXTENSIONS, workspace)) // .addArguments("-Dmaven.repo=" + MavenRepo.dir()) // .addArguments("build", "--no-daemon", "--stacktrace", "--no-build-cache", "--warning-mode=fail") // - .putEnvironment("JDK8", Helper.getJavaHome("8").orElseThrow(TestAbortedException::new).toString()) // + .putEnvironment("JDK17", Helper.getJavaHome("17").orElseThrow(TestAbortedException::new).toString()) // .redirectOutput(outputFiles) // .startAndWait(); diff --git a/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/GradleMissingEngineTests.java b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/GradleMissingEngineTests.java index fdc04d46445e..977c9c702d11 100644 --- a/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/GradleMissingEngineTests.java +++ b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/GradleMissingEngineTests.java @@ -37,7 +37,7 @@ void gradle_wrapper(@TempDir Path workspace, @FilePrefix("gradle") OutputFiles o .workingDir(copyToWorkspace(Projects.GRADLE_MISSING_ENGINE, workspace)) // .addArguments("-Dmaven.repo=" + MavenRepo.dir()) // .addArguments("build", "--no-daemon", "--stacktrace", "--no-build-cache", "--warning-mode=fail") // - .putEnvironment("JDK8", Helper.getJavaHome("8").orElseThrow(TestAbortedException::new).toString()) // + .putEnvironment("JDK17", Helper.getJavaHome("17").orElseThrow(TestAbortedException::new).toString()) // .redirectOutput(outputFiles).startAndWait(); assertEquals(1, result.exitCode()); diff --git a/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/GradleModuleFileTests.java b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/GradleModuleFileTests.java index c79c2b4e54f4..ca5b03192965 100644 --- a/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/GradleModuleFileTests.java +++ b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/GradleModuleFileTests.java @@ -46,7 +46,7 @@ void jupiterAggregatorGradleModuleMetadataVariants() throws Exception { " \"attributes\": {", // " \"org.gradle.category\": \"library\",", // " \"org.gradle.dependency.bundling\": \"external\",", // - " \"org.gradle.jvm.version\": 8,", // + " \"org.gradle.jvm.version\": 17,", // " \"org.gradle.libraryelements\": \"jar\",", // " \"org.gradle.usage\": \"java-api\"", // " },", // @@ -88,7 +88,7 @@ void jupiterAggregatorGradleModuleMetadataVariants() throws Exception { " \"attributes\": {", // " \"org.gradle.category\": \"library\",", // " \"org.gradle.dependency.bundling\": \"external\",", // - " \"org.gradle.jvm.version\": 8,", // + " \"org.gradle.jvm.version\": 17,", // " \"org.gradle.libraryelements\": \"jar\",", // " \"org.gradle.usage\": \"java-runtime\"", // " },", // diff --git a/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/GradleStarterTests.java b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/GradleStarterTests.java index 95d0a14a23f2..ef1c4f905b0f 100644 --- a/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/GradleStarterTests.java +++ b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/GradleStarterTests.java @@ -38,13 +38,13 @@ void gradle_wrapper(@TempDir Path workspace, @FilePrefix("gradle") OutputFiles o .workingDir(copyToWorkspace(Projects.GRADLE_STARTER, workspace)) // .addArguments("-Dmaven.repo=" + MavenRepo.dir()) // .addArguments("build", "--no-daemon", "--stacktrace", "--no-build-cache", "--warning-mode=fail") // - .putEnvironment("JDK8", Helper.getJavaHome("8").orElseThrow(TestAbortedException::new).toString()) // + .putEnvironment("JDK17", Helper.getJavaHome("17").orElseThrow(TestAbortedException::new).toString()) // .redirectOutput(outputFiles) // .startAndWait(); assertEquals(0, result.exitCode()); assertTrue(result.stdOut().lines().anyMatch(line -> line.contains("BUILD SUCCESSFUL"))); - assertThat(result.stdOut()).contains("Using Java version: 1.8"); + assertThat(result.stdOut()).contains("Using Java version: 17"); var testResultsDir = workspace.resolve("build/test-results/test"); verifyContainsExpectedStartedOpenTestReport(testResultsDir); diff --git a/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/JavaVersionsTests.java b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/JavaVersionsTests.java deleted file mode 100644 index 4a7cce72c99e..000000000000 --- a/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/JavaVersionsTests.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2015-2025 the original author or authors. - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v2.0 which - * accompanies this distribution and is available at - * - * https://www.eclipse.org/legal/epl-v20.html - */ - -package platform.tooling.support.tests; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assumptions.assumeTrue; -import static platform.tooling.support.ProcessStarters.currentJdkHome; -import static platform.tooling.support.tests.Projects.copyToWorkspace; - -import java.nio.file.Path; -import java.util.List; -import java.util.Map; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.JRE; -import org.junit.jupiter.api.io.TempDir; -import org.junit.platform.tests.process.OutputFiles; - -import platform.tooling.support.Helper; -import platform.tooling.support.MavenRepo; -import platform.tooling.support.ProcessStarters; - -/** - * @since 1.4 - */ -class JavaVersionsTests { - - @GlobalResource - LocalMavenRepo localMavenRepo; - - @TempDir - Path workspace; - - @Test - void java_8(@FilePrefix("maven") OutputFiles outputFiles) throws Exception { - var java8Home = Helper.getJavaHome("8"); - assumeTrue(java8Home.isPresent(), "Java 8 installation directory not found!"); - var actualLines = execute(java8Home.get(), outputFiles, Map.of()); - - assertTrue(actualLines.contains("[WARNING] Tests run: 2, Failures: 0, Errors: 0, Skipped: 1")); - } - - @Test - void java_default(@FilePrefix("maven") OutputFiles outputFiles) throws Exception { - var actualLines = execute(currentJdkHome(), outputFiles, MavenEnvVars.forJre(JRE.currentVersion())); - - assertTrue(actualLines.contains("[WARNING] Tests run: 2, Failures: 0, Errors: 0, Skipped: 1")); - } - - List execute(Path javaHome, OutputFiles outputFiles, Map environmentVars) throws Exception { - var result = ProcessStarters.maven(javaHome) // - .workingDir(copyToWorkspace(Projects.JAVA_VERSIONS, workspace)) // - .putEnvironment(environmentVars) // - .addArguments(localMavenRepo.toCliArgument(), "-Dmaven.repo=" + MavenRepo.dir()) // - .addArguments("--update-snapshots", "--batch-mode", "verify") // - .startAndWait(); - - assertEquals(0, result.exitCode()); - assertEquals("", result.stdErr()); - return result.stdOutLines(); - } - -} diff --git a/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/ManifestTests.java b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/ManifestTests.java index d215ca8e99c0..335053898a13 100644 --- a/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/ManifestTests.java +++ b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/ManifestTests.java @@ -56,10 +56,8 @@ void manifestEntriesAdhereToConventions(String module) throws Exception { assertValue(attributes, "Bundle-SymbolicName", module); assertValue(attributes, "Bundle-Version", MavenVersion.parseMavenString(version).getOSGiVersion().toString()); - switch (module) { - case "junit-platform-commons" -> assertValue(attributes, "Multi-Release", "true"); - case "junit-platform-console" -> assertValue(attributes, "Main-Class", - "org.junit.platform.console.ConsoleLauncher"); + if (module.equals("junit-platform-console")) { + assertValue(attributes, "Main-Class", "org.junit.platform.console.ConsoleLauncher"); } var domain = Domain.domain(manifest); domain.getExportPackage().forEach((pkg, attrs) -> { diff --git a/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/MavenStarterTests.java b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/MavenStarterTests.java index 9faf699942ea..751ca5c41ece 100644 --- a/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/MavenStarterTests.java +++ b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/MavenStarterTests.java @@ -41,7 +41,7 @@ class MavenStarterTests { @Test void verifyMavenStarterProject(@TempDir Path workspace, @FilePrefix("maven") OutputFiles outputFiles) throws Exception { - var result = ProcessStarters.maven(Helper.getJavaHome("8").orElseThrow(TestAbortedException::new)) // + var result = ProcessStarters.maven(Helper.getJavaHome("17").orElseThrow(TestAbortedException::new)) // .workingDir(copyToWorkspace(Projects.MAVEN_STARTER, workspace)) // .addArguments(localMavenRepo.toCliArgument(), "-Dmaven.repo=" + MavenRepo.dir()) // .addArguments("-Dsnapshot.repo.url=" + mavenRepoProxy.getBaseUri()) // @@ -53,7 +53,7 @@ void verifyMavenStarterProject(@TempDir Path workspace, @FilePrefix("maven") Out assertEquals("", result.stdErr()); assertTrue(result.stdOutLines().contains("[INFO] BUILD SUCCESS")); assertTrue(result.stdOutLines().contains("[INFO] Tests run: 5, Failures: 0, Errors: 0, Skipped: 0")); - assertThat(result.stdOut()).contains("Using Java version: 1.8"); + assertThat(result.stdOut()).contains("Using Java version: 17"); var testResultsDir = workspace.resolve("target/surefire-reports"); verifyContainsExpectedStartedOpenTestReport(testResultsDir); diff --git a/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/MavenSurefireCompatibilityTests.java b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/MavenSurefireCompatibilityTests.java index a59d90ecbf53..1f20e608fdc3 100644 --- a/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/MavenSurefireCompatibilityTests.java +++ b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/MavenSurefireCompatibilityTests.java @@ -44,7 +44,7 @@ class MavenSurefireCompatibilityTests { void testMavenSurefireCompatibilityProject(String surefireVersion, String extraArg, @TempDir Path workspace, @FilePrefix("maven") OutputFiles outputFiles) throws Exception { var extraArgs = extraArg == null ? new String[0] : new String[] { extraArg }; - var result = ProcessStarters.maven(Helper.getJavaHome("8").orElseThrow(TestAbortedException::new)) // + var result = ProcessStarters.maven(Helper.getJavaHome("17").orElseThrow(TestAbortedException::new)) // .workingDir(copyToWorkspace(Projects.MAVEN_SUREFIRE_COMPATIBILITY, workspace)) // .addArguments(localMavenRepo.toCliArgument(), "-Dmaven.repo=" + MavenRepo.dir()) // .addArguments("-Dsurefire.version=" + surefireVersion) // diff --git a/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/ReflectionCompatibilityTests.java b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/ReflectionCompatibilityTests.java index bc9135a1cc54..8c3b6231fc1f 100644 --- a/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/ReflectionCompatibilityTests.java +++ b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/ReflectionCompatibilityTests.java @@ -37,12 +37,12 @@ void gradle_wrapper(@TempDir Path workspace, @FilePrefix("gradle") OutputFiles o .workingDir(copyToWorkspace(Projects.REFLECTION_TESTS, workspace)) // .addArguments("-Dmaven.repo=" + MavenRepo.dir()) // .addArguments("build", "--no-daemon", "--stacktrace", "--no-build-cache", "--warning-mode=fail") // - .putEnvironment("JDK8", Helper.getJavaHome("8").orElseThrow(TestAbortedException::new).toString()) // + .putEnvironment("JDK17", Helper.getJavaHome("17").orElseThrow(TestAbortedException::new).toString()) // .redirectOutput(outputFiles) // .startAndWait(); assertEquals(0, result.exitCode()); assertTrue(result.stdOut().lines().anyMatch(line -> line.contains("BUILD SUCCESSFUL"))); - assertThat(result.stdOut()).contains("Using Java version: 1.8"); + assertThat(result.stdOut()).contains("Using Java version: 17"); } } diff --git a/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/StandaloneTests.java b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/StandaloneTests.java index 6cbb5bc931e1..65ae4f67d3e8 100644 --- a/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/StandaloneTests.java +++ b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/StandaloneTests.java @@ -160,7 +160,7 @@ void compile(@FilePrefix("javac") OutputFiles javacOutputFiles, @FilePrefix("jar var result = ProcessStarters.javaCommand("javac") // .workingDir(workspace) // .addArguments("-Xlint:-options") // - .addArguments("--release", "8") // + .addArguments("--release", "17") // .addArguments("-proc:none") // .addArguments("-d", workspace.resolve("bin").toString()) // .addArguments("--class-path", MavenRepo.jar("junit-platform-console-standalone").toString()) // @@ -453,9 +453,9 @@ void execute(@FilePrefix("console-launcher") OutputFiles outputFiles) throws Exc @Test @Order(4) @Execution(SAME_THREAD) - void executeOnJava8(@FilePrefix("console-launcher") OutputFiles outputFiles) throws Exception { - var java8Home = Helper.getJavaHome("8").orElseThrow(TestAbortedException::new); - var result = ProcessStarters.java(java8Home) // + void executeOnJava17(@FilePrefix("console-launcher") OutputFiles outputFiles) throws Exception { + var javaHome = Helper.getJavaHome("17").orElseThrow(TestAbortedException::new); + var result = ProcessStarters.java(javaHome) // .workingDir(workspace) // .addArguments("-showversion") // .addArguments("-enableassertions") // @@ -473,7 +473,7 @@ void executeOnJava8(@FilePrefix("console-launcher") OutputFiles outputFiles) thr assertEquals(1, result.exitCode()); var expectedOutLines = Files.readAllLines(workspace.resolve("expected-out.txt")); - var expectedErrLines = getExpectedErrLinesOnJava8(workspace); + var expectedErrLines = getExpectedErrLinesOnJava17(workspace); assertLinesMatch(expectedOutLines, result.stdOutLines()); assertLinesMatch(expectedErrLines, result.stdErrLines()); @@ -489,9 +489,9 @@ void executeOnJava8(@FilePrefix("console-launcher") OutputFiles outputFiles) thr @Order(5) @Execution(SAME_THREAD) // https://github.com/junit-team/junit5/issues/2600 - void executeOnJava8SelectPackage(@FilePrefix("console-launcher") OutputFiles outputFiles) throws Exception { - var java8Home = Helper.getJavaHome("8").orElseThrow(TestAbortedException::new); - var result = ProcessStarters.java(java8Home) // + void executeOnJava17SelectPackage(@FilePrefix("console-launcher") OutputFiles outputFiles) throws Exception { + var javaHome = Helper.getJavaHome("17").orElseThrow(TestAbortedException::new); + var result = ProcessStarters.java(javaHome) // .workingDir(workspace).addArguments("-showversion") // .addArguments("-enableassertions") // .addArguments("-Djava.util.logging.config.file=logging.properties") // @@ -508,7 +508,7 @@ void executeOnJava8SelectPackage(@FilePrefix("console-launcher") OutputFiles out assertEquals(1, result.exitCode()); var expectedOutLines = Files.readAllLines(workspace.resolve("expected-out.txt")); - var expectedErrLines = getExpectedErrLinesOnJava8(workspace); + var expectedErrLines = getExpectedErrLinesOnJava17(workspace); assertLinesMatch(expectedOutLines, result.stdOutLines()); assertLinesMatch(expectedErrLines, result.stdErrLines()); @@ -520,7 +520,7 @@ void executeOnJava8SelectPackage(@FilePrefix("console-launcher") OutputFiles out + " (group ID: org.junit.vintage, artifact ID: junit-vintage-engine, version: " + vintageVersion)); } - private static List getExpectedErrLinesOnJava8(Path workspace) throws IOException { + private static List getExpectedErrLinesOnJava17(Path workspace) throws IOException { var expectedErrLines = new ArrayList(); expectedErrLines.add(">> JAVA VERSION >>"); expectedErrLines.addAll(Files.readAllLines(workspace.resolve("expected-err.txt"))); diff --git a/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/UnalignedClasspathTests.java b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/UnalignedClasspathTests.java index a6467c511564..885cf901311c 100644 --- a/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/UnalignedClasspathTests.java +++ b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/UnalignedClasspathTests.java @@ -68,7 +68,7 @@ void verifyErrorMessageForUnalignedClasspath(JRE jre, Path javaHome, @TempDir Pa static Stream javaVersions() { return Stream.concat( // - Helper.getJavaHome("8").map(path -> Arguments.of(JRE.JAVA_8, path)).stream(), // + Helper.getJavaHome("17").map(path -> Arguments.of(JRE.JAVA_17, path)).stream(), // Stream.of(Arguments.of(JRE.currentVersion(), currentJdkHome())) // ); } diff --git a/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/VintageGradleIntegrationTests.java b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/VintageGradleIntegrationTests.java index 39a02d21168e..36e059d0a51f 100644 --- a/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/VintageGradleIntegrationTests.java +++ b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/VintageGradleIntegrationTests.java @@ -59,7 +59,7 @@ void supportedVersions(String version, @FilePrefix("gradle") OutputFiles outputF private ProcessResult run(OutputFiles outputFiles, String version) throws Exception { return ProcessStarters.gradlew() // .workingDir(copyToWorkspace(Projects.VINTAGE, workspace)) // - .putEnvironment("JDK8", Helper.getJavaHome("8").orElseThrow(TestAbortedException::new).toString()) // + .putEnvironment("JDK17", Helper.getJavaHome("17").orElseThrow(TestAbortedException::new).toString()) // .addArguments("build", "--no-daemon", "--stacktrace", "--no-build-cache", "--warning-mode=fail") // .addArguments("-Dmaven.repo=" + MavenRepo.dir()) // .addArguments("-Djunit4Version=" + version) // diff --git a/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/VintageMavenIntegrationTests.java b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/VintageMavenIntegrationTests.java index 7f735753f009..f7c8f5a8ed1c 100644 --- a/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/VintageMavenIntegrationTests.java +++ b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/VintageMavenIntegrationTests.java @@ -62,7 +62,7 @@ void supportedVersions(String version, @FilePrefix("maven") OutputFiles outputFi } private ProcessResult run(OutputFiles outputFiles, String version) throws Exception { - return ProcessStarters.maven(Helper.getJavaHome("8").orElseThrow(TestAbortedException::new)) // + return ProcessStarters.maven(Helper.getJavaHome("17").orElseThrow(TestAbortedException::new)) // .workingDir(copyToWorkspace(Projects.VINTAGE, workspace)) // .addArguments("clean", "test", "--update-snapshots", "--batch-mode") // .addArguments(localMavenRepo.toCliArgument(), "-Dmaven.repo=" + MavenRepo.dir()) //