Skip to content

Commit

Permalink
Merge pull request #11602 from murdos/error-prone
Browse files Browse the repository at this point in the history
chore(generator): configure Error Prone and fix existing issues
  • Loading branch information
murdos authored Dec 20, 2024
2 parents a9d4808 + af14698 commit 755f3c1
Show file tree
Hide file tree
Showing 30 changed files with 174 additions and 58 deletions.
10 changes: 10 additions & 0 deletions .mvn/jvm.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
--add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
--add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED
25 changes: 25 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,14 @@
<testcontainers.version>1.20.4</testcontainers.version>
<mongock.version>5.5.0</mongock.version>
<git-commit-id-plugin.version>9.0.1</git-commit-id-plugin.version>
<checkstyle.version>10.21.0</checkstyle.version>
<maven-checkstyle-plugin.version>3.6.0</maven-checkstyle-plugin.version>

<frontend-maven-plugin.version>1.15.1</frontend-maven-plugin.version>
<checksum-maven-plugin.version>1.11</checksum-maven-plugin.version>
<maven-antrun-plugin.version>3.1.0</maven-antrun-plugin.version>
<approvaltests.version>24.12.0</approvaltests.version>
<error-prone.version>2.36.0</error-prone.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -292,11 +294,27 @@
<configuration>
<release>${java.version}</release>
<parameters>true</parameters>
<compilerArgs>
<arg>-XDcompilePolicy=simple</arg>
<arg>--should-stop=ifError=FLOW</arg>
<arg>
-Xplugin:ErrorProne
-Xep:BadImport:OFF
-Xep:UnnecessaryLambda:OFF
-Xep:UnnecessaryStringBuilder:OFF
-Xep:ImmutableEnumChecker:OFF
</arg>
</compilerArgs>
<annotationProcessorPaths>
<path>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
</path>
<path>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_core</artifactId>
<version>${error-prone.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
Expand Down Expand Up @@ -571,6 +589,13 @@
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>${checkstyle.version}</version>
</dependency>
</dependencies>
</plugin>

<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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"))
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public Path pathInProject(JHipsterProjectFolder project) {
@Override
@ExcludeFromGeneratedCodeCoverage
public int hashCode() {
return new HashCodeBuilder().append(destination).hashCode();
return new HashCodeBuilder().append(destination).toHashCode();
}

@Override
Expand All @@ -66,11 +66,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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ record GitIgnorePattern(String value) implements GitIgnoreEntry {
Assert.notBlank("value", value);
}

@Override
public String get() {
return value;
}
Expand All @@ -28,6 +29,7 @@ public GitIgnoreComment(String value) {
this.value = value.startsWith(COMMENT_PREFIX) ? value : COMMENT_PREFIX + " " + value;
}

@Override
public String get() {
return value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ private GradleCorePlugin(GradleCorePluginBuilder builder) {
toolVersionSlug = Optional.ofNullable(builder.toolVersionSlug);
}

@Override
public GradlePluginId id() {
return id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,16 @@ public Collection<Object> 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public String get() {
}

public String majorVersion() {
return version().split("\\.")[0];
return version().split("\\.", -1)[0];
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -140,7 +151,7 @@ private String replaceType(Indentation indentation, Optional<NodeModuleFormat> n
.blockName("type")
.jsonContent(content)
.indentation(indentation)
.blockValue(nodeModuleFormat.orElseThrow().name().toLowerCase())
.blockValue(nodeModuleFormat.orElseThrow().name().toLowerCase(Locale.ROOT))
.apply();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public String render(String message, Map<String, ?> context) {
}
}

private static class CustomMustacheFactory extends DefaultMustacheFactory {
private static final class CustomMustacheFactory extends DefaultMustacheFactory {

@Override
public MustacheVisitor createMustacheVisitor() {
Expand Down
Loading

0 comments on commit 755f3c1

Please sign in to comment.