mirror of
https://gitee.com/dcren/initializr.git
synced 2026-02-25 21:22:58 +08:00
Harmonize ProjectDescription name
This commit is contained in:
@@ -72,9 +72,9 @@ public class BuildProjectGenerationConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DefaultMavenBuildCustomizer initializrMetadataMavenBuildCustomizer(ProjectDescription projectDescription,
|
||||
public DefaultMavenBuildCustomizer initializrMetadataMavenBuildCustomizer(ProjectDescription description,
|
||||
InitializrMetadata metadata) {
|
||||
return new DefaultMavenBuildCustomizer(projectDescription, metadata);
|
||||
return new DefaultMavenBuildCustomizer(description, metadata);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -84,14 +84,14 @@ public class BuildProjectGenerationConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DependencyManagementBuildCustomizer dependencyManagementBuildCustomizer(
|
||||
ProjectDescription projectDescription, InitializrMetadata metadata) {
|
||||
return new DependencyManagementBuildCustomizer(projectDescription, metadata);
|
||||
public DependencyManagementBuildCustomizer dependencyManagementBuildCustomizer(ProjectDescription description,
|
||||
InitializrMetadata metadata) {
|
||||
return new DependencyManagementBuildCustomizer(description, metadata);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SimpleBuildCustomizer projectDescriptionBuildCustomizer(ProjectDescription projectDescription) {
|
||||
return new SimpleBuildCustomizer(projectDescription);
|
||||
public SimpleBuildCustomizer projectDescriptionBuildCustomizer(ProjectDescription description) {
|
||||
return new SimpleBuildCustomizer(description);
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -39,12 +39,12 @@ import org.springframework.core.Ordered;
|
||||
*/
|
||||
public class DependencyManagementBuildCustomizer implements BuildCustomizer<Build> {
|
||||
|
||||
private final ProjectDescription projectDescription;
|
||||
private final ProjectDescription description;
|
||||
|
||||
private final InitializrMetadata metadata;
|
||||
|
||||
public DependencyManagementBuildCustomizer(ProjectDescription projectDescription, InitializrMetadata metadata) {
|
||||
this.projectDescription = projectDescription;
|
||||
public DependencyManagementBuildCustomizer(ProjectDescription description, InitializrMetadata metadata) {
|
||||
this.description = description;
|
||||
this.metadata = metadata;
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ public class DependencyManagementBuildCustomizer implements BuildCustomizer<Buil
|
||||
Map<String, Repository> repositories = new LinkedHashMap<>();
|
||||
mapDependencies(build).forEach((dependency) -> {
|
||||
if (dependency.getBom() != null) {
|
||||
resolveBom(resolvedBoms, dependency.getBom(), this.projectDescription.getPlatformVersion());
|
||||
resolveBom(resolvedBoms, dependency.getBom(), this.description.getPlatformVersion());
|
||||
}
|
||||
if (dependency.getRepository() != null) {
|
||||
String repositoryId = dependency.getRepository();
|
||||
|
||||
@@ -30,18 +30,18 @@ import org.springframework.core.Ordered;
|
||||
*/
|
||||
public class SimpleBuildCustomizer implements BuildCustomizer<Build> {
|
||||
|
||||
private final ProjectDescription projectDescription;
|
||||
private final ProjectDescription description;
|
||||
|
||||
public SimpleBuildCustomizer(ProjectDescription projectDescription) {
|
||||
this.projectDescription = projectDescription;
|
||||
public SimpleBuildCustomizer(ProjectDescription description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customize(Build build) {
|
||||
build.setGroup(this.projectDescription.getGroupId());
|
||||
build.setArtifact(this.projectDescription.getArtifactId());
|
||||
build.setVersion(this.projectDescription.getVersion());
|
||||
this.projectDescription.getRequestedDependencies()
|
||||
build.setGroup(this.description.getGroupId());
|
||||
build.setArtifact(this.description.getArtifactId());
|
||||
build.setVersion(this.description.getVersion());
|
||||
this.description.getRequestedDependencies()
|
||||
.forEach((id, dependency) -> build.dependencies().add(id, dependency));
|
||||
}
|
||||
|
||||
|
||||
@@ -78,8 +78,8 @@ public class GradleProjectGenerationConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public BuildCustomizer<GradleBuild> defaultGradleBuildCustomizer(ProjectDescription projectDescription) {
|
||||
return (build) -> build.setSourceCompatibility(projectDescription.getLanguage().jvmVersion());
|
||||
public BuildCustomizer<GradleBuild> defaultGradleBuildCustomizer(ProjectDescription description) {
|
||||
return (build) -> build.setSourceCompatibility(description.getLanguage().jvmVersion());
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -101,9 +101,9 @@ public class GradleProjectGenerationConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnPlatformVersion("2.0.0.M1")
|
||||
BuildCustomizer<GradleBuild> springBootPluginContributor(ProjectDescription projectDescription,
|
||||
BuildCustomizer<GradleBuild> springBootPluginContributor(ProjectDescription description,
|
||||
ObjectProvider<DependencyManagementPluginVersionResolver> versionResolver, InitializrMetadata metadata) {
|
||||
return new SpringBootPluginBuildCustomizer(projectDescription, versionResolver
|
||||
return new SpringBootPluginBuildCustomizer(description, versionResolver
|
||||
.getIfAvailable(() -> new InitializrDependencyManagementPluginVersionResolver(metadata)));
|
||||
}
|
||||
|
||||
@@ -145,11 +145,10 @@ public class GradleProjectGenerationConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
BuildCustomizer<GradleBuild> springBootPluginContributor(ProjectDescription projectDescription) {
|
||||
BuildCustomizer<GradleBuild> springBootPluginContributor(ProjectDescription description) {
|
||||
return (build) -> {
|
||||
build.buildscript(
|
||||
(buildscript) -> buildscript.dependency("org.springframework.boot:spring-boot-gradle-plugin:"
|
||||
+ projectDescription.getPlatformVersion()));
|
||||
build.buildscript((buildscript) -> buildscript.dependency(
|
||||
"org.springframework.boot:spring-boot-gradle-plugin:" + description.getPlatformVersion()));
|
||||
build.plugins().apply("org.springframework.boot");
|
||||
};
|
||||
}
|
||||
@@ -206,9 +205,9 @@ public class GradleProjectGenerationConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
BuildCustomizer<GradleBuild> springBootPluginContributor(ProjectDescription projectDescription) {
|
||||
BuildCustomizer<GradleBuild> springBootPluginContributor(ProjectDescription description) {
|
||||
return (build) -> build.plugins().add("org.springframework.boot",
|
||||
(plugin) -> plugin.setVersion(projectDescription.getPlatformVersion().toString()));
|
||||
(plugin) -> plugin.setVersion(description.getPlatformVersion().toString()));
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -43,9 +43,9 @@ public class OnGradleVersionCondition extends ProjectGenerationCondition {
|
||||
private static final VersionRange GRADLE_5_VERSION_RANGE = VersionParser.DEFAULT.parseRange("2.1.0.M1");
|
||||
|
||||
@Override
|
||||
protected boolean matches(ProjectDescription projectDescription, ConditionContext context,
|
||||
protected boolean matches(ProjectDescription description, ConditionContext context,
|
||||
AnnotatedTypeMetadata metadata) {
|
||||
String gradleGeneration = determineGradleGeneration(projectDescription.getPlatformVersion());
|
||||
String gradleGeneration = determineGradleGeneration(description.getPlatformVersion());
|
||||
if (gradleGeneration == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -34,22 +34,22 @@ public final class SpringBootPluginBuildCustomizer implements BuildCustomizer<Gr
|
||||
*/
|
||||
public static final int ORDER = -100;
|
||||
|
||||
private final ProjectDescription projectDescription;
|
||||
private final ProjectDescription description;
|
||||
|
||||
private final DependencyManagementPluginVersionResolver versionResolver;
|
||||
|
||||
public SpringBootPluginBuildCustomizer(ProjectDescription projectDescription,
|
||||
public SpringBootPluginBuildCustomizer(ProjectDescription description,
|
||||
DependencyManagementPluginVersionResolver versionResolver) {
|
||||
this.projectDescription = projectDescription;
|
||||
this.description = description;
|
||||
this.versionResolver = versionResolver;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customize(GradleBuild build) {
|
||||
build.plugins().add("org.springframework.boot",
|
||||
(plugin) -> plugin.setVersion(this.projectDescription.getPlatformVersion().toString()));
|
||||
(plugin) -> plugin.setVersion(this.description.getPlatformVersion().toString()));
|
||||
build.plugins().add("io.spring.dependency-management", (plugin) -> plugin
|
||||
.setVersion(this.versionResolver.resolveDependencyManagementPluginVersion(this.projectDescription)));
|
||||
.setVersion(this.versionResolver.resolveDependencyManagementPluginVersion(this.description)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -32,24 +32,24 @@ import io.spring.initializr.metadata.support.MetadataBuildItemMapper;
|
||||
*/
|
||||
public class DefaultMavenBuildCustomizer implements BuildCustomizer<MavenBuild> {
|
||||
|
||||
private final ProjectDescription projectDescription;
|
||||
private final ProjectDescription description;
|
||||
|
||||
private final InitializrMetadata metadata;
|
||||
|
||||
public DefaultMavenBuildCustomizer(ProjectDescription projectDescription, InitializrMetadata metadata) {
|
||||
this.projectDescription = projectDescription;
|
||||
public DefaultMavenBuildCustomizer(ProjectDescription description, InitializrMetadata metadata) {
|
||||
this.description = description;
|
||||
this.metadata = metadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customize(MavenBuild build) {
|
||||
build.setName(this.projectDescription.getName());
|
||||
build.setDescription(this.projectDescription.getDescription());
|
||||
build.setProperty("java.version", this.projectDescription.getLanguage().jvmVersion());
|
||||
build.setName(this.description.getName());
|
||||
build.setDescription(this.description.getDescription());
|
||||
build.setProperty("java.version", this.description.getLanguage().jvmVersion());
|
||||
build.plugins().add("org.springframework.boot", "spring-boot-maven-plugin");
|
||||
|
||||
Maven maven = this.metadata.getConfiguration().getEnv().getMaven();
|
||||
String springBootVersion = this.projectDescription.getPlatformVersion().toString();
|
||||
String springBootVersion = this.description.getPlatformVersion().toString();
|
||||
ParentPom parentPom = maven.resolveParentPom(springBootVersion);
|
||||
if (parentPom.isIncludeSpringBootBom()) {
|
||||
String versionProperty = "spring-boot.version";
|
||||
|
||||
@@ -44,7 +44,7 @@ import org.springframework.beans.factory.ObjectProvider;
|
||||
public class MainSourceCodeProjectContributor<T extends TypeDeclaration, C extends CompilationUnit<T>, S extends SourceCode<T, C>>
|
||||
implements ProjectContributor {
|
||||
|
||||
private final ProjectDescription projectDescription;
|
||||
private final ProjectDescription description;
|
||||
|
||||
private final Supplier<S> sourceFactory;
|
||||
|
||||
@@ -56,11 +56,11 @@ public class MainSourceCodeProjectContributor<T extends TypeDeclaration, C exten
|
||||
|
||||
private final ObjectProvider<MainSourceCodeCustomizer<?, ?, ?>> mainSourceCodeCustomizers;
|
||||
|
||||
public MainSourceCodeProjectContributor(ProjectDescription projectDescription, Supplier<S> sourceFactory,
|
||||
public MainSourceCodeProjectContributor(ProjectDescription description, Supplier<S> sourceFactory,
|
||||
SourceCodeWriter<S> sourceWriter, ObjectProvider<MainApplicationTypeCustomizer<?>> mainTypeCustomizers,
|
||||
ObjectProvider<MainCompilationUnitCustomizer<?, ?>> mainCompilationUnitCustomizers,
|
||||
ObjectProvider<MainSourceCodeCustomizer<?, ?, ?>> mainSourceCodeCustomizers) {
|
||||
this.projectDescription = projectDescription;
|
||||
this.description = description;
|
||||
this.sourceFactory = sourceFactory;
|
||||
this.sourceWriter = sourceWriter;
|
||||
this.mainTypeCustomizers = mainTypeCustomizers;
|
||||
@@ -71,14 +71,15 @@ public class MainSourceCodeProjectContributor<T extends TypeDeclaration, C exten
|
||||
@Override
|
||||
public void contribute(Path projectRoot) throws IOException {
|
||||
S sourceCode = this.sourceFactory.get();
|
||||
String applicationName = this.projectDescription.getApplicationName();
|
||||
C compilationUnit = sourceCode.createCompilationUnit(this.projectDescription.getPackageName(), applicationName);
|
||||
String applicationName = this.description.getApplicationName();
|
||||
C compilationUnit = sourceCode.createCompilationUnit(this.description.getPackageName(), applicationName);
|
||||
T mainApplicationType = compilationUnit.createTypeDeclaration(applicationName);
|
||||
customizeMainApplicationType(mainApplicationType);
|
||||
customizeMainCompilationUnit(compilationUnit);
|
||||
customizeMainSourceCode(sourceCode);
|
||||
this.sourceWriter.writeTo(this.projectDescription.getBuildSystem().getMainSource(projectRoot,
|
||||
this.projectDescription.getLanguage()), sourceCode);
|
||||
this.sourceWriter.writeTo(
|
||||
this.description.getBuildSystem().getMainSource(projectRoot, this.description.getLanguage()),
|
||||
sourceCode);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -66,17 +66,17 @@ public class SourceCodeProjectGenerationConfiguration {
|
||||
@ConditionalOnPackaging(WarPackaging.ID)
|
||||
static class WarPackagingConfiguration {
|
||||
|
||||
private final ProjectDescription projectDescription;
|
||||
private final ProjectDescription description;
|
||||
|
||||
WarPackagingConfiguration(ProjectDescription projectDescription) {
|
||||
this.projectDescription = projectDescription;
|
||||
WarPackagingConfiguration(ProjectDescription description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnPlatformVersion("[1.5.0.M1, 2.0.0.M1)")
|
||||
ServletInitializerContributor boot15ServletInitializerContributor(
|
||||
ObjectProvider<ServletInitializerCustomizer<?>> servletInitializerCustomizers) {
|
||||
return new ServletInitializerContributor(this.projectDescription.getPackageName(),
|
||||
return new ServletInitializerContributor(this.description.getPackageName(),
|
||||
"org.springframework.boot.web.support.SpringBootServletInitializer", servletInitializerCustomizers);
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public class SourceCodeProjectGenerationConfiguration {
|
||||
@ConditionalOnPlatformVersion("2.0.0.M1")
|
||||
ServletInitializerContributor boot20ServletInitializerContributor(
|
||||
ObjectProvider<ServletInitializerCustomizer<?>> servletInitializerCustomizers) {
|
||||
return new ServletInitializerContributor(this.projectDescription.getPackageName(),
|
||||
return new ServletInitializerContributor(this.description.getPackageName(),
|
||||
"org.springframework.boot.web.servlet.support.SpringBootServletInitializer",
|
||||
servletInitializerCustomizers);
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ import org.springframework.beans.factory.ObjectProvider;
|
||||
public class TestSourceCodeProjectContributor<T extends TypeDeclaration, C extends CompilationUnit<T>, S extends SourceCode<T, C>>
|
||||
implements ProjectContributor {
|
||||
|
||||
private final ProjectDescription projectDescription;
|
||||
private final ProjectDescription description;
|
||||
|
||||
private final Supplier<S> sourceFactory;
|
||||
|
||||
@@ -53,11 +53,11 @@ public class TestSourceCodeProjectContributor<T extends TypeDeclaration, C exten
|
||||
|
||||
private final ObjectProvider<TestSourceCodeCustomizer<?, ?, ?>> testSourceCodeCustomizers;
|
||||
|
||||
public TestSourceCodeProjectContributor(ProjectDescription projectDescription, Supplier<S> sourceFactory,
|
||||
public TestSourceCodeProjectContributor(ProjectDescription description, Supplier<S> sourceFactory,
|
||||
SourceCodeWriter<S> sourceWriter,
|
||||
ObjectProvider<TestApplicationTypeCustomizer<?>> testApplicationTypeCustomizers,
|
||||
ObjectProvider<TestSourceCodeCustomizer<?, ?, ?>> testSourceCodeCustomizers) {
|
||||
this.projectDescription = projectDescription;
|
||||
this.description = description;
|
||||
this.sourceFactory = sourceFactory;
|
||||
this.sourceWriter = sourceWriter;
|
||||
this.testApplicationTypeCustomizers = testApplicationTypeCustomizers;
|
||||
@@ -67,13 +67,14 @@ public class TestSourceCodeProjectContributor<T extends TypeDeclaration, C exten
|
||||
@Override
|
||||
public void contribute(Path projectRoot) throws IOException {
|
||||
S sourceCode = this.sourceFactory.get();
|
||||
String testName = this.projectDescription.getApplicationName() + "Tests";
|
||||
C compilationUnit = sourceCode.createCompilationUnit(this.projectDescription.getPackageName(), testName);
|
||||
String testName = this.description.getApplicationName() + "Tests";
|
||||
C compilationUnit = sourceCode.createCompilationUnit(this.description.getPackageName(), testName);
|
||||
T testApplicationType = compilationUnit.createTypeDeclaration(testName);
|
||||
customizeTestApplicationType(testApplicationType);
|
||||
customizeTestSourceCode(sourceCode);
|
||||
this.sourceWriter.writeTo(this.projectDescription.getBuildSystem().getTestSource(projectRoot,
|
||||
this.projectDescription.getLanguage()), sourceCode);
|
||||
this.sourceWriter.writeTo(
|
||||
this.description.getBuildSystem().getTestSource(projectRoot, this.description.getLanguage()),
|
||||
sourceCode);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -48,13 +48,13 @@ import org.springframework.context.annotation.Import;
|
||||
@Import(GroovyProjectGenerationDefaultContributorsConfiguration.class)
|
||||
public class GroovyProjectGenerationConfiguration {
|
||||
|
||||
private final ProjectDescription projectDescription;
|
||||
private final ProjectDescription description;
|
||||
|
||||
private final IndentingWriterFactory indentingWriterFactory;
|
||||
|
||||
public GroovyProjectGenerationConfiguration(ProjectDescription projectDescription,
|
||||
public GroovyProjectGenerationConfiguration(ProjectDescription description,
|
||||
IndentingWriterFactory indentingWriterFactory) {
|
||||
this.projectDescription = projectDescription;
|
||||
this.description = description;
|
||||
this.indentingWriterFactory = indentingWriterFactory;
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ public class GroovyProjectGenerationConfiguration {
|
||||
ObjectProvider<MainApplicationTypeCustomizer<?>> mainApplicationTypeCustomizers,
|
||||
ObjectProvider<MainCompilationUnitCustomizer<?, ?>> mainCompilationUnitCustomizers,
|
||||
ObjectProvider<MainSourceCodeCustomizer<?, ?, ?>> mainSourceCodeCustomizers) {
|
||||
return new MainSourceCodeProjectContributor<>(this.projectDescription, GroovySourceCode::new,
|
||||
return new MainSourceCodeProjectContributor<>(this.description, GroovySourceCode::new,
|
||||
new GroovySourceCodeWriter(this.indentingWriterFactory), mainApplicationTypeCustomizers,
|
||||
mainCompilationUnitCustomizers, mainSourceCodeCustomizers);
|
||||
}
|
||||
@@ -72,7 +72,7 @@ public class GroovyProjectGenerationConfiguration {
|
||||
public TestSourceCodeProjectContributor<GroovyTypeDeclaration, GroovyCompilationUnit, GroovySourceCode> testGroovySourceCodeProjectContributor(
|
||||
ObjectProvider<TestApplicationTypeCustomizer<?>> testApplicationTypeCustomizers,
|
||||
ObjectProvider<TestSourceCodeCustomizer<?, ?, ?>> testSourceCodeCustomizers) {
|
||||
return new TestSourceCodeProjectContributor<>(this.projectDescription, GroovySourceCode::new,
|
||||
return new TestSourceCodeProjectContributor<>(this.description, GroovySourceCode::new,
|
||||
new GroovySourceCodeWriter(this.indentingWriterFactory), testApplicationTypeCustomizers,
|
||||
testSourceCodeCustomizers);
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ class GroovyProjectGenerationDefaultContributorsConfiguration {
|
||||
|
||||
@Bean
|
||||
ServletInitializerCustomizer<GroovyTypeDeclaration> javaServletInitializerCustomizer(
|
||||
ProjectDescription projectDescription) {
|
||||
ProjectDescription description) {
|
||||
return (typeDeclaration) -> {
|
||||
GroovyMethodDeclaration configure = GroovyMethodDeclaration.method("configure")
|
||||
.modifiers(Modifier.PROTECTED)
|
||||
@@ -103,7 +103,7 @@ class GroovyProjectGenerationDefaultContributorsConfiguration {
|
||||
.parameters(new Parameter("org.springframework.boot.builder.SpringApplicationBuilder",
|
||||
"application"))
|
||||
.body(new GroovyReturnStatement(new GroovyMethodInvocation("application", "sources",
|
||||
projectDescription.getApplicationName())));
|
||||
description.getApplicationName())));
|
||||
configure.annotate(Annotation.name("java.lang.Override"));
|
||||
typeDeclaration.addMethodDeclaration(configure);
|
||||
};
|
||||
|
||||
@@ -48,13 +48,13 @@ import org.springframework.context.annotation.Import;
|
||||
@Import(JavaProjectGenerationDefaultContributorsConfiguration.class)
|
||||
public class JavaProjectGenerationConfiguration {
|
||||
|
||||
private final ProjectDescription projectDescription;
|
||||
private final ProjectDescription description;
|
||||
|
||||
private final IndentingWriterFactory indentingWriterFactory;
|
||||
|
||||
public JavaProjectGenerationConfiguration(ProjectDescription projectDescription,
|
||||
public JavaProjectGenerationConfiguration(ProjectDescription description,
|
||||
IndentingWriterFactory indentingWriterFactory) {
|
||||
this.projectDescription = projectDescription;
|
||||
this.description = description;
|
||||
this.indentingWriterFactory = indentingWriterFactory;
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ public class JavaProjectGenerationConfiguration {
|
||||
ObjectProvider<MainApplicationTypeCustomizer<?>> mainApplicationTypeCustomizers,
|
||||
ObjectProvider<MainCompilationUnitCustomizer<?, ?>> mainCompilationUnitCustomizers,
|
||||
ObjectProvider<MainSourceCodeCustomizer<?, ?, ?>> mainSourceCodeCustomizers) {
|
||||
return new MainSourceCodeProjectContributor<>(this.projectDescription, JavaSourceCode::new,
|
||||
return new MainSourceCodeProjectContributor<>(this.description, JavaSourceCode::new,
|
||||
new JavaSourceCodeWriter(this.indentingWriterFactory), mainApplicationTypeCustomizers,
|
||||
mainCompilationUnitCustomizers, mainSourceCodeCustomizers);
|
||||
}
|
||||
@@ -72,7 +72,7 @@ public class JavaProjectGenerationConfiguration {
|
||||
public TestSourceCodeProjectContributor<JavaTypeDeclaration, JavaCompilationUnit, JavaSourceCode> testJavaSourceCodeProjectContributor(
|
||||
ObjectProvider<TestApplicationTypeCustomizer<?>> testApplicationTypeCustomizers,
|
||||
ObjectProvider<TestSourceCodeCustomizer<?, ?, ?>> testSourceCodeCustomizers) {
|
||||
return new TestSourceCodeProjectContributor<>(this.projectDescription, JavaSourceCode::new,
|
||||
return new TestSourceCodeProjectContributor<>(this.description, JavaSourceCode::new,
|
||||
new JavaSourceCodeWriter(this.indentingWriterFactory), testApplicationTypeCustomizers,
|
||||
testSourceCodeCustomizers);
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ class JavaProjectGenerationDefaultContributorsConfiguration {
|
||||
|
||||
@Bean
|
||||
ServletInitializerCustomizer<JavaTypeDeclaration> javaServletInitializerCustomizer(
|
||||
ProjectDescription projectDescription) {
|
||||
ProjectDescription description) {
|
||||
return (typeDeclaration) -> {
|
||||
typeDeclaration.modifiers(Modifier.PUBLIC);
|
||||
JavaMethodDeclaration configure = JavaMethodDeclaration.method("configure")
|
||||
@@ -98,7 +98,7 @@ class JavaProjectGenerationDefaultContributorsConfiguration {
|
||||
.parameters(new Parameter("org.springframework.boot.builder.SpringApplicationBuilder",
|
||||
"application"))
|
||||
.body(new JavaReturnStatement(new JavaMethodInvocation("application", "sources",
|
||||
projectDescription.getApplicationName() + ".class")));
|
||||
description.getApplicationName() + ".class")));
|
||||
configure.annotate(Annotation.name("java.lang.Override"));
|
||||
typeDeclaration.addMethodDeclaration(configure);
|
||||
};
|
||||
|
||||
@@ -50,13 +50,13 @@ import org.springframework.context.annotation.Import;
|
||||
@Import(KotlinProjectGenerationDefaultContributorsConfiguration.class)
|
||||
public class KotlinProjectGenerationConfiguration {
|
||||
|
||||
private final ProjectDescription projectDescription;
|
||||
private final ProjectDescription description;
|
||||
|
||||
private final IndentingWriterFactory indentingWriterFactory;
|
||||
|
||||
public KotlinProjectGenerationConfiguration(ProjectDescription projectDescription,
|
||||
public KotlinProjectGenerationConfiguration(ProjectDescription description,
|
||||
IndentingWriterFactory indentingWriterFactory) {
|
||||
this.projectDescription = projectDescription;
|
||||
this.description = description;
|
||||
this.indentingWriterFactory = indentingWriterFactory;
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ public class KotlinProjectGenerationConfiguration {
|
||||
ObjectProvider<MainApplicationTypeCustomizer<?>> mainApplicationTypeCustomizers,
|
||||
ObjectProvider<MainCompilationUnitCustomizer<?, ?>> mainCompilationUnitCustomizers,
|
||||
ObjectProvider<MainSourceCodeCustomizer<?, ?, ?>> mainSourceCodeCustomizers) {
|
||||
return new MainSourceCodeProjectContributor<>(this.projectDescription, KotlinSourceCode::new,
|
||||
return new MainSourceCodeProjectContributor<>(this.description, KotlinSourceCode::new,
|
||||
new KotlinSourceCodeWriter(this.indentingWriterFactory), mainApplicationTypeCustomizers,
|
||||
mainCompilationUnitCustomizers, mainSourceCodeCustomizers);
|
||||
}
|
||||
@@ -74,7 +74,7 @@ public class KotlinProjectGenerationConfiguration {
|
||||
public TestSourceCodeProjectContributor<KotlinTypeDeclaration, KotlinCompilationUnit, KotlinSourceCode> testKotlinSourceCodeProjectContributor(
|
||||
ObjectProvider<TestApplicationTypeCustomizer<?>> testApplicationTypeCustomizers,
|
||||
ObjectProvider<TestSourceCodeCustomizer<?, ?, ?>> testSourceCodeCustomizers) {
|
||||
return new TestSourceCodeProjectContributor<>(this.projectDescription, KotlinSourceCode::new,
|
||||
return new TestSourceCodeProjectContributor<>(this.description, KotlinSourceCode::new,
|
||||
new KotlinSourceCodeWriter(this.indentingWriterFactory), testApplicationTypeCustomizers,
|
||||
testSourceCodeCustomizers);
|
||||
}
|
||||
@@ -84,13 +84,13 @@ public class KotlinProjectGenerationConfiguration {
|
||||
InitializrMetadata metadata) {
|
||||
String kotlinVersion = kotlinVersionResolver
|
||||
.getIfAvailable(() -> new InitializrMetadataKotlinVersionResolver(metadata))
|
||||
.resolveKotlinVersion(this.projectDescription);
|
||||
.resolveKotlinVersion(this.description);
|
||||
return new SimpleKotlinProjectSettings(kotlinVersion);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public KotlinJacksonBuildCustomizer kotlinJacksonBuildCustomizer(InitializrMetadata metadata) {
|
||||
return new KotlinJacksonBuildCustomizer(metadata, this.projectDescription);
|
||||
return new KotlinJacksonBuildCustomizer(metadata, this.description);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -74,8 +74,8 @@ class KotlinProjectGenerationDefaultContributorsConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
BuildCustomizer<Build> kotlinDependenciesConfigurer(ProjectDescription projectDescription) {
|
||||
return new KotlinDependenciesConfigurer(projectDescription.getPlatformVersion());
|
||||
BuildCustomizer<Build> kotlinDependenciesConfigurer(ProjectDescription description) {
|
||||
return new KotlinDependenciesConfigurer(description.getPlatformVersion());
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -106,12 +106,12 @@ class KotlinProjectGenerationDefaultContributorsConfiguration {
|
||||
|
||||
@Bean
|
||||
MainCompilationUnitCustomizer<KotlinTypeDeclaration, KotlinCompilationUnit> boot15MainFunctionContributor(
|
||||
ProjectDescription projectDescription) {
|
||||
ProjectDescription description) {
|
||||
return (compilationUnit) -> compilationUnit.addTopLevelFunction(
|
||||
KotlinFunctionDeclaration.function("main").parameters(new Parameter("Array<String>", "args"))
|
||||
.body(new KotlinExpressionStatement(
|
||||
new KotlinFunctionInvocation("org.springframework.boot.SpringApplication", "run",
|
||||
projectDescription.getApplicationName() + "::class.java", "*args"))));
|
||||
description.getApplicationName() + "::class.java", "*args"))));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -131,12 +131,12 @@ class KotlinProjectGenerationDefaultContributorsConfiguration {
|
||||
|
||||
@Bean
|
||||
MainCompilationUnitCustomizer<KotlinTypeDeclaration, KotlinCompilationUnit> mainFunctionContributor(
|
||||
ProjectDescription projectDescription) {
|
||||
ProjectDescription description) {
|
||||
return (compilationUnit) -> compilationUnit.addTopLevelFunction(
|
||||
KotlinFunctionDeclaration.function("main").parameters(new Parameter("Array<String>", "args"))
|
||||
.body(new KotlinExpressionStatement(
|
||||
new KotlinReifiedFunctionInvocation("org.springframework.boot.runApplication",
|
||||
projectDescription.getApplicationName(), "*args"))));
|
||||
description.getApplicationName(), "*args"))));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -150,7 +150,7 @@ class KotlinProjectGenerationDefaultContributorsConfiguration {
|
||||
|
||||
@Bean
|
||||
ServletInitializerCustomizer<KotlinTypeDeclaration> javaServletInitializerCustomizer(
|
||||
ProjectDescription projectDescription) {
|
||||
ProjectDescription description) {
|
||||
return (typeDeclaration) -> {
|
||||
KotlinFunctionDeclaration configure = KotlinFunctionDeclaration.function("configure")
|
||||
.modifiers(KotlinModifier.OVERRIDE)
|
||||
@@ -158,7 +158,7 @@ class KotlinProjectGenerationDefaultContributorsConfiguration {
|
||||
.parameters(new Parameter("org.springframework.boot.builder.SpringApplicationBuilder",
|
||||
"application"))
|
||||
.body(new KotlinReturnStatement(new KotlinFunctionInvocation("application", "sources",
|
||||
projectDescription.getApplicationName() + "::class.java")));
|
||||
description.getApplicationName() + "::class.java")));
|
||||
typeDeclaration.addFunctionDeclaration(configure);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -38,19 +38,18 @@ import org.springframework.util.ObjectUtils;
|
||||
*/
|
||||
public class RequestedDependenciesHelpDocumentCustomizer implements HelpDocumentCustomizer {
|
||||
|
||||
private final ProjectDescription projectDescription;
|
||||
private final ProjectDescription description;
|
||||
|
||||
private final InitializrMetadata metadata;
|
||||
|
||||
public RequestedDependenciesHelpDocumentCustomizer(ProjectDescription projectDescription,
|
||||
InitializrMetadata metadata) {
|
||||
this.projectDescription = projectDescription;
|
||||
public RequestedDependenciesHelpDocumentCustomizer(ProjectDescription description, InitializrMetadata metadata) {
|
||||
this.description = description;
|
||||
this.metadata = metadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customize(HelpDocument document) {
|
||||
this.projectDescription.getRequestedDependencies().forEach((id, dependency) -> {
|
||||
this.description.getRequestedDependencies().forEach((id, dependency) -> {
|
||||
Dependency dependencyMetadata = this.metadata.getDependencies().get(id);
|
||||
if (dependencyMetadata != null) {
|
||||
handleDependency(document, dependencyMetadata);
|
||||
|
||||
@@ -74,9 +74,9 @@ class DependencyManagementBuildCustomizerTests {
|
||||
}
|
||||
|
||||
private void customizeBuild(Build build, InitializrMetadata metadata) {
|
||||
MutableProjectDescription projectDescription = new MutableProjectDescription();
|
||||
projectDescription.setPlatformVersion(Version.parse("2.0.0.RELEASE"));
|
||||
new DependencyManagementBuildCustomizer(projectDescription, metadata).customize(build);
|
||||
MutableProjectDescription description = new MutableProjectDescription();
|
||||
description.setPlatformVersion(Version.parse("2.0.0.RELEASE"));
|
||||
new DependencyManagementBuildCustomizer(description, metadata).customize(build);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -40,33 +40,33 @@ public class ConditionalOnGradleVersionTests {
|
||||
|
||||
@Test
|
||||
void outcomeWithSpringBoot15() {
|
||||
MutableProjectDescription projectDescription = new MutableProjectDescription();
|
||||
projectDescription.setPlatformVersion(Version.parse("1.5.18.RELEASE"));
|
||||
String bean = outcomeFor(projectDescription);
|
||||
MutableProjectDescription description = new MutableProjectDescription();
|
||||
description.setPlatformVersion(Version.parse("1.5.18.RELEASE"));
|
||||
String bean = outcomeFor(description);
|
||||
assertThat(bean).isEqualTo("testGradle3");
|
||||
}
|
||||
|
||||
@Test
|
||||
void outcomeWithSpringBoot20() {
|
||||
MutableProjectDescription projectDescription = new MutableProjectDescription();
|
||||
projectDescription.setPlatformVersion(Version.parse("2.0.9.RELEASE"));
|
||||
String bean = outcomeFor(projectDescription);
|
||||
MutableProjectDescription description = new MutableProjectDescription();
|
||||
description.setPlatformVersion(Version.parse("2.0.9.RELEASE"));
|
||||
String bean = outcomeFor(description);
|
||||
assertThat(bean).isEqualTo("testGradle4");
|
||||
}
|
||||
|
||||
@Test
|
||||
void outcomeWithSpringBoot21() {
|
||||
MutableProjectDescription projectDescription = new MutableProjectDescription();
|
||||
projectDescription.setPlatformVersion(Version.parse("2.1.3.RELEASE"));
|
||||
String bean = outcomeFor(projectDescription);
|
||||
MutableProjectDescription description = new MutableProjectDescription();
|
||||
description.setPlatformVersion(Version.parse("2.1.3.RELEASE"));
|
||||
String bean = outcomeFor(description);
|
||||
assertThat(bean).isEqualTo("testGradle5");
|
||||
}
|
||||
|
||||
@Test
|
||||
void outcomeWithNoMatch() {
|
||||
MutableProjectDescription projectDescription = new MutableProjectDescription();
|
||||
projectDescription.setPlatformVersion(Version.parse("1.0.0.RELEASE"));
|
||||
this.projectTester.generate(projectDescription, (projectGenerationContext) -> {
|
||||
MutableProjectDescription description = new MutableProjectDescription();
|
||||
description.setPlatformVersion(Version.parse("1.0.0.RELEASE"));
|
||||
this.projectTester.generate(description, (projectGenerationContext) -> {
|
||||
assertThat(projectGenerationContext.getBeansOfType(String.class)).isEmpty();
|
||||
return null;
|
||||
});
|
||||
@@ -74,8 +74,8 @@ public class ConditionalOnGradleVersionTests {
|
||||
|
||||
@Test
|
||||
void outcomeWithNoAvailableSpringBootVersion() {
|
||||
MutableProjectDescription projectDescription = new MutableProjectDescription();
|
||||
this.projectTester.generate(projectDescription, (projectGenerationContext) -> {
|
||||
MutableProjectDescription description = new MutableProjectDescription();
|
||||
this.projectTester.generate(description, (projectGenerationContext) -> {
|
||||
assertThat(projectGenerationContext.getBeansOfType(String.class)).isEmpty();
|
||||
return null;
|
||||
});
|
||||
@@ -83,38 +83,37 @@ public class ConditionalOnGradleVersionTests {
|
||||
|
||||
@Test
|
||||
void outcomeWithSpringBoot15AndMultipleGenerations() {
|
||||
MutableProjectDescription projectDescription = new MutableProjectDescription();
|
||||
projectDescription.setPlatformVersion(Version.parse("1.5.18.RELEASE"));
|
||||
Map<String, String> candidates = candidatesFor(projectDescription, Gradle3Or4TestConfiguration.class);
|
||||
MutableProjectDescription description = new MutableProjectDescription();
|
||||
description.setPlatformVersion(Version.parse("1.5.18.RELEASE"));
|
||||
Map<String, String> candidates = candidatesFor(description, Gradle3Or4TestConfiguration.class);
|
||||
assertThat(candidates).containsOnlyKeys("gradle3", "gradle3AndLater");
|
||||
}
|
||||
|
||||
@Test
|
||||
void outcomeWithSpringBoot20AndMultipleGenerations() {
|
||||
MutableProjectDescription projectDescription = new MutableProjectDescription();
|
||||
projectDescription.setPlatformVersion(Version.parse("2.0.9.RELEASE"));
|
||||
Map<String, String> candidates = candidatesFor(projectDescription, Gradle3Or4TestConfiguration.class);
|
||||
MutableProjectDescription description = new MutableProjectDescription();
|
||||
description.setPlatformVersion(Version.parse("2.0.9.RELEASE"));
|
||||
Map<String, String> candidates = candidatesFor(description, Gradle3Or4TestConfiguration.class);
|
||||
assertThat(candidates).containsOnlyKeys("gradle4", "gradle3AndLater");
|
||||
}
|
||||
|
||||
@Test
|
||||
void outcomeWithSpringBoot21AndMultipleNonMatchingGenerations() {
|
||||
MutableProjectDescription projectDescription = new MutableProjectDescription();
|
||||
projectDescription.setPlatformVersion(Version.parse("2.1.3.RELEASE"));
|
||||
Map<String, String> candidates = candidatesFor(projectDescription, Gradle3Or4TestConfiguration.class);
|
||||
MutableProjectDescription description = new MutableProjectDescription();
|
||||
description.setPlatformVersion(Version.parse("2.1.3.RELEASE"));
|
||||
Map<String, String> candidates = candidatesFor(description, Gradle3Or4TestConfiguration.class);
|
||||
assertThat(candidates).containsOnlyKeys("gradle5");
|
||||
}
|
||||
|
||||
private String outcomeFor(MutableProjectDescription projectDescription) {
|
||||
return this.projectTester.generate(projectDescription, (projectGenerationContext) -> {
|
||||
private String outcomeFor(MutableProjectDescription description) {
|
||||
return this.projectTester.generate(description, (projectGenerationContext) -> {
|
||||
assertThat(projectGenerationContext.getBeansOfType(String.class)).hasSize(1);
|
||||
return projectGenerationContext.getBean(String.class);
|
||||
});
|
||||
}
|
||||
|
||||
private Map<String, String> candidatesFor(MutableProjectDescription projectDescription,
|
||||
Class<?>... extraConfigurations) {
|
||||
return this.projectTester.withConfiguration(extraConfigurations).generate(projectDescription,
|
||||
private Map<String, String> candidatesFor(MutableProjectDescription description, Class<?>... extraConfigurations) {
|
||||
return this.projectTester.withConfiguration(extraConfigurations).generate(description,
|
||||
(context) -> context.getBeansOfType(String.class));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user