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:
parametrize the preset json file name in the spring boot configuration
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..92a10f52b
--- /dev/null
+++ b/src/main/java/tech/jhipster/lite/project/domain/resource/JHipsterPresetFile.java
@@ -0,0 +1,10 @@
+package tech.jhipster.lite.project.domain.resource;
+
+import tech.jhipster.lite.project.domain.preset.PresetName;
+import tech.jhipster.lite.shared.error.domain.Assert;
+
+public record JHipsterPresetFile(PresetName name) {
+  public JHipsterPresetFile {
+    Assert.notNull("name", 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..a8bc9bf22 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().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..ff9f859e9
--- /dev/null
+++ b/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/JHipsterPresetFilePropertiesConfiguration.java
@@ -0,0 +1,17 @@
+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.preset.PresetName;
+import tech.jhipster.lite.project.domain.resource.JHipsterPresetFile;
+
+@Configuration
+@EnableConfigurationProperties(JHipsterPresetFileProperties.class)
+class JHipsterPresetFilePropertiesConfiguration {
+
+  @Bean
+  JHipsterPresetFile jhipsterPresetFile(JHipsterPresetFileProperties presetFileProperties) {
+    return new JHipsterPresetFile(PresetName.from(presetFileProperties.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/project/infrastructure/secondary/FakedJHipsterPresetFilePropertiesConfiguration.java b/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FakedJHipsterPresetFilePropertiesConfiguration.java
new file mode 100644
index 000000000..1332c55b5
--- /dev/null
+++ b/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FakedJHipsterPresetFilePropertiesConfiguration.java
@@ -0,0 +1,15 @@
+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.preset.PresetName;
+import tech.jhipster.lite.project.domain.resource.JHipsterPresetFile;
+
+@TestConfiguration
+public class FakedJHipsterPresetFilePropertiesConfiguration {
+
+  @Bean
+  JHipsterPresetFile jhipsterPresetFile() {
+    return new JHipsterPresetFile(PresetName.from("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..523538edf 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(PresetName.from("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(PresetName.from("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(PresetName.from("preset.json"))
       );
 
       Collection<Preset> presets = fileSystemProjectsRepository.getPresets();