Skip to content

Commit 060511c

Browse files
committed
Add new optional Spring Boot Virtual Threads Feature to Forge
1 parent d71a513 commit 060511c

File tree

3 files changed

+158
-0
lines changed

3 files changed

+158
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
import org.grails.forge.feature.Feature;
25+
import org.grails.forge.feature.config.ConfigurationFeature;
26+
import org.grails.forge.options.Options;
27+
28+
import java.util.Map;
29+
import java.util.Set;
30+
31+
@Singleton
32+
public class SpringBootVirtualThreads implements SpringThreadingFeature {
33+
34+
@Override
35+
public String getName() {
36+
return "spring-boot-virtual-threads";
37+
}
38+
39+
@Override
40+
public String getTitle() {
41+
return "Spring Boot Virtual Threads";
42+
}
43+
44+
@Override
45+
public String getDescription() {
46+
return "Enables Virtual Threads in Spring Boot for JDK 24+.";
47+
}
48+
49+
@Override
50+
public boolean supports(ApplicationType applicationType) {
51+
return true;
52+
}
53+
54+
@Override
55+
public void apply(GeneratorContext generatorContext) {
56+
Map<String, Object> config = generatorContext.getConfiguration();
57+
58+
// Enable by default only for JDK 24+
59+
config.put("spring.threads.virtual.enabled", generatorContext.getJdkVersion().majorVersion() >= 24);
60+
}
61+
62+
@Override
63+
public boolean isVisible() {
64+
return true;
65+
}
66+
67+
@Override
68+
public String getDocumentation() {
69+
return "https://docs.spring.io/spring-boot/reference/features/spring-application.html#features.spring-application.virtual-threads";
70+
}
71+
}
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+
}
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)