Skip to content

Commit de720c5

Browse files
authored
Merge pull request #420 from jdaugherty/7.0.x
Fix #405: Gracefully handle different JDK versions between Release and Snapshot versions
2 parents 060f525 + 173f994 commit de720c5

File tree

8 files changed

+181
-105
lines changed

8 files changed

+181
-105
lines changed

.sdkmanrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
java=17.0.12-librca

grails-forge-api/src/main/java/org/grails/forge/api/ApplicationController.java

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -161,24 +161,16 @@ public ApplicationTypeDTO getType(ApplicationType type, RequestInfo info) {
161161
* List the type features.
162162
* @param type The features
163163
* @param requestInfo The request info
164+
* @param filter features to filter by
164165
* @return The features
165166
*/
166167
@Override
167-
@Get("/application-types/{type}/features{?gorm,servlet,test,javaVersion}")
168+
@Get("/application-types/{type}/features{?filter*}")
168169
public FeatureList features(ApplicationType type,
169170
RequestInfo requestInfo,
170-
@Nullable TestFramework test,
171-
@Nullable GormImpl gorm,
172-
@Nullable ServletImpl servlet,
173-
@Nullable JdkVersion javaVersion) {
171+
@Nullable FeatureFilter filter) {
174172
List<FeatureDTO> featureDTOList = featureOperations
175-
.getFeatures(requestInfo.getLocale(),
176-
type,
177-
new Options(test != null ? test.toTestFramework() : null,
178-
gorm == null ? GormImpl.DEFAULT_OPTION : gorm,
179-
servlet == null ? ServletImpl.DEFAULT_OPTION : servlet,
180-
javaVersion == null ? JdkVersion.DEFAULT_OPTION : javaVersion,
181-
getOperatingSystem(requestInfo.getUserAgent())));
173+
.getFeatures(requestInfo.getLocale(), type, getOptions(filter, requestInfo));
182174

183175
final FeatureList featureList = new FeatureList(featureDTOList);
184176
featureList.addLink(
@@ -189,21 +181,11 @@ public FeatureList features(ApplicationType type,
189181
}
190182

191183
@Override
192-
@Get("/application-types/{type}/features/default{?gorm,servlet,test,javaVersion}")
184+
@Get("/application-types/{type}/features/default{?filter*}")
193185
public FeatureList defaultFeatures(ApplicationType type,
194186
RequestInfo requestInfo,
195-
@Nullable TestFramework test,
196-
@Nullable GormImpl gorm,
197-
@Nullable ServletImpl servlet,
198-
@Nullable JdkVersion javaVersion) {
199-
List<FeatureDTO> featureDTOList = featureOperations
200-
.getDefaultFeatures(requestInfo.getLocale(),
201-
type,
202-
new Options(test != null ? test.toTestFramework() : null,
203-
gorm == null ? GormImpl.DEFAULT_OPTION : gorm,
204-
servlet == null ? ServletImpl.DEFAULT_OPTION : servlet,
205-
javaVersion == null ? JdkVersion.DEFAULT_OPTION : javaVersion,
206-
getOperatingSystem(requestInfo.getUserAgent())));
187+
@Nullable FeatureFilter filter) {
188+
List<FeatureDTO> featureDTOList = featureOperations.getDefaultFeatures(requestInfo.getLocale(), type, getOptions(filter, requestInfo));
207189

208190
final FeatureList featureList = new FeatureList(featureDTOList);
209191
featureList.addLink(
@@ -240,4 +222,16 @@ private ApplicationTypeDTO typeToDTO(ApplicationType type, RequestInfo requestIn
240222
protected OperatingSystem getOperatingSystem(String userAgent) {
241223
return UserAgentParser.getOperatingSystem(userAgent);
242224
}
225+
226+
protected Options getOptions(@Nullable FeatureFilter filter, RequestInfo requestInfo) {
227+
if (filter == null) {
228+
return new Options(null, GormImpl.DEFAULT_OPTION, ServletImpl.DEFAULT_OPTION, JdkVersion.DEFAULT_OPTION, getOperatingSystem(requestInfo.getUserAgent()));
229+
}
230+
231+
return new Options(filter.getTest() != null ? filter.getTest().toTestFramework() : null,
232+
filter.getGorm() == null ? GormImpl.DEFAULT_OPTION : filter.getGorm(),
233+
filter.getServlet() == null ? ServletImpl.DEFAULT_OPTION : filter.getServlet(),
234+
filter.getJavaVersion() == null ? JdkVersion.DEFAULT_OPTION : filter.getJavaVersion(),
235+
getOperatingSystem(requestInfo.getUserAgent()));
236+
}
243237
}

grails-forge-api/src/main/java/org/grails/forge/api/ApplicationTypeOperations.java

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919
import io.micronaut.http.annotation.Get;
2020
import io.swagger.v3.oas.annotations.Parameter;
2121
import org.grails.forge.application.ApplicationType;
22-
import org.grails.forge.options.GormImpl;
23-
import org.grails.forge.options.JdkVersion;
24-
import org.grails.forge.options.ServletImpl;
22+
import org.grails.forge.options.FeatureFilter;
2523

2624
/**
2725
* Operations on application types.
@@ -52,35 +50,23 @@ public interface ApplicationTypeOperations {
5250
* List the type features.
5351
* @param type The features
5452
* @param serverURL The server URL
55-
* @param test The test framework
56-
* @param gorm The GORM
57-
* @param servlet The Servlet
58-
* @param javaVersion The java version
53+
* @param filter features to filter by
5954
* @return The features
6055
*/
61-
@Get("/application-types/{type}/features{?gorm,servlet,test,javaVersion}")
56+
@Get("/application-types/{type}/features{?filter*}")
6257
FeatureList features(ApplicationType type,
6358
@Parameter(hidden = true) RequestInfo serverURL,
64-
@Nullable TestFramework test,
65-
@Nullable GormImpl gorm,
66-
@Nullable ServletImpl servlet,
67-
@Nullable JdkVersion javaVersion);
59+
@Nullable FeatureFilter filter);
6860

6961
/**
7062
* List the default features.
7163
* @param type The features
7264
* @param serverURL The server URL
73-
* @param test The test framework
74-
* @param gorm The GORM
75-
* @param servlet The Servlet
76-
* @param javaVersion The java version
65+
* @param filter features to filter by
7766
* @return The features
7867
*/
79-
@Get("/application-types/{type}/features/default{?gorm,servlet,test,javaVersion}")
68+
@Get("/application-types/{type}/features/default{?filter*}")
8069
FeatureList defaultFeatures(ApplicationType type,
8170
@Parameter(hidden = true) RequestInfo serverURL,
82-
@Nullable TestFramework test,
83-
@Nullable GormImpl gorm,
84-
@Nullable ServletImpl servlet,
85-
@Nullable JdkVersion javaVersion);
71+
@Nullable FeatureFilter filter);
8672
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
jackson:
2+
mapper:
3+
ACCEPT_CASE_INSENSITIVE_ENUMS: true
4+
deserialization:
5+
READ_UNKNOWN_ENUM_VALUES_AS_NULL: true

grails-forge-api/src/test/groovy/org/grails/forge/api/ApplicationTypeClient.groovy

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,18 @@ import io.micronaut.http.annotation.Get
66
import io.micronaut.http.annotation.Header
77
import io.micronaut.http.client.annotation.Client
88
import org.grails.forge.application.ApplicationType
9-
import org.grails.forge.options.GormImpl
10-
import org.grails.forge.options.JdkVersion
11-
import org.grails.forge.options.ServletImpl
9+
import org.grails.forge.options.FeatureFilter
1210

1311
@Client('/')
1412
interface ApplicationTypeClient extends ApplicationTypeOperations {
1513

16-
@Get("/application-types/{type}/features{?gorm,servlet,test,javaVersion}")
14+
@Get("/application-types/{type}/features{?filter*}")
1715
@Header(name = HttpHeaders.ACCEPT_LANGUAGE, value = "es")
1816
FeatureList spanishFeatures(ApplicationType type,
19-
@Nullable TestFramework test,
20-
@Nullable GormImpl gorm,
21-
@Nullable ServletImpl servlet,
22-
@Nullable JdkVersion javaVersion);
17+
@Nullable FeatureFilter filter);
2318

24-
@Get("/application-types/{type}/features/default{?gorm,servlet,test,javaVersion}")
19+
@Get("/application-types/{type}/features/default{?filter*}")
2520
@Header(name = HttpHeaders.ACCEPT_LANGUAGE, value = "es")
2621
FeatureList spanishDefaultFeatures(ApplicationType type,
27-
@Nullable TestFramework test,
28-
@Nullable GormImpl gorm,
29-
@Nullable ServletImpl servlet,
30-
@Nullable JdkVersion javaVersion);
22+
@Nullable FeatureFilter filter);
3123
}
Lines changed: 74 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,54 @@
11
package org.grails.forge.api
22

3+
import com.fasterxml.jackson.core.JsonParser
4+
import com.fasterxml.jackson.databind.ObjectMapper
5+
import io.micronaut.http.HttpRequest
6+
import io.micronaut.http.client.HttpClient
7+
import io.micronaut.http.client.annotation.Client
8+
import io.micronaut.json.tree.JsonNode
39
import io.micronaut.test.extensions.spock.annotation.MicronautTest
410
import jakarta.inject.Inject
511
import org.grails.forge.application.ApplicationType
12+
import org.grails.forge.options.FeatureFilter
613
import org.grails.forge.options.GormImpl
714
import org.grails.forge.options.JdkVersion
15+
import org.grails.forge.options.TestFramework
816
import org.grails.forge.options.ServletImpl
917
import spock.lang.Specification
1018

1119
@MicronautTest
1220
class FeatureControllerSpec extends Specification {
1321

1422
@Inject
15-
ApplicationTypeClient client
23+
ApplicationTypeClient applicationTypeClient
24+
25+
@Inject
26+
@Client("/")
27+
HttpClient httpClient
1628

1729
void 'test list features'() {
1830
when:
19-
List<FeatureDTO> features = client
31+
List<FeatureDTO> features = applicationTypeClient
2032
.features(ApplicationType.DEFAULT_OPTION,
2133
RequestInfo.LOCAL,
22-
TestFramework.DEFAULT_OPTION,
23-
GormImpl.DEFAULT_OPTION,
24-
ServletImpl.DEFAULT_OPTION,
25-
JdkVersion.DEFAULT_OPTION).features
34+
new FeatureFilter(test: TestFramework.DEFAULT_OPTION,
35+
gorm: GormImpl.DEFAULT_OPTION,
36+
servlet: ServletImpl.DEFAULT_OPTION,
37+
javaVersion: JdkVersion.DEFAULT_OPTION)).features
2638

2739
then:
2840
!features.isEmpty()
2941
}
3042

3143
void 'test community features'() {
3244
when:
33-
List<FeatureDTO> communityFeatures = client
45+
List<FeatureDTO> communityFeatures = applicationTypeClient
3446
.features(ApplicationType.DEFAULT_OPTION,
3547
RequestInfo.LOCAL,
36-
TestFramework.DEFAULT_OPTION,
37-
GormImpl.DEFAULT_OPTION,
38-
ServletImpl.DEFAULT_OPTION,
39-
JdkVersion.DEFAULT_OPTION).features
48+
new FeatureFilter(test: TestFramework.DEFAULT_OPTION,
49+
gorm: GormImpl.DEFAULT_OPTION,
50+
servlet: ServletImpl.DEFAULT_OPTION,
51+
javaVersion: JdkVersion.DEFAULT_OPTION)).features
4052
.findAll { it.community }
4153

4254
then:
@@ -45,12 +57,12 @@ class FeatureControllerSpec extends Specification {
4557

4658
void 'test list features - spanish'() {
4759
when:
48-
List<FeatureDTO> features = client
60+
List<FeatureDTO> features = applicationTypeClient
4961
.spanishFeatures(ApplicationType.DEFAULT_OPTION,
50-
TestFramework.DEFAULT_OPTION,
51-
GormImpl.DEFAULT_OPTION,
52-
ServletImpl.DEFAULT_OPTION,
53-
JdkVersion.DEFAULT_OPTION).features
62+
new FeatureFilter(test: TestFramework.DEFAULT_OPTION,
63+
gorm: GormImpl.DEFAULT_OPTION,
64+
servlet: ServletImpl.DEFAULT_OPTION,
65+
javaVersion: JdkVersion.DEFAULT_OPTION)).features
5466
def mongoGorm = features.find { it.name == 'asciidoctor' }
5567

5668
then:
@@ -61,12 +73,12 @@ class FeatureControllerSpec extends Specification {
6173

6274
void 'test list default features - spanish'() {
6375
when:
64-
List<FeatureDTO> features = client
76+
List<FeatureDTO> features = applicationTypeClient
6577
.spanishDefaultFeatures(ApplicationType.DEFAULT_OPTION,
66-
TestFramework.DEFAULT_OPTION,
67-
GormImpl.DEFAULT_OPTION,
68-
ServletImpl.DEFAULT_OPTION,
69-
JdkVersion.DEFAULT_OPTION).features
78+
new FeatureFilter(test: TestFramework.DEFAULT_OPTION,
79+
gorm: GormImpl.DEFAULT_OPTION,
80+
servlet: ServletImpl.DEFAULT_OPTION,
81+
javaVersion: JdkVersion.DEFAULT_OPTION)).features
7082
def assetPipeline = features.find { it.name == 'asset-pipeline-grails' }
7183

7284
then:
@@ -77,68 +89,84 @@ class FeatureControllerSpec extends Specification {
7789

7890
void 'test list default features for application type'() {
7991
when:
80-
def features = client
92+
def features = applicationTypeClient
8193
.defaultFeatures(ApplicationType.PLUGIN,
8294
RequestInfo.LOCAL,
83-
TestFramework.DEFAULT_OPTION,
84-
GormImpl.DEFAULT_OPTION,
85-
ServletImpl.DEFAULT_OPTION,
86-
JdkVersion.DEFAULT_OPTION).features
95+
new FeatureFilter(test: TestFramework.DEFAULT_OPTION,
96+
gorm: GormImpl.DEFAULT_OPTION,
97+
servlet: ServletImpl.DEFAULT_OPTION,
98+
javaVersion: JdkVersion.DEFAULT_OPTION)).features
8799

88100
then:
89101
!features.any { it.name == 'geb-with-testcontainers' }
90102
features.any { it.name == 'gorm-hibernate5' }
91103

92104
when:
93-
features = client
105+
features = applicationTypeClient
94106
.defaultFeatures(ApplicationType.DEFAULT_OPTION,
95107
RequestInfo.LOCAL,
96-
TestFramework.DEFAULT_OPTION,
97-
GormImpl.DEFAULT_OPTION,
98-
ServletImpl.DEFAULT_OPTION,
99-
JdkVersion.DEFAULT_OPTION).features
108+
new FeatureFilter(test: TestFramework.DEFAULT_OPTION,
109+
gorm: GormImpl.DEFAULT_OPTION,
110+
servlet: ServletImpl.DEFAULT_OPTION,
111+
javaVersion: JdkVersion.DEFAULT_OPTION)).features
100112

101113
then:
102114
features.any { it.name == 'geb-with-testcontainers' }
103115
}
104116

105117
void 'test list features for application type'() {
106118
when:
107-
def features = client
119+
def features = applicationTypeClient
108120
.features(ApplicationType.PLUGIN,
109121
RequestInfo.LOCAL,
110-
TestFramework.DEFAULT_OPTION,
111-
GormImpl.DEFAULT_OPTION,
112-
ServletImpl.DEFAULT_OPTION,
113-
JdkVersion.DEFAULT_OPTION).features
122+
new FeatureFilter(test: TestFramework.DEFAULT_OPTION,
123+
gorm: GormImpl.DEFAULT_OPTION,
124+
servlet: ServletImpl.DEFAULT_OPTION,
125+
javaVersion: JdkVersion.DEFAULT_OPTION)).features
114126

115127
then:
116128
!features.any { it.name == 'geb-with-testcontainers' }
117129

118130
when:
119-
features = client
131+
features = applicationTypeClient
120132
.features(ApplicationType.DEFAULT_OPTION,
121133
RequestInfo.LOCAL,
122-
TestFramework.DEFAULT_OPTION,
123-
GormImpl.DEFAULT_OPTION,
124-
ServletImpl.DEFAULT_OPTION,
125-
JdkVersion.DEFAULT_OPTION).features
134+
new FeatureFilter(test: TestFramework.DEFAULT_OPTION,
135+
gorm: GormImpl.DEFAULT_OPTION,
136+
servlet: ServletImpl.DEFAULT_OPTION,
137+
javaVersion: JdkVersion.DEFAULT_OPTION)).features
126138

127139
then:
128140
features.any { it.name == 'gorm-mongodb' }
129141
}
130142

131143
void 'test list features for application type should NOT return default included features'() {
132144
when:
133-
def features = client
145+
def features = applicationTypeClient
134146
.features(ApplicationType.WEB,
135147
RequestInfo.LOCAL,
136-
TestFramework.DEFAULT_OPTION,
137-
GormImpl.DEFAULT_OPTION,
138-
ServletImpl.DEFAULT_OPTION,
139-
JdkVersion.DEFAULT_OPTION).features
148+
new FeatureFilter(test: TestFramework.DEFAULT_OPTION,
149+
gorm: GormImpl.DEFAULT_OPTION,
150+
servlet: ServletImpl.DEFAULT_OPTION,
151+
javaVersion: JdkVersion.DEFAULT_OPTION)).features
140152

141153
then:
142154
!features.any { it.name == 'asset-pipeline-grails' }
143155
}
156+
157+
void "test feature filter - invalid option as query parameter"() {
158+
when:
159+
String response = httpClient.toBlocking().withCloseable { client ->
160+
client.exchange(HttpRequest.GET('/application-types/' + ApplicationType.WEB.name + '/features?javaVersion=invalid'), String.class).body()
161+
}
162+
163+
then:
164+
response
165+
166+
and:
167+
ObjectMapper mapper = new ObjectMapper()
168+
def map = mapper.readValue(response, Map)
169+
170+
map.features.collect { it -> it.name }.find { it == 'gorm-mongodb'}
171+
}
144172
}

0 commit comments

Comments
 (0)