Add dialect support to Type metadata

Closes gh-1344
This commit is contained in:
Stephane Nicoll
2022-11-15 15:15:16 +01:00
parent 3ccc2011cd
commit 6b843967b2
5 changed files with 41 additions and 12 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
package io.spring.initializr.web.project;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import io.spring.initializr.generator.buildsystem.BuildSystem;
@@ -165,8 +166,10 @@ public class DefaultProjectRequestToDescriptionConverter
}
private BuildSystem getBuildSystem(ProjectRequest request, InitializrMetadata metadata) {
Type typeFromMetadata = metadata.getTypes().get(request.getType());
return BuildSystem.forId(typeFromMetadata.getTags().get("build"));
Map<String, String> typeTags = metadata.getTypes().get(request.getType()).getTags();
String id = typeTags.get("build");
String dialect = typeTags.get("dialect");
return BuildSystem.forIdAndDialect(id, dialect);
}
private Version getPlatformVersion(ProjectRequest request, InitializrMetadata metadata) {

View File

@@ -44,7 +44,7 @@ class InitializrMetadataV21JsonMapperTests {
@Test
void withNoAppUrl() throws IOException {
InitializrMetadata metadata = new InitializrMetadataTestBuilder()
.addType("foo", true, "/foo.zip", "none", "test").addDependencyGroup("foo", "one", "two").build();
.addType("foo", true, "/foo.zip", "none", null, "test").addDependencyGroup("foo", "one", "two").build();
String json = this.jsonMapper.write(metadata, null);
JsonNode result = objectMapper.readTree(json);
assertThat(get(result, "_links.foo.href"))
@@ -55,7 +55,7 @@ class InitializrMetadataV21JsonMapperTests {
@Test
void withAppUrl() throws IOException {
InitializrMetadata metadata = new InitializrMetadataTestBuilder()
.addType("foo", true, "/foo.zip", "none", "test").addDependencyGroup("foo", "one", "two").build();
.addType("foo", true, "/foo.zip", "none", null, "test").addDependencyGroup("foo", "one", "two").build();
String json = this.jsonMapper.write(metadata, "http://server:8080/my-app");
JsonNode result = objectMapper.readTree(json);
assertThat(get(result, "_links.foo.href"))

View File

@@ -68,6 +68,27 @@ class DefaultProjectRequestToDescriptionConverterTests {
.withMessage("Invalid type 'example-project' (missing build tag) check project metadata");
}
@Test
void convertWhenTypeDoesNotDefineDialectTagShouldUseDefaultDialect() {
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
.addType("foo", true, "/foo.zip", GradleBuildSystem.ID, null, "test").build();
ProjectRequest request = createProjectRequest();
request.setType("foo");
assertThat(this.converter.convert(request, metadata).getBuildSystem().dialect())
.isEqualTo(GradleBuildSystem.DIALECT_GROOVY);
}
@Test
void convertWhenTypeDefinesDialectTagShouldUseDialect() {
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
.addType("foo", true, "/foo.zip", GradleBuildSystem.ID, GradleBuildSystem.DIALECT_KOTLIN, "test")
.build();
ProjectRequest request = createProjectRequest();
request.setType("foo");
assertThat(this.converter.convert(request, metadata).getBuildSystem().dialect())
.isEqualTo(GradleBuildSystem.DIALECT_KOTLIN);
}
@Test
void convertWhenPlatformCompatibilityRangeIsNotSetShouldNotThrowException() {
this.metadata = InitializrMetadataTestBuilder.withDefaults().setPlatformCompatibilityRange(null).build();