Skip to content

Commit ab3470b

Browse files
committed
Make sealed MediaType work in Eclipse
1 parent a8cd41e commit ab3470b

File tree

5 files changed

+68
-42
lines changed

5 files changed

+68
-42
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import junitbuild.eclipse.EclipseClasspathExtension
2+
import org.gradle.plugins.ide.eclipse.model.Classpath
3+
import org.gradle.plugins.ide.eclipse.model.Library
4+
import org.gradle.plugins.ide.eclipse.model.ProjectDependency
5+
import org.gradle.plugins.ide.eclipse.model.SourceFolder
6+
7+
plugins {
8+
eclipse
9+
}
10+
11+
val extension = extensions.create<EclipseClasspathExtension>("eclipseClasspath").apply {
12+
hideModularity.convention(true)
13+
}
14+
15+
eclipse {
16+
jdt {
17+
sourceCompatibility = JavaVersion.VERSION_21
18+
targetCompatibility = JavaVersion.VERSION_21
19+
file {
20+
// Set properties for org.eclipse.jdt.core.prefs
21+
withProperties {
22+
// Configure Eclipse projects with -release compiler flag.
23+
setProperty("org.eclipse.jdt.core.compiler.release", "enabled")
24+
// Configure Eclipse projects with -parameters compiler flag.
25+
setProperty("org.eclipse.jdt.core.compiler.codegen.methodParameters", "generate")
26+
}
27+
}
28+
}
29+
classpath.file.whenMerged {
30+
this as Classpath
31+
// Remove classpath entries for non-existent libraries added by various
32+
// plugins, such as "junit-jupiter-api/build/classes/kotlin/testFixtures".
33+
entries.removeIf { it is Library && !file(it.path).exists() }
34+
// Remove classpath entries for the code generator model used by the
35+
// Java Template Engine (JTE) which is used to generate the JRE enum and
36+
// dependent tests.
37+
entries.removeIf { it is ProjectDependency && it.path.equals("/code-generator-model") }
38+
// Remove classpath entries for anything used by the Gradle Wrapper.
39+
entries.removeIf { it is Library && it.path.contains("gradle/wrapper") }
40+
if (extension.hideModularity.get()) {
41+
entries.filterIsInstance<SourceFolder>().forEach {
42+
it.excludes.add("**/module-info.java")
43+
}
44+
entries.filterIsInstance<ProjectDependency>().forEach {
45+
it.entryAttributes.remove("module")
46+
}
47+
entries.filterIsInstance<Library>().forEach {
48+
it.entryAttributes.remove("module")
49+
}
50+
}
51+
}
52+
}

gradle/plugins/common/src/main/kotlin/junitbuild.java-library-conventions.gradle.kts

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
22
import junitbuild.extensions.isSnapshot
3-
import org.gradle.plugins.ide.eclipse.model.Classpath
4-
import org.gradle.plugins.ide.eclipse.model.Library
5-
import org.gradle.plugins.ide.eclipse.model.ProjectDependency
6-
import org.gradle.plugins.ide.eclipse.model.SourceFolder
73

84
plugins {
95
`java-library`
10-
eclipse
116
id("junitbuild.base-conventions")
127
id("junitbuild.build-parameters")
138
id("junitbuild.checkstyle-conventions")
9+
id("junitbuild.eclipse-conventions")
1410
id("junitbuild.jacoco-java-conventions")
1511
}
1612

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

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

24-
eclipse {
25-
jdt {
26-
sourceCompatibility = JavaVersion.VERSION_21
27-
targetCompatibility = JavaVersion.VERSION_21
28-
file {
29-
// Set properties for org.eclipse.jdt.core.prefs
30-
withProperties {
31-
// Configure Eclipse projects with -release compiler flag.
32-
setProperty("org.eclipse.jdt.core.compiler.release", "enabled")
33-
// Configure Eclipse projects with -parameters compiler flag.
34-
setProperty("org.eclipse.jdt.core.compiler.codegen.methodParameters", "generate")
35-
}
36-
}
37-
}
38-
classpath.file.whenMerged {
39-
this as Classpath
40-
// Remove classpath entries for non-existent libraries added by various
41-
// plugins, such as "junit-jupiter-api/build/classes/kotlin/testFixtures".
42-
entries.removeIf { it is Library && !file(it.path).exists() }
43-
// Remove classpath entries for the code generator model used by the
44-
// Java Template Engine (JTE) which is used to generate the JRE enum and
45-
// dependent tests.
46-
entries.removeIf { it is ProjectDependency && it.path.equals("/code-generator-model") }
47-
// Remove classpath entries for anything used by the Gradle Wrapper.
48-
entries.removeIf { it is Library && it.path.contains("gradle/wrapper") }
49-
entries.filterIsInstance<SourceFolder>().forEach {
50-
it.excludes.add("**/module-info.java")
51-
}
52-
entries.filterIsInstance<ProjectDependency>().forEach {
53-
it.entryAttributes.remove("module")
54-
}
55-
entries.filterIsInstance<Library>().forEach {
56-
it.entryAttributes.remove("module")
57-
}
58-
}
59-
}
60-
6120
java {
6221
modularity.inferModulePath = true
6322
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package junitbuild.eclipse
2+
3+
import org.gradle.api.provider.Property
4+
5+
abstract class EclipseClasspathExtension {
6+
abstract val hideModularity: Property<Boolean>
7+
}

junit-jupiter-api/junit-jupiter-api.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ javadocConventions {
2828
addExtraModuleReferences(projects.junitPlatformEngine, projects.junitPlatformLauncher, projects.junitJupiterParams)
2929
}
3030

31+
eclipseClasspath {
32+
hideModularity = false
33+
}
34+
3135
tasks {
3236
compileJava {
3337
options.compilerArgs.add("-Xlint:-module") // due to qualified exports

junit-platform-commons/junit-platform-commons.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ javadocConventions {
2525
addExtraModuleReferences(projects.junitPlatformEngine)
2626
}
2727

28+
eclipseClasspath {
29+
hideModularity = false
30+
}
31+
2832
tasks.compileJava {
2933
options.compilerArgs.add("-Xlint:-module") // due to qualified exports
3034
val moduleName = javaModuleName

0 commit comments

Comments
 (0)