From d155afb392b1ff4c232d560f5ac965bb6296e7cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Mino?= Date: Wed, 18 Dec 2024 22:50:33 +0100 Subject: [PATCH] chore: fix bug patterns identified by Error Prone --- .../eureka/domain/EurekaModuleFactory.java | 3 +- .../license/domain/LicenseModuleFactory.java | 3 +- .../module/domain/DocumentationTitle.java | 3 +- .../lite/module/domain/JHipsterSlug.java | 3 +- .../module/domain/docker/DockerImageName.java | 3 +- .../domain/file/JHipsterDestination.java | 5 +- .../domain/gitignore/GitIgnoreEntry.java | 2 + .../domain/gradleplugin/GradleCorePlugin.java | 1 + .../domain/javaproperties/PropertyValue.java | 6 ++- .../module/domain/npm/NpmPackageVersion.java | 2 +- .../lite/module/domain/npm/NpmVersions.java | 2 +- .../packagejson/PackageJsonDependency.java | 2 +- .../properties/JHipsterProjectBaseName.java | 5 +- .../domain/replacement/EndOfFileReplacer.java | 2 +- .../resource/JHipsterHiddenModules.java | 3 +- .../FileSystemPackageJsonHandler.java | 19 +++++-- .../YamlFileSpringPropertiesHandler.java | 33 +++++++++--- .../gradle/GradleCommandHandler.java | 51 +++++++++++++++---- .../javadependency/maven/MavenScope.java | 7 +-- .../npm/FileSystemNpmLazyInstaller.java | 1 + .../npm/FileSystemNpmVersionReader.java | 8 ++- .../lite/project/domain/download/Project.java | 4 +- .../project/domain/download/ProjectName.java | 3 +- .../shared/base64/domain/Base64Utils.java | 4 +- .../lite/shared/enumeration/domain/Enums.java | 8 +-- .../secondary/AppliedModuleDocument.java | 4 +- .../shared/memoizer/domain/MemoizersTest.java | 3 +- 27 files changed, 134 insertions(+), 56 deletions(-) diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/springcloud/eureka/domain/EurekaModuleFactory.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/springcloud/eureka/domain/EurekaModuleFactory.java index 8e80a03e958..90f39919c0d 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/springboot/springcloud/eureka/domain/EurekaModuleFactory.java +++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/springcloud/eureka/domain/EurekaModuleFactory.java @@ -10,6 +10,7 @@ import static tech.jhipster.lite.module.domain.JHipsterModule.to; import static tech.jhipster.lite.module.domain.JHipsterModule.versionSlug; +import java.util.Locale; import tech.jhipster.lite.module.domain.JHipsterModule; import tech.jhipster.lite.module.domain.docker.DockerImages; import tech.jhipster.lite.module.domain.file.JHipsterSource; @@ -37,7 +38,7 @@ public JHipsterModule buildModule(JHipsterModuleProperties properties) { String jwtBase64secret = properties.getOrDefaultString(JWT_BASE_64_SECRET, Base64Utils.getBase64Secret()); String baseName = properties.projectBaseName().get(); - String lowerCaseBaseName = baseName.toLowerCase(); + String lowerCaseBaseName = baseName.toLowerCase(Locale.ROOT); //@formatter:off return moduleBuilder(properties) diff --git a/src/main/java/tech/jhipster/lite/generator/setup/license/domain/LicenseModuleFactory.java b/src/main/java/tech/jhipster/lite/generator/setup/license/domain/LicenseModuleFactory.java index 47e515b3296..38703a117de 100644 --- a/src/main/java/tech/jhipster/lite/generator/setup/license/domain/LicenseModuleFactory.java +++ b/src/main/java/tech/jhipster/lite/generator/setup/license/domain/LicenseModuleFactory.java @@ -5,6 +5,7 @@ import static tech.jhipster.lite.module.domain.JHipsterModule.to; import java.time.Year; +import java.time.ZoneId; import tech.jhipster.lite.module.domain.JHipsterModule; import tech.jhipster.lite.module.domain.file.JHipsterSource; import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties; @@ -17,7 +18,7 @@ public JHipsterModule buildMitModule(JHipsterModuleProperties properties) { //@formatter:off return moduleBuilder(properties) .context() - .put("currentYear", Year.now().getValue()) + .put("currentYear", Year.now(ZoneId.systemDefault()).getValue()) .and() .files() .add(SOURCE.template("MIT.txt"), to("LICENSE.txt")) diff --git a/src/main/java/tech/jhipster/lite/module/domain/DocumentationTitle.java b/src/main/java/tech/jhipster/lite/module/domain/DocumentationTitle.java index d4da903ccfc..24f98a9d906 100644 --- a/src/main/java/tech/jhipster/lite/module/domain/DocumentationTitle.java +++ b/src/main/java/tech/jhipster/lite/module/domain/DocumentationTitle.java @@ -1,5 +1,6 @@ package tech.jhipster.lite.module.domain; +import java.util.Locale; import org.apache.commons.lang3.StringUtils; import tech.jhipster.lite.shared.error.domain.Assert; @@ -11,7 +12,7 @@ public record DocumentationTitle(String title) { } public String filename() { - return StringUtils.stripAccents(title.toLowerCase()).replaceAll("\\W", SEPARATOR).replaceAll("-+", SEPARATOR); + return StringUtils.stripAccents(title.toLowerCase(Locale.ROOT)).replaceAll("\\W", SEPARATOR).replaceAll("-+", SEPARATOR); } public String get() { diff --git a/src/main/java/tech/jhipster/lite/module/domain/JHipsterSlug.java b/src/main/java/tech/jhipster/lite/module/domain/JHipsterSlug.java index efbd6b9aa66..fee1321eaf9 100644 --- a/src/main/java/tech/jhipster/lite/module/domain/JHipsterSlug.java +++ b/src/main/java/tech/jhipster/lite/module/domain/JHipsterSlug.java @@ -52,11 +52,10 @@ public boolean equals(Object obj) { return true; } - if (obj == null || getClass() != obj.getClass()) { + if (!(obj instanceof JHipsterSlug other)) { return false; } - JHipsterSlug other = (JHipsterSlug) obj; return new EqualsBuilder().append(slug, other.slug).isEquals(); } } diff --git a/src/main/java/tech/jhipster/lite/module/domain/docker/DockerImageName.java b/src/main/java/tech/jhipster/lite/module/domain/docker/DockerImageName.java index 2cb8341e3f2..85d999f0ef0 100644 --- a/src/main/java/tech/jhipster/lite/module/domain/docker/DockerImageName.java +++ b/src/main/java/tech/jhipster/lite/module/domain/docker/DockerImageName.java @@ -1,12 +1,13 @@ package tech.jhipster.lite.module.domain.docker; +import java.util.Locale; import tech.jhipster.lite.shared.error.domain.Assert; public record DockerImageName(String imageName) { public DockerImageName(String imageName) { Assert.notBlank("imageName", imageName); - this.imageName = imageName.toLowerCase(); + this.imageName = imageName.toLowerCase(Locale.ROOT); } public String get() { diff --git a/src/main/java/tech/jhipster/lite/module/domain/file/JHipsterDestination.java b/src/main/java/tech/jhipster/lite/module/domain/file/JHipsterDestination.java index da6aa216ffb..087a6e929bc 100644 --- a/src/main/java/tech/jhipster/lite/module/domain/file/JHipsterDestination.java +++ b/src/main/java/tech/jhipster/lite/module/domain/file/JHipsterDestination.java @@ -55,7 +55,7 @@ public Path pathInProject(JHipsterProjectFolder project) { @Override @ExcludeFromGeneratedCodeCoverage public int hashCode() { - return new HashCodeBuilder().append(destination).hashCode(); + return new HashCodeBuilder().append(destination).toHashCode(); } @Override @@ -65,11 +65,10 @@ public boolean equals(Object obj) { return true; } - if (obj == null || getClass() != obj.getClass()) { + if (!(obj instanceof JHipsterDestination other)) { return false; } - JHipsterDestination other = (JHipsterDestination) obj; return new EqualsBuilder().append(destination, other.destination).isEquals(); } diff --git a/src/main/java/tech/jhipster/lite/module/domain/gitignore/GitIgnoreEntry.java b/src/main/java/tech/jhipster/lite/module/domain/gitignore/GitIgnoreEntry.java index 04f5f9bf409..6f4c35119e8 100644 --- a/src/main/java/tech/jhipster/lite/module/domain/gitignore/GitIgnoreEntry.java +++ b/src/main/java/tech/jhipster/lite/module/domain/gitignore/GitIgnoreEntry.java @@ -10,6 +10,7 @@ record GitIgnorePattern(String value) implements GitIgnoreEntry { Assert.notBlank("value", value); } + @Override public String get() { return value; } @@ -28,6 +29,7 @@ public GitIgnoreComment(String value) { this.value = value.startsWith(COMMENT_PREFIX) ? value : COMMENT_PREFIX + " " + value; } + @Override public String get() { return value; } diff --git a/src/main/java/tech/jhipster/lite/module/domain/gradleplugin/GradleCorePlugin.java b/src/main/java/tech/jhipster/lite/module/domain/gradleplugin/GradleCorePlugin.java index 534a1f3c5cb..d4287c711ab 100644 --- a/src/main/java/tech/jhipster/lite/module/domain/gradleplugin/GradleCorePlugin.java +++ b/src/main/java/tech/jhipster/lite/module/domain/gradleplugin/GradleCorePlugin.java @@ -21,6 +21,7 @@ private GradleCorePlugin(GradleCorePluginBuilder builder) { toolVersionSlug = Optional.ofNullable(builder.toolVersionSlug); } + @Override public GradlePluginId id() { return id; } diff --git a/src/main/java/tech/jhipster/lite/module/domain/javaproperties/PropertyValue.java b/src/main/java/tech/jhipster/lite/module/domain/javaproperties/PropertyValue.java index 9630d6d8584..6819fc26deb 100644 --- a/src/main/java/tech/jhipster/lite/module/domain/javaproperties/PropertyValue.java +++ b/src/main/java/tech/jhipster/lite/module/domain/javaproperties/PropertyValue.java @@ -52,14 +52,16 @@ public Collection values() { @Override @ExcludeFromGeneratedCodeCoverage + @SuppressWarnings("UndefinedEquals") public boolean equals(Object obj) { if (obj == this) { return true; } - if (obj == null || obj.getClass() != this.getClass()) { + + if (!(obj instanceof PropertyValue that)) { return false; } - var that = (PropertyValue) obj; + return Objects.equals(this.values, that.values); } diff --git a/src/main/java/tech/jhipster/lite/module/domain/npm/NpmPackageVersion.java b/src/main/java/tech/jhipster/lite/module/domain/npm/NpmPackageVersion.java index 487fdedc273..5dc78ce9155 100644 --- a/src/main/java/tech/jhipster/lite/module/domain/npm/NpmPackageVersion.java +++ b/src/main/java/tech/jhipster/lite/module/domain/npm/NpmPackageVersion.java @@ -13,7 +13,7 @@ public String get() { } public String majorVersion() { - return version().split("\\.")[0]; + return version().split("\\.", -1)[0]; } @Override diff --git a/src/main/java/tech/jhipster/lite/module/domain/npm/NpmVersions.java b/src/main/java/tech/jhipster/lite/module/domain/npm/NpmVersions.java index beb8e6cc199..fcc3a2d8533 100644 --- a/src/main/java/tech/jhipster/lite/module/domain/npm/NpmVersions.java +++ b/src/main/java/tech/jhipster/lite/module/domain/npm/NpmVersions.java @@ -57,7 +57,7 @@ default NpmPackageVersion get(String packageName, NpmVersionSourceFactory source } /** - * @return The version of Node.js. + * The version of Node.js. */ default NpmPackageVersion nodeVersion() { return get("node", JHLiteNpmVersionSource.COMMON.build()); diff --git a/src/main/java/tech/jhipster/lite/module/domain/packagejson/PackageJsonDependency.java b/src/main/java/tech/jhipster/lite/module/domain/packagejson/PackageJsonDependency.java index 918933986ad..1afa89c9030 100644 --- a/src/main/java/tech/jhipster/lite/module/domain/packagejson/PackageJsonDependency.java +++ b/src/main/java/tech/jhipster/lite/module/domain/packagejson/PackageJsonDependency.java @@ -42,7 +42,7 @@ public boolean equals(Object obj) { return false; } var that = (PackageJsonDependency) obj; - return Objects.equals(this.packageName, that.packageName) && this.versionSource == that.versionSource; + return Objects.equals(this.packageName, that.packageName) && Objects.equals(this.versionSource, that.versionSource); } @Override diff --git a/src/main/java/tech/jhipster/lite/module/domain/properties/JHipsterProjectBaseName.java b/src/main/java/tech/jhipster/lite/module/domain/properties/JHipsterProjectBaseName.java index cfacdf615bc..38fdd330f08 100644 --- a/src/main/java/tech/jhipster/lite/module/domain/properties/JHipsterProjectBaseName.java +++ b/src/main/java/tech/jhipster/lite/module/domain/properties/JHipsterProjectBaseName.java @@ -1,5 +1,6 @@ package tech.jhipster.lite.module.domain.properties; +import java.util.Locale; import java.util.regex.Pattern; import org.apache.commons.lang3.StringUtils; import tech.jhipster.lite.shared.error.domain.Assert; @@ -37,10 +38,10 @@ public String capitalized() { } public String upperCased() { - return StringUtils.uncapitalize(name()).replaceAll("([A-Z])", "_$1").toUpperCase(); + return StringUtils.uncapitalize(name()).replaceAll("([A-Z])", "_$1").toUpperCase(Locale.ROOT); } public String kebabCase() { - return StringUtils.uncapitalize(name()).replaceAll("([A-Z])", "-$1").toLowerCase(); + return StringUtils.uncapitalize(name()).replaceAll("([A-Z])", "-$1").toLowerCase(Locale.ROOT); } } diff --git a/src/main/java/tech/jhipster/lite/module/domain/replacement/EndOfFileReplacer.java b/src/main/java/tech/jhipster/lite/module/domain/replacement/EndOfFileReplacer.java index 0b1f3a51379..19ec8b67127 100644 --- a/src/main/java/tech/jhipster/lite/module/domain/replacement/EndOfFileReplacer.java +++ b/src/main/java/tech/jhipster/lite/module/domain/replacement/EndOfFileReplacer.java @@ -8,7 +8,7 @@ /** * {@link ElementReplacer} that inserts content at the end of the file if the provided condition is met - * @param condition + * @param condition that must be met to insert content at the end of the file */ public record EndOfFileReplacer(ReplacementCondition condition) implements ElementReplacer { private static final Pattern EOF_PATTERN = Pattern.compile("\\z", Pattern.MULTILINE); diff --git a/src/main/java/tech/jhipster/lite/module/domain/resource/JHipsterHiddenModules.java b/src/main/java/tech/jhipster/lite/module/domain/resource/JHipsterHiddenModules.java index bf1911e84f5..b2bb21ad9e1 100644 --- a/src/main/java/tech/jhipster/lite/module/domain/resource/JHipsterHiddenModules.java +++ b/src/main/java/tech/jhipster/lite/module/domain/resource/JHipsterHiddenModules.java @@ -42,11 +42,10 @@ public boolean equals(Object obj) { return true; } - if (obj == null || getClass() != obj.getClass()) { + if (!(obj instanceof JHipsterHiddenModules other)) { return false; } - JHipsterHiddenModules other = (JHipsterHiddenModules) obj; return new EqualsBuilder().append(slugs, other.slugs).append(tags, other.tags).isEquals(); } } diff --git a/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/FileSystemPackageJsonHandler.java b/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/FileSystemPackageJsonHandler.java index 9f127a8dbe1..9072ed17996 100644 --- a/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/FileSystemPackageJsonHandler.java +++ b/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/FileSystemPackageJsonHandler.java @@ -3,8 +3,13 @@ import static tech.jhipster.lite.module.domain.JHipsterModule.LINE_BREAK; import java.io.IOException; -import java.nio.file.*; -import java.util.*; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardOpenOption; +import java.util.Collection; +import java.util.List; +import java.util.Locale; +import java.util.Optional; import java.util.function.Function; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -14,7 +19,13 @@ import tech.jhipster.lite.module.domain.JHipsterModuleContext; import tech.jhipster.lite.module.domain.file.TemplateRenderer; import tech.jhipster.lite.module.domain.npm.NpmVersions; -import tech.jhipster.lite.module.domain.packagejson.*; +import tech.jhipster.lite.module.domain.packagejson.JHipsterModulePackageJson; +import tech.jhipster.lite.module.domain.packagejson.NodeModuleFormat; +import tech.jhipster.lite.module.domain.packagejson.PackageJsonDependencies; +import tech.jhipster.lite.module.domain.packagejson.PackageJsonDependency; +import tech.jhipster.lite.module.domain.packagejson.PackageName; +import tech.jhipster.lite.module.domain.packagejson.PackageNames; +import tech.jhipster.lite.module.domain.packagejson.Scripts; import tech.jhipster.lite.module.domain.properties.JHipsterProjectFolder; import tech.jhipster.lite.shared.collection.domain.JHipsterCollections; import tech.jhipster.lite.shared.error.domain.Assert; @@ -140,7 +151,7 @@ private String replaceType(Indentation indentation, Optional n .blockName("type") .jsonContent(content) .indentation(indentation) - .blockValue(nodeModuleFormat.orElseThrow().name().toLowerCase()) + .blockValue(nodeModuleFormat.orElseThrow().name().toLowerCase(Locale.ROOT)) .apply(); } diff --git a/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/YamlFileSpringPropertiesHandler.java b/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/YamlFileSpringPropertiesHandler.java index 3f24e9f0a01..7b602ed668b 100644 --- a/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/YamlFileSpringPropertiesHandler.java +++ b/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/YamlFileSpringPropertiesHandler.java @@ -1,21 +1,40 @@ package tech.jhipster.lite.module.infrastructure.secondary; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.yaml.snakeyaml.comments.CommentType.BLOCK; -import java.io.*; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Writer; import java.nio.file.Files; import java.nio.file.Path; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Optional; import java.util.function.Function; import java.util.function.Predicate; -import org.yaml.snakeyaml.*; +import org.yaml.snakeyaml.DumperOptions; import org.yaml.snakeyaml.DumperOptions.FlowStyle; +import org.yaml.snakeyaml.LoaderOptions; +import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.comments.CommentLine; import org.yaml.snakeyaml.constructor.Constructor; -import org.yaml.snakeyaml.nodes.*; +import org.yaml.snakeyaml.nodes.MappingNode; +import org.yaml.snakeyaml.nodes.Node; +import org.yaml.snakeyaml.nodes.NodeTuple; +import org.yaml.snakeyaml.nodes.ScalarNode; +import org.yaml.snakeyaml.nodes.SequenceNode; +import org.yaml.snakeyaml.nodes.Tag; import org.yaml.snakeyaml.representer.Representer; import tech.jhipster.lite.module.domain.Indentation; -import tech.jhipster.lite.module.domain.javaproperties.*; +import tech.jhipster.lite.module.domain.javaproperties.Comment; +import tech.jhipster.lite.module.domain.javaproperties.PropertyKey; +import tech.jhipster.lite.module.domain.javaproperties.PropertyValue; import tech.jhipster.lite.shared.error.domain.Assert; import tech.jhipster.lite.shared.error.domain.GeneratorException; import tech.jhipster.lite.shared.generation.domain.ExcludeFromGeneratedCodeCoverage; @@ -187,14 +206,14 @@ private MappingNode loadConfiguration(File yamlFile) throws IOException { return new MappingNode(Tag.MAP, new ArrayList<>(), FlowStyle.AUTO); } - try (FileReader reader = new FileReader(yamlFile)) { + try (FileReader reader = new FileReader(yamlFile, UTF_8)) { return (MappingNode) yaml.compose(reader); } } private void saveConfiguration(Node actualConfiguration) throws IOException { Files.createDirectories(file.getParent()); - Writer writer = new FileWriter(file.toFile()); + Writer writer = new FileWriter(file.toFile(), UTF_8); yaml.serialize(actualConfiguration, writer); } diff --git a/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/javadependency/gradle/GradleCommandHandler.java b/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/javadependency/gradle/GradleCommandHandler.java index 009ca33a121..7fff6825103 100644 --- a/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/javadependency/gradle/GradleCommandHandler.java +++ b/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/javadependency/gradle/GradleCommandHandler.java @@ -1,6 +1,9 @@ package tech.jhipster.lite.module.infrastructure.secondary.javadependency.gradle; -import static tech.jhipster.lite.module.domain.JHipsterModule.*; +import static tech.jhipster.lite.module.domain.JHipsterModule.LINE_BREAK; +import static tech.jhipster.lite.module.domain.JHipsterModule.from; +import static tech.jhipster.lite.module.domain.JHipsterModule.regex; +import static tech.jhipster.lite.module.domain.JHipsterModule.to; import static tech.jhipster.lite.module.domain.replacement.ReplacementCondition.always; import static tech.jhipster.lite.module.domain.replacement.ReplacementCondition.notMatchingRegex; import static tech.jhipster.lite.module.infrastructure.secondary.javadependency.gradle.VersionsCatalog.libraryAlias; @@ -10,24 +13,54 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.util.*; +import java.util.Arrays; +import java.util.List; +import java.util.Locale; +import java.util.Optional; import java.util.function.Predicate; import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; -import tech.jhipster.lite.module.domain.*; +import tech.jhipster.lite.module.domain.Indentation; +import tech.jhipster.lite.module.domain.JHipsterModuleContext; +import tech.jhipster.lite.module.domain.JHipsterProjectFilePath; import tech.jhipster.lite.module.domain.buildproperties.BuildProperty; import tech.jhipster.lite.module.domain.buildproperties.PropertyKey; -import tech.jhipster.lite.module.domain.file.*; -import tech.jhipster.lite.module.domain.gradleplugin.*; +import tech.jhipster.lite.module.domain.file.JHipsterDestination; +import tech.jhipster.lite.module.domain.file.JHipsterFileContent; +import tech.jhipster.lite.module.domain.file.JHipsterModuleFile; +import tech.jhipster.lite.module.domain.file.JHipsterSource; +import tech.jhipster.lite.module.domain.file.JHipsterTemplatedFile; +import tech.jhipster.lite.module.domain.file.JHipsterTemplatedFiles; +import tech.jhipster.lite.module.domain.gradleplugin.BuildGradleImport; +import tech.jhipster.lite.module.domain.gradleplugin.GradleCommunityPlugin; +import tech.jhipster.lite.module.domain.gradleplugin.GradleCommunityProfilePlugin; +import tech.jhipster.lite.module.domain.gradleplugin.GradleCorePlugin; +import tech.jhipster.lite.module.domain.gradleplugin.GradlePluginConfiguration; import tech.jhipster.lite.module.domain.javabuild.DependencySlug; -import tech.jhipster.lite.module.domain.javabuild.command.*; +import tech.jhipster.lite.module.domain.javabuild.command.AddDirectJavaDependency; +import tech.jhipster.lite.module.domain.javabuild.command.AddDirectMavenPlugin; +import tech.jhipster.lite.module.domain.javabuild.command.AddGradleConfiguration; +import tech.jhipster.lite.module.domain.javabuild.command.AddGradlePlugin; +import tech.jhipster.lite.module.domain.javabuild.command.AddGradleTasksTestInstruction; +import tech.jhipster.lite.module.domain.javabuild.command.AddJavaBuildProfile; +import tech.jhipster.lite.module.domain.javabuild.command.AddJavaDependencyManagement; +import tech.jhipster.lite.module.domain.javabuild.command.AddMavenBuildExtension; +import tech.jhipster.lite.module.domain.javabuild.command.AddMavenPluginManagement; +import tech.jhipster.lite.module.domain.javabuild.command.RemoveDirectJavaDependency; +import tech.jhipster.lite.module.domain.javabuild.command.RemoveJavaDependencyManagement; +import tech.jhipster.lite.module.domain.javabuild.command.SetBuildProperty; +import tech.jhipster.lite.module.domain.javabuild.command.SetVersion; import tech.jhipster.lite.module.domain.javabuildprofile.BuildProfileActivation; import tech.jhipster.lite.module.domain.javabuildprofile.BuildProfileId; import tech.jhipster.lite.module.domain.javadependency.JavaDependency; import tech.jhipster.lite.module.domain.javadependency.JavaDependencyScope; import tech.jhipster.lite.module.domain.properties.JHipsterProjectFolder; -import tech.jhipster.lite.module.domain.replacement.*; +import tech.jhipster.lite.module.domain.replacement.ContentReplacers; +import tech.jhipster.lite.module.domain.replacement.MandatoryFileReplacer; +import tech.jhipster.lite.module.domain.replacement.MandatoryReplacer; +import tech.jhipster.lite.module.domain.replacement.RegexNeedleBeforeReplacer; +import tech.jhipster.lite.module.domain.replacement.RegexReplacer; import tech.jhipster.lite.module.infrastructure.secondary.FileSystemJHipsterModuleFiles; import tech.jhipster.lite.module.infrastructure.secondary.FileSystemReplacer; import tech.jhipster.lite.module.infrastructure.secondary.javadependency.JavaDependenciesCommandHandler; @@ -345,8 +378,8 @@ private static String convertToKotlinFormat(BuildProperty property) { private static String toCamelCasedKotlinVariable(PropertyKey key) { return Arrays.stream(key.get().split("[.-]")) - .map(s -> s.substring(0, 1).toUpperCase() + s.substring(1).toLowerCase()) - .collect(Collectors.collectingAndThen(Collectors.joining(), str -> str.substring(0, 1).toLowerCase() + str.substring(1))); + .map(s -> s.substring(0, 1).toUpperCase(Locale.ROOT) + s.substring(1).toLowerCase(Locale.ROOT)) + .collect(Collectors.collectingAndThen(Collectors.joining(), str -> str.substring(0, 1).toLowerCase(Locale.ROOT) + str.substring(1))); } private boolean propertyExistsFrom(PropertyKey key, Path buildGradleFile) { diff --git a/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/javadependency/maven/MavenScope.java b/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/javadependency/maven/MavenScope.java index 9a4ef4c6d44..ac500cf431c 100644 --- a/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/javadependency/maven/MavenScope.java +++ b/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/javadependency/maven/MavenScope.java @@ -1,5 +1,6 @@ package tech.jhipster.lite.module.infrastructure.secondary.javadependency.maven; +import java.util.Locale; import java.util.Map; import java.util.function.Function; import java.util.stream.Collectors; @@ -16,7 +17,7 @@ enum MavenScope { private static final Map SCOPES = buildScopes(); private static Map buildScopes() { - return Stream.of(values()).collect(Collectors.toUnmodifiableMap(scope -> scope.name().toLowerCase(), Function.identity())); + return Stream.of(values()).collect(Collectors.toUnmodifiableMap(MavenScope::key, Function.identity())); } static MavenScope from(String scope) { @@ -24,10 +25,10 @@ static MavenScope from(String scope) { return null; } - return SCOPES.get(scope.toLowerCase()); + return SCOPES.get(scope.toLowerCase(Locale.ROOT)); } String key() { - return name().toLowerCase(); + return name().toLowerCase(Locale.ROOT); } } diff --git a/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/npm/FileSystemNpmLazyInstaller.java b/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/npm/FileSystemNpmLazyInstaller.java index 6965926e59c..d5b81616ee8 100644 --- a/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/npm/FileSystemNpmLazyInstaller.java +++ b/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/npm/FileSystemNpmLazyInstaller.java @@ -26,6 +26,7 @@ class FileSystemNpmLazyInstaller implements NpmLazyInstaller { private static final Logger log = LoggerFactory.getLogger(FileSystemNpmLazyInstaller.class); private final NpmInstallationReader npmInstallationReader = new NpmInstallationReader(); + @Override public void runInstallIn(JHipsterProjectFolder folder) { Assert.notNull("folder", folder); diff --git a/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/npm/FileSystemNpmVersionReader.java b/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/npm/FileSystemNpmVersionReader.java index 7413a21daab..b55262b114e 100644 --- a/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/npm/FileSystemNpmVersionReader.java +++ b/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/npm/FileSystemNpmVersionReader.java @@ -1,12 +1,16 @@ package tech.jhipster.lite.module.infrastructure.secondary.npm; import java.util.Collection; +import java.util.Locale; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Stream; import tech.jhipster.lite.module.domain.ProjectFiles; -import tech.jhipster.lite.module.domain.npm.*; +import tech.jhipster.lite.module.domain.npm.NpmPackage; +import tech.jhipster.lite.module.domain.npm.NpmPackagesVersions; import tech.jhipster.lite.module.domain.npm.NpmPackagesVersions.NpmPackagesVersionsBuilder; +import tech.jhipster.lite.module.domain.npm.NpmVersionSource; +import tech.jhipster.lite.module.domain.npm.NpmVersionSourceFactory; import tech.jhipster.lite.shared.error.domain.Assert; public class FileSystemNpmVersionReader implements NpmVersionsReader { @@ -67,6 +71,6 @@ private String readVersionsFile(NpmVersionSource source) { } private String sourceFolder(NpmVersionSource source) { - return source.name().toLowerCase(); + return source.name().toLowerCase(Locale.ROOT); } } diff --git a/src/main/java/tech/jhipster/lite/project/domain/download/Project.java b/src/main/java/tech/jhipster/lite/project/domain/download/Project.java index 23ee7fceafd..2a5159d7136 100644 --- a/src/main/java/tech/jhipster/lite/project/domain/download/Project.java +++ b/src/main/java/tech/jhipster/lite/project/domain/download/Project.java @@ -5,6 +5,7 @@ import tech.jhipster.lite.shared.error.domain.Assert; import tech.jhipster.lite.shared.generation.domain.ExcludeFromGeneratedCodeCoverage; +@SuppressWarnings("ArrayRecordComponent") public record Project(ProjectName name, byte[] content) { public Project { Assert.notNull("name", name); @@ -28,11 +29,10 @@ public boolean equals(Object obj) { return true; } - if (obj == null || getClass() != obj.getClass()) { + if (!(obj instanceof Project other)) { return false; } - Project other = (Project) obj; return new EqualsBuilder().append(name, other.name).append(content, other.content).isEquals(); } diff --git a/src/main/java/tech/jhipster/lite/project/domain/download/ProjectName.java b/src/main/java/tech/jhipster/lite/project/domain/download/ProjectName.java index b3800bb928f..5b6c779f12c 100644 --- a/src/main/java/tech/jhipster/lite/project/domain/download/ProjectName.java +++ b/src/main/java/tech/jhipster/lite/project/domain/download/ProjectName.java @@ -1,5 +1,6 @@ package tech.jhipster.lite.project.domain.download; +import java.util.Locale; import tech.jhipster.lite.shared.error.domain.Assert; public record ProjectName(String name) { @@ -14,7 +15,7 @@ public ProjectName(String name) { private String format(String name) { Assert.notBlank("name", name); - return name.toLowerCase().replace(' ', '-').replaceAll("[^0-9a-z-]", "").trim(); + return name.toLowerCase(Locale.ROOT).replace(' ', '-').replaceAll("[^0-9a-z-]", "").trim(); } public String filename() { diff --git a/src/main/java/tech/jhipster/lite/shared/base64/domain/Base64Utils.java b/src/main/java/tech/jhipster/lite/shared/base64/domain/Base64Utils.java index 01cc2a0e829..a5c7a9ef58b 100644 --- a/src/main/java/tech/jhipster/lite/shared/base64/domain/Base64Utils.java +++ b/src/main/java/tech/jhipster/lite/shared/base64/domain/Base64Utils.java @@ -1,5 +1,7 @@ package tech.jhipster.lite.shared.base64.domain; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.security.SecureRandom; import java.util.Base64; @@ -10,7 +12,7 @@ public final class Base64Utils { private Base64Utils() {} public static String getBase64Secret() { - return Base64.getEncoder().encodeToString(getRandomHexString(64).getBytes()); + return Base64.getEncoder().encodeToString(getRandomHexString(64).getBytes(UTF_8)); } private static String getRandomHexString(int length) { diff --git a/src/main/java/tech/jhipster/lite/shared/enumeration/domain/Enums.java b/src/main/java/tech/jhipster/lite/shared/enumeration/domain/Enums.java index 35266eb75ba..9468bda182b 100644 --- a/src/main/java/tech/jhipster/lite/shared/enumeration/domain/Enums.java +++ b/src/main/java/tech/jhipster/lite/shared/enumeration/domain/Enums.java @@ -29,18 +29,18 @@ private static final class EnumMappings { @SuppressWarnings("unchecked") private , To extends Enum> To get(Enum from, Class to) { - return (To) cache.computeIfAbsent(new CacheKey<>(from.getClass(), to), buildCache(from)).get(from); + CacheKey key = new CacheKey<>(from.getDeclaringClass(), to); + return (To) cache.computeIfAbsent(key, buildCache(from)).get(from); } - @SuppressWarnings("unchecked") - private > Function, Map, Enum>> buildCache(Enum from) { + private Function, Map, Enum>> buildCache(Enum from) { return key -> { try { return Arrays.stream(key.from().getEnumConstants()).collect( Collectors.toMap(Function.identity(), source -> Enum.valueOf(key.to(), source.name())) ); } catch (IllegalArgumentException e) { - throw new UnmappableEnumException(from.getClass(), key.to()); + throw new UnmappableEnumException(from.getDeclaringClass(), key.to()); } }; } diff --git a/src/main/java/tech/jhipster/lite/statistic/infrastructure/secondary/AppliedModuleDocument.java b/src/main/java/tech/jhipster/lite/statistic/infrastructure/secondary/AppliedModuleDocument.java index c355ec5c417..c6fa1119cf7 100644 --- a/src/main/java/tech/jhipster/lite/statistic/infrastructure/secondary/AppliedModuleDocument.java +++ b/src/main/java/tech/jhipster/lite/statistic/infrastructure/secondary/AppliedModuleDocument.java @@ -92,12 +92,10 @@ public boolean equals(Object obj) { return true; } - if (obj == null || getClass() != obj.getClass()) { + if (!(obj instanceof AppliedModuleDocument other)) { return false; } - AppliedModuleDocument other = (AppliedModuleDocument) obj; - return new EqualsBuilder().append(id, other.id).isEquals(); } } diff --git a/src/test/java/tech/jhipster/lite/shared/memoizer/domain/MemoizersTest.java b/src/test/java/tech/jhipster/lite/shared/memoizer/domain/MemoizersTest.java index 1f5a513deb4..c3a6b20987e 100644 --- a/src/test/java/tech/jhipster/lite/shared/memoizer/domain/MemoizersTest.java +++ b/src/test/java/tech/jhipster/lite/shared/memoizer/domain/MemoizersTest.java @@ -1,6 +1,6 @@ package tech.jhipster.lite.shared.memoizer.domain; -import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Function; @@ -29,6 +29,7 @@ void shouldMemoizeFunctionResult() { } @Test + @SuppressWarnings("ReturnValueIgnored") void shouldMemoizeNullResult() { NullFactory factory = new NullFactory(); Function memoizer = Memoizers.of(factory);