From 95f8f0d9a50f1cfc3b6ff2499ac75c2252c9d8c0 Mon Sep 17 00:00:00 2001 From: Sergii Kondrusiev Date: Mon, 13 May 2024 15:54:13 +0300 Subject: [PATCH 01/21] Make Gretty java toolchain aware --- .../org/akhikhl/gretty/JavaExecParams.groovy | 6 +++++ .../org/akhikhl/gretty/LauncherBase.groovy | 1 + .../org/akhikhl/gretty/ServerConfig.groovy | 6 ++++- .../org/akhikhl/gretty/StarterLauncher.groovy | 10 ++++--- .../org/akhikhl/gretty/DefaultLauncher.groovy | 5 ++++ .../org/akhikhl/gretty/StartBaseTask.groovy | 27 +++++++++++++++++++ .../gretty/TaskWithServerConfig.groovy | 4 +++ 7 files changed, 55 insertions(+), 4 deletions(-) diff --git a/libs/gretty-core/src/main/groovy/org/akhikhl/gretty/JavaExecParams.groovy b/libs/gretty-core/src/main/groovy/org/akhikhl/gretty/JavaExecParams.groovy index 7a3c7b69f..6ca0ddefa 100644 --- a/libs/gretty-core/src/main/groovy/org/akhikhl/gretty/JavaExecParams.groovy +++ b/libs/gretty-core/src/main/groovy/org/akhikhl/gretty/JavaExecParams.groovy @@ -19,6 +19,8 @@ class JavaExecParams { String main + String jvmExecutable + List jvmArgs = [] List args = [] @@ -29,6 +31,10 @@ class JavaExecParams { Map systemProperties = [:] + void jvmExecutable(String jvmExecutable) { + this.jvmExecutable = jvmExecutable + } + void arg(String a) { args.add(a) } diff --git a/libs/gretty-core/src/main/groovy/org/akhikhl/gretty/LauncherBase.groovy b/libs/gretty-core/src/main/groovy/org/akhikhl/gretty/LauncherBase.groovy index f64c6d13a..4e86c3020 100644 --- a/libs/gretty-core/src/main/groovy/org/akhikhl/gretty/LauncherBase.groovy +++ b/libs/gretty-core/src/main/groovy/org/akhikhl/gretty/LauncherBase.groovy @@ -188,6 +188,7 @@ abstract class LauncherBase implements Launcher { params.debug = config.getDebug() params.debugSuspend = config.getDebugSuspend() params.debugPort = config.getDebugPort() + params.jvmExecutable = sconfig.jvmExecutable params.jvmArgs = sconfig.jvmArgs params.systemProperties = sconfig.systemProperties if(!sconfig.secureRandom) { diff --git a/libs/gretty-core/src/main/groovy/org/akhikhl/gretty/ServerConfig.groovy b/libs/gretty-core/src/main/groovy/org/akhikhl/gretty/ServerConfig.groovy index 68cf87829..9d6d8af3d 100644 --- a/libs/gretty-core/src/main/groovy/org/akhikhl/gretty/ServerConfig.groovy +++ b/libs/gretty-core/src/main/groovy/org/akhikhl/gretty/ServerConfig.groovy @@ -21,7 +21,7 @@ import groovy.transform.TypeCheckingMode class ServerConfig { static final int RANDOM_FREE_PORT = -1 - + String jvmExecutable List jvmArgs Map systemProperties String servletContainer @@ -161,4 +161,8 @@ class ServerConfig { systemProperties << m } } + + void jvmExecutable(String jvmExecutable) { + this.jvmExecutable = jvmExecutable + } } diff --git a/libs/gretty-starter/src/main/groovy/org/akhikhl/gretty/StarterLauncher.groovy b/libs/gretty-starter/src/main/groovy/org/akhikhl/gretty/StarterLauncher.groovy index b3567eb36..a9bee3cfb 100644 --- a/libs/gretty-starter/src/main/groovy/org/akhikhl/gretty/StarterLauncher.groovy +++ b/libs/gretty-starter/src/main/groovy/org/akhikhl/gretty/StarterLauncher.groovy @@ -57,13 +57,17 @@ class StarterLauncher extends LauncherBase { @Override protected void javaExec(JavaExecParams params) { - String javaExe = PlatformUtils.isWindows() ? 'java.exe' : 'java' - String javaPath = new File(System.getProperty("java.home"), "bin/$javaExe").absolutePath + String jvmExecutable = Optional.ofNullable(params.jvmExecutable).orElseGet({ + String javaExe = PlatformUtils.isWindows() ? 'java.exe' : 'java' + String javaPath = new File(System.getProperty("java.home"), "bin/$javaExe").absolutePath + return javaPath + }) + def classPath = [ new File(basedir, 'runner/*') ] classPath = classPath.collect { it.absolutePath }.join(System.getProperty('path.separator')) // Note that JavaExecParams debugging properties are intentionally ignored. // It is supposed that webapp debugging is performed via DefaultLauncher. - def procParams = [ javaPath ] + params.jvmArgs + ['-DgrettyProduct=true'] + params.systemProperties.collect { k, v -> "-D$k=$v" } + [ '-cp', classPath, params.main ] + params.args + def procParams = [ jvmExecutable ] + params.jvmArgs + ['-DgrettyProduct=true'] + params.systemProperties.collect { k, v -> "-D$k=$v" } + [ '-cp', classPath, params.main ] + params.args log.debug 'Launching runner process: {}', procParams.join(' ') Process proc = procParams.execute() proc.waitForProcessOutput(System.out, System.err) diff --git a/libs/gretty/src/main/groovy/org/akhikhl/gretty/DefaultLauncher.groovy b/libs/gretty/src/main/groovy/org/akhikhl/gretty/DefaultLauncher.groovy index 6497e1764..6b0bc588f 100644 --- a/libs/gretty/src/main/groovy/org/akhikhl/gretty/DefaultLauncher.groovy +++ b/libs/gretty/src/main/groovy/org/akhikhl/gretty/DefaultLauncher.groovy @@ -112,6 +112,11 @@ class DefaultLauncher extends LauncherBase { } log.info 'DEBUG MODE, port={}, suspend={}', params.debugPort, params.debugSuspend } + + if (params.jvmExecutable) { + spec.executable params.jvmExecutable + } + spec.jvmArgs jvmArgs spec.systemProperties params.systemProperties spec.mainClass.set(params.main) diff --git a/libs/gretty/src/main/groovy/org/akhikhl/gretty/StartBaseTask.groovy b/libs/gretty/src/main/groovy/org/akhikhl/gretty/StartBaseTask.groovy index d4d67d4b0..a27c445df 100644 --- a/libs/gretty/src/main/groovy/org/akhikhl/gretty/StartBaseTask.groovy +++ b/libs/gretty/src/main/groovy/org/akhikhl/gretty/StartBaseTask.groovy @@ -14,8 +14,12 @@ import org.akhikhl.gretty.scanner.JDKScannerManager import org.gradle.api.DefaultTask import org.gradle.api.Task import org.gradle.api.plugins.ExtensionAware +import org.gradle.api.plugins.JavaPluginExtension import org.gradle.api.tasks.Internal import org.gradle.api.tasks.TaskAction +import org.gradle.jvm.toolchain.JavaLauncher +import org.gradle.jvm.toolchain.JavaToolchainService +import org.gradle.jvm.toolchain.JavaToolchainSpec import org.gradle.process.JavaForkOptions import org.gradle.testing.jacoco.plugins.JacocoTaskExtension /** @@ -115,6 +119,10 @@ abstract class StartBaseTask extends DefaultTask { sconfig.systemProperty 'springloaded', 'exclusions=org.akhikhl.gretty..*' } + getJavaToolchainJvmExecutable().ifPresent({ jvmExecutable -> + sconfig.jvmExecutable(jvmExecutable) + }) + for(Closure c in prepareServerConfigClosures) { c = c.rehydrate(sconfig, c.owner, c.thisObject) c.resolveStrategy = Closure.DELEGATE_FIRST @@ -165,6 +173,25 @@ abstract class StartBaseTask extends DefaultTask { } } + private Optional getJavaToolchainLauncher() { + Optional toolchainService = Optional.ofNullable(project.extensions.getByType(JavaToolchainService)) + Optional launcher = Optional.ofNullable(project.extensions.getByType(JavaPluginExtension)) + .map({ it.getToolchain() }) + .flatMap({ JavaToolchainSpec spec -> + toolchainService + .map({ it.launcherFor(spec) }) + .map({ it.getOrElse(null) }) + }) + + return launcher + } + + private Optional getJavaToolchainJvmExecutable() { + return getJavaToolchainLauncher() + .map({ it.executablePath?.asFile?.path }) + } + + @Internal protected final LauncherConfig getLauncherConfig() { diff --git a/libs/gretty/src/main/groovy/org/akhikhl/gretty/TaskWithServerConfig.groovy b/libs/gretty/src/main/groovy/org/akhikhl/gretty/TaskWithServerConfig.groovy index 4981d79fe..a92a54dd3 100644 --- a/libs/gretty/src/main/groovy/org/akhikhl/gretty/TaskWithServerConfig.groovy +++ b/libs/gretty/src/main/groovy/org/akhikhl/gretty/TaskWithServerConfig.groovy @@ -10,6 +10,10 @@ import org.gradle.api.tasks.PathSensitive import org.gradle.api.tasks.PathSensitivity interface TaskWithServerConfig { + @Optional + @Input + String getJvmExecutable() + @Optional @Input List getJvmArgs() From 8f4b9ab964036c0d7b4845fc2bdc6e73d98ef20f Mon Sep 17 00:00:00 2001 From: Sergii Kondrusiev Date: Mon, 20 May 2024 15:33:00 +0300 Subject: [PATCH 02/21] Rename .groovy to .java --- .../org/akhikhl/examples/gretty/springbootapp/Application.java} | 0 .../examples/gretty/springbootwebservice/Application.java} | 0 .../examples/gretty/springbootwebservice/MyController.java} | 0 .../org/akhikhl/examples/gretty/springbootapp/Application.java} | 0 .../examples/gretty/springbootwebservice1/Application.java} | 0 .../examples/gretty/springbootwebservice1/MyController.java} | 0 .../examples/gretty/springbootwebservice2/Application.java} | 0 .../examples/gretty/springbootwebservice2/MyController.java} | 0 .../akhikhl/examples/gretty/springbootsimple/Application.java} | 0 .../akhikhl/examples/gretty/springbootsimple/MyController.java} | 0 10 files changed, 0 insertions(+), 0 deletions(-) rename integrationTests/spring-boot-farm-secure/spring-boot-app/src/main/{groovy/org/akhikhl/examples/gretty/springbootapp/Application.groovy => java/org/akhikhl/examples/gretty/springbootapp/Application.java} (100%) rename integrationTests/spring-boot-farm-secure/spring-boot-webservice/src/main/{groovy/org/akhikhl/examples/gretty/springbootwebservice/Application.groovy => java/org/akhikhl/examples/gretty/springbootwebservice/Application.java} (100%) rename integrationTests/spring-boot-farm-secure/spring-boot-webservice/src/main/{groovy/org/akhikhl/examples/gretty/springbootwebservice/MyController.groovy => java/org/akhikhl/examples/gretty/springbootwebservice/MyController.java} (100%) rename integrationTests/spring-boot-farm/spring-boot-app/src/main/{groovy/org/akhikhl/examples/gretty/springbootapp/Application.groovy => java/org/akhikhl/examples/gretty/springbootapp/Application.java} (100%) rename integrationTests/spring-boot-farm/spring-boot-webservice1/src/main/{groovy/org/akhikhl/examples/gretty/springbootwebservice1/Application.groovy => java/org/akhikhl/examples/gretty/springbootwebservice1/Application.java} (100%) rename integrationTests/spring-boot-farm/spring-boot-webservice1/src/main/{groovy/org/akhikhl/examples/gretty/springbootwebservice1/MyController.groovy => java/org/akhikhl/examples/gretty/springbootwebservice1/MyController.java} (100%) rename integrationTests/spring-boot-farm/spring-boot-webservice2/src/main/{groovy/org/akhikhl/examples/gretty/springbootwebservice2/Application.groovy => java/org/akhikhl/examples/gretty/springbootwebservice2/Application.java} (100%) rename integrationTests/spring-boot-farm/spring-boot-webservice2/src/main/{groovy/org/akhikhl/examples/gretty/springbootwebservice2/MyController.groovy => java/org/akhikhl/examples/gretty/springbootwebservice2/MyController.java} (100%) rename integrationTests/spring-boot-simple/src/main/{groovy/org/akhikhl/examples/gretty/springbootsimple/Application.groovy => java/org/akhikhl/examples/gretty/springbootsimple/Application.java} (100%) rename integrationTests/spring-boot-simple/src/main/{groovy/org/akhikhl/examples/gretty/springbootsimple/MyController.groovy => java/org/akhikhl/examples/gretty/springbootsimple/MyController.java} (100%) diff --git a/integrationTests/spring-boot-farm-secure/spring-boot-app/src/main/groovy/org/akhikhl/examples/gretty/springbootapp/Application.groovy b/integrationTests/spring-boot-farm-secure/spring-boot-app/src/main/java/org/akhikhl/examples/gretty/springbootapp/Application.java similarity index 100% rename from integrationTests/spring-boot-farm-secure/spring-boot-app/src/main/groovy/org/akhikhl/examples/gretty/springbootapp/Application.groovy rename to integrationTests/spring-boot-farm-secure/spring-boot-app/src/main/java/org/akhikhl/examples/gretty/springbootapp/Application.java diff --git a/integrationTests/spring-boot-farm-secure/spring-boot-webservice/src/main/groovy/org/akhikhl/examples/gretty/springbootwebservice/Application.groovy b/integrationTests/spring-boot-farm-secure/spring-boot-webservice/src/main/java/org/akhikhl/examples/gretty/springbootwebservice/Application.java similarity index 100% rename from integrationTests/spring-boot-farm-secure/spring-boot-webservice/src/main/groovy/org/akhikhl/examples/gretty/springbootwebservice/Application.groovy rename to integrationTests/spring-boot-farm-secure/spring-boot-webservice/src/main/java/org/akhikhl/examples/gretty/springbootwebservice/Application.java diff --git a/integrationTests/spring-boot-farm-secure/spring-boot-webservice/src/main/groovy/org/akhikhl/examples/gretty/springbootwebservice/MyController.groovy b/integrationTests/spring-boot-farm-secure/spring-boot-webservice/src/main/java/org/akhikhl/examples/gretty/springbootwebservice/MyController.java similarity index 100% rename from integrationTests/spring-boot-farm-secure/spring-boot-webservice/src/main/groovy/org/akhikhl/examples/gretty/springbootwebservice/MyController.groovy rename to integrationTests/spring-boot-farm-secure/spring-boot-webservice/src/main/java/org/akhikhl/examples/gretty/springbootwebservice/MyController.java diff --git a/integrationTests/spring-boot-farm/spring-boot-app/src/main/groovy/org/akhikhl/examples/gretty/springbootapp/Application.groovy b/integrationTests/spring-boot-farm/spring-boot-app/src/main/java/org/akhikhl/examples/gretty/springbootapp/Application.java similarity index 100% rename from integrationTests/spring-boot-farm/spring-boot-app/src/main/groovy/org/akhikhl/examples/gretty/springbootapp/Application.groovy rename to integrationTests/spring-boot-farm/spring-boot-app/src/main/java/org/akhikhl/examples/gretty/springbootapp/Application.java diff --git a/integrationTests/spring-boot-farm/spring-boot-webservice1/src/main/groovy/org/akhikhl/examples/gretty/springbootwebservice1/Application.groovy b/integrationTests/spring-boot-farm/spring-boot-webservice1/src/main/java/org/akhikhl/examples/gretty/springbootwebservice1/Application.java similarity index 100% rename from integrationTests/spring-boot-farm/spring-boot-webservice1/src/main/groovy/org/akhikhl/examples/gretty/springbootwebservice1/Application.groovy rename to integrationTests/spring-boot-farm/spring-boot-webservice1/src/main/java/org/akhikhl/examples/gretty/springbootwebservice1/Application.java diff --git a/integrationTests/spring-boot-farm/spring-boot-webservice1/src/main/groovy/org/akhikhl/examples/gretty/springbootwebservice1/MyController.groovy b/integrationTests/spring-boot-farm/spring-boot-webservice1/src/main/java/org/akhikhl/examples/gretty/springbootwebservice1/MyController.java similarity index 100% rename from integrationTests/spring-boot-farm/spring-boot-webservice1/src/main/groovy/org/akhikhl/examples/gretty/springbootwebservice1/MyController.groovy rename to integrationTests/spring-boot-farm/spring-boot-webservice1/src/main/java/org/akhikhl/examples/gretty/springbootwebservice1/MyController.java diff --git a/integrationTests/spring-boot-farm/spring-boot-webservice2/src/main/groovy/org/akhikhl/examples/gretty/springbootwebservice2/Application.groovy b/integrationTests/spring-boot-farm/spring-boot-webservice2/src/main/java/org/akhikhl/examples/gretty/springbootwebservice2/Application.java similarity index 100% rename from integrationTests/spring-boot-farm/spring-boot-webservice2/src/main/groovy/org/akhikhl/examples/gretty/springbootwebservice2/Application.groovy rename to integrationTests/spring-boot-farm/spring-boot-webservice2/src/main/java/org/akhikhl/examples/gretty/springbootwebservice2/Application.java diff --git a/integrationTests/spring-boot-farm/spring-boot-webservice2/src/main/groovy/org/akhikhl/examples/gretty/springbootwebservice2/MyController.groovy b/integrationTests/spring-boot-farm/spring-boot-webservice2/src/main/java/org/akhikhl/examples/gretty/springbootwebservice2/MyController.java similarity index 100% rename from integrationTests/spring-boot-farm/spring-boot-webservice2/src/main/groovy/org/akhikhl/examples/gretty/springbootwebservice2/MyController.groovy rename to integrationTests/spring-boot-farm/spring-boot-webservice2/src/main/java/org/akhikhl/examples/gretty/springbootwebservice2/MyController.java diff --git a/integrationTests/spring-boot-simple/src/main/groovy/org/akhikhl/examples/gretty/springbootsimple/Application.groovy b/integrationTests/spring-boot-simple/src/main/java/org/akhikhl/examples/gretty/springbootsimple/Application.java similarity index 100% rename from integrationTests/spring-boot-simple/src/main/groovy/org/akhikhl/examples/gretty/springbootsimple/Application.groovy rename to integrationTests/spring-boot-simple/src/main/java/org/akhikhl/examples/gretty/springbootsimple/Application.java diff --git a/integrationTests/spring-boot-simple/src/main/groovy/org/akhikhl/examples/gretty/springbootsimple/MyController.groovy b/integrationTests/spring-boot-simple/src/main/java/org/akhikhl/examples/gretty/springbootsimple/MyController.java similarity index 100% rename from integrationTests/spring-boot-simple/src/main/groovy/org/akhikhl/examples/gretty/springbootsimple/MyController.groovy rename to integrationTests/spring-boot-simple/src/main/java/org/akhikhl/examples/gretty/springbootsimple/MyController.java From 5eb2e8580d9d678d8943a6ea895a4ecce2716a22 Mon Sep 17 00:00:00 2001 From: Sergii Kondrusiev Date: Mon, 20 May 2024 15:33:03 +0300 Subject: [PATCH 03/21] Integration tests Apps and Controllers migrated from groovy to java implementation (to avoid groovy jvm version limitations) --- .../gretty/springbootapp/Application.java | 29 +++++---------- .../springbootwebservice/Application.java | 29 +++++---------- .../springbootwebservice/MyController.java | 35 ++++++++----------- .../gretty/springbootapp/Application.java | 29 +++++---------- .../springbootwebservice1/Application.java | 29 +++++---------- .../springbootwebservice1/MyController.java | 35 ++++++++----------- .../springbootwebservice2/Application.java | 29 +++++---------- .../springbootwebservice2/MyController.java | 35 ++++++++----------- .../gretty/springbootsimple/Application.java | 29 +++++---------- .../gretty/springbootsimple/MyController.java | 34 ++++++++---------- 10 files changed, 113 insertions(+), 200 deletions(-) diff --git a/integrationTests/spring-boot-farm-secure/spring-boot-app/src/main/java/org/akhikhl/examples/gretty/springbootapp/Application.java b/integrationTests/spring-boot-farm-secure/spring-boot-app/src/main/java/org/akhikhl/examples/gretty/springbootapp/Application.java index 37817aaa6..fce931f0e 100644 --- a/integrationTests/spring-boot-farm-secure/spring-boot-app/src/main/java/org/akhikhl/examples/gretty/springbootapp/Application.java +++ b/integrationTests/spring-boot-farm-secure/spring-boot-app/src/main/java/org/akhikhl/examples/gretty/springbootapp/Application.java @@ -1,27 +1,16 @@ -/* - * Gretty - * - * Copyright (C) 2013-2015 Andrey Hihlovskiy and contributors. - * - * See the file "LICENSE" for copying and usage permission. - * See the file "CONTRIBUTORS" for complete list of contributors. - */ -package org.akhikhl.examples.gretty.springbootapp +package org.akhikhl.examples.gretty.springbootapp; -import java.util.Arrays - -import org.springframework.boot.SpringApplication -import org.springframework.boot.autoconfigure.EnableAutoConfiguration -import org.springframework.context.annotation.ComponentScan -import org.springframework.context.annotation.Configuration +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; @Configuration @EnableAutoConfiguration @ComponentScan -class Application { +public class Application { + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } - static void main(String[] args) { - SpringApplication.run(Application.class, args) - } } - diff --git a/integrationTests/spring-boot-farm-secure/spring-boot-webservice/src/main/java/org/akhikhl/examples/gretty/springbootwebservice/Application.java b/integrationTests/spring-boot-farm-secure/spring-boot-webservice/src/main/java/org/akhikhl/examples/gretty/springbootwebservice/Application.java index 9a71801fb..c6bc1c355 100644 --- a/integrationTests/spring-boot-farm-secure/spring-boot-webservice/src/main/java/org/akhikhl/examples/gretty/springbootwebservice/Application.java +++ b/integrationTests/spring-boot-farm-secure/spring-boot-webservice/src/main/java/org/akhikhl/examples/gretty/springbootwebservice/Application.java @@ -1,27 +1,16 @@ -/* - * Gretty - * - * Copyright (C) 2013-2015 Andrey Hihlovskiy and contributors. - * - * See the file "LICENSE" for copying and usage permission. - * See the file "CONTRIBUTORS" for complete list of contributors. - */ -package org.akhikhl.examples.gretty.springbootwebservice +package org.akhikhl.examples.gretty.springbootwebservice; -import java.util.Arrays - -import org.springframework.boot.SpringApplication -import org.springframework.boot.autoconfigure.EnableAutoConfiguration -import org.springframework.context.annotation.ComponentScan -import org.springframework.context.annotation.Configuration +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; @Configuration @EnableAutoConfiguration @ComponentScan -class Application { +public class Application { + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } - static void main(String[] args) { - SpringApplication.run(Application.class, args) - } } - diff --git a/integrationTests/spring-boot-farm-secure/spring-boot-webservice/src/main/java/org/akhikhl/examples/gretty/springbootwebservice/MyController.java b/integrationTests/spring-boot-farm-secure/spring-boot-webservice/src/main/java/org/akhikhl/examples/gretty/springbootwebservice/MyController.java index a1a996071..e2df36cd6 100644 --- a/integrationTests/spring-boot-farm-secure/spring-boot-webservice/src/main/java/org/akhikhl/examples/gretty/springbootwebservice/MyController.java +++ b/integrationTests/spring-boot-farm-secure/spring-boot-webservice/src/main/java/org/akhikhl/examples/gretty/springbootwebservice/MyController.java @@ -1,23 +1,18 @@ -/* - * Gretty - * - * Copyright (C) 2013-2015 Andrey Hihlovskiy and contributors. - * - * See the file "LICENSE" for copying and usage permission. - * See the file "CONTRIBUTORS" for complete list of contributors. - */ -package org.akhikhl.examples.gretty.springbootwebservice +package org.akhikhl.examples.gretty.springbootwebservice; -import org.springframework.web.bind.annotation.RestController -import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.bind.annotation.RequestMethod +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; -@RestController -@RequestMapping('/mycontroller') -class MyController { +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Map; - @RequestMapping(value = '/getdate', method = RequestMethod.POST) - Map home() { - return [ date: new Date().format('EEE, d MMM yyyy') ] - } -} +@RestController +@RequestMapping("/mycontroller") +public class MyController { + @RequestMapping(value = "/getdate", method = RequestMethod.POST) + public Map home() { + return Map.of("date", new SimpleDateFormat("EEE, d MMM yyyy").format(new Date())); + } +} \ No newline at end of file diff --git a/integrationTests/spring-boot-farm/spring-boot-app/src/main/java/org/akhikhl/examples/gretty/springbootapp/Application.java b/integrationTests/spring-boot-farm/spring-boot-app/src/main/java/org/akhikhl/examples/gretty/springbootapp/Application.java index 37817aaa6..6f7e31571 100644 --- a/integrationTests/spring-boot-farm/spring-boot-app/src/main/java/org/akhikhl/examples/gretty/springbootapp/Application.java +++ b/integrationTests/spring-boot-farm/spring-boot-app/src/main/java/org/akhikhl/examples/gretty/springbootapp/Application.java @@ -1,27 +1,16 @@ -/* - * Gretty - * - * Copyright (C) 2013-2015 Andrey Hihlovskiy and contributors. - * - * See the file "LICENSE" for copying and usage permission. - * See the file "CONTRIBUTORS" for complete list of contributors. - */ -package org.akhikhl.examples.gretty.springbootapp +package org.akhikhl.examples.gretty.springbootapp; -import java.util.Arrays - -import org.springframework.boot.SpringApplication -import org.springframework.boot.autoconfigure.EnableAutoConfiguration -import org.springframework.context.annotation.ComponentScan -import org.springframework.context.annotation.Configuration +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; @Configuration @EnableAutoConfiguration @ComponentScan -class Application { +public class Application { + public static void main(java.lang.String[] args) { + SpringApplication.run(Application.class, args); + } - static void main(String[] args) { - SpringApplication.run(Application.class, args) - } } - diff --git a/integrationTests/spring-boot-farm/spring-boot-webservice1/src/main/java/org/akhikhl/examples/gretty/springbootwebservice1/Application.java b/integrationTests/spring-boot-farm/spring-boot-webservice1/src/main/java/org/akhikhl/examples/gretty/springbootwebservice1/Application.java index 99d806e81..f71df4632 100644 --- a/integrationTests/spring-boot-farm/spring-boot-webservice1/src/main/java/org/akhikhl/examples/gretty/springbootwebservice1/Application.java +++ b/integrationTests/spring-boot-farm/spring-boot-webservice1/src/main/java/org/akhikhl/examples/gretty/springbootwebservice1/Application.java @@ -1,27 +1,16 @@ -/* - * Gretty - * - * Copyright (C) 2013-2015 Andrey Hihlovskiy and contributors. - * - * See the file "LICENSE" for copying and usage permission. - * See the file "CONTRIBUTORS" for complete list of contributors. - */ -package org.akhikhl.examples.gretty.springbootwebservice1 +package org.akhikhl.examples.gretty.springbootwebservice1; -import java.util.Arrays - -import org.springframework.boot.SpringApplication -import org.springframework.boot.autoconfigure.EnableAutoConfiguration -import org.springframework.context.annotation.ComponentScan -import org.springframework.context.annotation.Configuration +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; @Configuration @EnableAutoConfiguration @ComponentScan -class Application { +public class Application { + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } - static void main(String[] args) { - SpringApplication.run(Application.class, args) - } } - diff --git a/integrationTests/spring-boot-farm/spring-boot-webservice1/src/main/java/org/akhikhl/examples/gretty/springbootwebservice1/MyController.java b/integrationTests/spring-boot-farm/spring-boot-webservice1/src/main/java/org/akhikhl/examples/gretty/springbootwebservice1/MyController.java index 7159e3940..d43639184 100644 --- a/integrationTests/spring-boot-farm/spring-boot-webservice1/src/main/java/org/akhikhl/examples/gretty/springbootwebservice1/MyController.java +++ b/integrationTests/spring-boot-farm/spring-boot-webservice1/src/main/java/org/akhikhl/examples/gretty/springbootwebservice1/MyController.java @@ -1,23 +1,18 @@ -/* - * Gretty - * - * Copyright (C) 2013-2015 Andrey Hihlovskiy and contributors. - * - * See the file "LICENSE" for copying and usage permission. - * See the file "CONTRIBUTORS" for complete list of contributors. - */ -package org.akhikhl.examples.gretty.springbootwebservice1 +package org.akhikhl.examples.gretty.springbootwebservice1; -import org.springframework.web.bind.annotation.RestController -import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.bind.annotation.RequestMethod +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; -@RestController -@RequestMapping('/mycontroller') -class MyController { +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Map; - @RequestMapping(value = '/getdate', method = RequestMethod.POST) - Map home() { - return [ date: new Date().format('EEE, d MMM yyyy') ] - } -} +@RestController +@RequestMapping("/mycontroller") +public class MyController { + @RequestMapping(value = "/getdate", method = RequestMethod.POST) + public Map home() { + return Map.of("date", new SimpleDateFormat("EEE, d MMM yyyy").format(new Date())); + } +} \ No newline at end of file diff --git a/integrationTests/spring-boot-farm/spring-boot-webservice2/src/main/java/org/akhikhl/examples/gretty/springbootwebservice2/Application.java b/integrationTests/spring-boot-farm/spring-boot-webservice2/src/main/java/org/akhikhl/examples/gretty/springbootwebservice2/Application.java index 79669d98a..047cc3c8c 100644 --- a/integrationTests/spring-boot-farm/spring-boot-webservice2/src/main/java/org/akhikhl/examples/gretty/springbootwebservice2/Application.java +++ b/integrationTests/spring-boot-farm/spring-boot-webservice2/src/main/java/org/akhikhl/examples/gretty/springbootwebservice2/Application.java @@ -1,27 +1,16 @@ -/* - * Gretty - * - * Copyright (C) 2013-2015 Andrey Hihlovskiy and contributors. - * - * See the file "LICENSE" for copying and usage permission. - * See the file "CONTRIBUTORS" for complete list of contributors. - */ -package org.akhikhl.examples.gretty.springbootwebservice2 +package org.akhikhl.examples.gretty.springbootwebservice2; -import java.util.Arrays - -import org.springframework.boot.SpringApplication -import org.springframework.boot.autoconfigure.EnableAutoConfiguration -import org.springframework.context.annotation.ComponentScan -import org.springframework.context.annotation.Configuration +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; @Configuration @EnableAutoConfiguration @ComponentScan -class Application { +public class Application { + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } - static void main(String[] args) { - SpringApplication.run(Application.class, args) - } } - diff --git a/integrationTests/spring-boot-farm/spring-boot-webservice2/src/main/java/org/akhikhl/examples/gretty/springbootwebservice2/MyController.java b/integrationTests/spring-boot-farm/spring-boot-webservice2/src/main/java/org/akhikhl/examples/gretty/springbootwebservice2/MyController.java index c9e4c82b1..4c5b3749d 100644 --- a/integrationTests/spring-boot-farm/spring-boot-webservice2/src/main/java/org/akhikhl/examples/gretty/springbootwebservice2/MyController.java +++ b/integrationTests/spring-boot-farm/spring-boot-webservice2/src/main/java/org/akhikhl/examples/gretty/springbootwebservice2/MyController.java @@ -1,23 +1,18 @@ -/* - * Gretty - * - * Copyright (C) 2013-2015 Andrey Hihlovskiy and contributors. - * - * See the file "LICENSE" for copying and usage permission. - * See the file "CONTRIBUTORS" for complete list of contributors. - */ -package org.akhikhl.examples.gretty.springbootwebservice2 +package org.akhikhl.examples.gretty.springbootwebservice2; -import org.springframework.web.bind.annotation.RestController -import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.bind.annotation.RequestMethod +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; -@RestController -@RequestMapping('/mycontroller') -class MyController { +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Map; - @RequestMapping(value = '/getdate', method = RequestMethod.POST) - Map home() { - return [ date: new Date().format('EEE, d MMM yyyy') ] - } -} +@RestController +@RequestMapping("/mycontroller") +public class MyController { + @RequestMapping(value = "/getdate", method = RequestMethod.POST) + public Map home() { + return Map.of("date", new SimpleDateFormat("EEE, d MMM yyyy").format(new Date())); + } +} \ No newline at end of file diff --git a/integrationTests/spring-boot-simple/src/main/java/org/akhikhl/examples/gretty/springbootsimple/Application.java b/integrationTests/spring-boot-simple/src/main/java/org/akhikhl/examples/gretty/springbootsimple/Application.java index b9917b067..6141caee9 100644 --- a/integrationTests/spring-boot-simple/src/main/java/org/akhikhl/examples/gretty/springbootsimple/Application.java +++ b/integrationTests/spring-boot-simple/src/main/java/org/akhikhl/examples/gretty/springbootsimple/Application.java @@ -1,27 +1,16 @@ -/* - * Gretty - * - * Copyright (C) 2013-2015 Andrey Hihlovskiy and contributors. - * - * See the file "LICENSE" for copying and usage permission. - * See the file "CONTRIBUTORS" for complete list of contributors. - */ -package org.akhikhl.examples.gretty.springbootsimple +package org.akhikhl.examples.gretty.springbootsimple; -import java.util.Arrays - -import org.springframework.boot.SpringApplication -import org.springframework.boot.autoconfigure.EnableAutoConfiguration -import org.springframework.context.annotation.ComponentScan -import org.springframework.context.annotation.Configuration +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; @Configuration @EnableAutoConfiguration @ComponentScan -class Application { +public class Application { + public static void main(java.lang.String[] args) { + SpringApplication.run(Application.class, args); + } - static void main(String[] args) { - SpringApplication.run(Application.class, args) - } } - diff --git a/integrationTests/spring-boot-simple/src/main/java/org/akhikhl/examples/gretty/springbootsimple/MyController.java b/integrationTests/spring-boot-simple/src/main/java/org/akhikhl/examples/gretty/springbootsimple/MyController.java index 63651dbab..0d97a6fcf 100644 --- a/integrationTests/spring-boot-simple/src/main/java/org/akhikhl/examples/gretty/springbootsimple/MyController.java +++ b/integrationTests/spring-boot-simple/src/main/java/org/akhikhl/examples/gretty/springbootsimple/MyController.java @@ -1,24 +1,18 @@ -/* - * Gretty - * - * Copyright (C) 2013-2015 Andrey Hihlovskiy and contributors. - * - * See the file "LICENSE" for copying and usage permission. - * See the file "CONTRIBUTORS" for complete list of contributors. - */ -package org.akhikhl.examples.gretty.springbootsimple +package org.akhikhl.examples.gretty.springbootsimple; -import org.springframework.web.bind.annotation.RestController -import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.bind.annotation.RequestMethod +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; -@RestController -@RequestMapping('/mycontroller') -class MyController { +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Map; - @RequestMapping(value = '/getdate', method = RequestMethod.POST) - Map home() { - return [ date: new Date().format('EEE, d MMM yyyy') ] - } +@RestController +@RequestMapping("/mycontroller") +public class MyController { + @RequestMapping(value = "/getdate", method = RequestMethod.POST) + public Map home() { + return Map.of("date", new SimpleDateFormat("EEE, d MMM yyyy").format(new Date())); + } } - From 147eb24fe91b7b8b18bc7814dd44aedc2ef4d0de Mon Sep 17 00:00:00 2001 From: Sergii Kondrusiev Date: Tue, 21 May 2024 17:02:55 +0300 Subject: [PATCH 04/21] Add docker wrapper to run integration tests locally similarly to ci.yml --- .gitignore | 1 + Dockerfile | 45 ++++++++++++++++++++++++ docker_gradlew.sh | 60 ++++++++++++++++++++++++++++++++ docker_integration_tests.sh | 68 +++++++++++++++++++++++++++++++++++++ 4 files changed, 174 insertions(+) create mode 100644 Dockerfile create mode 100644 docker_gradlew.sh create mode 100644 docker_integration_tests.sh diff --git a/.gitignore b/.gitignore index 78ae5c553..5d4e9da2f 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ build *.iws bin/ .DS_Store +.docker-gradle/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..3a195bd1f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,45 @@ +FROM ubuntu as base +RUN apt-get update + +FROM base as base-utils +ENV _BASH_UTILS_DIR=/root/.bashrc.d +COPY <<-EOF $_BASH_UTILS_DIR/0_on_bash_ready.bash +shopt -s expand_aliases +export _on_bash_ready_i=\$(find $_BASH_UTILS_DIR -type f | wc -l) +function on_bash_ready (){ + ((_on_bash_ready_i++)) + local file="$_BASH_UTILS_DIR/\${_on_bash_ready_i}.bash" + echo "\$@" >> \$file && \ + sed -i 's/\r\$//' \$file && \ + source \$file +} +EOF +RUN sed -i 's/\r$//' $_BASH_UTILS_DIR/0_on_bash_ready.bash +RUN echo "while read -r FILE; do source \$FILE; done < <( find $_BASH_UTILS_DIR -name '*.bash' | sort)" >> ~/.profile +SHELL ["/bin/bash", "-l", "-c"] + + +FROM base-utils as firefox +RUN apt-get install -y wget +RUN install -d -m 0755 /etc/apt/keyrings +RUN wget -q https://packages.mozilla.org/apt/repo-signing-key.gpg -O- | tee /etc/apt/keyrings/packages.mozilla.org.asc > /dev/null +RUN echo 'deb [signed-by=/etc/apt/keyrings/packages.mozilla.org.asc] https://packages.mozilla.org/apt mozilla main' | tee -a /etc/apt/sources.list.d/mozilla.list > /dev/null +RUN apt-get update && apt-get install -y firefox-devedition-l10n-eu +RUN ln -s /usr/bin/firefox-devedition /usr/bin/firefox + + +FROM firefox as firefox-sdkman +RUN apt-get install -y curl unzip zip findutils +RUN curl -s "https://get.sdkman.io?rcupdate=false" | bash +RUN on_bash_ready source /root/.sdkman/bin/sdkman-init.sh + +FROM firefox-sdkman as firefox-jdk +ARG JAVA_VERSIONS="8.0.412-amzn" +ENV JAVA_VERSIONS="$JAVA_VERSIONS" +RUN on_bash_ready 'alias install_jdk="sdk install java $1"' +RUN for version in ${JAVA_VERSIONS//,/ } ; do install_jdk $version ; done + + +FROM firefox-jdk as firefox-jdk-gradle +ARG GRADLE_VERSION="6.9.4" +RUN sdk install gradle $GRADLE_VERSION diff --git a/docker_gradlew.sh b/docker_gradlew.sh new file mode 100644 index 000000000..c0ecf867a --- /dev/null +++ b/docker_gradlew.sh @@ -0,0 +1,60 @@ +#!/usr/bin/env bash +set -e + +function build_docker_gradlew_image(){ + docker build -t "docker_gradlew" . \ + --build-arg JAVA_VERSIONS="$_javas" \ + --build-arg GRADLE_VERSION="$_gradle" +} + +function run_docker(){ + build_docker_gradlew_image "$*" + + local working_dir="-w //project/${_working_dir}" + + local project_volume="-v //$(realpath .)://project" + + local gradle_home_volume="" + if [ "$_gradle_home" ]; then + gradle_home_volume="-v //$(realpath $_gradle_home)://root/.gradle" + fi + + local params="$DOCKER_ARGS $project_volume $working_dir $gradle_home_volume" + + + echo "RUNNING:" docker run --rm -it $params docker_gradlew "$@" + docker run --rm -it $params docker_gradlew "$@" +} + +function run_docker_gradle() { + run_docker bash -lc "gradle $*" +} + + +JDK["8"]="8.0.412-amzn" +JDK["11"]="11.0.23-amzn" +JDK["17"]="17.0.11-amzn" +JDK["21"]="21.0.3-amzn" + +GRADLE["6"]="6.9.4" +GRADLE["7"]="7.6.4" + +POSITIONAL_ARGS=() +while [[ $# -gt 0 ]]; do + case "$1" in + -j|--java) export _javas+=",${JDK[$2]:=$2}" && shift 2 ;; + -g|--gradle) export _gradle=${GRADLE[$2]:=$2} && shift 2 ;; + -h|--gradle-home) export _gradle_home=$2 && shift 2 ;; + -w|--working-dir) export _working_dir=$2 && shift 2 ;; + -b|--bash) export _bash="Yes" && shift 1 ;; + + *) POSITIONAL_ARGS+=("$1") && shift ;; + esac +done +set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters + +if [ "$_bash" ]; then + run_docker bash -l +else + run_docker_gradle "${@}" +fi \ No newline at end of file diff --git a/docker_integration_tests.sh b/docker_integration_tests.sh new file mode 100644 index 000000000..b22742193 --- /dev/null +++ b/docker_integration_tests.sh @@ -0,0 +1,68 @@ +#!/usr/bin/env bash +set -e + +export common_gradle_args="--console=plain --no-daemon -Porg.gradle.java.installations.auto-download=false -PgeckoDriverPlatform=linux64" + +#ci.yml plugin build step +./docker_gradlew.sh \ + --java 11 \ + --gradle 6 \ + --gradle-home .docker-gradle \ + $common_gradle_args \ + build + +#ci.yml matrix case #1 +./docker_gradlew.sh \ + --java 8 \ + --gradle 6 \ + --gradle-home .docker-gradle \ + --working-dir integrationTests \ + $common_gradle_args \ + -PtestAllContainers="\"['jetty9.3','jetty9.4','tomcat85','tomcat9']\"" \ + testAll + +#ci.yml matrix case #2 +./docker_gradlew.sh \ + --java 11 \ + --gradle 6 \ + --gradle-home .docker-gradle \ + --working-dir integrationTests \ + $common_gradle_args \ + -PtestAllContainers="\"['jetty9.3','jetty9.4','jetty10','tomcat85','tomcat9']\"" \ + testAll +# + +#ci.yml matrix case #3 +./docker_gradlew.sh \ + --java 17 \ + --gradle 7 \ + --gradle-home .docker-gradle \ + --working-dir integrationTests \ + $common_gradle_args \ + -PtestAllContainers="\"['jetty9.3','jetty9.4','jetty10','tomcat85','tomcat9']\"" \ + -Pspock_version=2.3-groovy-3.0 -PgebVersion=5.1 \ + testAll + +#ci.yml matrix case #2 + toolchain java v17 +./docker_gradlew.sh \ + --java 17 --java 11 \ + --gradle 6 \ + --gradle-home .docker-gradle \ + --working-dir integrationTests \ + $common_gradle_args \ + -PtestAllContainers="\"['jetty9.3','jetty9.4','jetty10','tomcat85','tomcat9']\"" \ + -PtoolchainJavaVersion=17 \ + testAll + + +#ci.yml matrix case #3 + toolchain java v21 +./docker_gradlew.sh \ + --java 17 --java 11 \ + --gradle 7 \ + --gradle-home .docker-gradle \ + --working-dir integrationTests \ + $common_gradle_args \ + -PtestAllContainers="\"['jetty9.3','jetty9.4','jetty10','tomcat85','tomcat9']\"" \ + -Pspock_version=2.3-groovy-3.0 -PgebVersion=5.1 \ + -PtoolchainJavaVersion=17 \ + testAll \ No newline at end of file From 18bf481898767e63e9de438ce4bd4a084124eaa9 Mon Sep 17 00:00:00 2001 From: Sergii Kondrusiev Date: Tue, 21 May 2024 17:04:00 +0300 Subject: [PATCH 05/21] Added integration tests plugin to support java toolchains testing --- .../IntegrationTestPlugin.groovy | 13 +++- .../JavaToolchainIntegrationTestPlugin.groovy | 76 +++++++++++++++++++ ...aToolchainIntegrationTestPlugin.properties | 1 + .../gradle-java-toolchain/README.md | 26 +++++++ .../gradle-java-toolchain/build.gradle | 25 ++++++ .../gradle/toolchain/RequestResponseIT.groovy | 31 ++++++++ .../gretty/gradle/toolchain/Application.java | 16 ++++ .../gretty/gradle/toolchain/MyController.java | 17 +++++ .../src/main/resources/application.properties | 2 + .../src/main/resources/logback.xml | 31 ++++++++ .../src/main/webapp/WEB-INF/filter.groovy | 3 + .../src/main/webapp/WEB-INF/web.xml | 21 +++++ .../src/main/webapp/css/default.css | 18 +++++ .../src/main/webapp/index.html | 26 +++++++ .../src/main/webapp/js/functions.js | 12 +++ integrationTests/settings.gradle | 1 + .../spring-boot-app/build.gradle | 2 +- .../spring-boot-app/build.gradle | 2 +- .../spring-boot-simple/build.gradle | 2 +- .../springBootWebSocket/build.gradle | 2 +- 20 files changed, 321 insertions(+), 6 deletions(-) create mode 100644 integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/JavaToolchainIntegrationTestPlugin.groovy create mode 100644 integrationTests/buildSrc/gretty-integrationTest/src/main/resources/META-INF/gradle-plugins/org.gretty.internal.integrationTests.JavaToolchainIntegrationTestPlugin.properties create mode 100644 integrationTests/gradle-java-toolchain/README.md create mode 100644 integrationTests/gradle-java-toolchain/build.gradle create mode 100644 integrationTests/gradle-java-toolchain/src/integrationTest/groovy/org/akhikhl/examples/gretty/gradle/toolchain/RequestResponseIT.groovy create mode 100644 integrationTests/gradle-java-toolchain/src/main/java/org/akhikhl/examples/gretty/gradle/toolchain/Application.java create mode 100644 integrationTests/gradle-java-toolchain/src/main/java/org/akhikhl/examples/gretty/gradle/toolchain/MyController.java create mode 100644 integrationTests/gradle-java-toolchain/src/main/resources/application.properties create mode 100644 integrationTests/gradle-java-toolchain/src/main/resources/logback.xml create mode 100644 integrationTests/gradle-java-toolchain/src/main/webapp/WEB-INF/filter.groovy create mode 100644 integrationTests/gradle-java-toolchain/src/main/webapp/WEB-INF/web.xml create mode 100644 integrationTests/gradle-java-toolchain/src/main/webapp/css/default.css create mode 100644 integrationTests/gradle-java-toolchain/src/main/webapp/index.html create mode 100644 integrationTests/gradle-java-toolchain/src/main/webapp/js/functions.js diff --git a/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/IntegrationTestPlugin.groovy b/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/IntegrationTestPlugin.groovy index 1410474ca..630fa2a0e 100644 --- a/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/IntegrationTestPlugin.groovy +++ b/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/IntegrationTestPlugin.groovy @@ -18,6 +18,7 @@ class IntegrationTestPlugin extends BasePlugin { protected void applyPlugins(Project project) { super.applyPlugins(project) project.apply plugin: 'groovy' // this is needed for spock + project.apply plugin: JavaToolchainIntegrationTestPlugin } @Override @@ -48,6 +49,8 @@ class IntegrationTestPlugin extends BasePlugin { protected void configureExtensions(Project project) { super.configureExtensions(project) + project.extensions.add(JavaVersion, 'javaVersion', JavaToolchainIntegrationTestPlugin.getToolchainJavaVersion(project)) + project.ext.defineIntegrationTest = { def integrationTestTask_ = project.tasks.findByName('integrationTest') @@ -62,6 +65,8 @@ class IntegrationTestPlugin extends BasePlugin { else testClassesDirs = project.sourceSets.integrationTest.output.classesDirs classpath = project.sourceSets.integrationTest.runtimeClasspath + + JavaToolchainIntegrationTestPlugin.forceTaskToUseGradleJvm(it) } integrationTestTask_ @@ -79,13 +84,13 @@ class IntegrationTestPlugin extends BasePlugin { if (!integrationTestContainers) integrationTestContainers = ServletContainerConfig.getConfigNames().collect() // returns immutable and we want to filter later - if (JavaVersion.current().isJava9Compatible()) { + if (project.javaVersion.isJava9Compatible()) { // excluding jetty7 and jetty8 under JDK9, can no longer compile JSPs to default 1.5 target, // see https://github.com/gretty-gradle-plugin/gretty/issues/15 integrationTestContainers -= ['jetty7', 'jetty8'] } - if (JavaVersion.current().isJava10Compatible()) { + if (project.javaVersion.isJava10Compatible()) { // excluding jetty9 under JDK10, can no longer compile JSPs to default 1.7 target, integrationTestContainers -= ['jetty9'] } @@ -110,6 +115,8 @@ class IntegrationTestPlugin extends BasePlugin { else testClassesDirs = project.sourceSets.integrationTest.output.classesDirs classpath = project.sourceSets.integrationTest.runtimeClasspath + + JavaToolchainIntegrationTestPlugin.forceTaskToUseGradleJvm(thisTask) } integrationTestAllContainersTask.dependsOn project.tasks['integrationTest_' + container] @@ -187,6 +194,8 @@ class IntegrationTestPlugin extends BasePlugin { srcDir 'src/integrationTest/resources' } runtimeClasspath += project.rootProject.files('config/gebConfig') + + JavaToolchainIntegrationTestPlugin.forceSourceSetToUseGradleJvm(project, it) } } } diff --git a/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/JavaToolchainIntegrationTestPlugin.groovy b/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/JavaToolchainIntegrationTestPlugin.groovy new file mode 100644 index 000000000..d69fe34d4 --- /dev/null +++ b/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/JavaToolchainIntegrationTestPlugin.groovy @@ -0,0 +1,76 @@ +package org.akhikhl.gretty.internal.integrationTests + +import org.gradle.api.JavaVersion +import org.gradle.api.Project +import org.gradle.api.Task +import org.gradle.api.tasks.SourceSet +import org.gradle.api.tasks.compile.GroovyCompile +import org.gradle.api.tasks.compile.JavaCompile +import org.gradle.api.tasks.testing.Test +import org.gradle.jvm.toolchain.JavaLanguageVersion +import org.slf4j.Logger +import org.slf4j.LoggerFactory + +class JavaToolchainIntegrationTestPlugin extends BasePlugin { + private static final Logger log = LoggerFactory.getLogger(IntegrationTestPlugin) + + protected void configureExtensions(Project project) { + if (project.findProperty('toolchainJavaVersion')) { + defineToolchainDSL(project, Integer.parseInt("${project.toolchainJavaVersion}")) + } + } + + private void defineToolchainDSL(Project project, int javaVersion) { + project.java { + toolchain { + languageVersion = JavaLanguageVersion.of(javaVersion) + } + } + } + + public static void forceSourceSetToUseGradleJvm(Project project, SourceSet sourceSet) { + if (isPluginApplied(project)) { + project.tasks.named(sourceSet.getCompileTaskName('java')).configure({ forceTaskToUseGradleJvm(it) }) + project.tasks.named(sourceSet.getCompileTaskName('groovy')).configure({ forceTaskToUseGradleJvm(it) }) + } + } + + public static void forceTaskToUseGradleJvm(Task task) { + task.project.with { proj -> + if (isPluginApplied(proj)) { + if (task instanceof JavaCompile) { + task.javaCompiler.value(proj.javaToolchains.compilerFor(gradleJvmSpec)) + } + + if (task instanceof GroovyCompile) { + task.javaLauncher.value(proj.javaToolchains.launcherFor(gradleJvmSpec)) + } + + if (task instanceof Test) { + task.javaLauncher.value(proj.javaToolchains.launcherFor(gradleJvmSpec)) + } + } + } + } + + public static JavaVersion getToolchainJavaVersion(Project project) { + return Optional.ofNullable(project.findProperty('toolchainJavaVersion')) + .map({ Integer.parseInt("$it") }) + .map({ JavaVersion.toVersion(it) }) + .orElse(JavaVersion.current()) + } + + public static JavaVersion getGradleJavaVersion() { + return JavaVersion.current() + } + + private static def getGradleJvmSpec() { + def gradleJvmVerson = Integer.valueOf(getGradleJavaVersion().getMajorVersion()) + return { languageVersion = JavaLanguageVersion.of(gradleJvmVerson) } + } + + private static boolean isPluginApplied(Project project) { + return project.plugins.hasPlugin(JavaToolchainIntegrationTestPlugin.class) || + project.plugins.hasPlugin(JavaToolchainIntegrationTestPlugin.class.name) + } +} diff --git a/integrationTests/buildSrc/gretty-integrationTest/src/main/resources/META-INF/gradle-plugins/org.gretty.internal.integrationTests.JavaToolchainIntegrationTestPlugin.properties b/integrationTests/buildSrc/gretty-integrationTest/src/main/resources/META-INF/gradle-plugins/org.gretty.internal.integrationTests.JavaToolchainIntegrationTestPlugin.properties new file mode 100644 index 000000000..738554447 --- /dev/null +++ b/integrationTests/buildSrc/gretty-integrationTest/src/main/resources/META-INF/gradle-plugins/org.gretty.internal.integrationTests.JavaToolchainIntegrationTestPlugin.properties @@ -0,0 +1 @@ +implementation-class=org.akhikhl.gretty.internal.integrationTests.JavaToolchainIntegrationTestPlugin diff --git a/integrationTests/gradle-java-toolchain/README.md b/integrationTests/gradle-java-toolchain/README.md new file mode 100644 index 000000000..daabc03e4 --- /dev/null +++ b/integrationTests/gradle-java-toolchain/README.md @@ -0,0 +1,26 @@ +# spring-boot-simple + +Spring-boot webapp with gretty. + +## How to run + +```bash +cd examples/spring-boot-simple +gradle appRun +``` + +## How to test + +```bash +cd examples/spring-boot-simple +gradle integrationTest +``` + +## How to build a product + + +```bash +cd examples/spring-boot-simple +gradle buildProduct +``` + diff --git a/integrationTests/gradle-java-toolchain/build.gradle b/integrationTests/gradle-java-toolchain/build.gradle new file mode 100644 index 000000000..467f349b8 --- /dev/null +++ b/integrationTests/gradle-java-toolchain/build.gradle @@ -0,0 +1,25 @@ +apply plugin: 'org.gretty' +apply plugin: 'org.gretty.internal.integrationTests.IntegrationTestPlugin' + +dependencies { + implementation localGroovy() + implementation 'org.webjars:bootstrap:3.2.0' + implementation 'org.webjars:jquery:2.1.1' + // We use Velocity for example of template processing within the webapp. + implementation 'org.apache.velocity:velocity:1.7' +} + +gretty { + springBoot = true + if (project.javaVersion.isJava9Compatible()) jvmArgs "--add-opens", "java.base/java.lang=ALL-UNNAMED" +} + +defineIntegrationTest() +testAll.dependsOn defineIntegrationTestAllContainers(['jetty8', 'jetty9', 'jetty10', 'tomcat85', 'tomcat9']) + +tasks.withType(Test).configureEach { +// enabled = project.findProperty('toolchainJavaVersion') as boolean + if(project.findProperty('toolchainJavaVersion')) { + systemProperty 'toolchainJavaVersion', project.findProperty('toolchainJavaVersion') + } +} \ No newline at end of file diff --git a/integrationTests/gradle-java-toolchain/src/integrationTest/groovy/org/akhikhl/examples/gretty/gradle/toolchain/RequestResponseIT.groovy b/integrationTests/gradle-java-toolchain/src/integrationTest/groovy/org/akhikhl/examples/gretty/gradle/toolchain/RequestResponseIT.groovy new file mode 100644 index 000000000..5020c27ca --- /dev/null +++ b/integrationTests/gradle-java-toolchain/src/integrationTest/groovy/org/akhikhl/examples/gretty/gradle/toolchain/RequestResponseIT.groovy @@ -0,0 +1,31 @@ +/* + * Gretty + * + * Copyright (C) 2013-2015 Andrey Hihlovskiy and contributors. + * + * See the file "LICENSE" for copying and usage permission. + * See the file "CONTRIBUTORS" for complete list of contributors. + */ +package org.akhikhl.examples.gretty.gradle.toolchain + +import geb.spock.GebReportingSpec + +class RequestResponseIT extends GebReportingSpec { + + private static String baseURI + private static String toolchainJavaVersion + + void setupSpec() { + baseURI = System.getProperty('gretty.baseURI') + toolchainJavaVersion = System.getProperty('toolchainJavaVersion') ?: System.getProperty('java.vm.version') + } + + def 'should have toolchain java version returned from server side'() { + when: + go baseURI + $('#sendRequest').click() + waitFor { $("p.hide#result").size() == 0 } + then: + $('#result').text().startsWith('Got from server: ' + "$toolchainJavaVersion") + } +} diff --git a/integrationTests/gradle-java-toolchain/src/main/java/org/akhikhl/examples/gretty/gradle/toolchain/Application.java b/integrationTests/gradle-java-toolchain/src/main/java/org/akhikhl/examples/gretty/gradle/toolchain/Application.java new file mode 100644 index 000000000..eabad8a60 --- /dev/null +++ b/integrationTests/gradle-java-toolchain/src/main/java/org/akhikhl/examples/gretty/gradle/toolchain/Application.java @@ -0,0 +1,16 @@ +package org.akhikhl.examples.gretty.gradle.toolchain; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +@Configuration +@EnableAutoConfiguration +@ComponentScan +public class Application { + public static void main(java.lang.String[] args) { + SpringApplication.run(Application.class, args); + } + +} diff --git a/integrationTests/gradle-java-toolchain/src/main/java/org/akhikhl/examples/gretty/gradle/toolchain/MyController.java b/integrationTests/gradle-java-toolchain/src/main/java/org/akhikhl/examples/gretty/gradle/toolchain/MyController.java new file mode 100644 index 000000000..d592e93df --- /dev/null +++ b/integrationTests/gradle-java-toolchain/src/main/java/org/akhikhl/examples/gretty/gradle/toolchain/MyController.java @@ -0,0 +1,17 @@ +package org.akhikhl.examples.gretty.gradle.toolchain; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Collections; +import java.util.Map; + +@RestController +@RequestMapping("/mycontroller") +public class MyController { + @RequestMapping(value = "/getdate", method = RequestMethod.POST) + public Map home() { + return Collections.singletonMap("date", System.getProperty("java.vm.version")); + } +} diff --git a/integrationTests/gradle-java-toolchain/src/main/resources/application.properties b/integrationTests/gradle-java-toolchain/src/main/resources/application.properties new file mode 100644 index 000000000..cec2d09a4 --- /dev/null +++ b/integrationTests/gradle-java-toolchain/src/main/resources/application.properties @@ -0,0 +1,2 @@ +spring.jackson.serialization.INDENT_OUTPUT=true +spring.groovy.template.check-template-location=false \ No newline at end of file diff --git a/integrationTests/gradle-java-toolchain/src/main/resources/logback.xml b/integrationTests/gradle-java-toolchain/src/main/resources/logback.xml new file mode 100644 index 000000000..168f98c50 --- /dev/null +++ b/integrationTests/gradle-java-toolchain/src/main/resources/logback.xml @@ -0,0 +1,31 @@ + + + + + + + + + ${ENCODER_PATTERN} + + + + + ${LOG_DIR}/${LOG_FILE_NAME}.log + true + + ${LOG_DIR}/${LOG_FILE_NAME}-%d{yyyy-MM-dd_HH}.log + 7 + + + ${ENCODER_PATTERN} + + + + + + + + + + diff --git a/integrationTests/gradle-java-toolchain/src/main/webapp/WEB-INF/filter.groovy b/integrationTests/gradle-java-toolchain/src/main/webapp/WEB-INF/filter.groovy new file mode 100644 index 000000000..812d3d5d4 --- /dev/null +++ b/integrationTests/gradle-java-toolchain/src/main/webapp/WEB-INF/filter.groovy @@ -0,0 +1,3 @@ +filter relPath: '/', { + redirect 'index.html' +} diff --git a/integrationTests/gradle-java-toolchain/src/main/webapp/WEB-INF/web.xml b/integrationTests/gradle-java-toolchain/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..e625ab836 --- /dev/null +++ b/integrationTests/gradle-java-toolchain/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,21 @@ + + + + RedirectFilter + org.akhikhl.gretty.RedirectFilter + + + RedirectFilter + /* + REQUEST + FORWARD + + + + jsp + *.html + + diff --git a/integrationTests/gradle-java-toolchain/src/main/webapp/css/default.css b/integrationTests/gradle-java-toolchain/src/main/webapp/css/default.css new file mode 100644 index 000000000..a8c91d150 --- /dev/null +++ b/integrationTests/gradle-java-toolchain/src/main/webapp/css/default.css @@ -0,0 +1,18 @@ +body { + padding-top: 20px; + font-family: 'Open Sans', sans-serif; + font-size: 18px; +} + +h1 { + font-weight: 400; + font-size: 40px; +} + +.margin-base-vertical { + margin: 40px 0; +} + +#result { + margin-top: 16px; +} diff --git a/integrationTests/gradle-java-toolchain/src/main/webapp/index.html b/integrationTests/gradle-java-toolchain/src/main/webapp/index.html new file mode 100644 index 000000000..68c59822d --- /dev/null +++ b/integrationTests/gradle-java-toolchain/src/main/webapp/index.html @@ -0,0 +1,26 @@ + + + + Hello-world page + + + + + + + + + + +
+
+
+

Hello, world!

+

This is static HTML page.

+ +

+
+
+
+ + diff --git a/integrationTests/gradle-java-toolchain/src/main/webapp/js/functions.js b/integrationTests/gradle-java-toolchain/src/main/webapp/js/functions.js new file mode 100644 index 000000000..0a673c1f0 --- /dev/null +++ b/integrationTests/gradle-java-toolchain/src/main/webapp/js/functions.js @@ -0,0 +1,12 @@ +jQuery.noConflict(); + +jQuery(function($) { + $('#result').addClass('hide') + $('#sendRequest').click(function() { + $.ajax({ type: 'POST', url: 'mycontroller/getdate', dataType: 'json' }).done(function(data) { + $('#result').removeClass('hide bg-danger').addClass('bg-success').text('Got from server: ' + data.date); + }).fail(function(jqXHR, textStatus, errorThrown) { + $('#result').removeClass('hide bg-success').addClass('bg-danger').text('error: ' + errorThrown); + }); + }); +}); diff --git a/integrationTests/settings.gradle b/integrationTests/settings.gradle index 190d38137..0e48c75bc 100644 --- a/integrationTests/settings.gradle +++ b/integrationTests/settings.gradle @@ -7,6 +7,7 @@ include 'helloGrettyOverlay' include 'helloJersey' include 'extraResourceBases' include 'filterWebapp' +include 'gradle-java-toolchain' include 'testAnnotations' include 'testAnnotationsOverlay' include 'testDependency' diff --git a/integrationTests/spring-boot-farm-secure/spring-boot-app/build.gradle b/integrationTests/spring-boot-farm-secure/spring-boot-app/build.gradle index c64ad5ba2..de1f0951a 100644 --- a/integrationTests/spring-boot-farm-secure/spring-boot-app/build.gradle +++ b/integrationTests/spring-boot-farm-secure/spring-boot-app/build.gradle @@ -16,7 +16,7 @@ gretty { realm = 'auth' realmConfigFile = '../security' singleSignOn = true - if (JavaVersion.current().isJava9Compatible()) jvmArgs "--add-opens", "java.base/java.lang=ALL-UNNAMED" + if (project.javaVersion.isJava9Compatible()) jvmArgs "--add-opens", "java.base/java.lang=ALL-UNNAMED" } farm { diff --git a/integrationTests/spring-boot-farm/spring-boot-app/build.gradle b/integrationTests/spring-boot-farm/spring-boot-app/build.gradle index d4dc0b140..43cd607a6 100644 --- a/integrationTests/spring-boot-farm/spring-boot-app/build.gradle +++ b/integrationTests/spring-boot-farm/spring-boot-app/build.gradle @@ -10,7 +10,7 @@ dependencies { gretty { springBoot = true - if (JavaVersion.current().isJava9Compatible()) jvmArgs "--add-opens", "java.base/java.lang=ALL-UNNAMED" + if (project.javaVersion.isJava9Compatible()) jvmArgs "--add-opens", "java.base/java.lang=ALL-UNNAMED" } farm { diff --git a/integrationTests/spring-boot-simple/build.gradle b/integrationTests/spring-boot-simple/build.gradle index 46019a466..deaef4e9c 100644 --- a/integrationTests/spring-boot-simple/build.gradle +++ b/integrationTests/spring-boot-simple/build.gradle @@ -11,7 +11,7 @@ dependencies { gretty { springBoot = true - if (JavaVersion.current().isJava9Compatible()) jvmArgs "--add-opens", "java.base/java.lang=ALL-UNNAMED" + if (project.javaVersion.isJava9Compatible()) jvmArgs "--add-opens", "java.base/java.lang=ALL-UNNAMED" } defineIntegrationTest() diff --git a/integrationTests/springBootWebSocket/build.gradle b/integrationTests/springBootWebSocket/build.gradle index fbb984e33..e03024381 100644 --- a/integrationTests/springBootWebSocket/build.gradle +++ b/integrationTests/springBootWebSocket/build.gradle @@ -10,7 +10,7 @@ dependencies { gretty { springBoot = true servletContainer = 'tomcat9' - if (JavaVersion.current().isJava9Compatible()) jvmArgs "--add-opens", "java.base/java.lang=ALL-UNNAMED" + if (project.javaVersion.isJava9Compatible()) jvmArgs "--add-opens", "java.base/java.lang=ALL-UNNAMED" } defineIntegrationTest() From 8a093d69b72e2eee8f036bf9199887723e5cb901 Mon Sep 17 00:00:00 2001 From: Sergii Kondrusiev Date: Tue, 21 May 2024 17:08:24 +0300 Subject: [PATCH 06/21] Fixed java version compatibility issues (v8-v21). --- .../examples/gretty/springbootwebservice/MyController.java | 3 ++- .../examples/gretty/springbootwebservice1/MyController.java | 3 ++- .../examples/gretty/springbootwebservice2/MyController.java | 3 ++- .../akhikhl/examples/gretty/springbootsimple/MyController.java | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/integrationTests/spring-boot-farm-secure/spring-boot-webservice/src/main/java/org/akhikhl/examples/gretty/springbootwebservice/MyController.java b/integrationTests/spring-boot-farm-secure/spring-boot-webservice/src/main/java/org/akhikhl/examples/gretty/springbootwebservice/MyController.java index e2df36cd6..502c36fa0 100644 --- a/integrationTests/spring-boot-farm-secure/spring-boot-webservice/src/main/java/org/akhikhl/examples/gretty/springbootwebservice/MyController.java +++ b/integrationTests/spring-boot-farm-secure/spring-boot-webservice/src/main/java/org/akhikhl/examples/gretty/springbootwebservice/MyController.java @@ -4,6 +4,7 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; +import java.util.Collections; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Map; @@ -13,6 +14,6 @@ public class MyController { @RequestMapping(value = "/getdate", method = RequestMethod.POST) public Map home() { - return Map.of("date", new SimpleDateFormat("EEE, d MMM yyyy").format(new Date())); + return Collections.singletonMap("date", new SimpleDateFormat("EEE, d MMM yyyy").format(new Date())); } } \ No newline at end of file diff --git a/integrationTests/spring-boot-farm/spring-boot-webservice1/src/main/java/org/akhikhl/examples/gretty/springbootwebservice1/MyController.java b/integrationTests/spring-boot-farm/spring-boot-webservice1/src/main/java/org/akhikhl/examples/gretty/springbootwebservice1/MyController.java index d43639184..b9a0c9291 100644 --- a/integrationTests/spring-boot-farm/spring-boot-webservice1/src/main/java/org/akhikhl/examples/gretty/springbootwebservice1/MyController.java +++ b/integrationTests/spring-boot-farm/spring-boot-webservice1/src/main/java/org/akhikhl/examples/gretty/springbootwebservice1/MyController.java @@ -4,6 +4,7 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; +import java.util.Collections; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Map; @@ -13,6 +14,6 @@ public class MyController { @RequestMapping(value = "/getdate", method = RequestMethod.POST) public Map home() { - return Map.of("date", new SimpleDateFormat("EEE, d MMM yyyy").format(new Date())); + return Collections.singletonMap("date", new SimpleDateFormat("EEE, d MMM yyyy").format(new Date())); } } \ No newline at end of file diff --git a/integrationTests/spring-boot-farm/spring-boot-webservice2/src/main/java/org/akhikhl/examples/gretty/springbootwebservice2/MyController.java b/integrationTests/spring-boot-farm/spring-boot-webservice2/src/main/java/org/akhikhl/examples/gretty/springbootwebservice2/MyController.java index 4c5b3749d..521fbb522 100644 --- a/integrationTests/spring-boot-farm/spring-boot-webservice2/src/main/java/org/akhikhl/examples/gretty/springbootwebservice2/MyController.java +++ b/integrationTests/spring-boot-farm/spring-boot-webservice2/src/main/java/org/akhikhl/examples/gretty/springbootwebservice2/MyController.java @@ -4,6 +4,7 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; +import java.util.Collections; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Map; @@ -13,6 +14,6 @@ public class MyController { @RequestMapping(value = "/getdate", method = RequestMethod.POST) public Map home() { - return Map.of("date", new SimpleDateFormat("EEE, d MMM yyyy").format(new Date())); + return Collections.singletonMap("date", new SimpleDateFormat("EEE, d MMM yyyy").format(new Date())); } } \ No newline at end of file diff --git a/integrationTests/spring-boot-simple/src/main/java/org/akhikhl/examples/gretty/springbootsimple/MyController.java b/integrationTests/spring-boot-simple/src/main/java/org/akhikhl/examples/gretty/springbootsimple/MyController.java index 0d97a6fcf..70cee6163 100644 --- a/integrationTests/spring-boot-simple/src/main/java/org/akhikhl/examples/gretty/springbootsimple/MyController.java +++ b/integrationTests/spring-boot-simple/src/main/java/org/akhikhl/examples/gretty/springbootsimple/MyController.java @@ -4,6 +4,7 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; +import java.util.Collections; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Map; @@ -13,6 +14,6 @@ public class MyController { @RequestMapping(value = "/getdate", method = RequestMethod.POST) public Map home() { - return Map.of("date", new SimpleDateFormat("EEE, d MMM yyyy").format(new Date())); + return Collections.singletonMap("date", new SimpleDateFormat("EEE, d MMM yyyy").format(new Date())); } } From 3db2f5dc196372241ad8038b826991d5b175eb1e Mon Sep 17 00:00:00 2001 From: Sergii Kondrusiev Date: Tue, 21 May 2024 17:10:04 +0300 Subject: [PATCH 07/21] Fixed case when toolchains or JavaPlugin are not available --- .../main/groovy/org/akhikhl/gretty/StartBaseTask.groovy | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libs/gretty/src/main/groovy/org/akhikhl/gretty/StartBaseTask.groovy b/libs/gretty/src/main/groovy/org/akhikhl/gretty/StartBaseTask.groovy index a27c445df..3bb3fb2b7 100644 --- a/libs/gretty/src/main/groovy/org/akhikhl/gretty/StartBaseTask.groovy +++ b/libs/gretty/src/main/groovy/org/akhikhl/gretty/StartBaseTask.groovy @@ -174,13 +174,15 @@ abstract class StartBaseTask extends DefaultTask { } private Optional getJavaToolchainLauncher() { - Optional toolchainService = Optional.ofNullable(project.extensions.getByType(JavaToolchainService)) - Optional launcher = Optional.ofNullable(project.extensions.getByType(JavaPluginExtension)) + Optional toolchainService = Optional.ofNullable(project.extensions.findByName('javaToolchains')) + .filter({ it instanceof JavaToolchainService }) + + Optional launcher = Optional.ofNullable(project.extensions.findByType(JavaPluginExtension)) .map({ it.getToolchain() }) .flatMap({ JavaToolchainSpec spec -> toolchainService .map({ it.launcherFor(spec) }) - .map({ it.getOrElse(null) }) + .map({ it.getOrNull() }) }) return launcher From 4fb64b3209a3208e223003eba8443aff83b10fb3 Mon Sep 17 00:00:00 2001 From: Sergii Kondrusiev Date: Tue, 21 May 2024 17:11:00 +0300 Subject: [PATCH 08/21] Added java toolchain configurations into ci.yml file --- .github/workflows/ci.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a4fe0698e..f5abbd53a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,11 +52,21 @@ jobs: - java: 11 gradle: '6.9.4' container: "['jetty9.3','jetty9.4','jetty10','tomcat85','tomcat9']" - + + - java: 11 + gradle: '6.9.4' + container: "['jetty9.3','jetty9.4','jetty10','tomcat85','tomcat9']" + properties: '-PtoolchainJavaVersion=17' + - java: 17 gradle: '7.6.4' container: "['jetty9.3','jetty9.4','jetty10','tomcat85','tomcat9']" properties: '-Pspock_version=2.3-groovy-3.0 -PgebVersion=5.1' + + - java: 17 + gradle: '7.6.4' + container: "['jetty9.3','jetty9.4','jetty10','tomcat85','tomcat9']" + properties: '-Pspock_version=2.3-groovy-3.0 -PgebVersion=5.1 -PtoolchainJavaVersion=17' # TODO: add a JDK-21 build but fix the following issue before that: # groovy.lang.MissingPropertyException: Could not set unknown property 'classifier' for task ':libs:gretty:javadocJar' of type org.gradle.api.tasks.bundling.Jar From c723c48632a906109422b48f3a588399b0999460 Mon Sep 17 00:00:00 2001 From: Sergii Kondrusiev Date: Thu, 23 May 2024 11:28:45 +0300 Subject: [PATCH 09/21] Limited toolchain tests to one --- .../IntegrationTestPlugin.groovy | 32 +++++++-- .../JavaToolchainIntegrationTestPlugin.groovy | 70 ++++++++++++------- .../gradle-java-toolchain/build.gradle | 2 +- 3 files changed, 74 insertions(+), 30 deletions(-) diff --git a/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/IntegrationTestPlugin.groovy b/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/IntegrationTestPlugin.groovy index 630fa2a0e..702ee5197 100644 --- a/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/IntegrationTestPlugin.groovy +++ b/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/IntegrationTestPlugin.groovy @@ -18,7 +18,6 @@ class IntegrationTestPlugin extends BasePlugin { protected void applyPlugins(Project project) { super.applyPlugins(project) project.apply plugin: 'groovy' // this is needed for spock - project.apply plugin: JavaToolchainIntegrationTestPlugin } @Override @@ -51,6 +50,13 @@ class IntegrationTestPlugin extends BasePlugin { project.extensions.add(JavaVersion, 'javaVersion', JavaToolchainIntegrationTestPlugin.getToolchainJavaVersion(project)) + /** + * The caller project integration test would react on -PtoolchainJavaVersion=17 parameter and define appropriate toolchain DSL + **/ + project.ext.defineAsJavaToolchainAwareIntegrationTest = { + JavaToolchainIntegrationTestPlugin.applyPluginConditionally(project) + } + project.ext.defineIntegrationTest = { def integrationTestTask_ = project.tasks.findByName('integrationTest') @@ -66,7 +72,10 @@ class IntegrationTestPlugin extends BasePlugin { testClassesDirs = project.sourceSets.integrationTest.output.classesDirs classpath = project.sourceSets.integrationTest.runtimeClasspath - JavaToolchainIntegrationTestPlugin.forceTaskToUseGradleJvm(it) + JavaToolchainIntegrationTestPlugin.skipIrrelevantTasks(it) + JavaToolchainIntegrationTestPlugin.whenApplied(project) { plugin -> + plugin.forceTaskToUseGradleJvm(it) + } } integrationTestTask_ @@ -81,6 +90,11 @@ class IntegrationTestPlugin extends BasePlugin { integrationTestAllContainersTask = project.task('integrationTestAllContainers') + JavaToolchainIntegrationTestPlugin.skipIrrelevantTasks(integrationTestAllContainersTask) + JavaToolchainIntegrationTestPlugin.whenApplied(project) { plugin -> + plugin.forceTaskToUseGradleJvm(integrationTestAllContainersTask) + } + if (!integrationTestContainers) integrationTestContainers = ServletContainerConfig.getConfigNames().collect() // returns immutable and we want to filter later @@ -116,7 +130,10 @@ class IntegrationTestPlugin extends BasePlugin { testClassesDirs = project.sourceSets.integrationTest.output.classesDirs classpath = project.sourceSets.integrationTest.runtimeClasspath - JavaToolchainIntegrationTestPlugin.forceTaskToUseGradleJvm(thisTask) + JavaToolchainIntegrationTestPlugin.skipIrrelevantTasks(thisTask) + JavaToolchainIntegrationTestPlugin.whenApplied(project) { plugin -> + plugin.forceTaskToUseGradleJvm(thisTask) + } } integrationTestAllContainersTask.dependsOn project.tasks['integrationTest_' + container] @@ -124,10 +141,13 @@ class IntegrationTestPlugin extends BasePlugin { project.task('beforeIntegrationTest_' + container, type: AppBeforeIntegrationTestTask) { servletContainer = container integrationTestTask 'integrationTest_' + container + + JavaToolchainIntegrationTestPlugin.skipIrrelevantTasks(it) } project.task('afterIntegrationTest_' + container, type: AppAfterIntegrationTestTask) { integrationTestTask 'integrationTest_' + container + JavaToolchainIntegrationTestPlugin.skipIrrelevantTasks(it) } } @@ -194,8 +214,10 @@ class IntegrationTestPlugin extends BasePlugin { srcDir 'src/integrationTest/resources' } runtimeClasspath += project.rootProject.files('config/gebConfig') - - JavaToolchainIntegrationTestPlugin.forceSourceSetToUseGradleJvm(project, it) + + JavaToolchainIntegrationTestPlugin.whenApplied(project) { plugin -> + plugin.forceSourceSetToUseGradleJvm(project, it) + } } } } diff --git a/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/JavaToolchainIntegrationTestPlugin.groovy b/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/JavaToolchainIntegrationTestPlugin.groovy index d69fe34d4..9551bfde5 100644 --- a/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/JavaToolchainIntegrationTestPlugin.groovy +++ b/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/JavaToolchainIntegrationTestPlugin.groovy @@ -1,6 +1,8 @@ package org.akhikhl.gretty.internal.integrationTests +import org.gradle.api.Action import org.gradle.api.JavaVersion +import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.Task import org.gradle.api.tasks.SourceSet @@ -11,14 +13,31 @@ import org.gradle.jvm.toolchain.JavaLanguageVersion import org.slf4j.Logger import org.slf4j.LoggerFactory -class JavaToolchainIntegrationTestPlugin extends BasePlugin { +import java.util.function.Consumer + +class JavaToolchainIntegrationTestPlugin implements Plugin { + public static final String PLUGIN_ID = "org.gretty.internal.integrationTests.JavaToolchainIntegrationTestPlugin" private static final Logger log = LoggerFactory.getLogger(IntegrationTestPlugin) - protected void configureExtensions(Project project) { + static void applyPluginConditionally(Project project) { if (project.findProperty('toolchainJavaVersion')) { - defineToolchainDSL(project, Integer.parseInt("${project.toolchainJavaVersion}")) + project.apply plugin: PLUGIN_ID } } + + static void whenApplied(Project project, Consumer config) { + project.plugins.withId(PLUGIN_ID, new Action() { + @Override + void execute(Plugin plugin) { + config.accept((JavaToolchainIntegrationTestPlugin) plugin) + } + }) + } + + @Override + void apply(Project project) { + defineToolchainDSL(project, Integer.parseInt("${project.toolchainJavaVersion}")) + } private void defineToolchainDSL(Project project, int javaVersion) { project.java { @@ -28,27 +47,23 @@ class JavaToolchainIntegrationTestPlugin extends BasePlugin { } } - public static void forceSourceSetToUseGradleJvm(Project project, SourceSet sourceSet) { - if (isPluginApplied(project)) { - project.tasks.named(sourceSet.getCompileTaskName('java')).configure({ forceTaskToUseGradleJvm(it) }) - project.tasks.named(sourceSet.getCompileTaskName('groovy')).configure({ forceTaskToUseGradleJvm(it) }) - } + public void forceSourceSetToUseGradleJvm(Project project, SourceSet sourceSet) { + project.tasks.named(sourceSet.getCompileTaskName('java')).configure({ forceTaskToUseGradleJvm(it) }) + project.tasks.named(sourceSet.getCompileTaskName('groovy')).configure({ forceTaskToUseGradleJvm(it) }) } - public static void forceTaskToUseGradleJvm(Task task) { + public void forceTaskToUseGradleJvm(Task task) { task.project.with { proj -> - if (isPluginApplied(proj)) { - if (task instanceof JavaCompile) { - task.javaCompiler.value(proj.javaToolchains.compilerFor(gradleJvmSpec)) - } + if (task instanceof JavaCompile) { + task.javaCompiler.value(proj.javaToolchains.compilerFor(gradleJvmSpec)) + } - if (task instanceof GroovyCompile) { - task.javaLauncher.value(proj.javaToolchains.launcherFor(gradleJvmSpec)) - } + if (task instanceof GroovyCompile) { + task.javaLauncher.value(proj.javaToolchains.launcherFor(gradleJvmSpec)) + } - if (task instanceof Test) { - task.javaLauncher.value(proj.javaToolchains.launcherFor(gradleJvmSpec)) - } + if (task instanceof Test) { + task.javaLauncher.value(proj.javaToolchains.launcherFor(gradleJvmSpec)) } } } @@ -64,13 +79,20 @@ class JavaToolchainIntegrationTestPlugin extends BasePlugin { return JavaVersion.current() } + public static void skipIrrelevantTasks(Task task) { + task.project.with { + if (task.project.findProperty('toolchainJavaVersion')) { + task.enabled = false + } + + whenApplied(task.project) { + task.enabled = true + } + } + } + private static def getGradleJvmSpec() { def gradleJvmVerson = Integer.valueOf(getGradleJavaVersion().getMajorVersion()) return { languageVersion = JavaLanguageVersion.of(gradleJvmVerson) } } - - private static boolean isPluginApplied(Project project) { - return project.plugins.hasPlugin(JavaToolchainIntegrationTestPlugin.class) || - project.plugins.hasPlugin(JavaToolchainIntegrationTestPlugin.class.name) - } } diff --git a/integrationTests/gradle-java-toolchain/build.gradle b/integrationTests/gradle-java-toolchain/build.gradle index 467f349b8..66971744c 100644 --- a/integrationTests/gradle-java-toolchain/build.gradle +++ b/integrationTests/gradle-java-toolchain/build.gradle @@ -14,11 +14,11 @@ gretty { if (project.javaVersion.isJava9Compatible()) jvmArgs "--add-opens", "java.base/java.lang=ALL-UNNAMED" } +defineAsJavaToolchainAwareIntegrationTest() defineIntegrationTest() testAll.dependsOn defineIntegrationTestAllContainers(['jetty8', 'jetty9', 'jetty10', 'tomcat85', 'tomcat9']) tasks.withType(Test).configureEach { -// enabled = project.findProperty('toolchainJavaVersion') as boolean if(project.findProperty('toolchainJavaVersion')) { systemProperty 'toolchainJavaVersion', project.findProperty('toolchainJavaVersion') } From eaf06c6b2264a62da773eb46685aacf45b149cdc Mon Sep 17 00:00:00 2001 From: Sergii Kondrusiev Date: Thu, 23 May 2024 12:04:58 +0300 Subject: [PATCH 10/21] Fixed github ci test name --- .github/workflows/ci.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f5abbd53a..0cd619684 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,7 +37,7 @@ jobs: path: ${{ env.PRIVATE_REPO }} test: - name: Gradle ${{ matrix.gradle }} on Java ${{ matrix.java }} + name: Gradle ${{ matrix.gradle }} on Java ${{ matrix.java }}${{ matrix.toolchainJavaVersion && format(' (container on Java {0})', matrix.toolchainJavaVersion) || '' }} runs-on: ubuntu-latest needs: build @@ -56,7 +56,7 @@ jobs: - java: 11 gradle: '6.9.4' container: "['jetty9.3','jetty9.4','jetty10','tomcat85','tomcat9']" - properties: '-PtoolchainJavaVersion=17' + toolchainJavaVersion: 17 - java: 17 gradle: '7.6.4' @@ -66,7 +66,8 @@ jobs: - java: 17 gradle: '7.6.4' container: "['jetty9.3','jetty9.4','jetty10','tomcat85','tomcat9']" - properties: '-Pspock_version=2.3-groovy-3.0 -PgebVersion=5.1 -PtoolchainJavaVersion=17' + toolchainJavaVersion: 17 + properties: '-Pspock_version=2.3-groovy-3.0 -PgebVersion=5.1' # TODO: add a JDK-21 build but fix the following issue before that: # groovy.lang.MissingPropertyException: Could not set unknown property 'classifier' for task ':libs:gretty:javadocJar' of type org.gradle.api.tasks.bundling.Jar @@ -76,6 +77,7 @@ jobs: TEST_ALL_CONTAINERS: ${{ matrix.container }} GRADLE_VERSION: ${{ matrix.gradle }} EXTRA_PROPERTIES: ${{ matrix.properties }} + TOOLCHAIN_JAVA_ARGS: "-PtoolchainJavaVersion=${{ matrix.toolchainJavaVersion }}" steps: - uses: actions/checkout@v3 @@ -112,6 +114,7 @@ jobs: --warning-mode all \ -PprivateRepoDir=$PRIVATE_REPO \ $EXTRA_PROPERTIES \ + $TOOLCHAIN_JAVA_ARGS -PgeckoDriverPlatform=linux64 \ -PtestAllContainers=$TEST_ALL_CONTAINERS \ testAll From 4bd493c9c3cc89f2eb2be6266a4e85b4b219fb2a Mon Sep 17 00:00:00 2001 From: Sergii Kondrusiev Date: Thu, 23 May 2024 12:16:22 +0300 Subject: [PATCH 11/21] Fixed github ci test name to a shorter one --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0cd619684..8a199b4bf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,7 +37,7 @@ jobs: path: ${{ env.PRIVATE_REPO }} test: - name: Gradle ${{ matrix.gradle }} on Java ${{ matrix.java }}${{ matrix.toolchainJavaVersion && format(' (container on Java {0})', matrix.toolchainJavaVersion) || '' }} + name: Gradle ${{ matrix.gradle }} on Java ${{ matrix.java }}${{ matrix.toolchainJavaVersion && format(' (Java {0} Container)', matrix.toolchainJavaVersion) || '' }} runs-on: ubuntu-latest needs: build From cb759655c0256099a89fad8de0b442c8c5648934 Mon Sep 17 00:00:00 2001 From: Sergii Kondrusiev Date: Thu, 23 May 2024 12:22:55 +0300 Subject: [PATCH 12/21] Fixed github ci typo --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8a199b4bf..62296145e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -114,7 +114,7 @@ jobs: --warning-mode all \ -PprivateRepoDir=$PRIVATE_REPO \ $EXTRA_PROPERTIES \ - $TOOLCHAIN_JAVA_ARGS + $TOOLCHAIN_JAVA_ARGS \ -PgeckoDriverPlatform=linux64 \ -PtestAllContainers=$TEST_ALL_CONTAINERS \ testAll From f90f4f0adf5191f9f56423d427225f809b666e0d Mon Sep 17 00:00:00 2001 From: Sergii Kondrusiev Date: Thu, 23 May 2024 12:52:57 +0300 Subject: [PATCH 13/21] Fixed github ci another typo --- .github/workflows/ci.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 62296145e..3bd4fe423 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -77,7 +77,7 @@ jobs: TEST_ALL_CONTAINERS: ${{ matrix.container }} GRADLE_VERSION: ${{ matrix.gradle }} EXTRA_PROPERTIES: ${{ matrix.properties }} - TOOLCHAIN_JAVA_ARGS: "-PtoolchainJavaVersion=${{ matrix.toolchainJavaVersion }}" + TOOLCHAIN_JAVA_ARGS: "${{ matrix.toolchainJavaVersion && format('-PtoolchainJavaVersion={0}', matrix.toolchainJavaVersion) || '' }}" steps: - uses: actions/checkout@v3 @@ -113,8 +113,7 @@ jobs: ../gradlew --no-daemon \ --warning-mode all \ -PprivateRepoDir=$PRIVATE_REPO \ - $EXTRA_PROPERTIES \ - $TOOLCHAIN_JAVA_ARGS \ + $EXTRA_PROPERTIES $TOOLCHAIN_JAVA_ARGS \ -PgeckoDriverPlatform=linux64 \ -PtestAllContainers=$TEST_ALL_CONTAINERS \ testAll From 875a2913132e937f0e72fa9139b4bf7418014f57 Mon Sep 17 00:00:00 2001 From: Sergii Kondrusiev Date: Thu, 23 May 2024 16:14:17 +0300 Subject: [PATCH 14/21] Made more tests support java toolchain version 17 and 21 --- .github/workflows/ci.yml | 2 +- docker_integration_tests.sh | 4 +- .../integrationTests/BasePlugin.groovy | 12 ++++- .../IntegrationTestPlugin.groovy | 9 ---- .../JavaToolchainIntegrationTestPlugin.groovy | 25 +++++---- .../extraResourceBases/build.gradle | 1 + integrationTests/farm/MyWebApp/build.gradle | 1 + .../farm/MyWebService/build.gradle | 1 + .../gradle-java-toolchain/build.gradle | 1 - .../gretty/gradle/toolchain/PageSpec.groovy | 39 ++++++++++++++ .../gradle/toolchain/RequestResponseIT.groovy | 31 ----------- .../gretty/gradle/toolchain/Application.java | 16 ------ .../gradle/toolchain/ExampleServlet.java | 53 +++++++++++++++++++ .../gretty/gradle/toolchain/MyController.java | 17 ------ .../src/main/resources/application.properties | 2 - .../src/main/resources/logback.xml | 31 ----------- .../hellogretty/templates/servletpage.html | 26 +++++++++ .../src/main/webapp/WEB-INF/web.xml | 12 +++++ .../src/main/webapp/css/default.css | 4 -- .../src/main/webapp/index.html | 6 +-- .../src/main/webapp/js/functions.js | 12 ----- 21 files changed, 165 insertions(+), 140 deletions(-) create mode 100644 integrationTests/gradle-java-toolchain/src/integrationTest/groovy/org/akhikhl/examples/gretty/gradle/toolchain/PageSpec.groovy delete mode 100644 integrationTests/gradle-java-toolchain/src/integrationTest/groovy/org/akhikhl/examples/gretty/gradle/toolchain/RequestResponseIT.groovy delete mode 100644 integrationTests/gradle-java-toolchain/src/main/java/org/akhikhl/examples/gretty/gradle/toolchain/Application.java create mode 100644 integrationTests/gradle-java-toolchain/src/main/java/org/akhikhl/examples/gretty/gradle/toolchain/ExampleServlet.java delete mode 100644 integrationTests/gradle-java-toolchain/src/main/java/org/akhikhl/examples/gretty/gradle/toolchain/MyController.java delete mode 100644 integrationTests/gradle-java-toolchain/src/main/resources/application.properties delete mode 100644 integrationTests/gradle-java-toolchain/src/main/resources/logback.xml create mode 100644 integrationTests/gradle-java-toolchain/src/main/resources/org/akhikhl/examples/gretty/hellogretty/templates/servletpage.html delete mode 100644 integrationTests/gradle-java-toolchain/src/main/webapp/js/functions.js diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3bd4fe423..90cb530c0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -66,7 +66,7 @@ jobs: - java: 17 gradle: '7.6.4' container: "['jetty9.3','jetty9.4','jetty10','tomcat85','tomcat9']" - toolchainJavaVersion: 17 + toolchainJavaVersion: 21 properties: '-Pspock_version=2.3-groovy-3.0 -PgebVersion=5.1' # TODO: add a JDK-21 build but fix the following issue before that: diff --git a/docker_integration_tests.sh b/docker_integration_tests.sh index b22742193..8c52824e7 100644 --- a/docker_integration_tests.sh +++ b/docker_integration_tests.sh @@ -57,12 +57,12 @@ export common_gradle_args="--console=plain --no-daemon -Porg.gradle.java.install #ci.yml matrix case #3 + toolchain java v21 ./docker_gradlew.sh \ - --java 17 --java 11 \ + --java 21 --java 17 \ --gradle 7 \ --gradle-home .docker-gradle \ --working-dir integrationTests \ $common_gradle_args \ -PtestAllContainers="\"['jetty9.3','jetty9.4','jetty10','tomcat85','tomcat9']\"" \ -Pspock_version=2.3-groovy-3.0 -PgebVersion=5.1 \ - -PtoolchainJavaVersion=17 \ + -PtoolchainJavaVersion=21 \ testAll \ No newline at end of file diff --git a/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/BasePlugin.groovy b/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/BasePlugin.groovy index faa94f54d..8ba4ceb71 100644 --- a/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/BasePlugin.groovy +++ b/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/BasePlugin.groovy @@ -1,6 +1,7 @@ package org.akhikhl.gretty.internal.integrationTests import org.akhikhl.gretty.ServletContainerConfig +import org.gradle.api.JavaVersion import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.publish.maven.MavenPublication @@ -27,7 +28,16 @@ class BasePlugin implements Plugin { } protected void configureExtensions(Project project) { - // does nothing by default + if (!project.extensions.findByName('javaVersion')) { + project.extensions.add(JavaVersion, 'javaVersion', JavaToolchainIntegrationTestPlugin.getToolchainJavaVersion(project)) + + /** + * Exclude tasks that do not support toolchains when toolchainJavaVersion specified + */ + if (project.findProperty('toolchainJavaVersion')) { + JavaToolchainIntegrationTestPlugin.enableOnlyJavaToolchainAwareProjects(project) + } + } } protected void configurePublications(Project project) { diff --git a/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/IntegrationTestPlugin.groovy b/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/IntegrationTestPlugin.groovy index 702ee5197..99f98aa3e 100644 --- a/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/IntegrationTestPlugin.groovy +++ b/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/IntegrationTestPlugin.groovy @@ -3,7 +3,6 @@ package org.akhikhl.gretty.internal.integrationTests import org.akhikhl.gretty.AppAfterIntegrationTestTask import org.akhikhl.gretty.AppBeforeIntegrationTestTask import org.akhikhl.gretty.ServletContainerConfig -import org.gradle.api.JavaVersion import org.gradle.api.Project import org.gradle.api.tasks.Copy import org.gradle.api.tasks.testing.Test @@ -48,8 +47,6 @@ class IntegrationTestPlugin extends BasePlugin { protected void configureExtensions(Project project) { super.configureExtensions(project) - project.extensions.add(JavaVersion, 'javaVersion', JavaToolchainIntegrationTestPlugin.getToolchainJavaVersion(project)) - /** * The caller project integration test would react on -PtoolchainJavaVersion=17 parameter and define appropriate toolchain DSL **/ @@ -72,7 +69,6 @@ class IntegrationTestPlugin extends BasePlugin { testClassesDirs = project.sourceSets.integrationTest.output.classesDirs classpath = project.sourceSets.integrationTest.runtimeClasspath - JavaToolchainIntegrationTestPlugin.skipIrrelevantTasks(it) JavaToolchainIntegrationTestPlugin.whenApplied(project) { plugin -> plugin.forceTaskToUseGradleJvm(it) } @@ -90,7 +86,6 @@ class IntegrationTestPlugin extends BasePlugin { integrationTestAllContainersTask = project.task('integrationTestAllContainers') - JavaToolchainIntegrationTestPlugin.skipIrrelevantTasks(integrationTestAllContainersTask) JavaToolchainIntegrationTestPlugin.whenApplied(project) { plugin -> plugin.forceTaskToUseGradleJvm(integrationTestAllContainersTask) } @@ -130,7 +125,6 @@ class IntegrationTestPlugin extends BasePlugin { testClassesDirs = project.sourceSets.integrationTest.output.classesDirs classpath = project.sourceSets.integrationTest.runtimeClasspath - JavaToolchainIntegrationTestPlugin.skipIrrelevantTasks(thisTask) JavaToolchainIntegrationTestPlugin.whenApplied(project) { plugin -> plugin.forceTaskToUseGradleJvm(thisTask) } @@ -141,13 +135,10 @@ class IntegrationTestPlugin extends BasePlugin { project.task('beforeIntegrationTest_' + container, type: AppBeforeIntegrationTestTask) { servletContainer = container integrationTestTask 'integrationTest_' + container - - JavaToolchainIntegrationTestPlugin.skipIrrelevantTasks(it) } project.task('afterIntegrationTest_' + container, type: AppAfterIntegrationTestTask) { integrationTestTask 'integrationTest_' + container - JavaToolchainIntegrationTestPlugin.skipIrrelevantTasks(it) } } diff --git a/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/JavaToolchainIntegrationTestPlugin.groovy b/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/JavaToolchainIntegrationTestPlugin.groovy index 9551bfde5..19866ab1b 100644 --- a/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/JavaToolchainIntegrationTestPlugin.groovy +++ b/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/JavaToolchainIntegrationTestPlugin.groovy @@ -19,13 +19,13 @@ class JavaToolchainIntegrationTestPlugin implements Plugin { public static final String PLUGIN_ID = "org.gretty.internal.integrationTests.JavaToolchainIntegrationTestPlugin" private static final Logger log = LoggerFactory.getLogger(IntegrationTestPlugin) - static void applyPluginConditionally(Project project) { + public static void applyPluginConditionally(Project project) { if (project.findProperty('toolchainJavaVersion')) { project.apply plugin: PLUGIN_ID } } - - static void whenApplied(Project project, Consumer config) { + + public static void whenApplied(Project project, Consumer config) { project.plugins.withId(PLUGIN_ID, new Action() { @Override void execute(Plugin plugin) { @@ -35,11 +35,9 @@ class JavaToolchainIntegrationTestPlugin implements Plugin { } @Override - void apply(Project project) { - defineToolchainDSL(project, Integer.parseInt("${project.toolchainJavaVersion}")) - } + public void apply(Project project) { + int javaVersion = Integer.parseInt("${project.toolchainJavaVersion}") - private void defineToolchainDSL(Project project, int javaVersion) { project.java { toolchain { languageVersion = JavaLanguageVersion.of(javaVersion) @@ -79,14 +77,23 @@ class JavaToolchainIntegrationTestPlugin implements Plugin { return JavaVersion.current() } - public static void skipIrrelevantTasks(Task task) { + public static void enableOnlyJavaToolchainAwareProjects(Project project) { + ([project] + project.subprojects)*.afterEvaluate({ p -> + p.tasks.configureEach { t -> + enableOnlyJavaToolchainAwareTasks(t) + } + }) + } + + private static void enableOnlyJavaToolchainAwareTasks(Task task) { task.project.with { + def initialFlag = task.enabled if (task.project.findProperty('toolchainJavaVersion')) { task.enabled = false } whenApplied(task.project) { - task.enabled = true + task.enabled = initialFlag } } } diff --git a/integrationTests/extraResourceBases/build.gradle b/integrationTests/extraResourceBases/build.gradle index 96479db05..4ee3aa996 100644 --- a/integrationTests/extraResourceBases/build.gradle +++ b/integrationTests/extraResourceBases/build.gradle @@ -13,5 +13,6 @@ gretty { extraResourceBase 'extra1' } +defineAsJavaToolchainAwareIntegrationTest() defineIntegrationTest() testAll.dependsOn defineIntegrationTestAllContainers() diff --git a/integrationTests/farm/MyWebApp/build.gradle b/integrationTests/farm/MyWebApp/build.gradle index afd4aa6a1..3e0d85e8d 100644 --- a/integrationTests/farm/MyWebApp/build.gradle +++ b/integrationTests/farm/MyWebApp/build.gradle @@ -21,6 +21,7 @@ product { additionalFiles = ['./farm/README.md': './README.md'] } +defineAsJavaToolchainAwareIntegrationTest() defineIntegrationTest() testAll.dependsOn defineFarmIntegrationTestAllContainers({ diff --git a/integrationTests/farm/MyWebService/build.gradle b/integrationTests/farm/MyWebService/build.gradle index b8fd39886..c84076b2e 100644 --- a/integrationTests/farm/MyWebService/build.gradle +++ b/integrationTests/farm/MyWebService/build.gradle @@ -2,4 +2,5 @@ apply plugin: 'war' apply plugin: 'org.gretty' apply plugin: 'org.gretty.internal.integrationTests.IntegrationTestPlugin' +defineAsJavaToolchainAwareIntegrationTest() defineIntegrationTest() diff --git a/integrationTests/gradle-java-toolchain/build.gradle b/integrationTests/gradle-java-toolchain/build.gradle index 66971744c..798b623d1 100644 --- a/integrationTests/gradle-java-toolchain/build.gradle +++ b/integrationTests/gradle-java-toolchain/build.gradle @@ -10,7 +10,6 @@ dependencies { } gretty { - springBoot = true if (project.javaVersion.isJava9Compatible()) jvmArgs "--add-opens", "java.base/java.lang=ALL-UNNAMED" } diff --git a/integrationTests/gradle-java-toolchain/src/integrationTest/groovy/org/akhikhl/examples/gretty/gradle/toolchain/PageSpec.groovy b/integrationTests/gradle-java-toolchain/src/integrationTest/groovy/org/akhikhl/examples/gretty/gradle/toolchain/PageSpec.groovy new file mode 100644 index 000000000..20e4f43e9 --- /dev/null +++ b/integrationTests/gradle-java-toolchain/src/integrationTest/groovy/org/akhikhl/examples/gretty/gradle/toolchain/PageSpec.groovy @@ -0,0 +1,39 @@ +/* + * Gretty + * + * Copyright (C) 2013-2015 Andrey Hihlovskiy and contributors. + * + * See the file "LICENSE" for copying and usage permission. + * See the file "CONTRIBUTORS" for complete list of contributors. + */ +package org.akhikhl.examples.gretty.gradle.toolchain + +import geb.spock.GebReportingSpec + +class PageSpec extends GebReportingSpec { + + private static String baseURI + private static String toolchainJavaVersion + + void setupSpec() { + baseURI = System.getProperty('gretty.baseURI') + toolchainJavaVersion = System.getProperty('toolchainJavaVersion') ?: System.getProperty('java.vm.version') + } + + def 'should get expected static page'() { + when: + go "${baseURI}/index.html" + then: + $('h1').text() == 'Hello, world!' + $('p', 0).text() == /This is static HTML page./ + } + + def 'should get expected response from servlet'() { + when: + go "${baseURI}/dynamic" + then: + $('h1').text() == 'Hello, world!' + $('p', 0).text() == /This is dynamic HTML page generated by servlet./ + $('h2').text().startsWith('javaVersion=' + "$toolchainJavaVersion") + } +} diff --git a/integrationTests/gradle-java-toolchain/src/integrationTest/groovy/org/akhikhl/examples/gretty/gradle/toolchain/RequestResponseIT.groovy b/integrationTests/gradle-java-toolchain/src/integrationTest/groovy/org/akhikhl/examples/gretty/gradle/toolchain/RequestResponseIT.groovy deleted file mode 100644 index 5020c27ca..000000000 --- a/integrationTests/gradle-java-toolchain/src/integrationTest/groovy/org/akhikhl/examples/gretty/gradle/toolchain/RequestResponseIT.groovy +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Gretty - * - * Copyright (C) 2013-2015 Andrey Hihlovskiy and contributors. - * - * See the file "LICENSE" for copying and usage permission. - * See the file "CONTRIBUTORS" for complete list of contributors. - */ -package org.akhikhl.examples.gretty.gradle.toolchain - -import geb.spock.GebReportingSpec - -class RequestResponseIT extends GebReportingSpec { - - private static String baseURI - private static String toolchainJavaVersion - - void setupSpec() { - baseURI = System.getProperty('gretty.baseURI') - toolchainJavaVersion = System.getProperty('toolchainJavaVersion') ?: System.getProperty('java.vm.version') - } - - def 'should have toolchain java version returned from server side'() { - when: - go baseURI - $('#sendRequest').click() - waitFor { $("p.hide#result").size() == 0 } - then: - $('#result').text().startsWith('Got from server: ' + "$toolchainJavaVersion") - } -} diff --git a/integrationTests/gradle-java-toolchain/src/main/java/org/akhikhl/examples/gretty/gradle/toolchain/Application.java b/integrationTests/gradle-java-toolchain/src/main/java/org/akhikhl/examples/gretty/gradle/toolchain/Application.java deleted file mode 100644 index eabad8a60..000000000 --- a/integrationTests/gradle-java-toolchain/src/main/java/org/akhikhl/examples/gretty/gradle/toolchain/Application.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.akhikhl.examples.gretty.gradle.toolchain; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; - -@Configuration -@EnableAutoConfiguration -@ComponentScan -public class Application { - public static void main(java.lang.String[] args) { - SpringApplication.run(Application.class, args); - } - -} diff --git a/integrationTests/gradle-java-toolchain/src/main/java/org/akhikhl/examples/gretty/gradle/toolchain/ExampleServlet.java b/integrationTests/gradle-java-toolchain/src/main/java/org/akhikhl/examples/gretty/gradle/toolchain/ExampleServlet.java new file mode 100644 index 000000000..998a1de74 --- /dev/null +++ b/integrationTests/gradle-java-toolchain/src/main/java/org/akhikhl/examples/gretty/gradle/toolchain/ExampleServlet.java @@ -0,0 +1,53 @@ +/* + * Gretty + * + * Copyright (C) 2013-2015 Andrey Hihlovskiy and contributors. + * + * See the file "LICENSE" for copying and usage permission. + * See the file "CONTRIBUTORS" for complete list of contributors. + */ +package org.akhikhl.examples.gretty.gradle.toolchain; + +import org.apache.velocity.Template; +import org.apache.velocity.VelocityContext; +import org.apache.velocity.app.VelocityEngine; +import org.apache.velocity.runtime.RuntimeConstants; +import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; + +public class ExampleServlet extends HttpServlet { + + private static final long serialVersionUID = -6506276378398106663L; + + private VelocityEngine ve = new VelocityEngine(); + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + Template template = ve.getTemplate("/org/akhikhl/examples/gretty/hellogretty/templates/servletpage.html", "UTF-8"); + VelocityContext context = new VelocityContext(); + context.put("contextPath", request.getContextPath()); + context.put("today", new java.util.Date()); + context.put("javaVersion", System.getProperty("java.vm.version")); + PrintWriter out = response.getWriter(); + try { + template.merge(context, out); + out.flush(); + } finally { + out.close(); + } + } + + @Override + public void init() throws ServletException { + super.init(); + ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath"); + ve.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName()); + ve.init(); + } +} diff --git a/integrationTests/gradle-java-toolchain/src/main/java/org/akhikhl/examples/gretty/gradle/toolchain/MyController.java b/integrationTests/gradle-java-toolchain/src/main/java/org/akhikhl/examples/gretty/gradle/toolchain/MyController.java deleted file mode 100644 index d592e93df..000000000 --- a/integrationTests/gradle-java-toolchain/src/main/java/org/akhikhl/examples/gretty/gradle/toolchain/MyController.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.akhikhl.examples.gretty.gradle.toolchain; - -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RestController; - -import java.util.Collections; -import java.util.Map; - -@RestController -@RequestMapping("/mycontroller") -public class MyController { - @RequestMapping(value = "/getdate", method = RequestMethod.POST) - public Map home() { - return Collections.singletonMap("date", System.getProperty("java.vm.version")); - } -} diff --git a/integrationTests/gradle-java-toolchain/src/main/resources/application.properties b/integrationTests/gradle-java-toolchain/src/main/resources/application.properties deleted file mode 100644 index cec2d09a4..000000000 --- a/integrationTests/gradle-java-toolchain/src/main/resources/application.properties +++ /dev/null @@ -1,2 +0,0 @@ -spring.jackson.serialization.INDENT_OUTPUT=true -spring.groovy.template.check-template-location=false \ No newline at end of file diff --git a/integrationTests/gradle-java-toolchain/src/main/resources/logback.xml b/integrationTests/gradle-java-toolchain/src/main/resources/logback.xml deleted file mode 100644 index 168f98c50..000000000 --- a/integrationTests/gradle-java-toolchain/src/main/resources/logback.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - ${ENCODER_PATTERN} - - - - - ${LOG_DIR}/${LOG_FILE_NAME}.log - true - - ${LOG_DIR}/${LOG_FILE_NAME}-%d{yyyy-MM-dd_HH}.log - 7 - - - ${ENCODER_PATTERN} - - - - - - - - - - diff --git a/integrationTests/gradle-java-toolchain/src/main/resources/org/akhikhl/examples/gretty/hellogretty/templates/servletpage.html b/integrationTests/gradle-java-toolchain/src/main/resources/org/akhikhl/examples/gretty/hellogretty/templates/servletpage.html new file mode 100644 index 000000000..fe3f7ed23 --- /dev/null +++ b/integrationTests/gradle-java-toolchain/src/main/resources/org/akhikhl/examples/gretty/hellogretty/templates/servletpage.html @@ -0,0 +1,26 @@ + + + + Hello-world page + + + + + + + + + +
+
+
+

Hello, world!

+

This is dynamic HTML page generated by servlet.

+

Today is $today.

+

Click here to see static page.

+

javaVersion=$javaVersion

+
+
+
+ + diff --git a/integrationTests/gradle-java-toolchain/src/main/webapp/WEB-INF/web.xml b/integrationTests/gradle-java-toolchain/src/main/webapp/WEB-INF/web.xml index e625ab836..3399f8948 100644 --- a/integrationTests/gradle-java-toolchain/src/main/webapp/WEB-INF/web.xml +++ b/integrationTests/gradle-java-toolchain/src/main/webapp/WEB-INF/web.xml @@ -18,4 +18,16 @@ jsp *.html + + + ExampleServlet + ExampleServlet + org.akhikhl.examples.gretty.gradle.toolchain.ExampleServlet + 1 + + + + ExampleServlet + /dynamic + diff --git a/integrationTests/gradle-java-toolchain/src/main/webapp/css/default.css b/integrationTests/gradle-java-toolchain/src/main/webapp/css/default.css index a8c91d150..09e4763bb 100644 --- a/integrationTests/gradle-java-toolchain/src/main/webapp/css/default.css +++ b/integrationTests/gradle-java-toolchain/src/main/webapp/css/default.css @@ -12,7 +12,3 @@ h1 { .margin-base-vertical { margin: 40px 0; } - -#result { - margin-top: 16px; -} diff --git a/integrationTests/gradle-java-toolchain/src/main/webapp/index.html b/integrationTests/gradle-java-toolchain/src/main/webapp/index.html index 68c59822d..87e2f4029 100644 --- a/integrationTests/gradle-java-toolchain/src/main/webapp/index.html +++ b/integrationTests/gradle-java-toolchain/src/main/webapp/index.html @@ -8,8 +8,7 @@ - - +
@@ -17,8 +16,7 @@

Hello, world!

This is static HTML page.

- -

+

Click here to see dynamic page generated by servlet.

diff --git a/integrationTests/gradle-java-toolchain/src/main/webapp/js/functions.js b/integrationTests/gradle-java-toolchain/src/main/webapp/js/functions.js deleted file mode 100644 index 0a673c1f0..000000000 --- a/integrationTests/gradle-java-toolchain/src/main/webapp/js/functions.js +++ /dev/null @@ -1,12 +0,0 @@ -jQuery.noConflict(); - -jQuery(function($) { - $('#result').addClass('hide') - $('#sendRequest').click(function() { - $.ajax({ type: 'POST', url: 'mycontroller/getdate', dataType: 'json' }).done(function(data) { - $('#result').removeClass('hide bg-danger').addClass('bg-success').text('Got from server: ' + data.date); - }).fail(function(jqXHR, textStatus, errorThrown) { - $('#result').removeClass('hide bg-success').addClass('bg-danger').text('error: ' + errorThrown); - }); - }); -}); From 204a1a36d079a7a99cc5c2c782e6e1e2296dcd3c Mon Sep 17 00:00:00 2001 From: Sergii Kondrusiev Date: Mon, 27 May 2024 16:14:44 +0300 Subject: [PATCH 15/21] Enchanced enableOnlyJavaToolchainAwareProjects to make testAllJavaToolchains task depend only on those tasks/projects that support java toolchain. --- .github/workflows/ci.yml | 3 ++- docker_integration_tests.sh | 4 +-- .../integrationTests/BasePlugin.groovy | 10 +++----- .../IntegrationTestPlugin.groovy | 3 ++- .../JavaToolchainIntegrationTestPlugin.groovy | 25 +++---------------- 5 files changed, 13 insertions(+), 32 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 90cb530c0..28b4e4932 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -78,6 +78,7 @@ jobs: GRADLE_VERSION: ${{ matrix.gradle }} EXTRA_PROPERTIES: ${{ matrix.properties }} TOOLCHAIN_JAVA_ARGS: "${{ matrix.toolchainJavaVersion && format('-PtoolchainJavaVersion={0}', matrix.toolchainJavaVersion) || '' }}" + GRADLE_TEST_TASK: "${{ matrix.toolchainJavaVersion && 'testAllJavaToolchain' || 'testAll' }}" steps: - uses: actions/checkout@v3 @@ -116,5 +117,5 @@ jobs: $EXTRA_PROPERTIES $TOOLCHAIN_JAVA_ARGS \ -PgeckoDriverPlatform=linux64 \ -PtestAllContainers=$TEST_ALL_CONTAINERS \ - testAll + $GRADLE_TEST_TASK working-directory: integrationTests diff --git a/docker_integration_tests.sh b/docker_integration_tests.sh index 8c52824e7..d3827a9a7 100644 --- a/docker_integration_tests.sh +++ b/docker_integration_tests.sh @@ -52,7 +52,7 @@ export common_gradle_args="--console=plain --no-daemon -Porg.gradle.java.install $common_gradle_args \ -PtestAllContainers="\"['jetty9.3','jetty9.4','jetty10','tomcat85','tomcat9']\"" \ -PtoolchainJavaVersion=17 \ - testAll + testAllJavaToolchain #ci.yml matrix case #3 + toolchain java v21 @@ -65,4 +65,4 @@ export common_gradle_args="--console=plain --no-daemon -Porg.gradle.java.install -PtestAllContainers="\"['jetty9.3','jetty9.4','jetty10','tomcat85','tomcat9']\"" \ -Pspock_version=2.3-groovy-3.0 -PgebVersion=5.1 \ -PtoolchainJavaVersion=21 \ - testAll \ No newline at end of file + testAllJavaToolchain \ No newline at end of file diff --git a/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/BasePlugin.groovy b/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/BasePlugin.groovy index 8ba4ceb71..4ffd34bac 100644 --- a/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/BasePlugin.groovy +++ b/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/BasePlugin.groovy @@ -30,13 +30,6 @@ class BasePlugin implements Plugin { protected void configureExtensions(Project project) { if (!project.extensions.findByName('javaVersion')) { project.extensions.add(JavaVersion, 'javaVersion', JavaToolchainIntegrationTestPlugin.getToolchainJavaVersion(project)) - - /** - * Exclude tasks that do not support toolchains when toolchainJavaVersion specified - */ - if (project.findProperty('toolchainJavaVersion')) { - JavaToolchainIntegrationTestPlugin.enableOnlyJavaToolchainAwareProjects(project) - } } } @@ -108,6 +101,9 @@ class BasePlugin implements Plugin { if(!project.rootProject.tasks.findByName('testAll')) project.rootProject.task 'testAll' + if(!project.rootProject.tasks.findByName('testAllJavaToolchain')) + project.rootProject.task 'testAllJavaToolchain' + project.tasks.withType(Test).configureEach { if (GradleVersion.current().baseVersion.version.startsWith("7.")) { useJUnitPlatform() diff --git a/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/IntegrationTestPlugin.groovy b/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/IntegrationTestPlugin.groovy index 99f98aa3e..b243042d6 100644 --- a/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/IntegrationTestPlugin.groovy +++ b/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/IntegrationTestPlugin.groovy @@ -48,7 +48,8 @@ class IntegrationTestPlugin extends BasePlugin { super.configureExtensions(project) /** - * The caller project integration test would react on -PtoolchainJavaVersion=17 parameter and define appropriate toolchain DSL + * Makes the project aware of java toolchain if it has -PtoolchainJavaVersion=17 parameter. + * Toolchain DSL is configured automatically for the provided version of java. **/ project.ext.defineAsJavaToolchainAwareIntegrationTest = { JavaToolchainIntegrationTestPlugin.applyPluginConditionally(project) diff --git a/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/JavaToolchainIntegrationTestPlugin.groovy b/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/JavaToolchainIntegrationTestPlugin.groovy index 19866ab1b..231ba7ab0 100644 --- a/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/JavaToolchainIntegrationTestPlugin.groovy +++ b/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/JavaToolchainIntegrationTestPlugin.groovy @@ -43,6 +43,10 @@ class JavaToolchainIntegrationTestPlugin implements Plugin { languageVersion = JavaLanguageVersion.of(javaVersion) } } + + project.rootProject.tasks.named('testAllJavaToolchain').configure { + dependsOn project.tasks.testAll + } } public void forceSourceSetToUseGradleJvm(Project project, SourceSet sourceSet) { @@ -77,27 +81,6 @@ class JavaToolchainIntegrationTestPlugin implements Plugin { return JavaVersion.current() } - public static void enableOnlyJavaToolchainAwareProjects(Project project) { - ([project] + project.subprojects)*.afterEvaluate({ p -> - p.tasks.configureEach { t -> - enableOnlyJavaToolchainAwareTasks(t) - } - }) - } - - private static void enableOnlyJavaToolchainAwareTasks(Task task) { - task.project.with { - def initialFlag = task.enabled - if (task.project.findProperty('toolchainJavaVersion')) { - task.enabled = false - } - - whenApplied(task.project) { - task.enabled = initialFlag - } - } - } - private static def getGradleJvmSpec() { def gradleJvmVerson = Integer.valueOf(getGradleJavaVersion().getMajorVersion()) return { languageVersion = JavaLanguageVersion.of(gradleJvmVerson) } From 7f36888bce002f2977399339a67e2f24991e6edb Mon Sep 17 00:00:00 2001 From: Sergii Kondrusiev Date: Mon, 27 May 2024 16:15:24 +0300 Subject: [PATCH 16/21] fixup of integration test --- .../gradle-java-toolchain/README.md | 18 +++++++++++------- .../gradle-java-toolchain/build.gradle | 14 ++++++++++---- .../gretty/gradle/toolchain/PageSpec.groovy | 2 +- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/integrationTests/gradle-java-toolchain/README.md b/integrationTests/gradle-java-toolchain/README.md index daabc03e4..07c3a4a55 100644 --- a/integrationTests/gradle-java-toolchain/README.md +++ b/integrationTests/gradle-java-toolchain/README.md @@ -1,26 +1,30 @@ -# spring-boot-simple +# gradle-java-toolchain -Spring-boot webapp with gretty. +Simple gretty servlet application powered by gradle java toolchain. ## How to run ```bash -cd examples/spring-boot-simple +cd integrationTests/gradle-java-toolchain gradle appRun ``` + ## How to test ```bash -cd examples/spring-boot-simple -gradle integrationTest +cd integrationTests/gradle-java-toolchain +gradle integrationTest -PgeckoDriverPlatform=linux64 -PtoolchainJavaVersion=21 +``` +or +```bash +./docker_gradlew.sh --java 21 --java 11 --gradle 7 --working-dir integrationTests/gradle-java-toolchain -PtoolchainJavaVersion=21 -Pspock_version=2.3-groovy-3.0 -PgebVersion=5.1 integrationTest ``` - ## How to build a product ```bash -cd examples/spring-boot-simple +cd integrationTests/gradle-java-toolchain gradle buildProduct ``` diff --git a/integrationTests/gradle-java-toolchain/build.gradle b/integrationTests/gradle-java-toolchain/build.gradle index 798b623d1..644c17f65 100644 --- a/integrationTests/gradle-java-toolchain/build.gradle +++ b/integrationTests/gradle-java-toolchain/build.gradle @@ -17,8 +17,14 @@ defineAsJavaToolchainAwareIntegrationTest() defineIntegrationTest() testAll.dependsOn defineIntegrationTestAllContainers(['jetty8', 'jetty9', 'jetty10', 'tomcat85', 'tomcat9']) -tasks.withType(Test).configureEach { - if(project.findProperty('toolchainJavaVersion')) { - systemProperty 'toolchainJavaVersion', project.findProperty('toolchainJavaVersion') +//typical toolchain DSL +java { + toolchain { + languageVersion = JavaLanguageVersion.of("${project.javaVersion.majorVersion}") } -} \ No newline at end of file +} + +//toolchain aware integration test +tasks.withType(Test).configureEach { + systemProperty 'toolchainJavaVersion', "${project.javaVersion.majorVersion}" +} diff --git a/integrationTests/gradle-java-toolchain/src/integrationTest/groovy/org/akhikhl/examples/gretty/gradle/toolchain/PageSpec.groovy b/integrationTests/gradle-java-toolchain/src/integrationTest/groovy/org/akhikhl/examples/gretty/gradle/toolchain/PageSpec.groovy index 20e4f43e9..5861cc0af 100644 --- a/integrationTests/gradle-java-toolchain/src/integrationTest/groovy/org/akhikhl/examples/gretty/gradle/toolchain/PageSpec.groovy +++ b/integrationTests/gradle-java-toolchain/src/integrationTest/groovy/org/akhikhl/examples/gretty/gradle/toolchain/PageSpec.groovy @@ -17,7 +17,7 @@ class PageSpec extends GebReportingSpec { void setupSpec() { baseURI = System.getProperty('gretty.baseURI') - toolchainJavaVersion = System.getProperty('toolchainJavaVersion') ?: System.getProperty('java.vm.version') + toolchainJavaVersion = Objects.requireNonNull(System.getProperty('toolchainJavaVersion')) } def 'should get expected static page'() { From 2a9fe2d5fecb903bec80dd1a8cf71dd43dc0411e Mon Sep 17 00:00:00 2001 From: Sergii Kondrusiev Date: Tue, 28 May 2024 11:15:31 +0300 Subject: [PATCH 17/21] fixup of integration test --- .github/workflows/ci.yml | 7 ++++++- docker_integration_tests.sh | 12 +++++++++++- .../examples/gretty/gradle/toolchain/PageSpec.groovy | 1 + .../gretty/gradle/toolchain/ExampleServlet.java | 2 +- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 28b4e4932..1ba6e0b9a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,6 +49,11 @@ jobs: gradle: '6.9.4' container: "['jetty9.3','jetty9.4','tomcat85','tomcat9']" + - java: 8 + gradle: '6.9.4' + container: "['jetty9.3','jetty9.4','tomcat85','tomcat9']" + toolchainJavaVersion: 21 + - java: 11 gradle: '6.9.4' container: "['jetty9.3','jetty9.4','jetty10','tomcat85','tomcat9']" @@ -56,7 +61,7 @@ jobs: - java: 11 gradle: '6.9.4' container: "['jetty9.3','jetty9.4','jetty10','tomcat85','tomcat9']" - toolchainJavaVersion: 17 + toolchainJavaVersion: 21 - java: 17 gradle: '7.6.4' diff --git a/docker_integration_tests.sh b/docker_integration_tests.sh index d3827a9a7..b3ed70b8e 100644 --- a/docker_integration_tests.sh +++ b/docker_integration_tests.sh @@ -30,7 +30,6 @@ export common_gradle_args="--console=plain --no-daemon -Porg.gradle.java.install $common_gradle_args \ -PtestAllContainers="\"['jetty9.3','jetty9.4','jetty10','tomcat85','tomcat9']\"" \ testAll -# #ci.yml matrix case #3 ./docker_gradlew.sh \ @@ -42,6 +41,17 @@ export common_gradle_args="--console=plain --no-daemon -Porg.gradle.java.install -PtestAllContainers="\"['jetty9.3','jetty9.4','jetty10','tomcat85','tomcat9']\"" \ -Pspock_version=2.3-groovy-3.0 -PgebVersion=5.1 \ testAll + +#ci.yml matrix case #1 + toolchain java v21 +./docker_gradlew.sh \ + --java 21 --java 8 \ + --gradle 6 \ + --gradle-home .docker-gradle \ + --working-dir integrationTests \ + $common_gradle_args \ + -PtestAllContainers="\"['jetty9.3','jetty9.4','tomcat85','tomcat9']\"" \ + -PtoolchainJavaVersion=21 \ + testAllJavaToolchain #ci.yml matrix case #2 + toolchain java v17 ./docker_gradlew.sh \ diff --git a/integrationTests/gradle-java-toolchain/src/integrationTest/groovy/org/akhikhl/examples/gretty/gradle/toolchain/PageSpec.groovy b/integrationTests/gradle-java-toolchain/src/integrationTest/groovy/org/akhikhl/examples/gretty/gradle/toolchain/PageSpec.groovy index 5861cc0af..696a6babd 100644 --- a/integrationTests/gradle-java-toolchain/src/integrationTest/groovy/org/akhikhl/examples/gretty/gradle/toolchain/PageSpec.groovy +++ b/integrationTests/gradle-java-toolchain/src/integrationTest/groovy/org/akhikhl/examples/gretty/gradle/toolchain/PageSpec.groovy @@ -18,6 +18,7 @@ class PageSpec extends GebReportingSpec { void setupSpec() { baseURI = System.getProperty('gretty.baseURI') toolchainJavaVersion = Objects.requireNonNull(System.getProperty('toolchainJavaVersion')) + ?.with({ it == '8' ? '1.8' : it }) } def 'should get expected static page'() { diff --git a/integrationTests/gradle-java-toolchain/src/main/java/org/akhikhl/examples/gretty/gradle/toolchain/ExampleServlet.java b/integrationTests/gradle-java-toolchain/src/main/java/org/akhikhl/examples/gretty/gradle/toolchain/ExampleServlet.java index 998a1de74..38baac73a 100644 --- a/integrationTests/gradle-java-toolchain/src/main/java/org/akhikhl/examples/gretty/gradle/toolchain/ExampleServlet.java +++ b/integrationTests/gradle-java-toolchain/src/main/java/org/akhikhl/examples/gretty/gradle/toolchain/ExampleServlet.java @@ -33,7 +33,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t VelocityContext context = new VelocityContext(); context.put("contextPath", request.getContextPath()); context.put("today", new java.util.Date()); - context.put("javaVersion", System.getProperty("java.vm.version")); + context.put("javaVersion", System.getProperty("java.specification.version")); PrintWriter out = response.getWriter(); try { template.merge(context, out); From 708ac6cfef053499cd35217ff4da3805efe3f85f Mon Sep 17 00:00:00 2001 From: Sergii Kondrusiev Date: Tue, 28 May 2024 12:48:15 +0300 Subject: [PATCH 18/21] gradle JavaVersion can't recognize versions not supported by gradle, but supported by toolchain --- .../integrationTests/AnyJavaVersion.java | 45 +++++++++++++++++++ .../integrationTests/BasePlugin.groovy | 4 +- .../JavaToolchainIntegrationTestPlugin.groovy | 11 +++-- 3 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/AnyJavaVersion.java diff --git a/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/AnyJavaVersion.java b/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/AnyJavaVersion.java new file mode 100644 index 000000000..0d1202f74 --- /dev/null +++ b/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/AnyJavaVersion.java @@ -0,0 +1,45 @@ +package org.akhikhl.gretty.internal.integrationTests; + +import java.util.Objects; + +public class AnyJavaVersion implements Comparable { + private int majorVersion; + + private AnyJavaVersion(int majorVersion) { + this.majorVersion = majorVersion; + } + + public int getMajorVersion() { + return majorVersion; + } + + public boolean isJava9Compatible() { + return majorVersion >= 9; + } + + public boolean isJava10Compatible() { + return majorVersion >= 10; + } + + @Override + public int compareTo(AnyJavaVersion o) { + return Integer.compare(this.majorVersion, o.majorVersion); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + AnyJavaVersion that = (AnyJavaVersion) o; + return majorVersion == that.majorVersion; + } + + @Override + public int hashCode() { + return Objects.hashCode(majorVersion); + } + + public static AnyJavaVersion of(Integer integer) { + return new AnyJavaVersion(Objects.requireNonNull(integer)); + } +} \ No newline at end of file diff --git a/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/BasePlugin.groovy b/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/BasePlugin.groovy index 4ffd34bac..a65a77aec 100644 --- a/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/BasePlugin.groovy +++ b/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/BasePlugin.groovy @@ -1,7 +1,5 @@ package org.akhikhl.gretty.internal.integrationTests -import org.akhikhl.gretty.ServletContainerConfig -import org.gradle.api.JavaVersion import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.publish.maven.MavenPublication @@ -29,7 +27,7 @@ class BasePlugin implements Plugin { protected void configureExtensions(Project project) { if (!project.extensions.findByName('javaVersion')) { - project.extensions.add(JavaVersion, 'javaVersion', JavaToolchainIntegrationTestPlugin.getToolchainJavaVersion(project)) + project.extensions.add(AnyJavaVersion, 'javaVersion', JavaToolchainIntegrationTestPlugin.getToolchainJavaVersion(project)) } } diff --git a/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/JavaToolchainIntegrationTestPlugin.groovy b/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/JavaToolchainIntegrationTestPlugin.groovy index 231ba7ab0..ae9c4661c 100644 --- a/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/JavaToolchainIntegrationTestPlugin.groovy +++ b/integrationTests/buildSrc/gretty-integrationTest/src/main/groovy/org/akhikhl/gretty/internal/integrationTests/JavaToolchainIntegrationTestPlugin.groovy @@ -70,11 +70,14 @@ class JavaToolchainIntegrationTestPlugin implements Plugin { } } - public static JavaVersion getToolchainJavaVersion(Project project) { - return Optional.ofNullable(project.findProperty('toolchainJavaVersion')) + public static AnyJavaVersion getToolchainJavaVersion(Project project) { + //java 8 compatible, Optional.or() available from java 9 + String majorVersion = project.findProperty('toolchainJavaVersion') ?: JavaVersion.current().majorVersion + + return Optional.ofNullable(majorVersion) .map({ Integer.parseInt("$it") }) - .map({ JavaVersion.toVersion(it) }) - .orElse(JavaVersion.current()) + .map({ AnyJavaVersion.of(it) }) + .get() } public static JavaVersion getGradleJavaVersion() { From f3153bdb4e403d5b01f95826f0a4b8a7fe402dd2 Mon Sep 17 00:00:00 2001 From: Sergii Kondrusiev Date: Tue, 28 May 2024 12:49:50 +0300 Subject: [PATCH 19/21] Gradle doesn't recognize pre-installed java 21, so using java 17 --- .github/workflows/ci.yml | 4 ++-- docker_integration_tests.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1ba6e0b9a..084079b52 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,7 +52,7 @@ jobs: - java: 8 gradle: '6.9.4' container: "['jetty9.3','jetty9.4','tomcat85','tomcat9']" - toolchainJavaVersion: 21 + toolchainJavaVersion: 17 - java: 11 gradle: '6.9.4' @@ -61,7 +61,7 @@ jobs: - java: 11 gradle: '6.9.4' container: "['jetty9.3','jetty9.4','jetty10','tomcat85','tomcat9']" - toolchainJavaVersion: 21 + toolchainJavaVersion: 17 - java: 17 gradle: '7.6.4' diff --git a/docker_integration_tests.sh b/docker_integration_tests.sh index b3ed70b8e..a94bbf740 100644 --- a/docker_integration_tests.sh +++ b/docker_integration_tests.sh @@ -44,13 +44,13 @@ export common_gradle_args="--console=plain --no-daemon -Porg.gradle.java.install #ci.yml matrix case #1 + toolchain java v21 ./docker_gradlew.sh \ - --java 21 --java 8 \ + --java 17 --java 8 \ --gradle 6 \ --gradle-home .docker-gradle \ --working-dir integrationTests \ $common_gradle_args \ -PtestAllContainers="\"['jetty9.3','jetty9.4','tomcat85','tomcat9']\"" \ - -PtoolchainJavaVersion=21 \ + -PtoolchainJavaVersion=17 \ testAllJavaToolchain #ci.yml matrix case #2 + toolchain java v17 From c6005cbbcc19db97395cc42c15f0e3a6bca299d0 Mon Sep 17 00:00:00 2001 From: Sergii Kondrusiev Date: Tue, 28 May 2024 12:59:34 +0300 Subject: [PATCH 20/21] Added CLI option to print stacktrace on test failure --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 084079b52..8e33ce5d1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -122,5 +122,5 @@ jobs: $EXTRA_PROPERTIES $TOOLCHAIN_JAVA_ARGS \ -PgeckoDriverPlatform=linux64 \ -PtestAllContainers=$TEST_ALL_CONTAINERS \ - $GRADLE_TEST_TASK + $GRADLE_TEST_TASK -s working-directory: integrationTests From b98085e893d59f2de198b4edaf759af247ac519c Mon Sep 17 00:00:00 2001 From: Sergii Kondrusiev Date: Tue, 28 May 2024 13:24:24 +0300 Subject: [PATCH 21/21] revert: Added CLI option to print stacktrace on test failure --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8e33ce5d1..670a83155 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -122,5 +122,5 @@ jobs: $EXTRA_PROPERTIES $TOOLCHAIN_JAVA_ARGS \ -PgeckoDriverPlatform=linux64 \ -PtestAllContainers=$TEST_ALL_CONTAINERS \ - $GRADLE_TEST_TASK -s + $GRADLE_TEST_TASK working-directory: integrationTests