Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import junitbuild.eclipse.EclipseConventionsExtension
import org.gradle.plugins.ide.eclipse.model.Classpath
import org.gradle.plugins.ide.eclipse.model.Library
import org.gradle.plugins.ide.eclipse.model.ProjectDependency
import org.gradle.plugins.ide.eclipse.model.SourceFolder

plugins {
eclipse
}

val extension = extensions.create<EclipseConventionsExtension>("eclipseConventions").apply {
hideModularity.convention(true)
}

eclipse {
jdt {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
file {
// Set properties for org.eclipse.jdt.core.prefs
withProperties {
// Configure Eclipse projects with -release compiler flag.
setProperty("org.eclipse.jdt.core.compiler.release", "enabled")
// Configure Eclipse projects with -parameters compiler flag.
setProperty("org.eclipse.jdt.core.compiler.codegen.methodParameters", "generate")
}
}
}
classpath.file.whenMerged {
this as Classpath
// Remove classpath entries for non-existent libraries added by various
// plugins, such as "junit-jupiter-api/build/classes/kotlin/testFixtures".
entries.removeIf { it is Library && !file(it.path).exists() }
// Remove classpath entries for the code generator model used by the
// Java Template Engine (JTE) which is used to generate the JRE enum and
// dependent tests.
entries.removeIf { it is ProjectDependency && it.path.equals("/code-generator-model") }
// Remove classpath entries for anything used by the Gradle Wrapper.
entries.removeIf { it is Library && it.path.contains("gradle/wrapper") }
if (extension.hideModularity.get()) {
entries.filterIsInstance<SourceFolder>().forEach {
it.excludes.add("**/module-info.java")
}
entries.filterIsInstance<ProjectDependency>().forEach {
it.entryAttributes.remove("module")
}
entries.filterIsInstance<Library>().forEach {
it.entryAttributes.remove("module")
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import junitbuild.extensions.isSnapshot
import org.gradle.plugins.ide.eclipse.model.Classpath
import org.gradle.plugins.ide.eclipse.model.Library
import org.gradle.plugins.ide.eclipse.model.ProjectDependency
import org.gradle.plugins.ide.eclipse.model.SourceFolder

plugins {
`java-library`
eclipse
id("junitbuild.base-conventions")
id("junitbuild.build-parameters")
id("junitbuild.checkstyle-conventions")
id("junitbuild.eclipse-conventions")
id("junitbuild.jacoco-java-conventions")
}

Expand All @@ -21,43 +17,6 @@ val buildRevision: Any by rootProject.extra

val extension = extensions.create<JavaLibraryExtension>("javaLibrary")

eclipse {
jdt {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
file {
// Set properties for org.eclipse.jdt.core.prefs
withProperties {
// Configure Eclipse projects with -release compiler flag.
setProperty("org.eclipse.jdt.core.compiler.release", "enabled")
// Configure Eclipse projects with -parameters compiler flag.
setProperty("org.eclipse.jdt.core.compiler.codegen.methodParameters", "generate")
}
}
}
classpath.file.whenMerged {
this as Classpath
// Remove classpath entries for non-existent libraries added by various
// plugins, such as "junit-jupiter-api/build/classes/kotlin/testFixtures".
entries.removeIf { it is Library && !file(it.path).exists() }
// Remove classpath entries for the code generator model used by the
// Java Template Engine (JTE) which is used to generate the JRE enum and
// dependent tests.
entries.removeIf { it is ProjectDependency && it.path.equals("/code-generator-model") }
// Remove classpath entries for anything used by the Gradle Wrapper.
entries.removeIf { it is Library && it.path.contains("gradle/wrapper") }
entries.filterIsInstance<SourceFolder>().forEach {
it.excludes.add("**/module-info.java")
}
entries.filterIsInstance<ProjectDependency>().forEach {
it.entryAttributes.remove("module")
}
entries.filterIsInstance<Library>().forEach {
it.entryAttributes.remove("module")
}
}
}

java {
modularity.inferModulePath = true
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package junitbuild.eclipse

import org.gradle.api.provider.Property

abstract class EclipseConventionsExtension {
abstract val hideModularity: Property<Boolean>
}
4 changes: 4 additions & 0 deletions junit-jupiter-api/junit-jupiter-api.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ javadocConventions {
addExtraModuleReferences(projects.junitPlatformEngine, projects.junitPlatformLauncher, projects.junitJupiterParams)
}

eclipseConventions {
hideModularity = false
}

tasks {
compileJava {
options.compilerArgs.add("-Xlint:-module") // due to qualified exports
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@
* @see TestReporter#publishFile(String, MediaType, org.junit.jupiter.api.function.ThrowingConsumer)
* @see org.junit.jupiter.api.extension.ExtensionContext#publishFile(String, MediaType, org.junit.jupiter.api.function.ThrowingConsumer)
*/
@SuppressWarnings("removal")
@API(status = MAINTAINED, since = "5.14")
public class MediaType {
public sealed class MediaType permits org.junit.jupiter.api.extension.MediaType {

private static final Pattern PATTERN;

Expand Down Expand Up @@ -125,13 +126,6 @@ protected MediaType(String type, String subtype, @Nullable Charset charset) {
}

protected MediaType(String value) {
// Mimic sealed types, permitting only this class and api.extension.MediaType.
if (getClass() != MediaType.class
&& !getClass().getName().equals("org.junit.jupiter.api.extension.MediaType")) {
throw new IllegalStateException(
"Type '%s' is not permitted to extend MediaType".formatted(getClass().getName()));
}

String strippedValue = Preconditions.notBlank(value, "value must not be null or blank").strip();
Matcher matcher = PATTERN.matcher(strippedValue);
Preconditions.condition(matcher.matches(), () -> "Invalid media type: '" + strippedValue + "'");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.jspecify.annotations.NullMarked;
import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -42,7 +41,6 @@
* @see LoggerFactory
* @see LogRecordListener
*/
@NullMarked
@Target({ ElementType.TYPE, ElementType.PARAMETER })
@Retention(RetentionPolicy.RUNTIME)
@ExtendWith(TrackLogRecords.Extension.class)
Expand Down
4 changes: 4 additions & 0 deletions junit-platform-commons/junit-platform-commons.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ javadocConventions {
addExtraModuleReferences(projects.junitPlatformEngine)
}

eclipseConventions {
hideModularity = false
}

tasks.compileJava {
options.compilerArgs.add("-Xlint:-module") // due to qualified exports
val moduleName = javaModuleName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.junit.jupiter.api.EqualsAndHashCodeAssertions.assertEqualsAndHashCode;
import static org.junit.platform.commons.test.PreconditionAssertions.assertPreconditionViolationFor;
import static org.junit.platform.commons.test.PreconditionAssertions.assertPreconditionViolationNotNullFor;
import static org.junit.platform.commons.test.PreconditionAssertions.assertPreconditionViolationNotNullOrBlankFor;

import java.nio.charset.Charset;

import org.jspecify.annotations.Nullable;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.NullAndEmptySource;
Expand All @@ -33,31 +30,6 @@
*/
class MediaTypeTests {

@Test
void pseudoSealedType() {

class CustomMediaType extends MediaType {

CustomMediaType(String value) {
super(value);
}

CustomMediaType(String type, String subtype, @Nullable Charset charset) {
super(type, subtype, charset);
}
}

String message = "Type '%s' is not permitted to extend MediaType".formatted(CustomMediaType.class.getName());

assertThatIllegalStateException()//
.isThrownBy(() -> new CustomMediaType("text/plain"))//
.withMessage(message);

assertThatIllegalStateException()//
.isThrownBy(() -> new CustomMediaType("text", "plain", UTF_8))//
.withMessage(message);
}

@Test
void equals() {
var mediaType1 = MediaType.TEXT_PLAIN;
Expand Down
Loading