Skip to content

Commit 397643f

Browse files
authored
Merge pull request #14941 from apache/add-virtual-thread-feature
Add non-default, optional virtual thread feature to Forge for Java 24+
2 parents f6d9304 + 8a06aa0 commit 397643f

File tree

5 files changed

+158
-2
lines changed

5 files changed

+158
-2
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.grails.forge.feature.spring;
20+
21+
import jakarta.inject.Singleton;
22+
import org.grails.forge.application.ApplicationType;
23+
import org.grails.forge.application.generator.GeneratorContext;
24+
25+
import java.util.Map;
26+
27+
@Singleton
28+
public class SpringBootVirtualThreads implements SpringThreadingFeature {
29+
30+
@Override
31+
public String getName() {
32+
return "spring-boot-virtual-threads";
33+
}
34+
35+
@Override
36+
public String getTitle() {
37+
return "Spring Boot Virtual Threads";
38+
}
39+
40+
@Override
41+
public String getDescription() {
42+
return "Enables Virtual Threads in Spring Boot for JDK 24+.";
43+
}
44+
45+
@Override
46+
public boolean supports(ApplicationType applicationType) {
47+
return true;
48+
}
49+
50+
@Override
51+
public void apply(GeneratorContext generatorContext) {
52+
Map<String, Object> config = generatorContext.getConfiguration();
53+
54+
// Enable by default only for JDK 24+
55+
config.put("spring.threads.virtual.enabled", generatorContext.getJdkVersion().majorVersion() >= 24);
56+
}
57+
58+
@Override
59+
public boolean isVisible() {
60+
return true;
61+
}
62+
63+
@Override
64+
public String getDocumentation() {
65+
return "https://docs.spring.io/spring-boot/reference/features/spring-application.html#features.spring-application.virtual-threads";
66+
}
67+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.grails.forge.feature.spring;
20+
21+
import org.grails.forge.application.ApplicationType;
22+
import org.grails.forge.feature.Category;
23+
import org.grails.forge.feature.OneOfFeature;
24+
25+
public interface SpringThreadingFeature extends OneOfFeature {
26+
27+
@Override
28+
default Class<?> getFeatureClass() {
29+
return SpringThreadingFeature.class;
30+
}
31+
32+
@Override
33+
default boolean supports(ApplicationType applicationType) {
34+
return true;
35+
}
36+
37+
@Override
38+
default String getCategory() {
39+
return Category.SPRING;
40+
}
41+
}

grails-forge/grails-forge-core/src/main/java/org/grails/forge/feature/view/GrailsGsp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public void apply(GeneratorContext generatorContext) {
104104
.groupId("org.apache.grails")
105105
.artifactId("grails-gsp")
106106
.implementation());
107-
if(!generatorContext.isFeaturePresent(Sitemesh3.class)) {
107+
if (!generatorContext.isFeaturePresent(Sitemesh3.class)) {
108108
generatorContext.addDependency(Dependency.builder()
109109
.groupId("org.apache.grails")
110110
.artifactId("grails-layout")

grails-forge/grails-forge-core/src/main/java/org/grails/forge/options/JdkVersion.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
public enum JdkVersion {
3232
JDK_17(17),
3333
JDK_21(21),
34-
JDK_23(23);
34+
// 24 is the current non-LTS release and will be replaced by 25 (LTS) in Sep 2025
35+
// Spring Framework 6.2.x and Spring Boot 3.5.x will support 25
36+
JDK_24(24);
3537

3638
public static final JdkVersion DEFAULT_OPTION = JDK_17;
3739

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.grails.forge.feature.spring
21+
22+
import org.grails.forge.BeanContextSpec
23+
import org.grails.forge.application.generator.GeneratorContext
24+
import org.grails.forge.fixture.CommandOutputFixture
25+
import org.grails.forge.options.JdkVersion
26+
import org.grails.forge.options.Options
27+
import org.grails.forge.options.TestFramework
28+
29+
class SpringBootVirtualThreadsSpec extends BeanContextSpec implements CommandOutputFixture {
30+
31+
void "test spring boot virtual threads not enabled for JDK 17, when optional feature selected"() {
32+
when:
33+
GeneratorContext commandContext = buildGeneratorContext(['spring-boot-virtual-threads'], new Options(TestFramework.DEFAULT_OPTION, JdkVersion.JDK_17))
34+
35+
then:
36+
commandContext.configuration.get('spring.threads.virtual.enabled'.toString()) == false
37+
}
38+
39+
void "test spring boot virtual threads enabled for JDK 24+, when optional feature selected"() {
40+
when:
41+
GeneratorContext commandContext = buildGeneratorContext(['spring-boot-virtual-threads'], new Options(TestFramework.DEFAULT_OPTION, JdkVersion.JDK_24))
42+
43+
then:
44+
commandContext.configuration.get('spring.threads.virtual.enabled'.toString()) == true
45+
}
46+
}

0 commit comments

Comments
 (0)