From 6fc4f1916128e20cc6a0f7d40fa48376df69d3d5 Mon Sep 17 00:00:00 2001 From: Colin DAMON Date: Sat, 27 Apr 2024 20:10:21 +0200 Subject: [PATCH] Rework FileSystemProjectJavaBuildToolRepository --- ...eSystemProjectJavaBuildToolRepository.java | 36 +++++++++++++------ 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/javabuild/FileSystemProjectJavaBuildToolRepository.java b/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/javabuild/FileSystemProjectJavaBuildToolRepository.java index c4f187bf259..87b08ee1f2a 100644 --- a/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/javabuild/FileSystemProjectJavaBuildToolRepository.java +++ b/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/javabuild/FileSystemProjectJavaBuildToolRepository.java @@ -1,11 +1,9 @@ package tech.jhipster.lite.module.infrastructure.secondary.javabuild; -import java.util.Collection; import java.util.Optional; import org.springframework.stereotype.Component; import tech.jhipster.lite.module.domain.file.JHipsterDestination; import tech.jhipster.lite.module.domain.file.JHipsterFileToMove; -import tech.jhipster.lite.module.domain.file.JHipsterFilesToMove; import tech.jhipster.lite.module.domain.file.JHipsterModuleFile; import tech.jhipster.lite.module.domain.file.JHipsterModuleFiles; import tech.jhipster.lite.module.domain.javabuild.JavaBuildTool; @@ -22,29 +20,45 @@ public class FileSystemProjectJavaBuildToolRepository implements ProjectJavaBuil public Optional detect(JHipsterProjectFolder projectFolder) { if (projectFolder.fileExists(POM_XML)) { return Optional.of(JavaBuildTool.MAVEN); - } else if (projectFolder.fileExists(BUILD_GRADLE_KTS)) { + } + + if (projectFolder.fileExists(BUILD_GRADLE_KTS)) { return Optional.of(JavaBuildTool.GRADLE); } + return Optional.empty(); } @Override public Optional detect(JHipsterModuleFiles moduleFiles) { - if (hasDestinationFile(moduleFiles.filesToAdd(), POM_XML) || hasDestinationFile(moduleFiles.filesToMove(), POM_XML)) { + if (hasMavenFile(moduleFiles)) { return Optional.of(JavaBuildTool.MAVEN); - } else if ( - hasDestinationFile(moduleFiles.filesToAdd(), BUILD_GRADLE_KTS) || hasDestinationFile(moduleFiles.filesToMove(), BUILD_GRADLE_KTS) - ) { + } + + if (hasGradleFile(moduleFiles)) { return Optional.of(JavaBuildTool.GRADLE); } + return Optional.empty(); } - private static boolean hasDestinationFile(JHipsterFilesToMove filesToMove, String fileName) { - return filesToMove.stream().map(JHipsterFileToMove::destination).map(JHipsterDestination::get).anyMatch(fileName::equals); + private static boolean hasMavenFile(JHipsterModuleFiles moduleFiles) { + return hasBuildFiles(moduleFiles, POM_XML); + } + + private static boolean hasGradleFile(JHipsterModuleFiles moduleFiles) { + return hasBuildFiles(moduleFiles, BUILD_GRADLE_KTS); + } + + private static boolean hasBuildFiles(JHipsterModuleFiles moduleFiles, String file) { + return hasFileToAdd(moduleFiles, file) || hasFileToMove(moduleFiles, file); + } + + private static boolean hasFileToMove(JHipsterModuleFiles files, String fileName) { + return files.filesToMove().stream().map(JHipsterFileToMove::destination).map(JHipsterDestination::get).anyMatch(fileName::equals); } - private static boolean hasDestinationFile(Collection filesToAdd, String fileName) { - return filesToAdd.stream().map(JHipsterModuleFile::destination).map(JHipsterDestination::get).anyMatch(fileName::equals); + private static boolean hasFileToAdd(JHipsterModuleFiles files, String fileName) { + return files.filesToAdd().stream().map(JHipsterModuleFile::destination).map(JHipsterDestination::get).anyMatch(fileName::equals); } }