Skip to content

Commit

Permalink
Merge pull request #420 from jdaugherty/7.0.x
Browse files Browse the repository at this point in the history
Fix #405: Gracefully handle different JDK versions between Release and Snapshot versions
  • Loading branch information
jamesfredley authored Nov 1, 2024
2 parents 060f525 + 173f994 commit de720c5
Show file tree
Hide file tree
Showing 8 changed files with 181 additions and 105 deletions.
1 change: 1 addition & 0 deletions .sdkmanrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
java=17.0.12-librca
Original file line number Diff line number Diff line change
Expand Up @@ -161,24 +161,16 @@ public ApplicationTypeDTO getType(ApplicationType type, RequestInfo info) {
* List the type features.
* @param type The features
* @param requestInfo The request info
* @param filter features to filter by
* @return The features
*/
@Override
@Get("/application-types/{type}/features{?gorm,servlet,test,javaVersion}")
@Get("/application-types/{type}/features{?filter*}")
public FeatureList features(ApplicationType type,
RequestInfo requestInfo,
@Nullable TestFramework test,
@Nullable GormImpl gorm,
@Nullable ServletImpl servlet,
@Nullable JdkVersion javaVersion) {
@Nullable FeatureFilter filter) {
List<FeatureDTO> featureDTOList = featureOperations
.getFeatures(requestInfo.getLocale(),
type,
new Options(test != null ? test.toTestFramework() : null,
gorm == null ? GormImpl.DEFAULT_OPTION : gorm,
servlet == null ? ServletImpl.DEFAULT_OPTION : servlet,
javaVersion == null ? JdkVersion.DEFAULT_OPTION : javaVersion,
getOperatingSystem(requestInfo.getUserAgent())));
.getFeatures(requestInfo.getLocale(), type, getOptions(filter, requestInfo));

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

@Override
@Get("/application-types/{type}/features/default{?gorm,servlet,test,javaVersion}")
@Get("/application-types/{type}/features/default{?filter*}")
public FeatureList defaultFeatures(ApplicationType type,
RequestInfo requestInfo,
@Nullable TestFramework test,
@Nullable GormImpl gorm,
@Nullable ServletImpl servlet,
@Nullable JdkVersion javaVersion) {
List<FeatureDTO> featureDTOList = featureOperations
.getDefaultFeatures(requestInfo.getLocale(),
type,
new Options(test != null ? test.toTestFramework() : null,
gorm == null ? GormImpl.DEFAULT_OPTION : gorm,
servlet == null ? ServletImpl.DEFAULT_OPTION : servlet,
javaVersion == null ? JdkVersion.DEFAULT_OPTION : javaVersion,
getOperatingSystem(requestInfo.getUserAgent())));
@Nullable FeatureFilter filter) {
List<FeatureDTO> featureDTOList = featureOperations.getDefaultFeatures(requestInfo.getLocale(), type, getOptions(filter, requestInfo));

final FeatureList featureList = new FeatureList(featureDTOList);
featureList.addLink(
Expand Down Expand Up @@ -240,4 +222,16 @@ private ApplicationTypeDTO typeToDTO(ApplicationType type, RequestInfo requestIn
protected OperatingSystem getOperatingSystem(String userAgent) {
return UserAgentParser.getOperatingSystem(userAgent);
}

protected Options getOptions(@Nullable FeatureFilter filter, RequestInfo requestInfo) {
if (filter == null) {
return new Options(null, GormImpl.DEFAULT_OPTION, ServletImpl.DEFAULT_OPTION, JdkVersion.DEFAULT_OPTION, getOperatingSystem(requestInfo.getUserAgent()));
}

return new Options(filter.getTest() != null ? filter.getTest().toTestFramework() : null,
filter.getGorm() == null ? GormImpl.DEFAULT_OPTION : filter.getGorm(),
filter.getServlet() == null ? ServletImpl.DEFAULT_OPTION : filter.getServlet(),
filter.getJavaVersion() == null ? JdkVersion.DEFAULT_OPTION : filter.getJavaVersion(),
getOperatingSystem(requestInfo.getUserAgent()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
import io.micronaut.http.annotation.Get;
import io.swagger.v3.oas.annotations.Parameter;
import org.grails.forge.application.ApplicationType;
import org.grails.forge.options.GormImpl;
import org.grails.forge.options.JdkVersion;
import org.grails.forge.options.ServletImpl;
import org.grails.forge.options.FeatureFilter;

/**
* Operations on application types.
Expand Down Expand Up @@ -52,35 +50,23 @@ public interface ApplicationTypeOperations {
* List the type features.
* @param type The features
* @param serverURL The server URL
* @param test The test framework
* @param gorm The GORM
* @param servlet The Servlet
* @param javaVersion The java version
* @param filter features to filter by
* @return The features
*/
@Get("/application-types/{type}/features{?gorm,servlet,test,javaVersion}")
@Get("/application-types/{type}/features{?filter*}")
FeatureList features(ApplicationType type,
@Parameter(hidden = true) RequestInfo serverURL,
@Nullable TestFramework test,
@Nullable GormImpl gorm,
@Nullable ServletImpl servlet,
@Nullable JdkVersion javaVersion);
@Nullable FeatureFilter filter);

/**
* List the default features.
* @param type The features
* @param serverURL The server URL
* @param test The test framework
* @param gorm The GORM
* @param servlet The Servlet
* @param javaVersion The java version
* @param filter features to filter by
* @return The features
*/
@Get("/application-types/{type}/features/default{?gorm,servlet,test,javaVersion}")
@Get("/application-types/{type}/features/default{?filter*}")
FeatureList defaultFeatures(ApplicationType type,
@Parameter(hidden = true) RequestInfo serverURL,
@Nullable TestFramework test,
@Nullable GormImpl gorm,
@Nullable ServletImpl servlet,
@Nullable JdkVersion javaVersion);
@Nullable FeatureFilter filter);
}
5 changes: 5 additions & 0 deletions grails-forge-api/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
jackson:
mapper:
ACCEPT_CASE_INSENSITIVE_ENUMS: true
deserialization:
READ_UNKNOWN_ENUM_VALUES_AS_NULL: true
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,18 @@ import io.micronaut.http.annotation.Get
import io.micronaut.http.annotation.Header
import io.micronaut.http.client.annotation.Client
import org.grails.forge.application.ApplicationType
import org.grails.forge.options.GormImpl
import org.grails.forge.options.JdkVersion
import org.grails.forge.options.ServletImpl
import org.grails.forge.options.FeatureFilter

@Client('/')
interface ApplicationTypeClient extends ApplicationTypeOperations {

@Get("/application-types/{type}/features{?gorm,servlet,test,javaVersion}")
@Get("/application-types/{type}/features{?filter*}")
@Header(name = HttpHeaders.ACCEPT_LANGUAGE, value = "es")
FeatureList spanishFeatures(ApplicationType type,
@Nullable TestFramework test,
@Nullable GormImpl gorm,
@Nullable ServletImpl servlet,
@Nullable JdkVersion javaVersion);
@Nullable FeatureFilter filter);

@Get("/application-types/{type}/features/default{?gorm,servlet,test,javaVersion}")
@Get("/application-types/{type}/features/default{?filter*}")
@Header(name = HttpHeaders.ACCEPT_LANGUAGE, value = "es")
FeatureList spanishDefaultFeatures(ApplicationType type,
@Nullable TestFramework test,
@Nullable GormImpl gorm,
@Nullable ServletImpl servlet,
@Nullable JdkVersion javaVersion);
@Nullable FeatureFilter filter);
}
Original file line number Diff line number Diff line change
@@ -1,42 +1,54 @@
package org.grails.forge.api

import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.databind.ObjectMapper
import io.micronaut.http.HttpRequest
import io.micronaut.http.client.HttpClient
import io.micronaut.http.client.annotation.Client
import io.micronaut.json.tree.JsonNode
import io.micronaut.test.extensions.spock.annotation.MicronautTest
import jakarta.inject.Inject
import org.grails.forge.application.ApplicationType
import org.grails.forge.options.FeatureFilter
import org.grails.forge.options.GormImpl
import org.grails.forge.options.JdkVersion
import org.grails.forge.options.TestFramework
import org.grails.forge.options.ServletImpl
import spock.lang.Specification

@MicronautTest
class FeatureControllerSpec extends Specification {

@Inject
ApplicationTypeClient client
ApplicationTypeClient applicationTypeClient

@Inject
@Client("/")
HttpClient httpClient

void 'test list features'() {
when:
List<FeatureDTO> features = client
List<FeatureDTO> features = applicationTypeClient
.features(ApplicationType.DEFAULT_OPTION,
RequestInfo.LOCAL,
TestFramework.DEFAULT_OPTION,
GormImpl.DEFAULT_OPTION,
ServletImpl.DEFAULT_OPTION,
JdkVersion.DEFAULT_OPTION).features
new FeatureFilter(test: TestFramework.DEFAULT_OPTION,
gorm: GormImpl.DEFAULT_OPTION,
servlet: ServletImpl.DEFAULT_OPTION,
javaVersion: JdkVersion.DEFAULT_OPTION)).features

then:
!features.isEmpty()
}

void 'test community features'() {
when:
List<FeatureDTO> communityFeatures = client
List<FeatureDTO> communityFeatures = applicationTypeClient
.features(ApplicationType.DEFAULT_OPTION,
RequestInfo.LOCAL,
TestFramework.DEFAULT_OPTION,
GormImpl.DEFAULT_OPTION,
ServletImpl.DEFAULT_OPTION,
JdkVersion.DEFAULT_OPTION).features
new FeatureFilter(test: TestFramework.DEFAULT_OPTION,
gorm: GormImpl.DEFAULT_OPTION,
servlet: ServletImpl.DEFAULT_OPTION,
javaVersion: JdkVersion.DEFAULT_OPTION)).features
.findAll { it.community }

then:
Expand All @@ -45,12 +57,12 @@ class FeatureControllerSpec extends Specification {

void 'test list features - spanish'() {
when:
List<FeatureDTO> features = client
List<FeatureDTO> features = applicationTypeClient
.spanishFeatures(ApplicationType.DEFAULT_OPTION,
TestFramework.DEFAULT_OPTION,
GormImpl.DEFAULT_OPTION,
ServletImpl.DEFAULT_OPTION,
JdkVersion.DEFAULT_OPTION).features
new FeatureFilter(test: TestFramework.DEFAULT_OPTION,
gorm: GormImpl.DEFAULT_OPTION,
servlet: ServletImpl.DEFAULT_OPTION,
javaVersion: JdkVersion.DEFAULT_OPTION)).features
def mongoGorm = features.find { it.name == 'asciidoctor' }

then:
Expand All @@ -61,12 +73,12 @@ class FeatureControllerSpec extends Specification {

void 'test list default features - spanish'() {
when:
List<FeatureDTO> features = client
List<FeatureDTO> features = applicationTypeClient
.spanishDefaultFeatures(ApplicationType.DEFAULT_OPTION,
TestFramework.DEFAULT_OPTION,
GormImpl.DEFAULT_OPTION,
ServletImpl.DEFAULT_OPTION,
JdkVersion.DEFAULT_OPTION).features
new FeatureFilter(test: TestFramework.DEFAULT_OPTION,
gorm: GormImpl.DEFAULT_OPTION,
servlet: ServletImpl.DEFAULT_OPTION,
javaVersion: JdkVersion.DEFAULT_OPTION)).features
def assetPipeline = features.find { it.name == 'asset-pipeline-grails' }

then:
Expand All @@ -77,68 +89,84 @@ class FeatureControllerSpec extends Specification {

void 'test list default features for application type'() {
when:
def features = client
def features = applicationTypeClient
.defaultFeatures(ApplicationType.PLUGIN,
RequestInfo.LOCAL,
TestFramework.DEFAULT_OPTION,
GormImpl.DEFAULT_OPTION,
ServletImpl.DEFAULT_OPTION,
JdkVersion.DEFAULT_OPTION).features
new FeatureFilter(test: TestFramework.DEFAULT_OPTION,
gorm: GormImpl.DEFAULT_OPTION,
servlet: ServletImpl.DEFAULT_OPTION,
javaVersion: JdkVersion.DEFAULT_OPTION)).features

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

when:
features = client
features = applicationTypeClient
.defaultFeatures(ApplicationType.DEFAULT_OPTION,
RequestInfo.LOCAL,
TestFramework.DEFAULT_OPTION,
GormImpl.DEFAULT_OPTION,
ServletImpl.DEFAULT_OPTION,
JdkVersion.DEFAULT_OPTION).features
new FeatureFilter(test: TestFramework.DEFAULT_OPTION,
gorm: GormImpl.DEFAULT_OPTION,
servlet: ServletImpl.DEFAULT_OPTION,
javaVersion: JdkVersion.DEFAULT_OPTION)).features

then:
features.any { it.name == 'geb-with-testcontainers' }
}

void 'test list features for application type'() {
when:
def features = client
def features = applicationTypeClient
.features(ApplicationType.PLUGIN,
RequestInfo.LOCAL,
TestFramework.DEFAULT_OPTION,
GormImpl.DEFAULT_OPTION,
ServletImpl.DEFAULT_OPTION,
JdkVersion.DEFAULT_OPTION).features
new FeatureFilter(test: TestFramework.DEFAULT_OPTION,
gorm: GormImpl.DEFAULT_OPTION,
servlet: ServletImpl.DEFAULT_OPTION,
javaVersion: JdkVersion.DEFAULT_OPTION)).features

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

when:
features = client
features = applicationTypeClient
.features(ApplicationType.DEFAULT_OPTION,
RequestInfo.LOCAL,
TestFramework.DEFAULT_OPTION,
GormImpl.DEFAULT_OPTION,
ServletImpl.DEFAULT_OPTION,
JdkVersion.DEFAULT_OPTION).features
new FeatureFilter(test: TestFramework.DEFAULT_OPTION,
gorm: GormImpl.DEFAULT_OPTION,
servlet: ServletImpl.DEFAULT_OPTION,
javaVersion: JdkVersion.DEFAULT_OPTION)).features

then:
features.any { it.name == 'gorm-mongodb' }
}

void 'test list features for application type should NOT return default included features'() {
when:
def features = client
def features = applicationTypeClient
.features(ApplicationType.WEB,
RequestInfo.LOCAL,
TestFramework.DEFAULT_OPTION,
GormImpl.DEFAULT_OPTION,
ServletImpl.DEFAULT_OPTION,
JdkVersion.DEFAULT_OPTION).features
new FeatureFilter(test: TestFramework.DEFAULT_OPTION,
gorm: GormImpl.DEFAULT_OPTION,
servlet: ServletImpl.DEFAULT_OPTION,
javaVersion: JdkVersion.DEFAULT_OPTION)).features

then:
!features.any { it.name == 'asset-pipeline-grails' }
}

void "test feature filter - invalid option as query parameter"() {
when:
String response = httpClient.toBlocking().withCloseable { client ->
client.exchange(HttpRequest.GET('/application-types/' + ApplicationType.WEB.name + '/features?javaVersion=invalid'), String.class).body()
}

then:
response

and:
ObjectMapper mapper = new ObjectMapper()
def map = mapper.readValue(response, Map)

map.features.collect { it -> it.name }.find { it == 'gorm-mongodb'}
}
}
Loading

0 comments on commit de720c5

Please sign in to comment.