mirror of
https://gitee.com/dcren/initializr.git
synced 2025-04-05 17:38:06 +08:00
Use a strategy for Kotlin version resolution
Closes gh-926
This commit is contained in:
parent
ab8b1158fa
commit
93975d98b9
@ -28,6 +28,11 @@
|
||||
<artifactId>jmustache</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-autoconfigure</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.spring.initializr</groupId>
|
||||
<artifactId>initializr-generator</artifactId>
|
||||
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.spring.initializr.generator.spring.autoconfigure;
|
||||
|
||||
import io.spring.initializr.generator.spring.code.kotlin.InitializrMetadataKotlinVersionResolver;
|
||||
import io.spring.initializr.generator.spring.code.kotlin.KotlinVersionResolver;
|
||||
import io.spring.initializr.metadata.InitializrMetadataProvider;
|
||||
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
/**
|
||||
* {@link EnableAutoConfiguration Auto-configuration} for generation of Spring-based
|
||||
* projects.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class GeneratorSpringAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public KotlinVersionResolver kotlinVersionResolver(InitializrMetadataProvider metadataProvider) {
|
||||
return new InitializrMetadataKotlinVersionResolver(metadataProvider);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.spring.initializr.generator.spring.code.kotlin;
|
||||
|
||||
import io.spring.initializr.generator.project.ResolvedProjectDescription;
|
||||
import io.spring.initializr.metadata.InitializrMetadata;
|
||||
import io.spring.initializr.metadata.InitializrMetadataProvider;
|
||||
|
||||
/**
|
||||
* {@link KotlinVersionResolver} that resolves the version from the
|
||||
* {@link InitializrMetadata}.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class InitializrMetadataKotlinVersionResolver implements KotlinVersionResolver {
|
||||
|
||||
private final InitializrMetadataProvider metadataProvider;
|
||||
|
||||
public InitializrMetadataKotlinVersionResolver(InitializrMetadataProvider metadataProvider) {
|
||||
this.metadataProvider = metadataProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String resolveKotlinVersion(ResolvedProjectDescription description) {
|
||||
return this.metadataProvider.get().getConfiguration().getEnv().getKotlin()
|
||||
.resolveKotlinVersion(description.getPlatformVersion());
|
||||
}
|
||||
|
||||
}
|
@ -32,7 +32,6 @@ import io.spring.initializr.generator.spring.code.MainSourceCodeProjectContribut
|
||||
import io.spring.initializr.generator.spring.code.TestApplicationTypeCustomizer;
|
||||
import io.spring.initializr.generator.spring.code.TestSourceCodeCustomizer;
|
||||
import io.spring.initializr.generator.spring.code.TestSourceCodeProjectContributor;
|
||||
import io.spring.initializr.metadata.InitializrMetadata;
|
||||
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@ -80,8 +79,8 @@ public class KotlinProjectGenerationConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public KotlinProjectSettings kotlinProjectSettings(InitializrMetadata metadata) {
|
||||
return new MetadataKotlinProjectSettings(this.projectDescription, metadata);
|
||||
public KotlinProjectSettings kotlinProjectSettings(KotlinVersionResolver kotlinVersionResolver) {
|
||||
return new SimpleKotlinProjectSettings(kotlinVersionResolver.resolveKotlinVersion(this.projectDescription));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,25 +17,21 @@
|
||||
package io.spring.initializr.generator.spring.code.kotlin;
|
||||
|
||||
import io.spring.initializr.generator.project.ResolvedProjectDescription;
|
||||
import io.spring.initializr.metadata.InitializrMetadata;
|
||||
|
||||
/**
|
||||
* A {@link KotlinProjectSettings} that resolves the version to use from the metadata.
|
||||
* Strategy for resolving a Kotlin version from a platform version.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class MetadataKotlinProjectSettings implements KotlinProjectSettings {
|
||||
@FunctionalInterface
|
||||
public interface KotlinVersionResolver {
|
||||
|
||||
private final String version;
|
||||
|
||||
public MetadataKotlinProjectSettings(ResolvedProjectDescription projectDescription, InitializrMetadata metadata) {
|
||||
this.version = metadata.getConfiguration().getEnv().getKotlin()
|
||||
.resolveKotlinVersion(projectDescription.getPlatformVersion());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return this.version;
|
||||
}
|
||||
/**
|
||||
* Resolves the Kotlin version to use for the generation of the project with the given
|
||||
* {@code description}.
|
||||
* @param description the description of the project being generated
|
||||
* @return the corresponding Kotlin version
|
||||
*/
|
||||
String resolveKotlinVersion(ResolvedProjectDescription description);
|
||||
|
||||
}
|
@ -8,4 +8,7 @@ io.spring.initializr.generator.spring.code.java.JavaProjectGenerationConfigurati
|
||||
io.spring.initializr.generator.spring.code.kotlin.KotlinProjectGenerationConfiguration,\
|
||||
io.spring.initializr.generator.spring.configuration.ApplicationConfigurationProjectGenerationConfiguration,\
|
||||
io.spring.initializr.generator.spring.documentation.HelpDocumentProjectGenerationConfiguration,\
|
||||
io.spring.initializr.generator.spring.scm.git.GitProjectGenerationConfiguration
|
||||
io.spring.initializr.generator.spring.scm.git.GitProjectGenerationConfiguration
|
||||
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
io.spring.initializr.generator.spring.autoconfigure.GeneratorSpringAutoConfiguration
|
||||
|
@ -27,6 +27,8 @@ import io.spring.initializr.generator.language.Language;
|
||||
import io.spring.initializr.generator.project.ProjectDescription;
|
||||
import io.spring.initializr.generator.project.ProjectGenerationContext;
|
||||
import io.spring.initializr.generator.project.ResolvedProjectDescription;
|
||||
import io.spring.initializr.generator.spring.code.kotlin.InitializrMetadataKotlinVersionResolver;
|
||||
import io.spring.initializr.generator.spring.code.kotlin.KotlinVersionResolver;
|
||||
import io.spring.initializr.generator.spring.test.InitializrMetadataTestBuilder;
|
||||
import io.spring.initializr.generator.spring.test.ProjectAssert;
|
||||
import io.spring.initializr.generator.test.project.ProjectGeneratorTester;
|
||||
@ -102,6 +104,8 @@ public abstract class AbstractComplianceTests {
|
||||
context.getBean(ResolvedProjectDescription.class).getPlatformVersion()));
|
||||
context.registerBean(IndentingWriterFactory.class,
|
||||
() -> IndentingWriterFactory.create(new SimpleIndentStrategy("\t")));
|
||||
context.registerBean(KotlinVersionResolver.class,
|
||||
() -> new InitializrMetadataKotlinVersionResolver(() -> metadata));
|
||||
}
|
||||
|
||||
private void setupProjectDescription(Language language, String version, BuildSystem buildSystem,
|
||||
|
Loading…
Reference in New Issue
Block a user