This is an automated email from the ASF dual-hosted git repository.

ddekany pushed a commit to branch java-impl-static-linking
in repository https://gitbox.apache.org/repos/asf/freemarker.git


The following commit(s) were added to refs/heads/java-impl-static-linking by 
this push:
     new 3f2d6430 Build: test task to always use the jar, as "JEP 238: 
Multi-Release JAR Files" doesn't work otherwise
3f2d6430 is described below

commit 3f2d64309e1114b2adad3abf355711c6b59d1643
Author: ddekany <[email protected]>
AuthorDate: Fri Aug 2 00:33:17 2024 +0200

    Build: test task to always use the jar, as "JEP 238: Multi-Release JAR 
Files" doesn't work otherwise
---
 .../freemarker/build/FreemarkerRootExtension.kt    | 57 ++++++++--------------
 .../beans/Java16TestClassLoadingCorrectTest.java   |  5 ++
 2 files changed, 24 insertions(+), 38 deletions(-)

diff --git 
a/buildSrc/src/main/kotlin/freemarker/build/FreemarkerRootExtension.kt 
b/buildSrc/src/main/kotlin/freemarker/build/FreemarkerRootExtension.kt
index 8b9639d6..6bfc569a 100644
--- a/buildSrc/src/main/kotlin/freemarker/build/FreemarkerRootExtension.kt
+++ b/buildSrc/src/main/kotlin/freemarker/build/FreemarkerRootExtension.kt
@@ -19,7 +19,6 @@
 
 package freemarker.build
 
-import java.util.concurrent.atomic.AtomicBoolean
 import org.gradle.api.NamedDomainObjectProvider
 import org.gradle.api.Project
 import org.gradle.api.artifacts.VersionCatalogsExtension
@@ -34,17 +33,13 @@ import org.gradle.api.tasks.TaskProvider
 import org.gradle.api.tasks.bundling.Jar
 import org.gradle.api.tasks.compile.JavaCompile
 import org.gradle.api.tasks.javadoc.Javadoc
-import org.gradle.api.tasks.testing.Test
 import org.gradle.jvm.toolchain.JavaLanguageVersion
 import org.gradle.jvm.toolchain.JavaToolchainService
-import org.gradle.kotlin.dsl.dependencies
-import org.gradle.kotlin.dsl.named
-import org.gradle.kotlin.dsl.register
-import org.gradle.kotlin.dsl.setProperty
-import org.gradle.kotlin.dsl.the
+import org.gradle.kotlin.dsl.*
 import org.gradle.language.base.plugins.LifecycleBasePlugin
 import org.gradle.language.jvm.tasks.ProcessResources
 import org.gradle.testing.base.TestingExtension
+import java.util.concurrent.atomic.AtomicBoolean
 
 private const val TEST_UTILS_SOURCE_SET_NAME = "test-utils"
 
@@ -162,35 +157,6 @@ class FreemarkerModuleDef internal constructor(
         return "test${sourceSetName.replaceFirstChar { it.uppercaseChar() 
}}WithJar"
     }
 
-    private fun registerTestWithJar(testSuiteRef: Provider<JvmTestSuite>, 
testJavaVersion: JavaLanguageVersion) {
-        val tasks = context.project.tasks
-        val testWithJarTaskRef = 
context.project.tasks.register<Test>(testWithJarTaskName(sourceSetName)) {
-            group = LifecycleBasePlugin.VERIFICATION_GROUP
-            description = "Runs the tests in ${sourceSetName} with the jar as 
the dependency."
-
-            val testSourceSet = testSuiteRef.get().sources
-            testClassesDirs = testSourceSet.output.classesDirs
-
-            val jarClasspath = project.objects.fileCollection()
-            jarClasspath.from(tasks.named(JavaPlugin.JAR_TASK_NAME))
-            jarClasspath.from(testSourceSet.output)
-            jarClasspath.from(testUtils().output)
-            // Filtering out directories is strictly speaking incorrect.
-            // Our intent is to filter out the compiled classes that are 
declared as dependencies.
-            // The correct solution would be to split the configurations to 
separately
-            // track the external and internal dependencies. However, that 
would be a considerable
-            // complication of the build, and this solution should be good 
given that our external
-            // dependencies are always files (jars).
-            jarClasspath.from(testSourceSet.runtimeClasspath.filter { 
it.isFile })
-            classpath = jarClasspath
-
-            javaLauncher.set(context.javaToolchains.launcherFor {
-                languageVersion.set(testJavaVersion)
-            })
-        }
-        tasks.named(LifecycleBasePlugin.CHECK_TASK_NAME) { 
dependsOn(testWithJarTaskRef) }
-    }
-
     private fun configureTests(testJavaVersion: JavaLanguageVersion): 
NamedDomainObjectProvider<JvmTestSuite> {
         val testSuiteRef = getOrCreateTestSuiteRef()
         testSuiteRef.configure {
@@ -200,8 +166,6 @@ class FreemarkerModuleDef internal constructor(
             targets.all { configureTarget(this, sources, testJavaVersion) }
         }
 
-        registerTestWithJar(testSuiteRef, testJavaVersion)
-
         return testSuiteRef
     }
 
@@ -266,6 +230,23 @@ class FreemarkerModuleDef internal constructor(
                     .toString()
                 systemProperty("freemarker.test.resourcesDir", 
resourcesDestDir)
 
+                testClassesDirs = sources.output.classesDirs
+
+                // We have to build the jar and depend on that, because we 
depend on "JEP 238: Multi-Release JAR Files",
+                // which puts some classes into the jar under 
META-INF\versions\$javaVersion.
+                val jarClasspath = project.objects.fileCollection()
+                
jarClasspath.from(project.tasks.named(JavaPlugin.JAR_TASK_NAME))
+                jarClasspath.from(sources.output)
+                jarClasspath.from(testUtils().output)
+                // Filtering out directories is strictly speaking incorrect.
+                // Our intent is to filter out the compiled classes that are 
declared as dependencies.
+                // The correct solution would be to split the configurations 
to separately
+                // track the external and internal dependencies. However, that 
would be a considerable
+                // complication of the build, and this solution should be good 
given that our external
+                // dependencies are always files (jars).
+                jarClasspath.from(sources.runtimeClasspath.filter { it.isFile 
})
+                classpath = jarClasspath
+
                 javaLauncher.set(context.javaToolchains.launcherFor {
                     languageVersion.set(testRunnerJavaVersion)
                 })
diff --git 
a/freemarker-core16/src/test/java/freemarker/ext/beans/Java16TestClassLoadingCorrectTest.java
 
b/freemarker-core16/src/test/java/freemarker/ext/beans/Java16TestClassLoadingCorrectTest.java
index d4f4f020..d66d13b0 100644
--- 
a/freemarker-core16/src/test/java/freemarker/ext/beans/Java16TestClassLoadingCorrectTest.java
+++ 
b/freemarker-core16/src/test/java/freemarker/ext/beans/Java16TestClassLoadingCorrectTest.java
@@ -25,6 +25,8 @@ import org.junit.Test;
 
 import freemarker.core._Java16;
 import freemarker.core._Java16Impl;
+import freemarker.core._Java9;
+import freemarker.core._Java9Impl;
 
 public class Java16TestClassLoadingCorrectTest {
     @Test
@@ -33,5 +35,8 @@ public class Java16TestClassLoadingCorrectTest {
         assertTrue(
                 "Multi-Release JAR selection of the proper " + 
_Java16Impl.class.getName() + " variant didn't happen in the Java 16 test 
environment",
                 _Java16.INSTANCE.isSupported());
+        assertTrue(
+                "Multi-Release JAR selection of the proper " + 
_Java9Impl.class.getName() + " variant didn't happen in the Java 16 test 
environment",
+                _Java9.INSTANCE.isSupported());
     }
 }

Reply via email to