From 0245d231712a13c9f09a643e3942b51edc29a4c1 Mon Sep 17 00:00:00 2001 From: Valentin Delaye Date: Tue, 7 Jan 2025 12:22:07 +0100 Subject: [PATCH 1/5] Avoid hardcoding implicit JDK and workarround #580 --- .../core/extractor/JenkinsfileVisitor.java | 6 ++--- .../core/impl/PluginModernizer.java | 25 +++++++++++-------- .../pluginmodernizer/core/model/JDK.java | 20 +++++++++++++++ .../core/utils/StaticPomParser.java | 14 +++++++++++ .../core/extractor/FetchMetadataTest.java | 6 ++--- .../pluginmodernizer/core/model/JDKTest.java | 12 +++++++++ 6 files changed, 67 insertions(+), 16 deletions(-) diff --git a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/extractor/JenkinsfileVisitor.java b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/extractor/JenkinsfileVisitor.java index c7a235a3..f015b2c5 100644 --- a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/extractor/JenkinsfileVisitor.java +++ b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/extractor/JenkinsfileVisitor.java @@ -84,8 +84,8 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Plugi // Empty args means Java 8 in Windows and Linux if (args.size() == 1 && args.get(0) instanceof J.Empty) { - pluginMetadata.addPlatform(new PlatformConfig(Platform.LINUX, JDK.JAVA_8, null, true)); - pluginMetadata.addPlatform(new PlatformConfig(Platform.WINDOWS, JDK.JAVA_8, null, true)); + pluginMetadata.addPlatform(new PlatformConfig(Platform.LINUX, JDK.getImplicit(), null, true)); + pluginMetadata.addPlatform(new PlatformConfig(Platform.WINDOWS, JDK.getImplicit(), null, true)); return method; } @@ -112,7 +112,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Plugi for (PlatformConfig pc : platforms) { if (!pc.name().equals(Platform.UNKNOWN)) { if (platforms.stream().allMatch(p -> p.jdk() == null)) { - newPlatforms.add(new PlatformConfig(pc.name(), JDK.JAVA_8, null, false)); + newPlatforms.add(new PlatformConfig(pc.name(), JDK.getImplicit(), null, false)); continue; } for (PlatformConfig pc2 : platforms) { diff --git a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/impl/PluginModernizer.java b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/impl/PluginModernizer.java index ab00c849..da0e5c75 100644 --- a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/impl/PluginModernizer.java +++ b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/impl/PluginModernizer.java @@ -268,14 +268,19 @@ private void process(Plugin plugin) { return; } - // Handle Java 8 plugins and outdated - if (plugin.getMetadata().getJdks().stream().allMatch(jdk -> jdk.equals(JDK.JAVA_8))) { - String jenkinsVersion = new StaticPomParser( - plugin.getLocalRepository().resolve("pom.xml").toString()) - .getJenkinsVersion(); - LOG.debug("Found jenkins version {}", jenkinsVersion); - JDK jdk = JDK.get(jenkinsVersion).stream().findFirst().orElse(JDK.JAVA_8); - LOG.info("Plugin support Java {}. Need a first compile to general classes", jdk.getMajor()); + // Handle outdated plugin or unparsable Jenkinsfile + if (plugin.getMetadata().getJdks().stream().allMatch(jdk -> jdk.equals(JDK.getImplicit()))) { + LOG.info("Plugin look outdated or without Jenkinsfile."); + StaticPomParser parser = new StaticPomParser( + plugin.getLocalRepository().resolve("pom.xml").toString()); + String jenkinsVersion = parser.getJenkinsVersion(); + String baseline = parser.getBaseline(); + if (baseline != null && jenkinsVersion != null && jenkinsVersion.contains("${jenkins.baseline}")) { + jenkinsVersion = jenkinsVersion.replace("${jenkins.baseline}", baseline); + } + LOG.debug("Found jenkins version from pom {}", jenkinsVersion); + JDK jdk = JDK.get(jenkinsVersion).stream().findFirst().orElse(JDK.min()); + LOG.info("Plugin support Java {}. Need a first compile to generate classes", jdk.getMajor()); plugin.verifyQuickBuild(mavenInvoker, jdk); if (plugin.hasErrors()) { plugin.raiseLastError(); @@ -389,7 +394,7 @@ private void collectMetadata(Plugin plugin, boolean retryAfterFirstCompile) { */ private JDK compilePlugin(Plugin plugin) { PluginMetadata metadata = plugin.getMetadata(); - JDK jdk = JDK.min(metadata.getJdks()); + JDK jdk = JDK.min(metadata.getJdks(), metadata.getJenkinsVersion()); plugin.withJDK(jdk); plugin.clean(mavenInvoker); plugin.compile(mavenInvoker); @@ -412,7 +417,7 @@ private JDK verifyPlugin(Plugin plugin) { "No JDKs found in metadata for plugin {}. Using same JDK as rewrite for verification", plugin.getName()); } else { - jdk = JDK.min(metadata.getJdks()); + jdk = JDK.min(metadata.getJdks(), metadata.getJenkinsVersion()); LOG.info("Using minimum JDK {} from metadata for plugin {}", jdk.getMajor(), plugin.getName()); } // If the plugin was modernized we should find next JDK compatible diff --git a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/model/JDK.java b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/model/JDK.java index 5c9fd0de..f3662c61 100644 --- a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/model/JDK.java +++ b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/model/JDK.java @@ -139,6 +139,14 @@ public boolean supported(String jenkinsVersion) { return get(jenkinsVersion).contains(this); } + /** + * Get the implicit JDK when not specified on Jenkinsfile + * @return The implicit JDK + */ + public static JDK getImplicit() { + return JDK.JAVA_8; + } + /** * Has next predicate * @param jdk The JDK @@ -221,6 +229,18 @@ public static JDK min(Set jdks) { return jdks.stream().min(JDK::compareMajor).orElseThrow(); } + /** + * Return the minimum JDK + * @param jdks List of JDKS. Can be null or empty + * @return The minimum JDK. If the list is empty, return the minimum JDK available + */ + public static JDK min(Set jdks, String jenkinsVersion) { + if (jdks == null || jdks.isEmpty() && jenkinsVersion == null) { + return JDK.min(); + } + return JDK.get(jenkinsVersion).stream().min(JDK::compareMajor).orElseThrow(); + } + /** * Return a list of all JDK sorted by major version * @return The list of JDKs diff --git a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/utils/StaticPomParser.java b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/utils/StaticPomParser.java index 8c696100..79e87ba4 100644 --- a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/utils/StaticPomParser.java +++ b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/utils/StaticPomParser.java @@ -82,6 +82,20 @@ public String getJenkinsVersion() { } } + /** + * Return the Jenkins baseline of the POM file. + * @return the Jenkins baseline or null if not found + */ + public String getBaseline() { + XPath xPath = XPathFactory.newInstance().newXPath(); + try { + return xPath.compile("/project/properties/jenkins.baseline").evaluate(document); + } catch (Exception e) { + LOG.warn("Error getting baseline: {}", e.getMessage()); + return null; + } + } + /** * Return the groupId of the POM file. * @return the groupId or null if not found diff --git a/plugin-modernizer-core/src/test/java/io/jenkins/tools/pluginmodernizer/core/extractor/FetchMetadataTest.java b/plugin-modernizer-core/src/test/java/io/jenkins/tools/pluginmodernizer/core/extractor/FetchMetadataTest.java index 8b84080e..22a45161 100644 --- a/plugin-modernizer-core/src/test/java/io/jenkins/tools/pluginmodernizer/core/extractor/FetchMetadataTest.java +++ b/plugin-modernizer-core/src/test/java/io/jenkins/tools/pluginmodernizer/core/extractor/FetchMetadataTest.java @@ -554,8 +554,8 @@ void testPluginWithJenkinsfileWithJdkInfoVersionVar() { void testPluginWithJenkinsfileDefault() { // Keep in sync with https://github.com/jenkins-infra/pipeline-library with default JDK and 2 platforms - EXPECTED_METADATA.addPlatform(Platform.LINUX, JDK.JAVA_8, null); - EXPECTED_METADATA.addPlatform(Platform.WINDOWS, JDK.JAVA_8, null); + EXPECTED_METADATA.addPlatform(Platform.LINUX, JDK.getImplicit(), null); + EXPECTED_METADATA.addPlatform(Platform.WINDOWS, JDK.getImplicit(), null); rewriteRun( recipeSpec -> recipeSpec.recipe(new FetchMetadata()), @@ -574,7 +574,7 @@ void testPluginWithJenkinsfileDefault() { Set jdkVersion = pluginMetadata.getJdks(); assertEquals(1, jdkVersion.size()); assertNull(pluginMetadata.isUseContainerAgent()); - assertTrue(jdkVersion.contains(JDK.JAVA_8)); + assertTrue(jdkVersion.contains(JDK.getImplicit())); // Assert platform Set platforms = pluginMetadata.getPlatforms(); diff --git a/plugin-modernizer-core/src/test/java/io/jenkins/tools/pluginmodernizer/core/model/JDKTest.java b/plugin-modernizer-core/src/test/java/io/jenkins/tools/pluginmodernizer/core/model/JDKTest.java index cbd7479c..335a8780 100644 --- a/plugin-modernizer-core/src/test/java/io/jenkins/tools/pluginmodernizer/core/model/JDKTest.java +++ b/plugin-modernizer-core/src/test/java/io/jenkins/tools/pluginmodernizer/core/model/JDKTest.java @@ -3,6 +3,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; +import java.util.Set; import org.junit.jupiter.api.Test; public class JDKTest { @@ -47,6 +48,17 @@ public void all() { assertEquals(JDK.JAVA_21, JDK.all().get(3)); } + @Test + public void min() { + assertEquals(JDK.JAVA_8, JDK.min()); + assertEquals(JDK.JAVA_8, JDK.min(Set.of(JDK.values()))); + assertEquals(JDK.JAVA_8, JDK.min(Set.of(JDK.values()), "2.164.1")); + assertEquals(JDK.JAVA_8, JDK.min(Set.of(JDK.values()), "2.346.1")); + assertEquals(JDK.JAVA_11, JDK.min(Set.of(JDK.values()), "2.361.1")); + assertEquals(JDK.JAVA_11, JDK.min(Set.of(JDK.values()), "2.462.3")); + assertEquals(JDK.JAVA_17, JDK.min(Set.of(JDK.values()), "2.479.1")); + } + @Test public void getBuildableJdk() { From bf1f1ca34ec59f54c5dd331e794c1e7445b0985a Mon Sep 17 00:00:00 2001 From: Valentin Delaye Date: Tue, 7 Jan 2025 14:31:50 +0100 Subject: [PATCH 2/5] Fix missing title for SetupGitIgnore recipe --- .../src/main/jte/pr-title-SetupGitIgnore.jte | 5 +++++ .../core/utils/TemplateUtilsTest.java | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 plugin-modernizer-core/src/main/jte/pr-title-SetupGitIgnore.jte diff --git a/plugin-modernizer-core/src/main/jte/pr-title-SetupGitIgnore.jte b/plugin-modernizer-core/src/main/jte/pr-title-SetupGitIgnore.jte new file mode 100644 index 00000000..cd0910f2 --- /dev/null +++ b/plugin-modernizer-core/src/main/jte/pr-title-SetupGitIgnore.jte @@ -0,0 +1,5 @@ +@import io.jenkins.tools.pluginmodernizer.core.model.Plugin +@import io.jenkins.tools.pluginmodernizer.core.model.Recipe +@param Plugin plugin +@param Recipe recipe +Setup .gitignore file \ No newline at end of file diff --git a/plugin-modernizer-core/src/test/java/io/jenkins/tools/pluginmodernizer/core/utils/TemplateUtilsTest.java b/plugin-modernizer-core/src/test/java/io/jenkins/tools/pluginmodernizer/core/utils/TemplateUtilsTest.java index 6ccb75d1..8fc2fe4b 100644 --- a/plugin-modernizer-core/src/test/java/io/jenkins/tools/pluginmodernizer/core/utils/TemplateUtilsTest.java +++ b/plugin-modernizer-core/src/test/java/io/jenkins/tools/pluginmodernizer/core/utils/TemplateUtilsTest.java @@ -236,4 +236,24 @@ public void testFriendlyPrTitleEnsureRelativePath() { // Assert assertEquals("Disable local resolution of parent pom", result); } + + @Test + public void testFriendlyPrTitleSetupGitIgnore() { + + // Mocks + Plugin plugin = mock(Plugin.class); + PluginMetadata metadata = mock(PluginMetadata.class); + Recipe recipe = mock(Recipe.class); + + doReturn(metadata).when(plugin).getMetadata(); + doReturn("io.jenkins.tools.pluginmodernizer.SetupGitIgnore") + .when(recipe) + .getName(); + + // Test + String result = TemplateUtils.renderPullRequestTitle(plugin, recipe); + + // Assert + assertEquals("Setup .gitignore file", result); + } } From 6151d9ed261ec6c837e01aa66cb33c055cdc046c Mon Sep 17 00:00:00 2001 From: gounthar Date: Wed, 8 Jan 2025 14:54:51 +0100 Subject: [PATCH 3/5] fix(java): Typos --- .../tools/pluginmodernizer/core/impl/PluginModernizer.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/impl/PluginModernizer.java b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/impl/PluginModernizer.java index 720e8381..dd09ed3c 100644 --- a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/impl/PluginModernizer.java +++ b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/impl/PluginModernizer.java @@ -271,7 +271,7 @@ private void process(Plugin plugin) { // Handle outdated plugin or unparsable Jenkinsfile if (plugin.getMetadata().getJdks().stream().allMatch(jdk -> jdk.equals(JDK.getImplicit()))) { - LOG.info("Plugin look outdated or without Jenkinsfile."); + LOG.info("Plugin looks outdated or without Jenkinsfile."); StaticPomParser parser = new StaticPomParser( plugin.getLocalRepository().resolve("pom.xml").toString()); String jenkinsVersion = parser.getJenkinsVersion(); @@ -281,7 +281,7 @@ private void process(Plugin plugin) { } LOG.debug("Found jenkins version from pom {}", jenkinsVersion); JDK jdk = JDK.get(jenkinsVersion).stream().findFirst().orElse(JDK.min()); - LOG.info("Plugin support Java {}. Need a first compile to generate classes", jdk.getMajor()); + LOG.info("Plugin supports Java {}. Need a first compilation to generate classes", jdk.getMajor()); plugin.verifyQuickBuild(mavenInvoker, jdk); if (plugin.hasErrors()) { plugin.raiseLastError(); From 868716e78df898a8c5771329482eba5bc0dc9707 Mon Sep 17 00:00:00 2001 From: gounthar Date: Wed, 8 Jan 2025 18:57:13 +0100 Subject: [PATCH 4/5] fix(java): Typos. --- .../core/github/GHService.java | 26 ++++++------ .../core/impl/MavenInvoker.java | 40 +++++++++---------- .../core/impl/PluginModernizer.java | 4 +- .../pluginmodernizer/core/model/Plugin.java | 8 ++-- .../core/utils/JdkFetcher.java | 10 ++--- 5 files changed, 44 insertions(+), 44 deletions(-) diff --git a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/github/GHService.java b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/github/GHService.java index 44bacfc6..b0b5324c 100644 --- a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/github/GHService.java +++ b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/github/GHService.java @@ -93,11 +93,11 @@ public void validate() { } if (getGithubOwner() == null) { throw new ModernizerException( - "GitHub owner (username/organization) is not set. Please set GH_OWNER or GITHUB_OWNER environment variable. Or use --github-owner if running from CLI"); + "GitHub owner (username/organization) is not set. Please set GH_OWNER or GITHUB_OWNER environment variable. Or use --github-owner if running from CLI."); } if (config.getGithubAppId() != null && config.getGithubAppSourceInstallationId() != null) { if (Settings.GITHUB_APP_PRIVATE_KEY_FILE == null) { - throw new ModernizerException("GitHub App not configured. Please set GH_APP_PRIVATE_KEY_FILE"); + throw new ModernizerException("GitHub App is not configured. Please set GH_APP_PRIVATE_KEY_FILE."); } } } @@ -125,7 +125,7 @@ public void connect() { if (config.getGithubAppId() != null && config.getGithubAppSourceInstallationId() != null && config.getGithubAppTargetInstallationId() != null) { - LOG.debug("Connecting to GitHub using GitHub App..."); + LOG.debug("Connecting to GitHub using GitHub App…"); LOG.debug("GitHub App ID: {}", config.getGithubAppId()); LOG.debug("GitHub App Source Installation ID: {}", config.getGithubAppSourceInstallationId()); LOG.debug("GitHub App Target Installation ID: {}", config.getGithubAppTargetInstallationId()); @@ -146,7 +146,7 @@ public void connect() { } // Connect with token else { - LOG.debug("Connecting to GitHub using token..."); + LOG.debug("Connecting to GitHub using token…"); github = new GitHubBuilder() .withEndpoint(config.getGithubApiUrl().toString()) .withOAuthToken(Settings.GITHUB_TOKEN) @@ -287,7 +287,7 @@ public void fork(Plugin plugin) { LOG.info("Plugin {} is archived. Not forking", plugin); return; } - LOG.info("Forking plugin {} locally from repo {}...", plugin, plugin.getRepositoryName()); + LOG.info("Forking plugin {} locally from repo {}…", plugin, plugin.getRepositoryName()); try { GHRepository fork = forkPlugin(plugin); LOG.debug("Forked repository: {}", fork.getHtmlUrl()); @@ -345,11 +345,11 @@ private GHRepository forkRepository(GHRepository originalRepo, GHOrganization or throws IOException, InterruptedException { if (organization == null) { LOG.info( - "Forking the repository to personal account {}...", + "Forking the repository to personal account {}…", getCurrentUser().getLogin()); return originalRepo.fork(); } else { - LOG.info("Forking the repository to organisation {}...", organization.getLogin()); + LOG.info("Forking the repository to organisation {}…", organization.getLogin()); return originalRepo.forkTo(organization); } } @@ -499,9 +499,9 @@ public void deleteFork(Plugin plugin) { return; } if (config.isDebug()) { - LOG.debug("Deleting fork for plugin {} from repo {}...", plugin, repository.getHtmlUrl()); + LOG.debug("Deleting fork for plugin {} from repo {}…", plugin, repository.getHtmlUrl()); } else { - LOG.info("Deleting fork for plugin {}...", plugin); + LOG.info("Deleting fork for plugin {}…", plugin); } try { repository.delete(); @@ -528,12 +528,12 @@ public void fetch(Plugin plugin) { if (config.isDebug()) { LOG.debug( - "Fetch plugin code {} from {} into directory {}...", + "Fetch plugin code {} from {} into directory {}…", plugin, repository.getHtmlUrl(), plugin.getRepositoryName()); } else { - LOG.info("Fetching plugin code locally {}...", plugin); + LOG.info("Fetching plugin code locally {}…", plugin); } try { fetchRepository(plugin); @@ -742,12 +742,12 @@ public GHUser getCurrentUser() { try { // Get myself if (config.getGithubAppId() == null) { - LOG.debug("Getting current user using token..."); + LOG.debug("Getting current user using token…"); return github.getMyself(); } // Get the bot user else { - LOG.debug("Getting current user using GitHub App..."); + LOG.debug("Getting current user using GitHub App…"); LOG.debug("GitHub App name: {}", app.getName()); return github.getUser("%s[bot]".formatted(app.getName())); } diff --git a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/impl/MavenInvoker.java b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/impl/MavenInvoker.java index 1d582cc1..e619392a 100644 --- a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/impl/MavenInvoker.java +++ b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/impl/MavenInvoker.java @@ -70,7 +70,7 @@ public class MavenInvoker { } return new ComparableVersion(versionValue); } catch (MavenInvocationException e) { - LOG.error("Failed to check for maven version", e); + LOG.error("Failed to check for maven version.", e); return null; } } @@ -81,9 +81,9 @@ public class MavenInvoker { * @param goals The goals to run. For example, "clean" */ public void invokeGoal(Plugin plugin, String... goals) { - LOG.debug("Running {} phase for plugin {}", goals, plugin.getName()); + LOG.debug("Running {} phase for plugin {}.", goals, plugin.getName()); LOG.debug( - "Running maven on directory {}", + "Running maven on directory {}.", plugin.getLocalRepository().toAbsolutePath().toFile()); invokeGoals(plugin, goals); } @@ -93,9 +93,9 @@ public void invokeGoal(Plugin plugin, String... goals) { * @param plugin The plugin to run the rewrite on */ public void collectMetadata(Plugin plugin) { - LOG.info("Collecting metadata for plugin {}... Please be patient", plugin); + LOG.info("Collecting metadata for plugin {}… Please be patient.", plugin); invokeGoals(plugin, getSingleRecipeArgs(Settings.FETCH_METADATA_RECIPE)); - LOG.info("Done"); + LOG.info("Done."); } /** @@ -105,7 +105,7 @@ public void collectMetadata(Plugin plugin) { public void invokeRewrite(Plugin plugin) { plugin.addTags(config.getRecipe().getTags()); LOG.info( - "Running recipes {} for plugin {}... Please be patient", + "Running recipes {} for plugin {}… Please be patient.", config.getRecipe().getName(), plugin); invokeGoals(plugin, getSingleRecipeArgs(config.getRecipe())); @@ -144,7 +144,7 @@ private void invokeGoals(Plugin plugin, String... goals) { // In order to rewrite on outdated plugins set add-opens if (jdk.getMajor() >= 17) { - LOG.debug("Adding --add-opens for JDK 17+"); + LOG.debug("Adding --add-opens for JDK 17+."); request.setMavenOpts( "--add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED"); } @@ -152,7 +152,7 @@ private void invokeGoals(Plugin plugin, String... goals) { request.setBatchMode(true); request.setNoTransferProgress(false); request.setErrorHandler((message) -> { - LOG.error(plugin.getMarker(), String.format("Something went wrong when running maven: %s", message)); + LOG.error(plugin.getMarker(), String.format("Something went wrong when running maven: %s.", message)); }); request.setOutputHandler((message) -> { LOG.info(plugin.getMarker(), message); @@ -160,7 +160,7 @@ private void invokeGoals(Plugin plugin, String... goals) { InvocationResult result = invoker.execute(request); handleInvocationResult(plugin, result); } catch (MavenInvocationException | InterruptedException | IOException e) { - plugin.addError("Maven invocation failed", e); + plugin.addError("Maven invocation failed.", e); } } @@ -169,10 +169,10 @@ private void invokeGoals(Plugin plugin, String... goals) { * @param plugin The plugin to validate */ private void validatePom(Plugin plugin) { - LOG.debug("Validating POM for plugin: {}", plugin); + LOG.debug("Validating POM for plugin: {}.", plugin); if (!plugin.getLocalRepository().resolve("pom.xml").toFile().isFile()) { - plugin.addError("POM file not found"); - throw new PluginProcessingException("POM file not found", plugin); + plugin.addError("POM file not found."); + throw new PluginProcessingException("POM file not found.", plugin); } } @@ -184,7 +184,7 @@ public void validateMaven() { Path mavenHome = config.getMavenHome(); if (mavenHome == null) { throw new ModernizerException( - "Neither MAVEN_HOME nor M2_HOME environment variables are set. Or use --maven-home if running from CLI"); + "Neither MAVEN_HOME nor M2_HOME environment variables are set. Or use --maven-home if running from CLI."); } if (!Files.isDirectory(mavenHome) || !Files.isExecutable(mavenHome.resolve("bin/mvn"))) { @@ -206,14 +206,14 @@ public void validateMaven() { */ public void validateMavenVersion() { ComparableVersion mavenVersion = getMavenVersion(); - LOG.debug("Maven version detected: {}", mavenVersion); + LOG.debug("Detected Maven version: {}.", mavenVersion); if (mavenVersion == null) { - LOG.error("Failed to check Maven version. Aborting build."); - throw new ModernizerException("Failed to check Maven version."); + LOG.error("Failed to check the Maven version. Aborting build."); + throw new ModernizerException("Failed to check the Maven version."); } if (mavenVersion.compareTo(Settings.MAVEN_MINIMAL_VERSION) < 0) { LOG.error( - "Maven version detected {}, is too old. Please use at least version {}", + "Detected Maven version ({}) is too old. Please use at least version {}.", mavenVersion, Settings.MAVEN_MINIMAL_VERSION); throw new ModernizerException("Maven version is too old."); @@ -244,15 +244,15 @@ private InvocationRequest createInvocationRequest(Plugin plugin, String... args) */ private void handleInvocationResult(Plugin plugin, InvocationResult result) { if (result.getExitCode() != 0) { - LOG.error(plugin.getMarker(), "Build fail with code: {}", result.getExitCode()); + LOG.error(plugin.getMarker(), "Build failed with code: {}.", result.getExitCode()); if (result.getExecutionException() != null) { - plugin.addError("Maven generic exception occurred", result.getExecutionException()); + plugin.addError("Maven generic exception occurred.", result.getExecutionException()); } else { String errorMessage; if (config.isDebug()) { errorMessage = "Build failed with code: " + result.getExitCode(); } else { - errorMessage = "Build failed"; + errorMessage = "Build failed."; } plugin.addError(errorMessage); } diff --git a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/impl/PluginModernizer.java b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/impl/PluginModernizer.java index dd09ed3c..00aae0ba 100644 --- a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/impl/PluginModernizer.java +++ b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/impl/PluginModernizer.java @@ -271,7 +271,7 @@ private void process(Plugin plugin) { // Handle outdated plugin or unparsable Jenkinsfile if (plugin.getMetadata().getJdks().stream().allMatch(jdk -> jdk.equals(JDK.getImplicit()))) { - LOG.info("Plugin looks outdated or without Jenkinsfile."); + LOG.info("Plugin looks outdated, or without Jenkinsfile."); StaticPomParser parser = new StaticPomParser( plugin.getLocalRepository().resolve("pom.xml").toString()); String jenkinsVersion = parser.getJenkinsVersion(); @@ -357,7 +357,7 @@ private void process(Plugin plugin) { * @param plugin The plugin */ private void collectMetadata(Plugin plugin, boolean retryAfterFirstCompile) { - LOG.trace("Collecting metadata for plugin {}... Please be patient", plugin.getName()); + LOG.trace("Collecting metadata for plugin {}… Please be patient.", plugin.getName()); plugin.withJDK(JDK.JAVA_17); try { plugin.collectMetadata(mavenInvoker); diff --git a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/model/Plugin.java b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/model/Plugin.java index f0eda555..b6e67676 100644 --- a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/model/Plugin.java +++ b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/model/Plugin.java @@ -505,7 +505,7 @@ public void compile(MavenInvoker maven) { return; } LOG.info( - "Compiling plugin {} with JDK {} ... Please be patient", + "Compiling plugin {} with JDK {}… Please be patient", name, this.getJDK().getMajor()); maven.invokeGoal(this, "compile"); @@ -521,7 +521,7 @@ public void compile(MavenInvoker maven) { * @param jdk The JDK to use */ public void verifyQuickBuild(MavenInvoker maven, JDK jdk) { - LOG.info("Verifying plugin without tests {} using with JDK {} ... Please be patient", name, jdk.getMajor()); + LOG.info("Verifying plugin without tests {} using with JDK {}… Please be patient", name, jdk.getMajor()); this.withJDK(jdk); maven.invokeGoal(this, "verify", "-DskipTests", "-Pquick-build", "-Denforcer.skip=true"); if (!hasErrors()) { @@ -539,7 +539,7 @@ public void verify(MavenInvoker maven) { return; } LOG.info( - "Verifying plugin {} with JDK {}... Please be patient", + "Verifying plugin {} with JDK {}… Please be patient", name, this.getJDK().getMajor()); maven.invokeGoal(this, "verify"); @@ -560,7 +560,7 @@ public void format(MavenInvoker maven) { return; } LOG.info( - "Formatting plugin {} with JDK {}... Please be patient", + "Formatting plugin {} with JDK {}… Please be patient", name, this.getJDK().getMajor()); maven.invokeGoal(this, "spotless:apply"); diff --git a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/utils/JdkFetcher.java b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/utils/JdkFetcher.java index f53f0600..1a948f81 100644 --- a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/utils/JdkFetcher.java +++ b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/utils/JdkFetcher.java @@ -69,21 +69,21 @@ public Path getJdkPath(int jdkVersion) throws IOException, InterruptedException * @throws InterruptedException If the operation is interrupted. */ private void downloadAndSetupJdk(int jdkVersion, Path extractionDir) throws IOException, InterruptedException { - LOG.info("Downloading the JDK..."); + LOG.info("Downloading the JDK…"); Path downloadedFile = downloadJdk(jdkVersion); - LOG.info("Download successful"); + LOG.info("Download successful."); - LOG.info("Extracting..."); + LOG.info("Extracting…"); Files.createDirectories(extractionDir); String os = getOSName(); if (os.contains("windows")) { extractZip(downloadedFile, extractionDir); } else if (os.contains("linux") || os.contains("mac")) { extractTarGz(downloadedFile, extractionDir); - LOG.info("Setting executable permissions for files in bin directory"); + LOG.info("Setting executable permissions for files in bin directory."); setJavaBinariesPermissions(extractionDir); } - LOG.info("Extraction successful"); + LOG.info("Extraction successful."); } /** From 399b6e3cc862421f39285688d4191b225c874a0f Mon Sep 17 00:00:00 2001 From: gounthar Date: Wed, 8 Jan 2025 19:07:51 +0100 Subject: [PATCH 5/5] fix(java): Typos. --- .../core/impl/PluginModernizer.java | 22 ++++++------- .../pluginmodernizer/core/model/Plugin.java | 32 +++++++++---------- .../core/utils/JdkFetcher.java | 8 ++--- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/impl/PluginModernizer.java b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/impl/PluginModernizer.java index 00aae0ba..3cb2a615 100644 --- a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/impl/PluginModernizer.java +++ b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/impl/PluginModernizer.java @@ -368,12 +368,12 @@ private void collectMetadata(Plugin plugin, boolean retryAfterFirstCompile) { if (retryAfterFirstCompile) { plugin.removeErrors(); LOG.warn( - "Failed to collect metadata for plugin {}. Will retry after a first compile using lowest JDK", + "Failed to collect metadata for plugin {}. Will retry after a first compile using the lowest JDK.", plugin.getName()); plugin.verifyQuickBuild(mavenInvoker, JDK.JAVA_8); if (plugin.hasErrors()) { LOG.debug( - "Plugin {} failed to compile with JDK 8. Skipping metadata collection after retry", + "Plugin {} failed to compile with JDK 8. Skipping metadata collection after retry.", plugin.getName()); plugin.raiseLastError(); } @@ -415,11 +415,11 @@ private JDK verifyPlugin(Plugin plugin) { if (metadata.getJdks() == null || metadata.getJdks().isEmpty()) { jdk = JDK.JAVA_17; LOG.info( - "No JDKs found in metadata for plugin {}. Using same JDK as rewrite for verification", + "No JDKs found in metadata for plugin {}. Using same JDK as rewrite for verification.", plugin.getName()); } else { jdk = JDK.min(metadata.getJdks(), metadata.getJenkinsVersion()); - LOG.info("Using minimum JDK {} from metadata for plugin {}", jdk.getMajor(), plugin.getName()); + LOG.info("Using minimum JDK {} from metadata for plugin {}.", jdk.getMajor(), plugin.getName()); } // If the plugin was modernized we should find next JDK compatible // For example a Java 8 plugin was modernized to Java 11 @@ -433,7 +433,7 @@ private JDK verifyPlugin(Plugin plugin) { plugin.format(mavenInvoker); plugin.verify(mavenInvoker); if (plugin.hasErrors()) { - LOG.info("Plugin {} failed to verify with JDK {}", plugin.getName(), jdk.getMajor()); + LOG.info("Plugin {} failed to verify with JDK {}.", plugin.getName(), jdk.getMajor()); plugin.withoutErrors(); } plugin.withoutErrors(); @@ -453,7 +453,7 @@ private void printResults(List plugins) { // Display error if (plugin.hasErrors()) { for (PluginProcessingException error : plugin.getErrors()) { - LOG.error("Error: {}", error.getMessage()); + LOG.error("Error: {}.", error.getMessage()); if (config.isDebug()) { LOG.error("Stacktrace: ", error); } @@ -464,20 +464,20 @@ private void printResults(List plugins) { else { if (config.isFetchMetadataOnly()) { LOG.info( - "Metadata was fetched for plugin {} and is available at {}", + "Metadata was fetched for the {} plugin and is available at {}.", plugin.getName(), plugin.getMetadata().getLocation().toAbsolutePath()); } else if (config.isDryRun()) { - LOG.info("Dry run mode. Changes were commited on on " + plugin.getLocalRepository() - + " but not pushed"); + LOG.info("Dry run mode. Changes were commited on " + plugin.getLocalRepository() + + ", but not pushed."); } else { // Change were made - LOG.info("Pull request was open on " + LOG.info("Pull request was opened on " + plugin.getRemoteRepository(this.ghService).getHtmlUrl()); // Display changes depending on the recipe if (config.getRecipe().getName().equals("io.jenkins.tools.pluginmodernizer.UpgradeBomVersion")) { - LOG.info("New BOM version: {}", plugin.getMetadata().getBomVersion()); + LOG.info("New BOM version: {}.", plugin.getMetadata().getBomVersion()); } } } diff --git a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/model/Plugin.java b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/model/Plugin.java index b6e67676..b40375f1 100644 --- a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/model/Plugin.java +++ b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/model/Plugin.java @@ -501,11 +501,11 @@ public void clean(MavenInvoker maven) { */ public void compile(MavenInvoker maven) { if (config.isFetchMetadataOnly()) { - LOG.info("Skipping compilation for plugin {} as only metadata is required", name); + LOG.info("Skipping compilation for plugin {} as only metadata is required.", name); return; } LOG.info( - "Compiling plugin {} with JDK {}… Please be patient", + "Compiling plugin {} with JDK {}… Please be patient.", name, this.getJDK().getMajor()); maven.invokeGoal(this, "compile"); @@ -521,7 +521,7 @@ public void compile(MavenInvoker maven) { * @param jdk The JDK to use */ public void verifyQuickBuild(MavenInvoker maven, JDK jdk) { - LOG.info("Verifying plugin without tests {} using with JDK {}… Please be patient", name, jdk.getMajor()); + LOG.info("Verifying plugin {} without tests, using JDK {}… Please be patient.", name, jdk.getMajor()); this.withJDK(jdk); maven.invokeGoal(this, "verify", "-DskipTests", "-Pquick-build", "-Denforcer.skip=true"); if (!hasErrors()) { @@ -535,11 +535,11 @@ public void verifyQuickBuild(MavenInvoker maven, JDK jdk) { */ public void verify(MavenInvoker maven) { if (config.isFetchMetadataOnly()) { - LOG.info("Skipping verification for plugin {} as only metadata is required", name); + LOG.info("Skipping verification for plugin {} as only metadata is required.", name); return; } LOG.info( - "Verifying plugin {} with JDK {}… Please be patient", + "Verifying plugin {} with JDK {}… Please be patient.", name, this.getJDK().getMajor()); maven.invokeGoal(this, "verify"); @@ -552,15 +552,15 @@ public void verify(MavenInvoker maven) { */ public void format(MavenInvoker maven) { if (!isUsingSpotless()) { - LOG.info("Skipping formatting for plugin {} as it is not using Spotless", name); + LOG.info("Skipping formatting for plugin {}, as it is not using Spotless.", name); return; } if (config.isFetchMetadataOnly()) { - LOG.info("Skipping formatting for plugin {} as only metadata is required", name); + LOG.info("Skipping formatting for plugin {}, as only metadata is required.", name); return; } LOG.info( - "Formatting plugin {} with JDK {}… Please be patient", + "Formatting plugin {} with JDK {}… Please be patient.", name, this.getJDK().getMajor()); maven.invokeGoal(this, "spotless:apply"); @@ -572,7 +572,7 @@ public void format(MavenInvoker maven) { * @param pluginService The update center service */ public void enrichMetadata(PluginService pluginService) { - LOG.debug("Setting extra flags for plugin {}", name); + LOG.debug("Setting extra flags for plugin {}.", name); if (metadata == null) { throw new IllegalStateException("Metadata not found for plugin " + name); } @@ -594,7 +594,7 @@ public void collectMetadata(MavenInvoker maven) { // Static parse of the pom file and check for pattern preventing minimal build Path pom = getLocalRepository().resolve("pom.xml"); if (!getLocalRepository().resolve("target").toFile().mkdir()) { - LOG.trace("Failed to create target directory for plugin {}", name); + LOG.trace("Failed to create target directory for plugin {}.", name); } Document document = staticPomParse(pom); @@ -606,7 +606,7 @@ public void collectMetadata(MavenInvoker maven) { .collect(Collectors.toSet())); if (!pluginMetadata.getErrors().isEmpty()) { - LOG.debug("Precondition errors found for plugin {}", name); + LOG.debug("Precondition errors found for plugin {}.", name); pluginMetadata.save(); return; } @@ -622,7 +622,7 @@ public void collectMetadata(MavenInvoker maven) { public void runOpenRewrite(MavenInvoker maven) { withJDK(JDK.JAVA_17); if (config.isFetchMetadataOnly()) { - LOG.info("Skipping OpenRewrite recipe application for plugin {} as only metadata is required", name); + LOG.info("Skipping OpenRewrite recipe application for plugin {}, as only metadata is required.", name); return; } maven.invokeRewrite(this); @@ -634,7 +634,7 @@ public void runOpenRewrite(MavenInvoker maven) { */ public void fork(GHService service) { if (config.isFetchMetadataOnly()) { - LOG.debug("Skipping fork for plugin {} as only metadata is required", name); + LOG.debug("Skipping fork for plugin {}, as only metadata is required.", name); return; } service.fork(this); @@ -646,7 +646,7 @@ public void fork(GHService service) { */ public void sync(GHService service) { if (config.isFetchMetadataOnly()) { - LOG.debug("Skipping sync for plugin {} as only metadata is required", name); + LOG.debug("Skipping sync for plugin {}, as only metadata is required.", name); return; } service.sync(this); @@ -813,7 +813,7 @@ public void copyMetadata(CacheManager cacheManager) { CacheManager.PLUGIN_METADATA_CACHE_KEY, new PluginMetadata(pluginCacheManager))); LOG.debug( - "Copied plugin {} metadata to cache: {}", + "Copied {} plugin metadata to cache: {}.", getName(), getMetadata().getLocation().toAbsolutePath()); } @@ -839,7 +839,7 @@ private CacheManager buildPluginTargetDirectoryCacheManager() { */ private Document staticPomParse(Path pom) { if (pom == null || !pom.toFile().exists()) { - addError("No pom file found"); + addError("No pom file found."); raiseLastError(); return null; } diff --git a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/utils/JdkFetcher.java b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/utils/JdkFetcher.java index 1a948f81..fa5c7e07 100644 --- a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/utils/JdkFetcher.java +++ b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/utils/JdkFetcher.java @@ -159,7 +159,7 @@ private String fetchLatestReleaseUrl(int jdkVersion) throws IOException, Interru } } } else { - LOG.error("Failed to fetch releases. HTTP Status Code: {}", response.statusCode()); + LOG.error("Failed to fetch releases. HTTP Status Code: {}.", response.statusCode()); } return null; } @@ -316,7 +316,7 @@ private void setJavaBinariesPermissions(Path jdkPath) { Path binDir = jdkPath.resolve("bin"); if (!Files.isDirectory(binDir)) { - LOG.error("The bin directory does not exist: {}", binDir); + LOG.error("The bin directory does not exist: {}.", binDir); return; } @@ -332,11 +332,11 @@ private void setJavaBinariesPermissions(Path jdkPath) { try { Files.setPosixFilePermissions(file, executablePermissions); } catch (IOException e) { - LOG.error("Failed to set executable permissions for {}: {}", file, e.getMessage()); + LOG.error("Failed to set executable permissions for {}: {}.", file, e.getMessage()); } }); } catch (IOException e) { - LOG.error("Failed to list files in directory {}: {}", binDir, e.getMessage()); + LOG.error("Failed to list files in directory {}: {}.", binDir, e.getMessage()); } } }