Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce factory method for ProjectGenerator creation #1582

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class ProjectGenerationInvoker<R extends ProjectRequest> {

private final ProjectAssetGenerator<Path> projectAssetGenerator = new DefaultProjectAssetGenerator();

private final transient Map<Path, List<Path>> temporaryFiles = new ConcurrentHashMap<>();
private final Map<Path, List<Path>> temporaryFiles = new ConcurrentHashMap<>();

public ProjectGenerationInvoker(ApplicationContext parentApplicationContext,
ProjectRequestToDescriptionConverter<R> requestConverter) {
Expand All @@ -83,8 +83,7 @@ public ProjectGenerationResult invokeProjectStructureGeneration(R request) {
InitializrMetadata metadata = this.parentApplicationContext.getBean(InitializrMetadataProvider.class).get();
try {
ProjectDescription description = this.requestConverter.convert(request, metadata);
ProjectGenerator projectGenerator = new ProjectGenerator((
projectGenerationContext) -> customizeProjectGenerationContext(projectGenerationContext, metadata));
ProjectGenerator projectGenerator = createProjectGenerator(metadata);
ProjectGenerationResult result = projectGenerator.generate(description,
generateProject(description, request));
addTempFile(result.getRootDirectory(), result.getRootDirectory());
Expand Down Expand Up @@ -125,8 +124,7 @@ public byte[] invokeBuildGeneration(R request) {
InitializrMetadata metadata = this.parentApplicationContext.getBean(InitializrMetadataProvider.class).get();
try {
ProjectDescription description = this.requestConverter.convert(request, metadata);
ProjectGenerator projectGenerator = new ProjectGenerator((
projectGenerationContext) -> customizeProjectGenerationContext(projectGenerationContext, metadata));
ProjectGenerator projectGenerator = createProjectGenerator(metadata);
return projectGenerator.generate(description, generateBuild(request));
}
catch (ProjectGenerationException ex) {
Expand All @@ -135,6 +133,16 @@ public byte[] invokeBuildGeneration(R request) {
}
}

/**
* Creates the project generator using provided metadata.
* @param metadata metadata to build the {@link ProjectGenerator} used by this invoker
* @return project generator used to generate the project
*/
protected ProjectGenerator createProjectGenerator(InitializrMetadata metadata) {
return new ProjectGenerator(
(projectGenerationContext) -> customizeProjectGenerationContext(projectGenerationContext, metadata));
}

private ProjectAssetGenerator<byte[]> generateBuild(R request) {
return (context) -> {
byte[] content = generateBuild(context);
Expand Down