Class ProjectGenerator
java.lang.Object
io.spring.initializr.generator.project.ProjectGenerator
Main entry point for project generation that processes a
ProjectDescription
by
creating a dedicated ProjectGenerationContext
with all available
ProjectGenerationConfiguration
classes. Once the context has been started for a
particular ProjectDescription
, a ProjectAssetGenerator
can query it and
generate an appropriate asset (for instance, a project structure on disk).- Author:
- Andy Wilkinson, Stephane Nicoll
-
Constructor Summary
ConstructorsConstructorDescriptionProjectGenerator
(Consumer<ProjectGenerationContext> contextConsumer) Create an instance with a customizer for theProjectGenerationContext
and a default factory for theProjectGenerationContext
that disables bean definition overriding.ProjectGenerator
(Consumer<ProjectGenerationContext> contextConsumer, Supplier<? extends ProjectGenerationContext> contextFactory) Create an instance with a customizer for the project generator application context and a factory for theProjectGenerationContext
. -
Method Summary
Modifier and TypeMethodDescription<T> T
generate
(ProjectDescription description, ProjectAssetGenerator<T> projectAssetGenerator) Generate project assets using the specifiedProjectAssetGenerator
for the specifiedProjectDescription
.Return theProjectGenerationConfiguration
class names that should be considered.
-
Constructor Details
-
ProjectGenerator
public ProjectGenerator(Consumer<ProjectGenerationContext> contextConsumer, Supplier<? extends ProjectGenerationContext> contextFactory) Create an instance with a customizer for the project generator application context and a factory for theProjectGenerationContext
.- Parameters:
contextConsumer
- a consumer of the project generation context after contributors and theProjectDescription
have been registered but before it is refreshedcontextFactory
- the factory to use to createProjectGenerationContext
instances
-
ProjectGenerator
Create an instance with a customizer for theProjectGenerationContext
and a default factory for theProjectGenerationContext
that disables bean definition overriding.- Parameters:
contextConsumer
- a consumer of the project generation context after contributors and theProjectDescription
have been registered but before it is refreshed- See Also:
-
GenericApplicationContext.setAllowBeanDefinitionOverriding(boolean)
-
-
Method Details
-
generate
public <T> T generate(ProjectDescription description, ProjectAssetGenerator<T> projectAssetGenerator) throws ProjectGenerationException Generate project assets using the specifiedProjectAssetGenerator
for the specifiedProjectDescription
.Create a dedicated
ProjectGenerationContext
using the suppliedcontextFactory
and then apply the following:- Register a
ProjectDescription
bean based on the givendescription
post-processed by availableProjectDescriptionCustomizer
beans. - Process all registered
ProjectGenerationConfiguration
classes. - Apply the
contextConsumer
to further customize the context before it is refreshed.
- Type Parameters:
T
- the type that gathers the project assets- Parameters:
description
- the description of the project to generateprojectAssetGenerator
- theProjectAssetGenerator
to invoke- Returns:
- the generated content
- Throws:
ProjectGenerationException
- if an error occurs while generating the project
- Register a
-
getCandidateProjectGenerationConfigurations
Return theProjectGenerationConfiguration
class names that should be considered. By default this method will load candidates usingSpringFactoriesLoader
withProjectGenerationConfiguration
.- Parameters:
description
- the description of the project to generate- Returns:
- a list of candidate configurations
-