Skip to content

Commit

Permalink
Merge pull request #11668 from murdos/modernizer-maven-plugin
Browse files Browse the repository at this point in the history
chore(generator): configure Modernizer maven plugin
  • Loading branch information
pascalgrimaud authored Jan 2, 2025
2 parents d8b44c4 + cd8a78b commit d95b7e3
Show file tree
Hide file tree
Showing 46 changed files with 274 additions and 208 deletions.
20 changes: 20 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
<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>
<modernizer-maven-plugin.version>3.0.0</modernizer-maven-plugin.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -383,6 +384,25 @@
</executions>
</plugin>

<plugin>
<groupId>org.gaul</groupId>
<artifactId>modernizer-maven-plugin</artifactId>
<version>${modernizer-maven-plugin.version}</version>
<configuration>
<javaVersion>${java.version}</javaVersion>
<failOnViolations>true</failOnViolations>
</configuration>
<executions>
<execution>
<id>modernizer</id>
<phase>verify</phase>
<goals>
<goal>modernizer</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>net.nicoulaj.maven.plugins</groupId>
<artifactId>checksum-maven-plugin</artifactId>
Expand Down
71 changes: 59 additions & 12 deletions src/main/java/tech/jhipster/lite/module/domain/JHipsterModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import static tech.jhipster.lite.module.domain.replacement.ReplacementCondition.notContainingReplacement;

import java.nio.file.Paths;
import java.util.*;
import java.nio.file.Path;
import java.util.Collection;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.function.Consumer;
import java.util.function.Function;
Expand All @@ -14,43 +17,87 @@
import tech.jhipster.lite.module.domain.JHipsterModulePreActions.JHipsterModulePreActionsBuilder;
import tech.jhipster.lite.module.domain.buildproperties.JHipsterModuleBuildProperties;
import tech.jhipster.lite.module.domain.buildproperties.JHipsterModuleBuildProperties.JHipsterModuleBuildPropertiesBuilder;
import tech.jhipster.lite.module.domain.file.*;
import tech.jhipster.lite.module.domain.file.JHipsterDestination;
import tech.jhipster.lite.module.domain.file.JHipsterFilesToDelete;
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.file.JHipsterModuleFiles.JHipsterModuleFilesBuilder;
import tech.jhipster.lite.module.domain.file.JHipsterSource;
import tech.jhipster.lite.module.domain.gitignore.JHipsterModuleGitIgnore;
import tech.jhipster.lite.module.domain.gitignore.JHipsterModuleGitIgnore.JHipsterModuleGitIgnoreBuilder;
import tech.jhipster.lite.module.domain.gradleconfiguration.JHipsterModuleGradleConfigurations;
import tech.jhipster.lite.module.domain.gradleconfiguration.JHipsterModuleGradleConfigurations.JHipsterModuleGradleConfigurationBuilder;
import tech.jhipster.lite.module.domain.gradleplugin.*;
import tech.jhipster.lite.module.domain.gradleplugin.GradleCommunityPlugin;
import tech.jhipster.lite.module.domain.gradleplugin.GradleCommunityPlugin.GradleCommunityPluginIdBuilder;
import tech.jhipster.lite.module.domain.gradleplugin.GradleCommunityProfilePlugin;
import tech.jhipster.lite.module.domain.gradleplugin.GradleCommunityProfilePlugin.GradleCommunityProfilePluginIdBuilder;
import tech.jhipster.lite.module.domain.gradleplugin.GradleCorePlugin;
import tech.jhipster.lite.module.domain.gradleplugin.GradleCorePlugin.GradleCorePluginIdBuilder;
import tech.jhipster.lite.module.domain.gradleplugin.JHipsterModuleGradlePlugins;
import tech.jhipster.lite.module.domain.gradleplugin.JHipsterModuleGradlePlugins.JHipsterModuleGradlePluginBuilder;
import tech.jhipster.lite.module.domain.javabuild.*;
import tech.jhipster.lite.module.domain.javabuild.ArtifactId;
import tech.jhipster.lite.module.domain.javabuild.GroupId;
import tech.jhipster.lite.module.domain.javabuild.JHipsterModuleMavenBuildExtensions;
import tech.jhipster.lite.module.domain.javabuild.JHipsterModuleMavenBuildExtensions.JHipsterModuleMavenBuildExtensionsBuilder;
import tech.jhipster.lite.module.domain.javabuild.MavenBuildExtension;
import tech.jhipster.lite.module.domain.javabuild.MavenBuildExtension.MavenBuildExtensionGroupIdBuilder;
import tech.jhipster.lite.module.domain.javabuildprofile.*;
import tech.jhipster.lite.module.domain.javabuild.VersionSlug;
import tech.jhipster.lite.module.domain.javabuildprofile.BuildProfileActivation;
import tech.jhipster.lite.module.domain.javabuildprofile.BuildProfileActivation.BuildProfileActivationBuilder;
import tech.jhipster.lite.module.domain.javabuildprofile.BuildProfileId;
import tech.jhipster.lite.module.domain.javabuildprofile.JHipsterModuleJavaBuildProfiles;
import tech.jhipster.lite.module.domain.javabuildprofile.JHipsterModuleJavaBuildProfiles.JHipsterModuleJavaBuildProfilesBuilder;
import tech.jhipster.lite.module.domain.javadependency.*;
import tech.jhipster.lite.module.domain.javadependency.DependencyId;
import tech.jhipster.lite.module.domain.javadependency.JHipsterModuleJavaDependencies;
import tech.jhipster.lite.module.domain.javadependency.JHipsterModuleJavaDependencies.JHipsterModuleJavaDependenciesBuilder;
import tech.jhipster.lite.module.domain.javadependency.JavaDependency;
import tech.jhipster.lite.module.domain.javadependency.JavaDependency.JavaDependencyGroupIdBuilder;
import tech.jhipster.lite.module.domain.javaproperties.*;
import tech.jhipster.lite.module.domain.javaproperties.Comment;
import tech.jhipster.lite.module.domain.javaproperties.JHipsterModuleSpringFactories;
import tech.jhipster.lite.module.domain.javaproperties.JHipsterModuleSpringFactories.JHipsterModuleSpringFactoriesBuilder;
import tech.jhipster.lite.module.domain.javaproperties.JHipsterModuleSpringProperties;
import tech.jhipster.lite.module.domain.javaproperties.JHipsterModuleSpringProperties.JHipsterModuleSpringPropertiesBuilder;
import tech.jhipster.lite.module.domain.javaproperties.PropertyKey;
import tech.jhipster.lite.module.domain.javaproperties.PropertyValue;
import tech.jhipster.lite.module.domain.javaproperties.SpringComment;
import tech.jhipster.lite.module.domain.javaproperties.SpringComments;
import tech.jhipster.lite.module.domain.javaproperties.SpringFactories;
import tech.jhipster.lite.module.domain.javaproperties.SpringFactory;
import tech.jhipster.lite.module.domain.javaproperties.SpringFactoryType;
import tech.jhipster.lite.module.domain.javaproperties.SpringProfile;
import tech.jhipster.lite.module.domain.javaproperties.SpringProperties;
import tech.jhipster.lite.module.domain.javaproperties.SpringProperty;
import tech.jhipster.lite.module.domain.javaproperties.SpringPropertyType;
import tech.jhipster.lite.module.domain.jooqplugin.JooqModuleCodegenConfiguration;
import tech.jhipster.lite.module.domain.mavenplugin.*;
import tech.jhipster.lite.module.domain.mavenplugin.JHipsterModuleMavenPlugins;
import tech.jhipster.lite.module.domain.mavenplugin.JHipsterModuleMavenPlugins.JHipsterModuleMavenPluginsBuilder;
import tech.jhipster.lite.module.domain.mavenplugin.MavenPlugin;
import tech.jhipster.lite.module.domain.mavenplugin.MavenPlugin.MavenPluginGroupIdBuilder;
import tech.jhipster.lite.module.domain.mavenplugin.MavenPluginExecution;
import tech.jhipster.lite.module.domain.mavenplugin.MavenPluginExecution.MavenPluginExecutionGoalsBuilder;
import tech.jhipster.lite.module.domain.packagejson.*;
import tech.jhipster.lite.module.domain.packagejson.JHipsterModulePackageJson;
import tech.jhipster.lite.module.domain.packagejson.JHipsterModulePackageJson.JHipsterModulePackageJsonBuilder;
import tech.jhipster.lite.module.domain.packagejson.PackageName;
import tech.jhipster.lite.module.domain.packagejson.ScriptCommand;
import tech.jhipster.lite.module.domain.packagejson.ScriptKey;
import tech.jhipster.lite.module.domain.postaction.JHipsterModulePostActions;
import tech.jhipster.lite.module.domain.postaction.JHipsterModulePostActions.JHipsterModulePostActionsBuilder;
import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties;
import tech.jhipster.lite.module.domain.properties.JHipsterProjectFolder;
import tech.jhipster.lite.module.domain.replacement.*;
import tech.jhipster.lite.module.domain.replacement.EndOfFileReplacer;
import tech.jhipster.lite.module.domain.replacement.FileStartReplacer;
import tech.jhipster.lite.module.domain.replacement.JHipsterModuleMandatoryReplacementsFactory;
import tech.jhipster.lite.module.domain.replacement.JHipsterModuleMandatoryReplacementsFactory.JHipsterModuleMandatoryReplacementsFactoryBuilder;
import tech.jhipster.lite.module.domain.replacement.JHipsterModuleOptionalReplacementsFactory;
import tech.jhipster.lite.module.domain.replacement.JHipsterModuleOptionalReplacementsFactory.JHipsterModuleOptionalReplacementsFactoryBuilder;
import tech.jhipster.lite.module.domain.replacement.RegexNeedleAfterReplacer;
import tech.jhipster.lite.module.domain.replacement.RegexNeedleBeforeReplacer;
import tech.jhipster.lite.module.domain.replacement.RegexReplacer;
import tech.jhipster.lite.module.domain.replacement.ReplacementCondition;
import tech.jhipster.lite.module.domain.replacement.TextNeedleAfterReplacer;
import tech.jhipster.lite.module.domain.replacement.TextNeedleBeforeReplacer;
import tech.jhipster.lite.module.domain.replacement.TextReplacer;
import tech.jhipster.lite.module.domain.startupcommand.JHipsterModuleStartupCommands;
import tech.jhipster.lite.module.domain.startupcommand.JHipsterModuleStartupCommands.JHipsterModuleStartupCommandsBuilder;
import tech.jhipster.lite.module.domain.startupcommand.JHipsterStartupCommands;
Expand Down Expand Up @@ -210,7 +257,7 @@ public static MavenPluginGroupIdBuilder mavenPlugin() {
public static JHipsterSource from(String source) {
Assert.notBlank("source", source);

return new JHipsterSource(Paths.get("/generator", source));
return new JHipsterSource(Path.of("/generator", source));
}

public static JHipsterProjectFilePath path(String path) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package tech.jhipster.lite.module.domain;

import static tech.jhipster.lite.module.domain.javabuild.JavaBuildTool.*;
import static tech.jhipster.lite.module.domain.properties.SpringConfigurationFormat.*;
import static tech.jhipster.lite.module.domain.javabuild.JavaBuildTool.GRADLE;
import static tech.jhipster.lite.module.domain.javabuild.JavaBuildTool.MAVEN;
import static tech.jhipster.lite.module.domain.properties.SpringConfigurationFormat.PROPERTIES;

import java.time.Instant;
import java.util.Collection;
Expand Down Expand Up @@ -142,7 +143,12 @@ private JHipsterStartupCommands buildStartupCommands(JHipsterModule module) {
if (javaBuildTool.isEmpty()) {
return module.startupCommands();
}
var filteredCommands = module.startupCommands().get().stream().filter(isStartupCommandCompatibleWith(javaBuildTool.get())).toList();
var filteredCommands = module
.startupCommands()
.get()
.stream()
.filter(isStartupCommandCompatibleWith(javaBuildTool.orElseThrow()))
.toList();
return new JHipsterStartupCommands(filteredCommands);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import tech.jhipster.lite.shared.error.domain.Assert;

public record JHipsterProjectFolder(String folder) {
Expand All @@ -13,7 +12,7 @@ public record JHipsterProjectFolder(String folder) {
public Path filePath(String file) {
Assert.notNull("file", file);

return Paths.get(folder(), file);
return Path.of(folder(), file);
}

public boolean fileExists(String fileName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.stream.Stream;
import org.springframework.stereotype.Repository;
import tech.jhipster.lite.module.domain.GeneratedProjectRepository;
Expand All @@ -22,7 +21,7 @@ public JHipsterProjectFilesPaths list(JHipsterProjectFolder folder, JHipsterFile
Assert.notNull("folder", folder);
Assert.notNull("files", files);

try (Stream<Path> content = Files.walk(Paths.get(folder.get()))) {
try (Stream<Path> content = Files.walk(Path.of(folder.get()))) {
return new JHipsterProjectFilesPaths(
content
.filter(file -> !Files.isDirectory(file))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.yaml.snakeyaml.comments.CommentType.BLOCK;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -65,7 +63,7 @@ public void setValue(PropertyKey key, PropertyValue value) {
Assert.notNull("value", value);

try {
MappingNode configuration = loadConfiguration(file.toFile());
MappingNode configuration = loadConfiguration();
appendPropertyToConfiguration(key, value, configuration);
saveConfiguration(configuration);
} catch (IOException exception) {
Expand All @@ -79,7 +77,7 @@ public void setComment(PropertyKey key, Comment comment) {
Assert.notNull("comment", comment);

try {
MappingNode configuration = loadConfiguration(file.toFile());
MappingNode configuration = loadConfiguration();
addCommentToConfiguration(key, comment, configuration);
saveConfiguration(configuration);
} catch (IOException exception) {
Expand Down Expand Up @@ -201,19 +199,19 @@ private static List<String> extractKeysParts(PropertyKey key) {
return Arrays.stream(key.get().split("\\.(?![^'\\[]*])")).map(subKey -> subKey.replace("'[", "[").replace("]'", "]")).toList();
}

private MappingNode loadConfiguration(File yamlFile) throws IOException {
if (!yamlFile.exists()) {
private MappingNode loadConfiguration() throws IOException {
if (!file.toFile().exists()) {
return new MappingNode(Tag.MAP, new ArrayList<>(), FlowStyle.AUTO);
}

try (FileReader reader = new FileReader(yamlFile, UTF_8)) {
try (Reader reader = Files.newBufferedReader(file, UTF_8)) {
return (MappingNode) yaml.compose(reader);
}
}

private void saveConfiguration(Node actualConfiguration) throws IOException {
Files.createDirectories(file.getParent());
Writer writer = new FileWriter(file.toFile(), UTF_8);
Writer writer = Files.newBufferedWriter(file, UTF_8);
yaml.serialize(actualConfiguration, writer);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Optional;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
Expand Down Expand Up @@ -66,6 +67,6 @@ public void commitAll(JHipsterProjectFolder folder, GitCommitMessage message) {
}

private File folderFile(JHipsterProjectFolder folder) {
return new File(folder.get());
return Path.of(folder.get()).toFile();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Repository;
import tech.jhipster.lite.module.domain.ProjectFiles;
Expand Down Expand Up @@ -35,7 +34,7 @@ public GradleVersionCatalogDependenciesReader(ProjectFiles files) {
}

private static Path writeToTemporaryFile(String tomlConfigContent) throws IOException {
File tempFile = File.createTempFile("gradle-deps", ".toml", Paths.get(System.getProperty("java.io.tmpdir")).toFile());
File tempFile = File.createTempFile("gradle-deps", ".toml", Path.of(System.getProperty("java.io.tmpdir")).toFile());
Files.writeString(tempFile.toPath(), tomlConfigContent);
return tempFile.toPath();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;
Expand All @@ -27,7 +26,7 @@ class FileSystemProjectDownloader {
public Optional<Project> download(ProjectPath path) {
Assert.notNull("path", path);

Path source = Paths.get(path.get());
Path source = Path.of(path.get());

if (notAProject(source)) {
return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Optional;
import org.springframework.stereotype.Repository;
import tech.jhipster.lite.project.domain.ProjectPath;
Expand Down Expand Up @@ -82,6 +81,6 @@ public ProjectHistory getHistory(ProjectPath path) {
}

private Path historyFilePath(ProjectPath path) {
return Paths.get(path.get(), HISTORY_FOLDER, HISTORY_FILE);
return Path.of(path.get(), HISTORY_FOLDER, HISTORY_FILE);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package tech.jhipster.lite.shared.projectfolder.domain;

import java.nio.file.Paths;
import java.nio.file.Path;
import java.util.UUID;
import tech.jhipster.lite.shared.error.domain.Assert;

Expand All @@ -23,6 +23,6 @@ public boolean isInvalid(String folderPath) {

@Override
public String generatePath() {
return Paths.get(prefix).resolve(UUID.randomUUID().toString()).toString();
return Path.of(prefix).resolve(UUID.randomUUID().toString()).toString();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package tech.jhipster.lite.shared.projectfolder.domain;

import java.nio.file.Paths;
import java.nio.file.Path;
import java.util.UUID;
import org.apache.commons.lang3.SystemUtils;

Expand All @@ -13,6 +13,6 @@ public boolean isInvalid(String folderPath) {

@Override
public String generatePath() {
return Paths.get(SystemUtils.JAVA_IO_TMPDIR).resolve(UUID.randomUUID().toString()).toString();
return Path.of(SystemUtils.JAVA_IO_TMPDIR).resolve(UUID.randomUUID().toString()).toString();
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package tech.jhipster.lite.statistic.infrastructure.secondary;

import java.time.Instant;
import java.util.*;
import java.util.Collection;
import java.util.Collections;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Predicate;
import org.springframework.stereotype.Repository;
import tech.jhipster.lite.module.domain.JHipsterModuleSlug;
import tech.jhipster.lite.shared.error.domain.Assert;
import tech.jhipster.lite.statistic.domain.*;
import tech.jhipster.lite.statistic.domain.AppliedModule;
import tech.jhipster.lite.statistic.domain.Statistics;
import tech.jhipster.lite.statistic.domain.StatisticsRepository;
import tech.jhipster.lite.statistic.domain.criteria.StatisticsCriteria;

@Repository
Expand Down Expand Up @@ -40,11 +44,11 @@ public Statistics get(StatisticsCriteria criteria) {
}

private static Predicate<AppliedModule> isAfter(Optional<Instant> startTime) {
return appliedModule -> (startTime.isEmpty() || appliedModule.date().isAfter(startTime.get()));
return appliedModule -> startTime.map(start -> appliedModule.date().isAfter(start)).orElse(true);
}

private static Predicate<AppliedModule> isBefore(Optional<Instant> endTime) {
return appliedModule -> (endTime.isEmpty() || appliedModule.date().isBefore(endTime.get()));
return appliedModule -> endTime.map(end -> appliedModule.date().isBefore(end)).orElse(true);
}

private static Predicate<AppliedModule> hasModuleSlug(Optional<JHipsterModuleSlug> moduleSlug) {
Expand Down
Loading

0 comments on commit d95b7e3

Please sign in to comment.