Skip to content

Commit

Permalink
Merge pull request #1582 from zambrovski
Browse files Browse the repository at this point in the history
* pr/1582:
  Introduce factory method for ProjectGenerator creation

Closes gh-1582
  • Loading branch information
mhalbritter committed Nov 11, 2024
2 parents 9e26824 + 832cfae commit 1d8a6cb
Showing 1 changed file with 13 additions and 5 deletions.
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

0 comments on commit 1d8a6cb

Please sign in to comment.