mirror of
https://gitee.com/dcren/initializr.git
synced 2025-09-18 17:48:14 +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));
|
||||
}
|
||||
|
||||
|
@@ -52,10 +52,10 @@ class ProjectGeneratorTests {
|
||||
description.setBuildSystem(new MavenBuildSystem());
|
||||
Version platformVersion = Version.parse("2.1.0.RELEASE");
|
||||
description.setPackageName("com.example.test");
|
||||
ProjectDescription ProjectDescription = this.projectTester.generate(description,
|
||||
ProjectDescription customizedDescription = this.projectTester.generate(description,
|
||||
(projectGenerationContext) -> projectGenerationContext.getBean(ProjectDescription.class));
|
||||
assertThat(ProjectDescription.getPlatformVersion()).isEqualTo(platformVersion);
|
||||
assertThat(ProjectDescription.getPackageName()).isEqualTo("com.example.test");
|
||||
assertThat(customizedDescription.getPlatformVersion()).isEqualTo(platformVersion);
|
||||
assertThat(customizedDescription.getPackageName()).isEqualTo("com.example.test");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -73,10 +73,10 @@ class ProjectGeneratorTests {
|
||||
description.setGroupId("com.example.demo");
|
||||
description.setName("Original");
|
||||
|
||||
ProjectDescription ProjectDescription = tester.generate(description,
|
||||
ProjectDescription customizedDescription = tester.generate(description,
|
||||
(projectGenerationContext) -> projectGenerationContext.getBean(ProjectDescription.class));
|
||||
assertThat(ProjectDescription.getGroupId()).isEqualTo("com.acme");
|
||||
assertThat(ProjectDescription.getName()).isEqualTo("Test");
|
||||
assertThat(customizedDescription.getGroupId()).isEqualTo("com.acme");
|
||||
assertThat(customizedDescription.getName()).isEqualTo("Test");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -33,13 +33,13 @@ import org.springframework.util.StringUtils;
|
||||
class OnBuildSystemCondition extends ProjectGenerationCondition {
|
||||
|
||||
@Override
|
||||
protected boolean matches(ProjectDescription projectDescription, ConditionContext context,
|
||||
protected boolean matches(ProjectDescription description, ConditionContext context,
|
||||
AnnotatedTypeMetadata metadata) {
|
||||
MultiValueMap<String, Object> attributes = metadata
|
||||
.getAllAnnotationAttributes(ConditionalOnBuildSystem.class.getName());
|
||||
String buildSystemId = (String) attributes.getFirst("value");
|
||||
String dialect = (String) attributes.getFirst("dialect");
|
||||
BuildSystem buildSystem = projectDescription.getBuildSystem();
|
||||
BuildSystem buildSystem = description.getBuildSystem();
|
||||
if (buildSystem.id().equals(buildSystemId)) {
|
||||
if (StringUtils.hasText(dialect)) {
|
||||
return dialect.equals(buildSystem.dialect());
|
||||
|
@@ -31,15 +31,15 @@ import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||
class OnLanguageCondition extends ProjectGenerationCondition {
|
||||
|
||||
@Override
|
||||
protected boolean matches(ProjectDescription projectDescription, ConditionContext context,
|
||||
protected boolean matches(ProjectDescription description, ConditionContext context,
|
||||
AnnotatedTypeMetadata metadata) {
|
||||
if (projectDescription.getLanguage() == null) {
|
||||
if (description.getLanguage() == null) {
|
||||
return false;
|
||||
}
|
||||
String languageId = (String) metadata.getAllAnnotationAttributes(ConditionalOnLanguage.class.getName())
|
||||
.getFirst("value");
|
||||
Language language = Language.forId(languageId, null);
|
||||
return projectDescription.getLanguage().id().equals(language.id());
|
||||
return description.getLanguage().id().equals(language.id());
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -31,15 +31,15 @@ import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||
class OnPackagingCondition extends ProjectGenerationCondition {
|
||||
|
||||
@Override
|
||||
protected boolean matches(ProjectDescription projectDescription, ConditionContext context,
|
||||
protected boolean matches(ProjectDescription description, ConditionContext context,
|
||||
AnnotatedTypeMetadata metadata) {
|
||||
if (projectDescription.getPackaging() == null) {
|
||||
if (description.getPackaging() == null) {
|
||||
return false;
|
||||
}
|
||||
String packagingId = (String) metadata.getAllAnnotationAttributes(ConditionalOnPackaging.class.getName())
|
||||
.getFirst("value");
|
||||
Packaging packaging = Packaging.forId(packagingId);
|
||||
return projectDescription.getPackaging().id().equals(packaging.id());
|
||||
return description.getPackaging().id().equals(packaging.id());
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -35,9 +35,9 @@ import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||
class OnPlatformVersionCondition extends ProjectGenerationCondition {
|
||||
|
||||
@Override
|
||||
protected boolean matches(ProjectDescription projectDescription, ConditionContext context,
|
||||
protected boolean matches(ProjectDescription description, ConditionContext context,
|
||||
AnnotatedTypeMetadata metadata) {
|
||||
Version platformVersion = projectDescription.getPlatformVersion();
|
||||
Version platformVersion = description.getPlatformVersion();
|
||||
if (platformVersion == null) {
|
||||
return false;
|
||||
}
|
||||
|
@@ -30,11 +30,11 @@ import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||
class OnRequestedDependencyCondition extends ProjectGenerationCondition {
|
||||
|
||||
@Override
|
||||
protected boolean matches(ProjectDescription projectDescription, ConditionContext context,
|
||||
protected boolean matches(ProjectDescription description, ConditionContext context,
|
||||
AnnotatedTypeMetadata metadata) {
|
||||
String id = (String) metadata.getAnnotationAttributes(ConditionalOnRequestedDependency.class.getName())
|
||||
.get("value");
|
||||
return projectDescription.getRequestedDependencies().containsKey(id);
|
||||
return description.getRequestedDependencies().containsKey(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -31,11 +31,11 @@ public abstract class ProjectGenerationCondition implements Condition {
|
||||
|
||||
@Override
|
||||
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
|
||||
ProjectDescription projectDescription = context.getBeanFactory().getBean(ProjectDescription.class);
|
||||
return matches(projectDescription, context, metadata);
|
||||
ProjectDescription description = context.getBeanFactory().getBean(ProjectDescription.class);
|
||||
return matches(description, context, metadata);
|
||||
}
|
||||
|
||||
protected abstract boolean matches(ProjectDescription projectDescription, ConditionContext context,
|
||||
protected abstract boolean matches(ProjectDescription description, ConditionContext context,
|
||||
AnnotatedTypeMetadata metadata);
|
||||
|
||||
}
|
||||
|
@@ -54,9 +54,9 @@ public class DefaultProjectAssetGenerator implements ProjectAssetGenerator<Path>
|
||||
|
||||
@Override
|
||||
public Path generate(ProjectGenerationContext context) throws IOException {
|
||||
ProjectDescription projectDescription = context.getBean(ProjectDescription.class);
|
||||
Path projectRoot = resolveProjectDirectoryFactory(context).createProjectDirectory(projectDescription);
|
||||
Path projectDirectory = initializerProjectDirectory(projectRoot, projectDescription);
|
||||
ProjectDescription description = context.getBean(ProjectDescription.class);
|
||||
Path projectRoot = resolveProjectDirectoryFactory(context).createProjectDirectory(description);
|
||||
Path projectDirectory = initializerProjectDirectory(projectRoot, description);
|
||||
List<ProjectContributor> contributors = context.getBeanProvider(ProjectContributor.class).orderedStream()
|
||||
.collect(Collectors.toList());
|
||||
for (ProjectContributor contributor : contributors) {
|
||||
|
@@ -39,30 +39,29 @@ class ConditionalOnBuildSystemTests {
|
||||
|
||||
@Test
|
||||
void outcomeWithMavenBuildSystem() {
|
||||
MutableProjectDescription projectDescription = new MutableProjectDescription();
|
||||
projectDescription.setBuildSystem(new MavenBuildSystem());
|
||||
assertThat(candidatesFor(projectDescription, BuildSystemTestConfiguration.class)).containsOnlyKeys("maven");
|
||||
MutableProjectDescription description = new MutableProjectDescription();
|
||||
description.setBuildSystem(new MavenBuildSystem());
|
||||
assertThat(candidatesFor(description, BuildSystemTestConfiguration.class)).containsOnlyKeys("maven");
|
||||
}
|
||||
|
||||
@Test
|
||||
void outcomeWithGradleBuildSystem() {
|
||||
MutableProjectDescription projectDescription = new MutableProjectDescription();
|
||||
projectDescription.setBuildSystem(new GradleBuildSystem());
|
||||
assertThat(candidatesFor(projectDescription, BuildSystemTestConfiguration.class)).containsOnlyKeys("gradle");
|
||||
MutableProjectDescription description = new MutableProjectDescription();
|
||||
description.setBuildSystem(new GradleBuildSystem());
|
||||
assertThat(candidatesFor(description, BuildSystemTestConfiguration.class)).containsOnlyKeys("gradle");
|
||||
}
|
||||
|
||||
@Test
|
||||
void conditionalOnGradleWithKotlinDialectMatchesWhenGradleBuildSystemUsesKotlinDialect() {
|
||||
MutableProjectDescription projectDescription = new MutableProjectDescription();
|
||||
projectDescription.setBuildSystem(new GradleBuildSystem("kotlin"));
|
||||
assertThat(candidatesFor(projectDescription, BuildSystemTestConfiguration.class)).containsOnlyKeys("gradle",
|
||||
MutableProjectDescription description = new MutableProjectDescription();
|
||||
description.setBuildSystem(new GradleBuildSystem("kotlin"));
|
||||
assertThat(candidatesFor(description, BuildSystemTestConfiguration.class)).containsOnlyKeys("gradle",
|
||||
"gradleKotlin");
|
||||
}
|
||||
|
||||
private Map<String, String> candidatesFor(MutableProjectDescription projectDescription,
|
||||
Class<?>... extraConfigurations) {
|
||||
private Map<String, String> candidatesFor(MutableProjectDescription description, Class<?>... extraConfigurations) {
|
||||
try (ProjectGenerationContext context = new ProjectGenerationContext()) {
|
||||
context.registerBean(ProjectDescription.class, () -> projectDescription);
|
||||
context.registerBean(ProjectDescription.class, () -> description);
|
||||
context.register(extraConfigurations);
|
||||
context.refresh();
|
||||
return context.getBeansOfType(String.class);
|
||||
|
@@ -40,9 +40,9 @@ class ConditionalOnLanguageTests {
|
||||
|
||||
@Test
|
||||
void outcomeWithJavaLanguage() {
|
||||
MutableProjectDescription projectDescription = new MutableProjectDescription();
|
||||
projectDescription.setLanguage(new JavaLanguage());
|
||||
assertCondition(projectDescription, (context) -> {
|
||||
MutableProjectDescription description = new MutableProjectDescription();
|
||||
description.setLanguage(new JavaLanguage());
|
||||
assertCondition(description, (context) -> {
|
||||
assertThat(context.getBeansOfType(String.class)).hasSize(1);
|
||||
assertThat(context.getBean(String.class)).isEqualTo("testJava");
|
||||
});
|
||||
@@ -50,9 +50,9 @@ class ConditionalOnLanguageTests {
|
||||
|
||||
@Test
|
||||
void outcomeWithGroovyBuildSystem() {
|
||||
MutableProjectDescription projectDescription = new MutableProjectDescription();
|
||||
projectDescription.setLanguage(new GroovyLanguage());
|
||||
assertCondition(projectDescription, (context) -> {
|
||||
MutableProjectDescription description = new MutableProjectDescription();
|
||||
description.setLanguage(new GroovyLanguage());
|
||||
assertCondition(description, (context) -> {
|
||||
assertThat(context.getBeansOfType(String.class)).hasSize(1);
|
||||
assertThat(context.getBean(String.class)).isEqualTo("testGroovy");
|
||||
});
|
||||
@@ -60,21 +60,20 @@ class ConditionalOnLanguageTests {
|
||||
|
||||
@Test
|
||||
void outcomeWithNoMatch() {
|
||||
MutableProjectDescription projectDescription = new MutableProjectDescription();
|
||||
projectDescription.setLanguage(new KotlinLanguage());
|
||||
assertCondition(projectDescription, (context) -> assertThat(context.getBeansOfType(String.class)).isEmpty());
|
||||
MutableProjectDescription description = new MutableProjectDescription();
|
||||
description.setLanguage(new KotlinLanguage());
|
||||
assertCondition(description, (context) -> assertThat(context.getBeansOfType(String.class)).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void outcomeWithNoAvailableLanguage() {
|
||||
MutableProjectDescription projectDescription = new MutableProjectDescription();
|
||||
assertCondition(projectDescription, (context) -> assertThat(context.getBeansOfType(String.class)).isEmpty());
|
||||
MutableProjectDescription description = new MutableProjectDescription();
|
||||
assertCondition(description, (context) -> assertThat(context.getBeansOfType(String.class)).isEmpty());
|
||||
}
|
||||
|
||||
private void assertCondition(MutableProjectDescription projectDescription,
|
||||
Consumer<ProjectGenerationContext> context) {
|
||||
private void assertCondition(MutableProjectDescription description, Consumer<ProjectGenerationContext> context) {
|
||||
try (ProjectGenerationContext projectContext = new ProjectGenerationContext()) {
|
||||
projectContext.registerBean(ProjectDescription.class, () -> projectDescription);
|
||||
projectContext.registerBean(ProjectDescription.class, () -> description);
|
||||
projectContext.register(LanguageTestConfiguration.class);
|
||||
projectContext.refresh();
|
||||
context.accept(projectContext);
|
||||
|
@@ -39,9 +39,9 @@ class ConditionalOnPackagingTests {
|
||||
|
||||
@Test
|
||||
void outcomeWithJarPackaging() {
|
||||
MutableProjectDescription projectDescription = new MutableProjectDescription();
|
||||
projectDescription.setPackaging(new JarPackaging());
|
||||
assertCondition(projectDescription, (context) -> {
|
||||
MutableProjectDescription description = new MutableProjectDescription();
|
||||
description.setPackaging(new JarPackaging());
|
||||
assertCondition(description, (context) -> {
|
||||
assertThat(context.getBeansOfType(String.class)).hasSize(1);
|
||||
assertThat(context.getBean(String.class)).isEqualTo("testJar");
|
||||
});
|
||||
@@ -49,9 +49,9 @@ class ConditionalOnPackagingTests {
|
||||
|
||||
@Test
|
||||
void outcomeWithWarPackaging() {
|
||||
MutableProjectDescription projectDescription = new MutableProjectDescription();
|
||||
projectDescription.setPackaging(new WarPackaging());
|
||||
assertCondition(projectDescription, (context) -> {
|
||||
MutableProjectDescription description = new MutableProjectDescription();
|
||||
description.setPackaging(new WarPackaging());
|
||||
assertCondition(description, (context) -> {
|
||||
assertThat(context.getBeansOfType(String.class)).hasSize(1);
|
||||
assertThat(context.getBean(String.class)).isEqualTo("testWar");
|
||||
});
|
||||
@@ -59,14 +59,13 @@ class ConditionalOnPackagingTests {
|
||||
|
||||
@Test
|
||||
void outcomeWithNoAvailablePackaging() {
|
||||
MutableProjectDescription projectDescription = new MutableProjectDescription();
|
||||
assertCondition(projectDescription, (context) -> assertThat(context.getBeansOfType(String.class)).isEmpty());
|
||||
MutableProjectDescription description = new MutableProjectDescription();
|
||||
assertCondition(description, (context) -> assertThat(context.getBeansOfType(String.class)).isEmpty());
|
||||
}
|
||||
|
||||
private void assertCondition(MutableProjectDescription projectDescription,
|
||||
Consumer<ProjectGenerationContext> context) {
|
||||
private void assertCondition(MutableProjectDescription description, Consumer<ProjectGenerationContext> context) {
|
||||
try (ProjectGenerationContext projectContext = new ProjectGenerationContext()) {
|
||||
projectContext.registerBean(ProjectDescription.class, () -> projectDescription);
|
||||
projectContext.registerBean(ProjectDescription.class, () -> description);
|
||||
projectContext.register(PackagingTestConfiguration.class);
|
||||
projectContext.refresh();
|
||||
context.accept(projectContext);
|
||||
|
@@ -38,60 +38,57 @@ class ConditionalOnPlatformVersionTests {
|
||||
|
||||
@Test
|
||||
void outcomeWithMatchingRange() {
|
||||
MutableProjectDescription projectDescription = new MutableProjectDescription();
|
||||
projectDescription.setPlatformVersion(Version.parse("1.2.0.RELEASE"));
|
||||
assertThat(candidatesFor(projectDescription, PlatformVersionTestConfiguration.class)).containsOnlyKeys("first");
|
||||
MutableProjectDescription description = new MutableProjectDescription();
|
||||
description.setPlatformVersion(Version.parse("1.2.0.RELEASE"));
|
||||
assertThat(candidatesFor(description, PlatformVersionTestConfiguration.class)).containsOnlyKeys("first");
|
||||
}
|
||||
|
||||
@Test
|
||||
void outcomeWithMatchingOpenRange() {
|
||||
MutableProjectDescription projectDescription = new MutableProjectDescription();
|
||||
projectDescription.setPlatformVersion(Version.parse("2.0.1.RELEASE"));
|
||||
assertThat(candidatesFor(projectDescription, PlatformVersionTestConfiguration.class))
|
||||
.containsOnlyKeys("second");
|
||||
MutableProjectDescription description = new MutableProjectDescription();
|
||||
description.setPlatformVersion(Version.parse("2.0.1.RELEASE"));
|
||||
assertThat(candidatesFor(description, PlatformVersionTestConfiguration.class)).containsOnlyKeys("second");
|
||||
}
|
||||
|
||||
@Test
|
||||
void outcomeWithMatchingStartOfOpenRange() {
|
||||
MutableProjectDescription projectDescription = new MutableProjectDescription();
|
||||
projectDescription.setPlatformVersion(Version.parse("2.0.0.M1"));
|
||||
assertThat(candidatesFor(projectDescription, PlatformVersionTestConfiguration.class))
|
||||
.containsOnlyKeys("second");
|
||||
MutableProjectDescription description = new MutableProjectDescription();
|
||||
description.setPlatformVersion(Version.parse("2.0.0.M1"));
|
||||
assertThat(candidatesFor(description, PlatformVersionTestConfiguration.class)).containsOnlyKeys("second");
|
||||
}
|
||||
|
||||
@Test
|
||||
void outcomeWithNoMatch() {
|
||||
MutableProjectDescription projectDescription = new MutableProjectDescription();
|
||||
projectDescription.setPlatformVersion(Version.parse("0.1.0"));
|
||||
assertThat(candidatesFor(projectDescription, PlatformVersionTestConfiguration.class)).isEmpty();
|
||||
MutableProjectDescription description = new MutableProjectDescription();
|
||||
description.setPlatformVersion(Version.parse("0.1.0"));
|
||||
assertThat(candidatesFor(description, PlatformVersionTestConfiguration.class)).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void outcomeWithNoAvailablePlatformVersion() {
|
||||
MutableProjectDescription projectDescription = new MutableProjectDescription();
|
||||
assertThat(candidatesFor(projectDescription, PlatformVersionTestConfiguration.class)).isEmpty();
|
||||
MutableProjectDescription description = new MutableProjectDescription();
|
||||
assertThat(candidatesFor(description, PlatformVersionTestConfiguration.class)).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void outcomeWithSeveralRangesAndMatchingVersion() {
|
||||
MutableProjectDescription projectDescription = new MutableProjectDescription();
|
||||
projectDescription.setPlatformVersion(Version.parse("2.1.0.RELEASE"));
|
||||
assertThat(candidatesFor(projectDescription, PlatformVersionTestConfiguration.class,
|
||||
MutableProjectDescription description = new MutableProjectDescription();
|
||||
description.setPlatformVersion(Version.parse("2.1.0.RELEASE"));
|
||||
assertThat(candidatesFor(description, PlatformVersionTestConfiguration.class,
|
||||
OneOrTwoPlatformVersionTestConfiguration.class)).containsOnlyKeys("second", "firstOrSecond");
|
||||
}
|
||||
|
||||
@Test
|
||||
void outcomeWithSeveralRangesAndNonMatchingVersion() {
|
||||
MutableProjectDescription projectDescription = new MutableProjectDescription();
|
||||
projectDescription.setPlatformVersion(Version.parse("2.0.0.M2"));
|
||||
assertThat(candidatesFor(projectDescription, PlatformVersionTestConfiguration.class,
|
||||
MutableProjectDescription description = new MutableProjectDescription();
|
||||
description.setPlatformVersion(Version.parse("2.0.0.M2"));
|
||||
assertThat(candidatesFor(description, PlatformVersionTestConfiguration.class,
|
||||
OneOrTwoPlatformVersionTestConfiguration.class)).containsOnlyKeys("second");
|
||||
}
|
||||
|
||||
private Map<String, String> candidatesFor(MutableProjectDescription projectDescription,
|
||||
Class<?>... extraConfigurations) {
|
||||
private Map<String, String> candidatesFor(MutableProjectDescription description, Class<?>... extraConfigurations) {
|
||||
try (ProjectGenerationContext context = new ProjectGenerationContext()) {
|
||||
context.registerBean(ProjectDescription.class, () -> projectDescription);
|
||||
context.registerBean(ProjectDescription.class, () -> description);
|
||||
context.register(PlatformVersionTestConfiguration.class);
|
||||
context.register(extraConfigurations);
|
||||
context.refresh();
|
||||
|
@@ -39,9 +39,9 @@ class ConditionalOnRequestedDependencyTests {
|
||||
|
||||
@Test
|
||||
void outcomeWithMatchingDependency() {
|
||||
MutableProjectDescription projectDescription = new MutableProjectDescription();
|
||||
projectDescription.addDependency("web", mock(Dependency.class));
|
||||
assertCondition(projectDescription, (context) -> {
|
||||
MutableProjectDescription description = new MutableProjectDescription();
|
||||
description.addDependency("web", mock(Dependency.class));
|
||||
assertCondition(description, (context) -> {
|
||||
assertThat(context.getBeansOfType(String.class)).hasSize(1);
|
||||
assertThat(context.getBean(String.class)).isEqualTo("webDependency");
|
||||
});
|
||||
@@ -49,15 +49,14 @@ class ConditionalOnRequestedDependencyTests {
|
||||
|
||||
@Test
|
||||
void outcomeWithNoMatch() {
|
||||
MutableProjectDescription projectDescription = new MutableProjectDescription();
|
||||
projectDescription.addDependency("another", mock(Dependency.class));
|
||||
assertCondition(projectDescription, (context) -> assertThat(context.getBeansOfType(String.class)).isEmpty());
|
||||
MutableProjectDescription description = new MutableProjectDescription();
|
||||
description.addDependency("another", mock(Dependency.class));
|
||||
assertCondition(description, (context) -> assertThat(context.getBeansOfType(String.class)).isEmpty());
|
||||
}
|
||||
|
||||
private void assertCondition(MutableProjectDescription projectDescription,
|
||||
Consumer<ProjectGenerationContext> context) {
|
||||
private void assertCondition(MutableProjectDescription description, Consumer<ProjectGenerationContext> context) {
|
||||
try (ProjectGenerationContext projectContext = new ProjectGenerationContext()) {
|
||||
projectContext.registerBean(ProjectDescription.class, () -> projectDescription);
|
||||
projectContext.registerBean(ProjectDescription.class, () -> description);
|
||||
projectContext.register(RequestedDependencyTestConfiguration.class);
|
||||
projectContext.refresh();
|
||||
context.accept(projectContext);
|
||||
|
@@ -73,10 +73,10 @@ public class ProjectGenerationInvoker {
|
||||
public ProjectGenerationResult invokeProjectStructureGeneration(ProjectRequest request) {
|
||||
InitializrMetadata metadata = this.parentApplicationContext.getBean(InitializrMetadataProvider.class).get();
|
||||
try {
|
||||
ProjectDescription projectDescription = this.converter.convert(request, metadata);
|
||||
ProjectDescription description = this.converter.convert(request, metadata);
|
||||
ProjectGenerator projectGenerator = new ProjectGenerator((
|
||||
projectGenerationContext) -> customizeProjectGenerationContext(projectGenerationContext, metadata));
|
||||
ProjectGenerationResult result = projectGenerator.generate(projectDescription, generateProject(request));
|
||||
ProjectGenerationResult result = projectGenerator.generate(description, generateProject(request));
|
||||
addTempFile(result.getRootDirectory(), result.getRootDirectory());
|
||||
return result;
|
||||
}
|
||||
@@ -104,10 +104,10 @@ public class ProjectGenerationInvoker {
|
||||
public byte[] invokeBuildGeneration(ProjectRequest request) {
|
||||
InitializrMetadata metadata = this.parentApplicationContext.getBean(InitializrMetadataProvider.class).get();
|
||||
try {
|
||||
ProjectDescription projectDescription = this.converter.convert(request, metadata);
|
||||
ProjectDescription description = this.converter.convert(request, metadata);
|
||||
ProjectGenerator projectGenerator = new ProjectGenerator((
|
||||
projectGenerationContext) -> customizeProjectGenerationContext(projectGenerationContext, metadata));
|
||||
return projectGenerator.generate(projectDescription, generateBuild(request));
|
||||
return projectGenerator.generate(description, generateBuild(request));
|
||||
}
|
||||
catch (ProjectGenerationException ex) {
|
||||
publishProjectFailedEvent(request, metadata, ex);
|
||||
@@ -160,7 +160,7 @@ public class ProjectGenerationInvoker {
|
||||
}
|
||||
|
||||
private byte[] generateBuild(ProjectGenerationContext context) throws IOException {
|
||||
ProjectDescription projectDescription = context.getBean(ProjectDescription.class);
|
||||
ProjectDescription description = context.getBean(ProjectDescription.class);
|
||||
StringWriter out = new StringWriter();
|
||||
BuildWriter buildWriter = context.getBeanProvider(BuildWriter.class).getIfAvailable();
|
||||
if (buildWriter != null) {
|
||||
@@ -168,8 +168,7 @@ public class ProjectGenerationInvoker {
|
||||
return out.toString().getBytes();
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException(
|
||||
"No BuildWriter implementation found for " + projectDescription.getLanguage());
|
||||
throw new IllegalStateException("No BuildWriter implementation found for " + description.getLanguage());
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -27,12 +27,12 @@ import io.spring.initializr.generator.project.ProjectDescription;
|
||||
*/
|
||||
public class ProjectGenerationResult {
|
||||
|
||||
private final ProjectDescription projectDescription;
|
||||
private final ProjectDescription description;
|
||||
|
||||
private final Path rootDirectory;
|
||||
|
||||
ProjectGenerationResult(ProjectDescription projectDescription, Path rootDirectory) {
|
||||
this.projectDescription = projectDescription;
|
||||
ProjectGenerationResult(ProjectDescription description, Path rootDirectory) {
|
||||
this.description = description;
|
||||
this.rootDirectory = rootDirectory;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public class ProjectGenerationResult {
|
||||
* @return the project description
|
||||
*/
|
||||
public ProjectDescription getProjectDescription() {
|
||||
return this.projectDescription;
|
||||
return this.description;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user