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 theProjectGenerationContextand a default factory for theProjectGenerationContextthat 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> Tgenerate(ProjectDescription description, ProjectAssetGenerator<T> projectAssetGenerator) Generate project assets using the specifiedProjectAssetGeneratorfor the specifiedProjectDescription.Return theProjectGenerationConfigurationclass 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 theProjectDescriptionhave been registered but before it is refreshedcontextFactory- the factory to use to createProjectGenerationContextinstances
-
ProjectGenerator
Create an instance with a customizer for theProjectGenerationContextand a default factory for theProjectGenerationContextthat disables bean definition overriding.- Parameters:
contextConsumer- a consumer of the project generation context after contributors and theProjectDescriptionhave 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 specifiedProjectAssetGeneratorfor the specifiedProjectDescription.Create a dedicated
ProjectGenerationContextusing the suppliedcontextFactoryand then apply the following:- Register a
ProjectDescriptionbean based on the givendescriptionpost-processed by availableProjectDescriptionCustomizerbeans. - Process all registered
ProjectGenerationConfigurationclasses. - Apply the
contextConsumerto 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- theProjectAssetGeneratorto invoke- Returns:
- the generated content
- Throws:
ProjectGenerationException- if an error occurs while generating the project
- Register a
-
getCandidateProjectGenerationConfigurations
Return theProjectGenerationConfigurationclass names that should be considered. By default this method will load candidates usingSpringFactoriesLoaderwithProjectGenerationConfiguration.- Parameters:
description- the description of the project to generate- Returns:
- a list of candidate configurations
-