Repository: jhipster/jhipster-lite (java)

Issue:
preset.json in spring config 
See https://github.com/jhipster/jhipster-lite/blob/main/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemProjectsRepository.java#L29

Instead of hard coding this file, it should be nice to allow this as config in spring properties

Several use cases:
- in jhlite extension, we could use specific presets
- in spring profile vue, we could have vue instead of angular
- etc



Pull request description:
define preset json file name at spring boot application config
Fix #10553 

Patch:
diff --git a/src/main/java/tech/jhipster/lite/project/domain/resource/JHipsterPresetFile.java b/src/main/java/tech/jhipster/lite/project/domain/resource/JHipsterPresetFile.java
new file mode 100644
index 000000000..f47e6e3ba
--- /dev/null
+++ b/src/main/java/tech/jhipster/lite/project/domain/resource/JHipsterPresetFile.java
@@ -0,0 +1,3 @@
+package tech.jhipster.lite.project.domain.resource;
+
+public record JHipsterPresetFile(String name) {}
diff --git a/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemProjectsRepository.java b/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemProjectsRepository.java
index be5c1dc38..34215e22d 100644
--- a/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemProjectsRepository.java
+++ b/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemProjectsRepository.java
@@ -15,6 +15,7 @@ import tech.jhipster.lite.project.domain.ProjectsRepository;
 import tech.jhipster.lite.project.domain.download.Project;
 import tech.jhipster.lite.project.domain.history.ProjectHistory;
 import tech.jhipster.lite.project.domain.preset.Preset;
+import tech.jhipster.lite.project.domain.resource.JHipsterPresetFile;
 import tech.jhipster.lite.shared.error.domain.Assert;
 import tech.jhipster.lite.shared.error.domain.GeneratorException;
 
@@ -26,18 +27,24 @@ class FileSystemProjectsRepository implements ProjectsRepository {
   private static final String HISTORY_FOLDER = ".jhipster/modules";
   private static final String HISTORY_FILE = "history.json";
   private static final String PRESET_FOLDER = "/";
-  private static final String PRESET_FILE = "preset.json";
 
   private final ObjectMapper json;
   private final ProjectFormatter formatter;
   private final ProjectFiles projectFiles;
+  private final JHipsterPresetFile presetFile;
   private final ObjectWriter writer;
   private final FileSystemProjectDownloader downloader;
 
-  public FileSystemProjectsRepository(ObjectMapper json, ProjectFormatter formatter, ProjectFiles projectFiles) {
+  public FileSystemProjectsRepository(
+    ObjectMapper json,
+    ProjectFormatter formatter,
+    ProjectFiles projectFiles,
+    JHipsterPresetFile presetFile
+  ) {
     this.json = json;
     this.formatter = formatter;
     this.projectFiles = projectFiles;
+    this.presetFile = presetFile;
 
     writer = json.writerWithDefaultPrettyPrinter();
     downloader = new FileSystemProjectDownloader();
@@ -102,6 +109,6 @@ class FileSystemProjectsRepository implements ProjectsRepository {
   }
 
   private String presetFilePath() {
-    return PRESET_FOLDER + PRESET_FILE;
+    return PRESET_FOLDER + presetFile.name();
   }
 }
diff --git a/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/JHipsterPresetFileProperties.java b/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/JHipsterPresetFileProperties.java
new file mode 100644
index 000000000..4c9627666
--- /dev/null
+++ b/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/JHipsterPresetFileProperties.java
@@ -0,0 +1,17 @@
+package tech.jhipster.lite.project.infrastructure.secondary;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+@ConfigurationProperties("jhlite-preset-file")
+class JHipsterPresetFileProperties {
+
+  private String name;
+
+  public void setName(String name) {
+    this.name = name;
+  }
+
+  public String getName() {
+    return name;
+  }
+}
diff --git a/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/JHipsterPresetFilePropertiesConfiguration.java b/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/JHipsterPresetFilePropertiesConfiguration.java
new file mode 100644
index 000000000..8cb2a1a7a
--- /dev/null
+++ b/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/JHipsterPresetFilePropertiesConfiguration.java
@@ -0,0 +1,16 @@
+package tech.jhipster.lite.project.infrastructure.secondary;
+
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import tech.jhipster.lite.project.domain.resource.JHipsterPresetFile;
+
+@Configuration
+@EnableConfigurationProperties(JHipsterPresetFileProperties.class)
+class JHipsterPresetFilePropertiesConfiguration {
+
+  @Bean
+  JHipsterPresetFile jhipsterPresetFile() {
+    return new JHipsterPresetFile(new JHipsterPresetFileProperties().getName());
+  }
+}
diff --git a/src/main/resources/config/application.yml b/src/main/resources/config/application.yml
index b8d18f725..364a4bbc1 100644
--- a/src/main/resources/config/application.yml
+++ b/src/main/resources/config/application.yml
@@ -69,6 +69,9 @@ jhlite-hidden-resources:
   slugs:
     - svelte-core
 
+jhlite-preset-file:
+  name: preset.json
+
 server:
   port: 7471
 


Test patch:
diff --git a/src/test/java/tech/jhipster/lite/cucumber/CucumberConfiguration.java b/src/test/java/tech/jhipster/lite/cucumber/CucumberConfiguration.java
index 35a5b75ed..e78d24cdd 100644
--- a/src/test/java/tech/jhipster/lite/cucumber/CucumberConfiguration.java
+++ b/src/test/java/tech/jhipster/lite/cucumber/CucumberConfiguration.java
@@ -15,12 +15,18 @@ import org.springframework.web.client.RestTemplate;
 import tech.jhipster.lite.JHLiteApp;
 import tech.jhipster.lite.cucumber.rest.CucumberRestTestContext;
 import tech.jhipster.lite.project.infrastructure.secondary.FakedFileSystemProjectFilesConfiguration;
+import tech.jhipster.lite.project.infrastructure.secondary.FakedJHipsterPresetFilePropertiesConfiguration;
 import tech.jhipster.lite.project.infrastructure.secondary.MockedProjectFormatterConfiguration;
 
 @ActiveProfiles("test")
 @CucumberContextConfiguration
 @SpringBootTest(
-  classes = { JHLiteApp.class, MockedProjectFormatterConfiguration.class, FakedFileSystemProjectFilesConfiguration.class },
+  classes = {
+    JHLiteApp.class,
+    MockedProjectFormatterConfiguration.class,
+    FakedFileSystemProjectFilesConfiguration.class,
+    FakedJHipsterPresetFilePropertiesConfiguration.class,
+  },
   webEnvironment = WebEnvironment.RANDOM_PORT
 )
 public class CucumberConfiguration {
diff --git a/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FakedJHipsterPresetFilePropertiesConfiguration.java b/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FakedJHipsterPresetFilePropertiesConfiguration.java
new file mode 100644
index 000000000..cf4d34188
--- /dev/null
+++ b/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FakedJHipsterPresetFilePropertiesConfiguration.java
@@ -0,0 +1,14 @@
+package tech.jhipster.lite.project.infrastructure.secondary;
+
+import org.springframework.boot.test.context.TestConfiguration;
+import org.springframework.context.annotation.Bean;
+import tech.jhipster.lite.project.domain.resource.JHipsterPresetFile;
+
+@TestConfiguration
+public class FakedJHipsterPresetFilePropertiesConfiguration {
+
+  @Bean
+  JHipsterPresetFile jhipsterPresetFile() {
+    return new JHipsterPresetFile("preset.json");
+  }
+}
diff --git a/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemProjectsRepositoryTest.java b/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemProjectsRepositoryTest.java
index cb5e06cad..8d8c13b8e 100644
--- a/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemProjectsRepositoryTest.java
+++ b/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemProjectsRepositoryTest.java
@@ -33,6 +33,7 @@ import tech.jhipster.lite.project.domain.download.ProjectName;
 import tech.jhipster.lite.project.domain.history.ProjectHistory;
 import tech.jhipster.lite.project.domain.preset.Preset;
 import tech.jhipster.lite.project.domain.preset.PresetName;
+import tech.jhipster.lite.project.domain.resource.JHipsterPresetFile;
 import tech.jhipster.lite.shared.error.domain.GeneratorException;
 
 @UnitTest
@@ -41,7 +42,8 @@ class FileSystemProjectsRepositoryTest {
   private static final FileSystemProjectsRepository projects = new FileSystemProjectsRepository(
     JsonHelper.jsonMapper(),
     mock(ProjectFormatter.class),
-    mock(ProjectFiles.class)
+    mock(ProjectFiles.class),
+    mock(JHipsterPresetFile.class)
   );
 
   @Nested
@@ -148,7 +150,8 @@ class FileSystemProjectsRepositoryTest {
       FileSystemProjectsRepository fileSystemProjectsRepository = new FileSystemProjectsRepository(
         json,
         mock(ProjectFormatter.class),
-        mock(ProjectFiles.class)
+        mock(ProjectFiles.class),
+        mock(JHipsterPresetFile.class)
       );
 
       assertThatThrownBy(() -> fileSystemProjectsRepository.save(projectHistory())).isExactlyInstanceOf(GeneratorException.class);
@@ -191,7 +194,8 @@ class FileSystemProjectsRepositoryTest {
       FileSystemProjectsRepository fileSystemProjectsRepository = new FileSystemProjectsRepository(
         json,
         mock(ProjectFormatter.class),
-        mock(ProjectFiles.class)
+        mock(ProjectFiles.class),
+        mock(JHipsterPresetFile.class)
       );
 
       assertThatThrownBy(() -> fileSystemProjectsRepository.getHistory(path)).isExactlyInstanceOf(GeneratorException.class);
@@ -229,7 +233,8 @@ class FileSystemProjectsRepositoryTest {
       FileSystemProjectsRepository fileSystemProjectsRepository = new FileSystemProjectsRepository(
         json,
         mock(ProjectFormatter.class),
-        mockProjectFilesWithValidPresetJson()
+        mockProjectFilesWithValidPresetJson(),
+        new JHipsterPresetFile("preset.json")
       );
 
       assertThatThrownBy(fileSystemProjectsRepository::getPresets).isExactlyInstanceOf(GeneratorException.class);
@@ -242,7 +247,8 @@ class FileSystemProjectsRepositoryTest {
       FileSystemProjectsRepository fileSystemProjectsRepository = new FileSystemProjectsRepository(
         JsonHelper.jsonMapper(),
         mock(ProjectFormatter.class),
-        projectFiles
+        projectFiles,
+        new JHipsterPresetFile("preset.json")
       );
 
       assertThatThrownBy(fileSystemProjectsRepository::getPresets).isExactlyInstanceOf(GeneratorException.class);
@@ -253,7 +259,8 @@ class FileSystemProjectsRepositoryTest {
       FileSystemProjectsRepository fileSystemProjectsRepository = new FileSystemProjectsRepository(
         JsonHelper.jsonMapper(),
         mock(ProjectFormatter.class),
-        mockProjectFilesWithValidPresetJson()
+        mockProjectFilesWithValidPresetJson(),
+        new JHipsterPresetFile("preset.json")
       );
 
       Collection<Preset> presets = fileSystemProjectsRepository.getPresets();