Repository: jhipster/jhipster-lite
Pull request #10609 (2024-08-19 08:40:07)

Revert "parametrize the preset json file name in the spring boot configuration"
Reverts jhipster/jhipster-lite#10590

There're still some issues with customjhlite:
```
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jhipsterPresetFile' defined in class path resource [tech/jhipster/lite/project/infrastructure/secondary/JHipsterPresetFilePropertiesConfiguration.class]: Failed to instantiate [tech.jhipster.lite.project.domain.resource.JHipsterPresetFile]: Factory method 'jhipsterPresetFile' threw exception with message: The field "name" is mandatory and wasn't set (null)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:648)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:636)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1355)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1185)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:562)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:522)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:337)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:335)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
	at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:254)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1443)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1353)
	at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:904)
	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:782)
	... 80 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [tech.jhipster.lite.project.domain.resource.JHipsterPresetFile]: Factory method 'jhipsterPresetFile' threw exception with message: The field "name" is mandatory and wasn't set (null)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:178)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:644)
	... 94 common frames omitted
Caused by: tech.jhipster.lite.shared.error.domain.MissingMandatoryValueException: The field "name" is mandatory and wasn't set (null)
	at tech.jhipster.lite.shared.error.domain.MissingMandatoryValueException.forNullValue(MissingMandatoryValueException.java:14)
	at tech.jhipster.lite.shared.error.domain.Assert.notNull(Assert.java:41)
	at tech.jhipster.lite.shared.error.domain.Assert$StringAsserter.notNull(Assert.java:334)
	at tech.jhipster.lite.shared.error.domain.Assert$StringAsserter.notBlank(Assert.java:347)
	at tech.jhipster.lite.shared.error.domain.Assert.notBlank(Assert.java:56)
	at tech.jhipster.lite.project.domain.preset.PresetName.<init>(PresetName.java:7)
	at tech.jhipster.lite.project.domain.preset.PresetName.from(PresetName.java:11)
	at tech.jhipster.lite.project.infrastructure.secondary.JHipsterPresetFilePropertiesConfiguration.jhipsterPresetFile(JHipsterPresetFilePropertiesConfiguration.java:15)
	at tech.jhipster.lite.project.infrastructure.secondary.JHipsterPresetFilePropertiesConfiguration$$SpringCGLIB$$0.CGLIB$jhipsterPresetFile$0(<generated>)
	at tech.jhipster.lite.project.infrastructure.secondary.JHipsterPresetFilePropertiesConfiguration$$SpringCGLIB$$FastClass$$1.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:258)
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:348)
	at tech.jhipster.lite.project.infrastructure.secondary.JHipsterPresetFilePropertiesConfiguration$$SpringCGLIB$$0.jhipsterPresetFile(<generated>)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:146)
	... 95 common frames omitted
```


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
deleted file mode 100644
index 92a10f52b..000000000
--- a/src/main/java/tech/jhipster/lite/project/domain/resource/JHipsterPresetFile.java
+++ /dev/null
@@ -1,10 +0,0 @@
-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 a8bc9bf22..be5c1dc38 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,7 +15,6 @@ 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;
 
@@ -27,24 +26,18 @@ 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,
-    JHipsterPresetFile presetFile
-  ) {
+  public FileSystemProjectsRepository(ObjectMapper json, ProjectFormatter formatter, ProjectFiles projectFiles) {
     this.json = json;
     this.formatter = formatter;
     this.projectFiles = projectFiles;
-    this.presetFile = presetFile;
 
     writer = json.writerWithDefaultPrettyPrinter();
     downloader = new FileSystemProjectDownloader();
@@ -109,6 +102,6 @@ class FileSystemProjectsRepository implements ProjectsRepository {
   }
 
   private String presetFilePath() {
-    return PRESET_FOLDER + presetFile.name().name();
+    return PRESET_FOLDER + PRESET_FILE;
   }
 }
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
deleted file mode 100644
index 4c9627666..000000000
--- a/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/JHipsterPresetFileProperties.java
+++ /dev/null
@@ -1,17 +0,0 @@
-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
deleted file mode 100644
index ff9f859e9..000000000
--- a/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/JHipsterPresetFilePropertiesConfiguration.java
+++ /dev/null
@@ -1,17 +0,0 @@
-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 364a4bbc1..b8d18f725 100644
--- a/src/main/resources/config/application.yml
+++ b/src/main/resources/config/application.yml
@@ -69,9 +69,6 @@ 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
deleted file mode 100644
index 1332c55b5..000000000
--- a/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FakedJHipsterPresetFilePropertiesConfiguration.java
+++ /dev/null
@@ -1,15 +0,0 @@
-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 523538edf..cb5e06cad 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,7 +33,6 @@ 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
@@ -42,8 +41,7 @@ class FileSystemProjectsRepositoryTest {
   private static final FileSystemProjectsRepository projects = new FileSystemProjectsRepository(
     JsonHelper.jsonMapper(),
     mock(ProjectFormatter.class),
-    mock(ProjectFiles.class),
-    mock(JHipsterPresetFile.class)
+    mock(ProjectFiles.class)
   );
 
   @Nested
@@ -150,8 +148,7 @@ class FileSystemProjectsRepositoryTest {
       FileSystemProjectsRepository fileSystemProjectsRepository = new FileSystemProjectsRepository(
         json,
         mock(ProjectFormatter.class),
-        mock(ProjectFiles.class),
-        mock(JHipsterPresetFile.class)
+        mock(ProjectFiles.class)
       );
 
       assertThatThrownBy(() -> fileSystemProjectsRepository.save(projectHistory())).isExactlyInstanceOf(GeneratorException.class);
@@ -194,8 +191,7 @@ class FileSystemProjectsRepositoryTest {
       FileSystemProjectsRepository fileSystemProjectsRepository = new FileSystemProjectsRepository(
         json,
         mock(ProjectFormatter.class),
-        mock(ProjectFiles.class),
-        mock(JHipsterPresetFile.class)
+        mock(ProjectFiles.class)
       );
 
       assertThatThrownBy(() -> fileSystemProjectsRepository.getHistory(path)).isExactlyInstanceOf(GeneratorException.class);
@@ -233,8 +229,7 @@ class FileSystemProjectsRepositoryTest {
       FileSystemProjectsRepository fileSystemProjectsRepository = new FileSystemProjectsRepository(
         json,
         mock(ProjectFormatter.class),
-        mockProjectFilesWithValidPresetJson(),
-        new JHipsterPresetFile(PresetName.from("preset.json"))
+        mockProjectFilesWithValidPresetJson()
       );
 
       assertThatThrownBy(fileSystemProjectsRepository::getPresets).isExactlyInstanceOf(GeneratorException.class);
@@ -247,8 +242,7 @@ class FileSystemProjectsRepositoryTest {
       FileSystemProjectsRepository fileSystemProjectsRepository = new FileSystemProjectsRepository(
         JsonHelper.jsonMapper(),
         mock(ProjectFormatter.class),
-        projectFiles,
-        new JHipsterPresetFile(PresetName.from("preset.json"))
+        projectFiles
       );
 
       assertThatThrownBy(fileSystemProjectsRepository::getPresets).isExactlyInstanceOf(GeneratorException.class);
@@ -259,8 +253,7 @@ class FileSystemProjectsRepositoryTest {
       FileSystemProjectsRepository fileSystemProjectsRepository = new FileSystemProjectsRepository(
         JsonHelper.jsonMapper(),
         mock(ProjectFormatter.class),
-        mockProjectFilesWithValidPresetJson(),
-        new JHipsterPresetFile(PresetName.from("preset.json"))
+        mockProjectFilesWithValidPresetJson()
       );
 
       Collection<Preset> presets = fileSystemProjectsRepository.getPresets();