From bd5ab9af1e03929ce19fe5215729b4ff5d91554a Mon Sep 17 00:00:00 2001 From: Pascal Grimaud Date: Fri, 28 Jan 2022 15:59:45 +0100 Subject: [PATCH] Refactoring and move package.json to dependencies/common --- .github/dependabot.yml | 2 +- .../generator/init/domain/InitDomainService.java | 2 +- .../npm/domain/NpmDomainService.java | 9 +++++++-- .../packagemanager/npm/domain/NpmService.java | 2 +- .../typescript/domain/TypescriptDomainService.java | 2 +- .../dependencies/{ => common}/package.json | 0 .../init/domain/InitDomainServiceTest.java | 2 +- .../npm/domain/NpmDomainServiceTest.java | 14 +++++++------- .../domain/TypescriptDomainServiceTest.java | 2 +- 9 files changed, 20 insertions(+), 15 deletions(-) rename src/main/resources/generator/dependencies/{ => common}/package.json (100%) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index c8e03a0286a..4046ec4f248 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -46,7 +46,7 @@ updates: labels: - 'area: dependencies' - package-ecosystem: 'npm' - directory: '/src/main/resources/generator/dependencies/' + directory: '/src/main/resources/generator/dependencies/common' schedule: interval: 'daily' open-pull-requests-limit: 20 diff --git a/src/main/java/tech/jhipster/lite/generator/init/domain/InitDomainService.java b/src/main/java/tech/jhipster/lite/generator/init/domain/InitDomainService.java index fdab1df237d..17f42cbec1b 100644 --- a/src/main/java/tech/jhipster/lite/generator/init/domain/InitDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/init/domain/InitDomainService.java @@ -52,7 +52,7 @@ private void addDevDependencies(Project project) { List .of("@prettier/plugin-xml", "husky", "lint-staged", "prettier", "prettier-plugin-java", "prettier-plugin-packagejson") .forEach(dependency -> - npmService.getVersion(dependency).ifPresent(version -> npmService.addDevDependency(project, dependency, version)) + npmService.getVersionInCommon(dependency).ifPresent(version -> npmService.addDevDependency(project, dependency, version)) ); } diff --git a/src/main/java/tech/jhipster/lite/generator/packagemanager/npm/domain/NpmDomainService.java b/src/main/java/tech/jhipster/lite/generator/packagemanager/npm/domain/NpmDomainService.java index b9a1140d2f6..f856e5e7efc 100644 --- a/src/main/java/tech/jhipster/lite/generator/packagemanager/npm/domain/NpmDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/packagemanager/npm/domain/NpmDomainService.java @@ -71,10 +71,15 @@ public void prettify(Project project) { } @Override - public Optional getVersion(String name) { + public Optional getVersionInCommon(String name) { + return getVersion("common", name); + } + + private Optional getVersion(String folderType, String name) { + Assert.notBlank("folderType", folderType); Assert.notBlank("name", name); return FileUtils - .readLineInClasspath(getPath(TEMPLATE_FOLDER, DEPENDENCIES_FOLDER, PACKAGE_JSON), DQ + name + DQ) + .readLineInClasspath(getPath(TEMPLATE_FOLDER, DEPENDENCIES_FOLDER, folderType, PACKAGE_JSON), DQ + name + DQ) .map(readValue -> { String[] result = readValue.split(":"); if (result.length == 2) { diff --git a/src/main/java/tech/jhipster/lite/generator/packagemanager/npm/domain/NpmService.java b/src/main/java/tech/jhipster/lite/generator/packagemanager/npm/domain/NpmService.java index e4a73d89d69..ba7c5deec2d 100644 --- a/src/main/java/tech/jhipster/lite/generator/packagemanager/npm/domain/NpmService.java +++ b/src/main/java/tech/jhipster/lite/generator/packagemanager/npm/domain/NpmService.java @@ -11,5 +11,5 @@ public interface NpmService { void install(Project project); void prettify(Project project); - Optional getVersion(String name); + Optional getVersionInCommon(String name); } diff --git a/src/main/java/tech/jhipster/lite/generator/typescript/domain/TypescriptDomainService.java b/src/main/java/tech/jhipster/lite/generator/typescript/domain/TypescriptDomainService.java index 605c27ee55d..3c26423f35b 100644 --- a/src/main/java/tech/jhipster/lite/generator/typescript/domain/TypescriptDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/typescript/domain/TypescriptDomainService.java @@ -21,7 +21,7 @@ public void init(Project project) { Typescript .devDependencies() .forEach(dependency -> - npmService.getVersion(dependency).ifPresent(version -> npmService.addDevDependency(project, dependency, version)) + npmService.getVersionInCommon(dependency).ifPresent(version -> npmService.addDevDependency(project, dependency, version)) ); Typescript.scripts().forEach((name, cmd) -> npmService.addScript(project, name, cmd)); Typescript.files().forEach(file -> projectRepository.add(project, SOURCE, file)); diff --git a/src/main/resources/generator/dependencies/package.json b/src/main/resources/generator/dependencies/common/package.json similarity index 100% rename from src/main/resources/generator/dependencies/package.json rename to src/main/resources/generator/dependencies/common/package.json diff --git a/src/test/java/tech/jhipster/lite/generator/init/domain/InitDomainServiceTest.java b/src/test/java/tech/jhipster/lite/generator/init/domain/InitDomainServiceTest.java index 873343fdef4..3fc518b4757 100644 --- a/src/test/java/tech/jhipster/lite/generator/init/domain/InitDomainServiceTest.java +++ b/src/test/java/tech/jhipster/lite/generator/init/domain/InitDomainServiceTest.java @@ -42,7 +42,7 @@ void shouldInit() { @Test void shouldAddPackageJson() { Project project = tmpProject(); - when(npmService.getVersion(anyString())).thenReturn(Optional.of("0.0.0")); + when(npmService.getVersionInCommon(anyString())).thenReturn(Optional.of("0.0.0")); assertThatCode(() -> initDomainService.addPackageJson(project)).doesNotThrowAnyException(); diff --git a/src/test/java/tech/jhipster/lite/generator/packagemanager/npm/domain/NpmDomainServiceTest.java b/src/test/java/tech/jhipster/lite/generator/packagemanager/npm/domain/NpmDomainServiceTest.java index 208fc0e8b73..6e3695d49f5 100644 --- a/src/test/java/tech/jhipster/lite/generator/packagemanager/npm/domain/NpmDomainServiceTest.java +++ b/src/test/java/tech/jhipster/lite/generator/packagemanager/npm/domain/NpmDomainServiceTest.java @@ -76,40 +76,40 @@ void shouldPrettify() { } @Nested - class GetVersionTest { + class GetVersionInCommonTest { @Test void shouldGetVersion() { - assertThat(npmDomainService.getVersion("prettier-plugin-java")).isNotEmpty(); + assertThat(npmDomainService.getVersionInCommon("prettier-plugin-java")).isNotEmpty(); } @Test void shouldNotGetVersionForNull() { - assertThatThrownBy(() -> npmDomainService.getVersion(null)) + assertThatThrownBy(() -> npmDomainService.getVersionInCommon(null)) .isExactlyInstanceOf(MissingMandatoryValueException.class) .hasMessageContaining("name"); } @Test void shouldNotGetVersionForBlank() { - assertThatThrownBy(() -> npmDomainService.getVersion(" ")) + assertThatThrownBy(() -> npmDomainService.getVersionInCommon(" ")) .isExactlyInstanceOf(MissingMandatoryValueException.class) .hasMessageContaining("name"); } @Test void shouldNotGetVersion() { - assertThat(npmDomainService.getVersion("unknown")).isEmpty(); + assertThat(npmDomainService.getVersionInCommon("unknown")).isEmpty(); } @Test void shouldNotGetVersionForDescription() { - assertThat(npmDomainService.getVersion("description")).isEmpty(); + assertThat(npmDomainService.getVersionInCommon("description")).isEmpty(); } @Test void shouldNotGetVersionForCloseBracket() { - assertThat(npmDomainService.getVersion("}")).isEmpty(); + assertThat(npmDomainService.getVersionInCommon("}")).isEmpty(); } } } diff --git a/src/test/java/tech/jhipster/lite/generator/typescript/domain/TypescriptDomainServiceTest.java b/src/test/java/tech/jhipster/lite/generator/typescript/domain/TypescriptDomainServiceTest.java index 40ff59685a0..efb546f411c 100644 --- a/src/test/java/tech/jhipster/lite/generator/typescript/domain/TypescriptDomainServiceTest.java +++ b/src/test/java/tech/jhipster/lite/generator/typescript/domain/TypescriptDomainServiceTest.java @@ -34,7 +34,7 @@ class TypescriptDomainServiceTest { @Test void shouldInit() { Project project = tmpProject(); - when(npmService.getVersion(anyString())).thenReturn(Optional.of("0.0.0")); + when(npmService.getVersionInCommon(anyString())).thenReturn(Optional.of("0.0.0")); typescriptDomainService.init(project);