From 44b4dff348314dd94171b142ebbb2d3333636e93 Mon Sep 17 00:00:00 2001 From: Bruno Verachten Date: Wed, 8 Jan 2025 17:04:34 +0100 Subject: [PATCH 01/11] Implement a way to customize the pull request body Fixes #75 Add support for customizing the pull request body using `jte` template files. * Add a new method `hasBodyTemplate` in `TemplateUtils.java` to check for specific `jte` templates for the pull request body. * Update the `renderPullRequestBody` method in `TemplateUtils.java` to use specific `jte` templates if available. * Create a new `jte` template `pr-body-SetupJenkinsfile.jte` for customizing the pull request body for the `SetupJenkinsfile` recipe, including a detailed explanation of why this recipe is important. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/gounthar/plugin-modernizer-tool/issues/75?shareId=XXXX-XXXX-XXXX-XXXX). --- .../core/utils/TemplateUtils.java | 15 +++++++++++++++ .../src/main/jte/pr-body-SetupJenkinsfile.jte | 16 ++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 plugin-modernizer-core/src/main/jte/pr-body-SetupJenkinsfile.jte diff --git a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/utils/TemplateUtils.java b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/utils/TemplateUtils.java index 0d3f075d..4fb8b6ae 100644 --- a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/utils/TemplateUtils.java +++ b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/utils/TemplateUtils.java @@ -31,6 +31,10 @@ private TemplateUtils() {} * @return The rendered pull request body */ public static String renderPullRequestBody(Plugin plugin, Recipe recipe) { + if (hasBodyTemplate(recipe)) { + String shortName = recipe.getName().replaceAll(Settings.RECIPE_FQDN_PREFIX + ".", ""); + return renderTemplate("pr-body-%s.jte".formatted(shortName), Map.of("plugin", plugin, "recipe", recipe)); + } return renderTemplate("pr-body.jte", Map.of("plugin", plugin, "recipe", recipe)); } @@ -86,4 +90,15 @@ private static boolean hasTitleTemplate(Recipe recipe) { TemplateEngine templateEngine = TemplateEngine.createPrecompiled(ContentType.Html); return templateEngine.hasTemplate("pr-title-%s.jte".formatted(shortName)); } + + /** + * Check if a body template exists for one recipe + * @param recipe The recipe to check + * @return True if a body template exists + */ + private static boolean hasBodyTemplate(Recipe recipe) { + String shortName = recipe.getName().replaceAll(Settings.RECIPE_FQDN_PREFIX + ".", ""); + TemplateEngine templateEngine = TemplateEngine.createPrecompiled(ContentType.Html); + return templateEngine.hasTemplate("pr-body-%s.jte".formatted(shortName)); + } } diff --git a/plugin-modernizer-core/src/main/jte/pr-body-SetupJenkinsfile.jte b/plugin-modernizer-core/src/main/jte/pr-body-SetupJenkinsfile.jte new file mode 100644 index 00000000..cf57247a --- /dev/null +++ b/plugin-modernizer-core/src/main/jte/pr-body-SetupJenkinsfile.jte @@ -0,0 +1,16 @@ +@import io.jenkins.tools.pluginmodernizer.core.model.Plugin +@import io.jenkins.tools.pluginmodernizer.core.model.Recipe +@param Plugin plugin +@param Recipe recipe +Hello `${plugin.getName()}` developers! + +This is an automated pull request created by the [Jenkins Plugin Modernizer](https://github.com/jenkins-infra/plugin-modernizer-tool) tool. The tool has applied the following recipes to modernize the plugin: +
+ ${recipe.getDisplayName()} +

${recipe.getName()}

+
${recipe.getDescription()}
+
+ +### Why is this important? + +The `SetupJenkinsfile` recipe is crucial for ensuring that your Jenkins plugin is built and tested using the Jenkins infrastructure. By adding a Jenkinsfile, you enable continuous integration and continuous delivery (CI/CD) for your plugin, which helps in maintaining the quality and reliability of the plugin. It also ensures that your plugin is tested against the latest Jenkins core and other plugins, providing early feedback on any potential issues. From 9aadec0d4f2cb2841e445c638a54ecd0c9e6695e Mon Sep 17 00:00:00 2001 From: Bruno Verachten Date: Wed, 8 Jan 2025 17:05:36 +0100 Subject: [PATCH 02/11] Update pr-body-SetupJenkinsfile.jte --- .../src/main/jte/pr-body-SetupJenkinsfile.jte | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/plugin-modernizer-core/src/main/jte/pr-body-SetupJenkinsfile.jte b/plugin-modernizer-core/src/main/jte/pr-body-SetupJenkinsfile.jte index cf57247a..8e3815a5 100644 --- a/plugin-modernizer-core/src/main/jte/pr-body-SetupJenkinsfile.jte +++ b/plugin-modernizer-core/src/main/jte/pr-body-SetupJenkinsfile.jte @@ -2,7 +2,7 @@ @import io.jenkins.tools.pluginmodernizer.core.model.Recipe @param Plugin plugin @param Recipe recipe -Hello `${plugin.getName()}` developers! +Hello `${plugin.getName()}` developers! :wave: This is an automated pull request created by the [Jenkins Plugin Modernizer](https://github.com/jenkins-infra/plugin-modernizer-tool) tool. The tool has applied the following recipes to modernize the plugin:
@@ -11,6 +11,15 @@ This is an automated pull request created by the [Jenkins Plugin Modernizer](htt
${recipe.getDescription()}
-### Why is this important? +## Why is this important? -The `SetupJenkinsfile` recipe is crucial for ensuring that your Jenkins plugin is built and tested using the Jenkins infrastructure. By adding a Jenkinsfile, you enable continuous integration and continuous delivery (CI/CD) for your plugin, which helps in maintaining the quality and reliability of the plugin. It also ensures that your plugin is tested against the latest Jenkins core and other plugins, providing early feedback on any potential issues. +Starting with the Jenkins 2.463 weekly release, Jenkins now requires Java 17 or newer. +The first Long-Term Support (LTS) release requiring Java 17 or newer (version 2.479.x) was released at the end of October 2024. + +The Jenkins core team strongly recommends that all users adopt either Java 17 or Java 21. +The adoption of Java 17 has almost surpassed that of Java 11, and the usage of Java 21 is rapidly increasing. + +There will come a time when we no longer support plugins built with JDK 8 or 11. + +While this PR does not automatically make your plugin compatible with Java 17 or 21, it represents the first step towards a new era. Your plugin will be built and tested within the Jenkins infrastructure using Java 17 and 21. +After this PR is merged, we will submit additional automated PRs to enable your plugin to build with Java 17 and 21. From 44b881c58fb4c4ee809107e2df3f3dac9f4f10c9 Mon Sep 17 00:00:00 2001 From: gounthar Date: Wed, 8 Jan 2025 17:09:08 +0100 Subject: [PATCH 03/11] fix(jte): Adding aria-label for better accessibility. --- .../src/main/jte/pr-body-SetupJenkinsfile.jte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-modernizer-core/src/main/jte/pr-body-SetupJenkinsfile.jte b/plugin-modernizer-core/src/main/jte/pr-body-SetupJenkinsfile.jte index 8e3815a5..f89c3d83 100644 --- a/plugin-modernizer-core/src/main/jte/pr-body-SetupJenkinsfile.jte +++ b/plugin-modernizer-core/src/main/jte/pr-body-SetupJenkinsfile.jte @@ -5,7 +5,7 @@ Hello `${plugin.getName()}` developers! :wave: This is an automated pull request created by the [Jenkins Plugin Modernizer](https://github.com/jenkins-infra/plugin-modernizer-tool) tool. The tool has applied the following recipes to modernize the plugin: -
+
${recipe.getDisplayName()}

${recipe.getName()}

${recipe.getDescription()}
From f335e37bcd729caa8fb39a6b1ec26a649a72b196 Mon Sep 17 00:00:00 2001 From: gounthar Date: Wed, 8 Jan 2025 17:13:57 +0100 Subject: [PATCH 04/11] fix(jte): Extracting common template name generation logic. --- .../core/utils/TemplateUtils.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/utils/TemplateUtils.java b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/utils/TemplateUtils.java index 4fb8b6ae..e41a8cfe 100644 --- a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/utils/TemplateUtils.java +++ b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/utils/TemplateUtils.java @@ -24,22 +24,29 @@ public class TemplateUtils { */ private TemplateUtils() {} + private static String getTemplateNameForRecipe(String prefix, Recipe recipe) { + String shortName = recipe.getName().replaceAll(Settings.RECIPE_FQDN_PREFIX + ".", ""); + return "%s-%s.jte".formatted(prefix, shortName); + } + /** * Render the pull request body + * * @param plugin Plugin to modernize * @param recipe Recipe to apply * @return The rendered pull request body */ public static String renderPullRequestBody(Plugin plugin, Recipe recipe) { if (hasBodyTemplate(recipe)) { - String shortName = recipe.getName().replaceAll(Settings.RECIPE_FQDN_PREFIX + ".", ""); - return renderTemplate("pr-body-%s.jte".formatted(shortName), Map.of("plugin", plugin, "recipe", recipe)); + return renderTemplate( + getTemplateNameForRecipe("pr-body", recipe), Map.of("plugin", plugin, "recipe", recipe)); } return renderTemplate("pr-body.jte", Map.of("plugin", plugin, "recipe", recipe)); } /** * Render the commit message + * * @param plugin Plugin to modernize * @param recipe Recipe to apply * @return The rendered commit message @@ -50,6 +57,7 @@ public static String renderCommitMessage(Plugin plugin, Recipe recipe) { /** * Render the pull request title + * * @param plugin Plugin to modernize * @param recipe Recipe to apply * @return The rendered pull request title @@ -64,8 +72,9 @@ public static String renderPullRequestTitle(Plugin plugin, Recipe recipe) { /** * Render a generic template + * * @param templateName Name of the template - * @param params Parameters to pass to the template + * @param params Parameters to pass to the template * @return The rendered template */ private static String renderTemplate(String templateName, Map params) { @@ -82,6 +91,7 @@ private static String renderTemplate(String templateName, Map pa /** * Check if a title template exists for one recipe + * * @param recipe The recipe to check * @return True if a title template exists */ @@ -93,12 +103,12 @@ private static boolean hasTitleTemplate(Recipe recipe) { /** * Check if a body template exists for one recipe + * * @param recipe The recipe to check * @return True if a body template exists */ private static boolean hasBodyTemplate(Recipe recipe) { - String shortName = recipe.getName().replaceAll(Settings.RECIPE_FQDN_PREFIX + ".", ""); TemplateEngine templateEngine = TemplateEngine.createPrecompiled(ContentType.Html); - return templateEngine.hasTemplate("pr-body-%s.jte".formatted(shortName)); + return templateEngine.hasTemplate(getTemplateNameForRecipe("pr-body", recipe)); } } From 230c3925cd1c32fce7d14e167cc01694e6ac4157 Mon Sep 17 00:00:00 2001 From: gounthar Date: Wed, 8 Jan 2025 17:15:42 +0100 Subject: [PATCH 05/11] fix(jte): Extracting common template name generation logic. --- .../tools/pluginmodernizer/core/utils/TemplateUtils.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/utils/TemplateUtils.java b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/utils/TemplateUtils.java index e41a8cfe..ca5778ba 100644 --- a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/utils/TemplateUtils.java +++ b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/utils/TemplateUtils.java @@ -64,8 +64,7 @@ public static String renderCommitMessage(Plugin plugin, Recipe recipe) { */ public static String renderPullRequestTitle(Plugin plugin, Recipe recipe) { if (hasTitleTemplate(recipe)) { - String shortName = recipe.getName().replaceAll(Settings.RECIPE_FQDN_PREFIX + ".", ""); - return renderTemplate("pr-title-%s.jte".formatted(shortName), Map.of("plugin", plugin, "recipe", recipe)); + return renderTemplate("pr-title-%s.jte".formatted(getTemplateNameForRecipe("pr-title", recipe)), Map.of("plugin", plugin, "recipe", recipe)); } return renderTemplate("pr-title.jte", Map.of("plugin", plugin, "recipe", recipe)); } From bd7ccc6ba02c0abd5075e20dd7e7b0a1d36717c1 Mon Sep 17 00:00:00 2001 From: gounthar Date: Wed, 8 Jan 2025 17:25:56 +0100 Subject: [PATCH 06/11] fix(jte): Spotless. --- .../tools/pluginmodernizer/core/utils/TemplateUtils.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/utils/TemplateUtils.java b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/utils/TemplateUtils.java index ca5778ba..96f29a09 100644 --- a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/utils/TemplateUtils.java +++ b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/utils/TemplateUtils.java @@ -64,7 +64,9 @@ public static String renderCommitMessage(Plugin plugin, Recipe recipe) { */ public static String renderPullRequestTitle(Plugin plugin, Recipe recipe) { if (hasTitleTemplate(recipe)) { - return renderTemplate("pr-title-%s.jte".formatted(getTemplateNameForRecipe("pr-title", recipe)), Map.of("plugin", plugin, "recipe", recipe)); + return renderTemplate( + "pr-title-%s.jte".formatted(getTemplateNameForRecipe("pr-title", recipe)), + Map.of("plugin", plugin, "recipe", recipe)); } return renderTemplate("pr-title.jte", Map.of("plugin", plugin, "recipe", recipe)); } From 6eb05d34998db71356a26fbfddc554e81201f3d1 Mon Sep 17 00:00:00 2001 From: gounthar Date: Wed, 8 Jan 2025 17:27:43 +0100 Subject: [PATCH 07/11] fix(jte): Adds a custom title for the SetupJenkinsfile recipe. --- .../src/main/jte/pr-title-SetupJenkinsfile.jte | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 plugin-modernizer-core/src/main/jte/pr-title-SetupJenkinsfile.jte diff --git a/plugin-modernizer-core/src/main/jte/pr-title-SetupJenkinsfile.jte b/plugin-modernizer-core/src/main/jte/pr-title-SetupJenkinsfile.jte new file mode 100644 index 00000000..a786ff2e --- /dev/null +++ b/plugin-modernizer-core/src/main/jte/pr-title-SetupJenkinsfile.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 +feat(ci): Builds on the Jenkins Infrastructure From a6acc17af1f018eceebd459c18a6cb81490f3a59 Mon Sep 17 00:00:00 2001 From: gounthar Date: Wed, 8 Jan 2025 17:36:51 +0100 Subject: [PATCH 08/11] fix(jte): Reverts the custom title "optimization" --- .../tools/pluginmodernizer/core/utils/TemplateUtils.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/utils/TemplateUtils.java b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/utils/TemplateUtils.java index 96f29a09..40b6f783 100644 --- a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/utils/TemplateUtils.java +++ b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/utils/TemplateUtils.java @@ -64,9 +64,8 @@ public static String renderCommitMessage(Plugin plugin, Recipe recipe) { */ public static String renderPullRequestTitle(Plugin plugin, Recipe recipe) { if (hasTitleTemplate(recipe)) { - return renderTemplate( - "pr-title-%s.jte".formatted(getTemplateNameForRecipe("pr-title", recipe)), - Map.of("plugin", plugin, "recipe", recipe)); + String shortName = recipe.getName().replaceAll(Settings.RECIPE_FQDN_PREFIX + ".", ""); + return renderTemplate("pr-title-%s.jte".formatted(getTemplateNameForRecipe("pr-title", recipe)), Map.of("plugin", plugin, "recipe", recipe)); } return renderTemplate("pr-title.jte", Map.of("plugin", plugin, "recipe", recipe)); } From 95c6d43f9ef071ff0977b81f8cbf79de87ccf2c1 Mon Sep 17 00:00:00 2001 From: gounthar Date: Wed, 8 Jan 2025 17:39:23 +0100 Subject: [PATCH 09/11] fix(jte): Reverts the custom title "optimization" --- .../tools/pluginmodernizer/core/utils/TemplateUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/utils/TemplateUtils.java b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/utils/TemplateUtils.java index 40b6f783..e41a8cfe 100644 --- a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/utils/TemplateUtils.java +++ b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/utils/TemplateUtils.java @@ -65,7 +65,7 @@ public static String renderCommitMessage(Plugin plugin, Recipe recipe) { public static String renderPullRequestTitle(Plugin plugin, Recipe recipe) { if (hasTitleTemplate(recipe)) { String shortName = recipe.getName().replaceAll(Settings.RECIPE_FQDN_PREFIX + ".", ""); - return renderTemplate("pr-title-%s.jte".formatted(getTemplateNameForRecipe("pr-title", recipe)), Map.of("plugin", plugin, "recipe", recipe)); + return renderTemplate("pr-title-%s.jte".formatted(shortName), Map.of("plugin", plugin, "recipe", recipe)); } return renderTemplate("pr-title.jte", Map.of("plugin", plugin, "recipe", recipe)); } From 1b41c1b3480eb120a94d7284756118adfadb24c5 Mon Sep 17 00:00:00 2001 From: gounthar Date: Wed, 8 Jan 2025 17:57:26 +0100 Subject: [PATCH 10/11] fix(jte): Fix the double "jte" suffix. --- .../tools/pluginmodernizer/core/utils/TemplateUtils.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/utils/TemplateUtils.java b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/utils/TemplateUtils.java index e41a8cfe..e3288fa3 100644 --- a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/utils/TemplateUtils.java +++ b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/utils/TemplateUtils.java @@ -64,8 +64,8 @@ public static String renderCommitMessage(Plugin plugin, Recipe recipe) { */ public static String renderPullRequestTitle(Plugin plugin, Recipe recipe) { if (hasTitleTemplate(recipe)) { - String shortName = recipe.getName().replaceAll(Settings.RECIPE_FQDN_PREFIX + ".", ""); - return renderTemplate("pr-title-%s.jte".formatted(shortName), Map.of("plugin", plugin, "recipe", recipe)); + return renderTemplate( + getTemplateNameForRecipe("pr-title", recipe), Map.of("plugin", plugin, "recipe", recipe)); } return renderTemplate("pr-title.jte", Map.of("plugin", plugin, "recipe", recipe)); } From e6222a8c350171b1645d0aa0044723fb98d29478 Mon Sep 17 00:00:00 2001 From: Bruno Verachten Date: Wed, 8 Jan 2025 20:34:48 +0100 Subject: [PATCH 11/11] Fix clean phase before committing changes Fixes #78 Add a call to the 'clean' phase before committing changes in `PluginModernizer.java`. * Clean the target folder before committing changes if not in dry-run mode * Modify the `start` method to include the clean phase before committing, pushing, and opening a pull request --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/gounthar/plugin-modernizer-tool/issues/78?shareId=XXXX-XXXX-XXXX-XXXX). --- .../tools/pluginmodernizer/core/impl/PluginModernizer.java | 5 +++++ 1 file changed, 5 insertions(+) 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..d405ef4a 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 @@ -329,6 +329,11 @@ private void process(Plugin plugin) { plugin.getName(), plugin.getMetadata().toJson()); + // Clean target folder before committing changes + if (!config.isDryRun()) { + plugin.clean(mavenInvoker); + } + plugin.commit(ghService); plugin.push(ghService); plugin.openPullRequest(ghService);