From 7f804b52d617bf1b4e87ee1f5329abd7dc8269f0 Mon Sep 17 00:00:00 2001 From: Valentin Delaye Date: Sun, 8 Dec 2024 10:51:25 +0100 Subject: [PATCH] Run only one recipe per execution --- .gitpod/init.sh | 2 +- README.md | 16 ++++---- docker-compose.yml | 2 +- .../tools/pluginmodernizer/cli/Main.java | 9 ++--- .../tools/pluginmodernizer/cli/MainTest.java | 40 ++++--------------- .../pluginmodernizer/core/config/Config.java | 20 +++++----- .../core/github/GHService.java | 7 ++-- .../core/impl/MavenInvoker.java | 28 ++----------- .../core/impl/PluginModernizer.java | 12 ++++-- .../core/utils/TemplateUtils.java | 19 +++++---- .../src/main/jte/commit.jte | 5 +-- .../src/main/jte/pr-body.jte | 5 +-- .../src/main/jte/pr-title.jte | 6 +-- .../core/config/ConfigTest.java | 16 ++++---- .../core/github/GHServiceTest.java | 7 ++++ 15 files changed, 75 insertions(+), 119 deletions(-) diff --git a/.gitpod/init.sh b/.gitpod/init.sh index 49cd7d6e..7e3857c6 100755 --- a/.gitpod/init.sh +++ b/.gitpod/init.sh @@ -45,7 +45,7 @@ echo -e "If you want to use another GitHub handle, please set the ${color_green} echo -e "\nWe propose you to work with two Jenkins plugin repositories: ${color_cyan}badge-plugin${color_reset} and ${color_cyan}build-timestamp-plugin${color_reset}." echo -e "You could, though, use other plugin repositories as well (like ${color_cyan}plot-plugin${color_reset}) by entering their name in the following ${color_cyan}java${color_reset} command." echo -e "\nYou can now proceed with the modernizer tool thanks to the following commands:" -echo -e "${color_cyan}java -jar plugin-modernizer-cli/target/jenkins-plugin-modernizer-999999-SNAPSHOT.jar --dry-run --plugins badge,build-timestamp --recipes AddPluginsBom,AddCodeOwner --export-datatables${color_reset}" +echo -e "${color_cyan}java -jar plugin-modernizer-cli/target/jenkins-plugin-modernizer-999999-SNAPSHOT.jar --dry-run --plugins badge,build-timestamp --recipe AddCodeOwner --export-datatables${color_reset}" echo -e "\nBy the way, you can copy/paste from/to the terminal to execute the commands. Enjoy! 🚀" echo -e "See ${color_blue}https://www.gitpod.io/docs/configure/user-settings/browser-settings#browser-settings${color_reset} to know more.\n" diff --git a/README.md b/README.md index 46da0075..e3aa3432 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,7 @@ To activate app authentication, just set the following CLI argument ## CLI Options - `--plugins` or `-p`: (optional) Name(s) of plugin directory cloned inside the `test-plugins` directory. -- `--recipes` or `-r`: (required) Name(s) of recipes to apply to the plugins. +- `--recipe` or `-r`: (required) Name of recipe to apply to the plugins. - `--plugin-file` or `-f`: (optional) Path to the text file that contains a list of plugins. (see example [plugin file](docs/example-plugins.txt)) @@ -143,7 +143,7 @@ Plugins can be passed to the CLI tool in two ways: Pass the plugin names directly using the `-p` or `--plugins option`. The expected input format for plugins is `artifact ID`. ```shell -java -jar plugin-modernizer-cli/target/jenkins-plugin-modernizer-999999-SNAPSHOT.jar --plugins git,git-client,jobcacher --recipes AddPluginsBom,AddCodeOwner +java -jar plugin-modernizer-cli/target/jenkins-plugin-modernizer-999999-SNAPSHOT.jar --plugins git,git-client,jobcacher --recipe AddPluginsBom ``` Here, `git`, `git-client`, and `jobcacher` are plugin artifact IDs (also known as plugin names), while `AddPluginsBom` and `AddCodeOwners` are recipe names. For more details about available recipes, refer to the [recipe_data.yaml](plugin-modernizer-core/src/main/resources/recipe_data.yaml) file. @@ -153,7 +153,7 @@ Pass the path to a file that contains plugin names. The expected input format fo See example [plugin file](docs/example-plugins.txt) ```shell -java -jar plugin-modernizer-cli/target/jenkins-plugin-modernizer-999999-SNAPSHOT.jar --plugin-file path/to/plugin-file --recipes AddPluginsBom,AddCodeOwner +java -jar plugin-modernizer-cli/target/jenkins-plugin-modernizer-999999-SNAPSHOT.jar --plugin-file path/to/plugin-file --recipe AddPluginsBom ``` ## Configuring Environmental Variables @@ -172,14 +172,14 @@ java -jar plugin-modernizer-cli/target/jenkins-plugin-modernizer-999999-SNAPSHOT ### without dry-run ```shell -java -jar plugin-modernizer-cli/target/jenkins-plugin-modernizer-999999-SNAPSHOT.jar --plugins git,git-client,jobcacher --recipes AddPluginsBom,AddCodeOwner +java -jar plugin-modernizer-cli/target/jenkins-plugin-modernizer-999999-SNAPSHOT.jar --plugins git,git-client,jobcacher --recipe AddPluginsBom ``` The above command creates pull requests in the respective remote repositories after applying the changes. ### with dry-run ```shell -java -jar plugin-modernizer-cli/target/jenkins-plugin-modernizer-999999-SNAPSHOT.jar --plugins git,git-client,jobcacher --recipes AddPluginsBom,AddCodeOwner --dry-run +java -jar plugin-modernizer-cli/target/jenkins-plugin-modernizer-999999-SNAPSHOT.jar --plugins git,git-client,jobcacher --recipe AddPluginsBom --dry-run ``` The above command generates patch files instead of applying changes directly. These patch files are saved in `/target/rewrite/rewrite.patch` inside each plugin directory. No pull requests will be created. @@ -190,7 +190,7 @@ The above command generates patch files instead of applying changes directly. Th ### with export-datatables ```shell -java -jar plugin-modernizer-cli/target/jenkins-plugin-modernizer-999999-SNAPSHOT.jar --plugins git,git-client,jobcacher --recipes AddPluginsBom,AddCodeOwner --export-datatables +java -jar plugin-modernizer-cli/target/jenkins-plugin-modernizer-999999-SNAPSHOT.jar --plugins git,git-client,jobcacher --recipe AddPluginsBom --export-datatables ``` The above command creates a report of the changes made through OpenRewrite in csv format. The report will be generated in `target/rewrite/datatables` inside the plugin directory. @@ -222,7 +222,7 @@ docker run \ -e GH_OWNER=${GH_OWNER} \ -v $(pwd)/plugins.txt:/plugins.txt \ ghcr.io/jenkins-infra/plugin-modernizer-tool:main \ - --plugin-file /plugins.txt --recipes AddPluginsBom,AddCodeOwner + --plugin-file /plugins.txt --recipe AddCodeOwner ``` ### Explanation @@ -232,7 +232,7 @@ docker run \ - `-v $(pwd)/plugins.txt:/plugins.txt`: Mounts the plugins.txt file from the current directory to the Docker container. - `ghcr.io/jenkins-infra/plugin-modernizer-tool:main`: Specifies the Docker image to use. - `--plugin-file /plugins.txt`: Specifies the path to the plugin file inside the Docker container. -- `--recipes AddPluginsBom,AddCodeOwner`: Specifies the recipes to apply. +- `--recipe AddPluginsBom,`: Specifies the recipe to apply. This command will run the Plugin Modernizer Tool inside the Docker container using the specified environment variables and plugin file. diff --git a/docker-compose.yml b/docker-compose.yml index 750e8b87..b27d7095 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,7 +10,7 @@ services: env_file: - .env command: - - --recipes ${RECIPES} + - --recipe ${RECIPE} - --plugins ${PLUGINS} - --debug - --dry-run diff --git a/plugin-modernizer-cli/src/main/java/io/jenkins/tools/pluginmodernizer/cli/Main.java b/plugin-modernizer-cli/src/main/java/io/jenkins/tools/pluginmodernizer/cli/Main.java index 91d5f592..b8f229cf 100644 --- a/plugin-modernizer-cli/src/main/java/io/jenkins/tools/pluginmodernizer/cli/Main.java +++ b/plugin-modernizer-cli/src/main/java/io/jenkins/tools/pluginmodernizer/cli/Main.java @@ -72,12 +72,11 @@ static class PluginOptions { private PluginOptions pluginOptions; @Option( - names = {"-r", "--recipes"}, + names = {"-r", "--recipe"}, required = true, - description = "List of Recipes to be applied.", - split = ",", + description = "Recipe to be applied.", converter = RecipeConverter.class) - private List recipes; + private Recipe recipe; @Option( names = {"-g", "--github-owner"}, @@ -197,7 +196,7 @@ public Config setup() { .withGitHubAppSourceInstallationId(githubAppSourceInstallationId) .withGitHubAppTargetInstallationId(githubAppTargetInstallationId) .withPlugins(pluginOptions != null ? pluginOptions.plugins : new ArrayList<>()) - .withRecipes(recipes) + .withRecipe(recipe) .withDryRun(dryRun) .withSkipPush(skipPush) .withSkipBuild(skipBuild) diff --git a/plugin-modernizer-cli/src/test/java/io/jenkins/tools/pluginmodernizer/cli/MainTest.java b/plugin-modernizer-cli/src/test/java/io/jenkins/tools/pluginmodernizer/cli/MainTest.java index 5a3ea3aa..38126e3d 100644 --- a/plugin-modernizer-cli/src/test/java/io/jenkins/tools/pluginmodernizer/cli/MainTest.java +++ b/plugin-modernizer-cli/src/test/java/io/jenkins/tools/pluginmodernizer/cli/MainTest.java @@ -70,12 +70,9 @@ public void testGetRecipes() { String[] args = {"-p", "plugin1,plugin2", "-r", "FetchMetadata"}; commandLine.execute(args); - List recipes = main.setup().getRecipes(); - assertNotNull(recipes); - assertEquals(1, recipes.size()); - assertEquals( - "io.jenkins.tools.pluginmodernizer.FetchMetadata", - recipes.get(0).getName()); + Recipe recipe = main.setup().getRecipe(); + assertNotNull(recipe); + assertEquals("io.jenkins.tools.pluginmodernizer.FetchMetadata", recipe.getName()); } @Test @@ -83,12 +80,9 @@ public void testGetRecipesWithFQDN() { String[] args = {"-p", "plugin1,plugin2", "-r", "io.jenkins.tools.pluginmodernizer.FetchMetadata"}; commandLine.execute(args); - List recipes = main.setup().getRecipes(); - assertNotNull(recipes); - assertEquals(1, recipes.size()); - assertEquals( - "io.jenkins.tools.pluginmodernizer.FetchMetadata", - recipes.get(0).getName()); + Recipe recipe = main.setup().getRecipe(); + assertNotNull(recipe); + assertEquals("io.jenkins.tools.pluginmodernizer.FetchMetadata", recipe.getName()); } @Test @@ -163,32 +157,14 @@ public void testSkipPushOptions() throws IOException { @Test public void testSkipPullRequestOptions() throws IOException { - String[] args = { - "-p", - "plugin1,plugin2", - "-r", - "FetchMetadata", - "--skip-push", - "--recipes", - "FetchMetadata", - "--skip-pull-request" - }; + String[] args = {"-p", "plugin1,plugin2", "--skip-push", "--recipe", "FetchMetadata", "--skip-pull-request"}; commandLine.execute(args); assertTrue(main.setup().isSkipPullRequest()); } @Test public void testCleanLocalData() throws IOException { - String[] args = { - "-p", - "plugin1,plugin2", - "-r", - "FetchMetadata", - "--skip-push", - "--recipes", - "FetchMetadata", - "--clean-local-data" - }; + String[] args = {"-p", "plugin1,plugin2", "--skip-push", "--recipe", "FetchMetadata", "--clean-local-data"}; commandLine.execute(args); assertTrue(main.setup().isRemoveLocalData()); } diff --git a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/config/Config.java b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/config/Config.java index 7f274ba3..818974d7 100644 --- a/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/config/Config.java +++ b/plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/config/Config.java @@ -14,7 +14,7 @@ public class Config { private final String version; private final List plugins; - private final List recipes; + private final Recipe recipe; private final URL jenkinsUpdateCenter; private final URL jenkinsPluginVersions; private final URL pluginHealthScore; @@ -41,7 +41,7 @@ private Config( Long githubAppSourceInstallationId, Long githubAppTargetInstallationId, List plugins, - List recipes, + Recipe recipe, URL jenkinsUpdateCenter, URL jenkinsPluginVersions, URL pluginHealthScore, @@ -62,7 +62,7 @@ private Config( this.githubAppSourceInstallationId = githubAppSourceInstallationId; this.githubAppTargetInstallationId = githubAppTargetInstallationId; this.plugins = plugins; - this.recipes = recipes; + this.recipe = recipe; this.jenkinsUpdateCenter = jenkinsUpdateCenter; this.jenkinsPluginVersions = jenkinsPluginVersions; this.pluginHealthScore = pluginHealthScore; @@ -103,8 +103,8 @@ public List getPlugins() { return plugins; } - public List getRecipes() { - return recipes; + public Recipe getRecipe() { + return recipe; } /** @@ -112,7 +112,7 @@ public List getRecipes() { * @return True if only fetching metadata */ public boolean isFetchMetadataOnly() { - return recipes.size() == 1 && recipes.get(0).getName().equals(Settings.FETCH_METADATA_RECIPE.getName()); + return recipe.getName().equals(Settings.FETCH_METADATA_RECIPE.getName()); } public URL getJenkinsUpdateCenter() { @@ -186,7 +186,7 @@ public static class Builder { private Long githubAppSourceInstallationId; private Long githubAppTargetInstallationId; private List plugins; - private List recipes; + private Recipe recipe; private URL jenkinsUpdateCenter = Settings.DEFAULT_UPDATE_CENTER_URL; private URL jenkinsPluginVersions = Settings.DEFAULT_PLUGIN_VERSIONS; private URL pluginStatsInstallations = Settings.DEFAULT_PLUGINS_STATS_INSTALLATIONS_URL; @@ -232,8 +232,8 @@ public Builder withPlugins(List plugins) { return this; } - public Builder withRecipes(List recipes) { - this.recipes = recipes; + public Builder withRecipe(Recipe recipe) { + this.recipe = recipe; return this; } @@ -327,7 +327,7 @@ public Config build() { githubAppSourceInstallationId, githubAppTargetInstallationId, plugins, - recipes, + recipe, jenkinsUpdateCenter, jenkinsPluginVersions, pluginHealthScore, 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 3935b9a2..30edf010 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 @@ -507,6 +507,7 @@ private void fetchRepository(Plugin plugin) throws GitAPIException { .setMode(ResetCommand.ResetType.HARD) .setRef("origin/" + defaultBranch) .call(); + git.clean().setCleanDirectories(true).setDryRun(false).call(); Ref ref = git.checkout() .setCreateBranch(false) .setName(defaultBranch) @@ -571,7 +572,7 @@ public void commitChanges(Plugin plugin) { } try (Git git = Git.open(plugin.getLocalRepository().toFile())) { git.getRepository().scanForRepoChanges(); - String commitMessage = TemplateUtils.renderCommitMessage(plugin, config.getRecipes()); + String commitMessage = TemplateUtils.renderCommitMessage(plugin, config.getRecipe()); LOG.debug("Commit message: {}", commitMessage); Status status = git.status().call(); if (status.hasUncommittedChanges()) { @@ -702,8 +703,8 @@ public void openPullRequest(Plugin plugin) { refreshToken(config.getGithubAppTargetInstallationId()); // Renders parts and log then even if dry-run - String prTitle = TemplateUtils.renderPullRequestTitle(plugin, config.getRecipes()); - String prBody = TemplateUtils.renderPullRequestBody(plugin, config.getRecipes()); + String prTitle = TemplateUtils.renderPullRequestTitle(plugin, config.getRecipe()); + String prBody = TemplateUtils.renderPullRequestBody(plugin, config.getRecipe()); LOG.debug("Pull request title: {}", prTitle); LOG.debug("Pull request body: {}", prBody); LOG.debug("Draft mode: {}", config.isDraft()); 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 61f717b8..25bde252 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 @@ -16,7 +16,6 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicReference; -import java.util.stream.Collectors; import org.apache.maven.artifact.versioning.ComparableVersion; import org.apache.maven.shared.invoker.DefaultInvocationRequest; import org.apache.maven.shared.invoker.InvocationRequest; @@ -99,15 +98,12 @@ public void collectMetadata(Plugin plugin) { * @param plugin The plugin to run the rewrite on */ public void invokeRewrite(Plugin plugin) { - plugin.addTags(config.getRecipes().stream() - .flatMap(recipe -> recipe.getTags().stream()) - .collect(Collectors.toSet())); + plugin.addTags(config.getRecipe().getTags()); LOG.info( "Running recipes {} for plugin {}... Please be patient", - String.join( - ",", config.getRecipes().stream().map(Recipe::getName).toList()), + config.getRecipe().getName(), plugin); - invokeGoals(plugin, getRewriteArgs()); + invokeGoals(plugin, getSingleRecipeArgs(config.getRecipe())); LOG.info("Done"); } @@ -125,24 +121,6 @@ private String[] getSingleRecipeArgs(Recipe recipe) { return goals.toArray(String[]::new); } - /** - * Get the rewrite arguments to be executed for each plugin - * @return The list of arguments to be passed to the rewrite plugin - */ - private String[] getRewriteArgs() { - List goals = new ArrayList<>(); - goals.add("org.openrewrite.maven:rewrite-maven-plugin:" + Settings.MAVEN_REWRITE_PLUGIN_VERSION + ":run"); - goals.add("-Drewrite.exportDatatables=" + config.isExportDatatables()); - - String activeRecipesStr = - config.getRecipes().stream().map(Recipe::getName).collect(Collectors.joining(", ")); - LOG.debug("Active recipes: {}", activeRecipesStr); - goals.add("-Drewrite.activeRecipes=" + String.join(",", activeRecipesStr)); - goals.add("-Drewrite.recipeArtifactCoordinates=io.jenkins.plugin-modernizer:plugin-modernizer-core:" - + config.getVersion()); - return goals.toArray(String[]::new); - } - /** * Invoke a list of maven goal on the plugin * @param plugin The plugin to run the goals on 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 88997da1..db1f86e0 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 @@ -11,8 +11,6 @@ import io.jenkins.tools.pluginmodernizer.core.utils.PluginService; import jakarta.inject.Inject; import java.util.List; -import java.util.stream.Collectors; -import org.openrewrite.Recipe; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -54,8 +52,7 @@ public void start() { // Debug config LOG.debug("Plugins: {}", config.getPlugins()); - LOG.debug( - "Recipes: {}", config.getRecipes().stream().map(Recipe::getName).collect(Collectors.joining(", "))); + LOG.debug("Recipe: {}", config.getRecipe().getName()); LOG.debug("GitHub owner: {}", config.getGithubOwner()); LOG.debug("Update Center Url: {}", config.getJenkinsUpdateCenter()); LOG.debug("Plugin versions Url: {}", config.getJenkinsPluginVersions()); @@ -340,6 +337,13 @@ private void printResults(List plugins) { else { LOG.info("Pull request was open 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()); + } } } } 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 4415a3fd..5277a9c9 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 @@ -6,7 +6,6 @@ import gg.jte.output.StringOutput; import io.jenkins.tools.pluginmodernizer.core.model.ModernizerException; import io.jenkins.tools.pluginmodernizer.core.model.Plugin; -import java.util.List; import java.util.Map; import org.openrewrite.Recipe; import org.slf4j.Logger; @@ -27,31 +26,31 @@ private TemplateUtils() {} /** * Render the pull request body * @param plugin Plugin to modernize - * @param recipes List of recipes to apply + * @param recipe Recipe to apply * @return The rendered pull request body */ - public static String renderPullRequestBody(Plugin plugin, List recipes) { - return renderTemplate("pr-body.jte", Map.of("plugin", plugin, "recipes", recipes)); + public static String renderPullRequestBody(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 recipes List of recipes to apply + * @param recipe Recipe to apply * @return The rendered commit message */ - public static String renderCommitMessage(Plugin plugin, List recipes) { - return renderTemplate("commit.jte", Map.of("plugin", plugin, "recipes", recipes)); + public static String renderCommitMessage(Plugin plugin, Recipe recipe) { + return renderTemplate("commit.jte", Map.of("plugin", plugin, "recipe", recipe)); } /** * Render the pull request title * @param plugin Plugin to modernize - * @param recipes List of recipes to apply + * @param recipe Recipe to apply * @return The rendered pull request title */ - public static String renderPullRequestTitle(Plugin plugin, List recipes) { - return renderTemplate("pr-title.jte", Map.of("plugin", plugin, "recipes", recipes)); + public static String renderPullRequestTitle(Plugin plugin, Recipe recipe) { + return renderTemplate("pr-title.jte", Map.of("plugin", plugin, "recipe", recipe)); } /** diff --git a/plugin-modernizer-core/src/main/jte/commit.jte b/plugin-modernizer-core/src/main/jte/commit.jte index fcab96b0..5a220667 100644 --- a/plugin-modernizer-core/src/main/jte/commit.jte +++ b/plugin-modernizer-core/src/main/jte/commit.jte @@ -1,7 +1,6 @@ @import io.jenkins.tools.pluginmodernizer.core.model.Plugin @import org.openrewrite.Recipe -@import java.util.List @import static io.jenkins.tools.pluginmodernizer.core.config.Settings.RECIPE_FQDN_PREFIX @param Plugin plugin -@param List recipes -Applied recipes ${recipes.stream().map(r -> r.getName().replaceAll(RECIPE_FQDN_PREFIX + ".", "")).collect(java.util.stream.Collectors.joining(", "))} \ No newline at end of file +@param Recipe recipe +Applied recipe ${recipe.getName().replaceAll(RECIPE_FQDN_PREFIX + ".", "")} \ No newline at end of file diff --git a/plugin-modernizer-core/src/main/jte/pr-body.jte b/plugin-modernizer-core/src/main/jte/pr-body.jte index 895c5221..190cee6d 100644 --- a/plugin-modernizer-core/src/main/jte/pr-body.jte +++ b/plugin-modernizer-core/src/main/jte/pr-body.jte @@ -1,15 +1,12 @@ @import io.jenkins.tools.pluginmodernizer.core.model.Plugin @import org.openrewrite.Recipe -@import java.util.List @param Plugin plugin -@param List recipes +@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: -@for(var recipe : recipes)
${recipe.getDisplayName()}

${recipe.getName()}

${recipe.getDescription()}
-@endfor diff --git a/plugin-modernizer-core/src/main/jte/pr-title.jte b/plugin-modernizer-core/src/main/jte/pr-title.jte index 279aac36..186ca192 100644 --- a/plugin-modernizer-core/src/main/jte/pr-title.jte +++ b/plugin-modernizer-core/src/main/jte/pr-title.jte @@ -1,8 +1,6 @@ -@import io.jenkins.tools.pluginmodernizer.core.config.Settings @import io.jenkins.tools.pluginmodernizer.core.model.Plugin @import org.openrewrite.Recipe -@import java.util.List @import static io.jenkins.tools.pluginmodernizer.core.config.Settings.RECIPE_FQDN_PREFIX @param Plugin plugin -@param List recipes -Applied recipes ${recipes.stream().map(r -> r.getName().replaceAll(RECIPE_FQDN_PREFIX + ".", "")).collect(java.util.stream.Collectors.joining(", "))} +@param Recipe recipe +Applied recipes ${recipe.getName().replaceAll(RECIPE_FQDN_PREFIX + ".", "")} \ No newline at end of file diff --git a/plugin-modernizer-core/src/test/java/io/jenkins/tools/pluginmodernizer/core/config/ConfigTest.java b/plugin-modernizer-core/src/test/java/io/jenkins/tools/pluginmodernizer/core/config/ConfigTest.java index 7eb29454..6e4a9417 100644 --- a/plugin-modernizer-core/src/test/java/io/jenkins/tools/pluginmodernizer/core/config/ConfigTest.java +++ b/plugin-modernizer-core/src/test/java/io/jenkins/tools/pluginmodernizer/core/config/ConfigTest.java @@ -10,7 +10,6 @@ import java.net.URL; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.Arrays; import java.util.List; import java.util.stream.Stream; import org.junit.jupiter.api.Test; @@ -25,9 +24,8 @@ public void testConfigBuilderWithAllFields() throws MalformedURLException { String githubOwner = "test-owner"; List plugins = Stream.of("plugin1", "plugin2").map(Plugin::build).toList(); - List recipes = Arrays.asList(Mockito.mock(Recipe.class), Mockito.mock(Recipe.class)); - Mockito.doReturn("recipe1").when(recipes.get(0)).getName(); - Mockito.doReturn("recipe2").when(recipes.get(1)).getName(); + Recipe recipe = Mockito.mock(Recipe.class); + Mockito.doReturn("recipe1").when(recipe).getName(); URL jenkinsUpdateCenter = new URL("https://updates.jenkins.io/current/update-center.actual.json"); Path cachePath = Paths.get("/path/to/cache"); Path mavenHome = Paths.get("/path/to/maven"); @@ -37,7 +35,7 @@ public void testConfigBuilderWithAllFields() throws MalformedURLException { .withVersion(version) .withGitHubOwner(githubOwner) .withPlugins(plugins) - .withRecipes(recipes) + .withRecipe(recipe) .withJenkinsUpdateCenter(jenkinsUpdateCenter) .withCachePath(cachePath) .withMavenHome(mavenHome) @@ -52,7 +50,7 @@ public void testConfigBuilderWithAllFields() throws MalformedURLException { assertEquals(version, config.getVersion()); assertEquals(githubOwner, config.getGithubOwner()); assertEquals(plugins, config.getPlugins()); - assertEquals(recipes, config.getRecipes()); + assertEquals(recipe, config.getRecipe()); assertEquals(jenkinsUpdateCenter, config.getJenkinsUpdateCenter()); assertEquals(cachePath, config.getCachePath()); assertEquals(mavenHome, config.getMavenHome()); @@ -71,7 +69,7 @@ public void testConfigBuilderWithDefaultValues() { assertNull(config.getVersion()); assertNull(config.getPlugins()); - assertNull(config.getRecipes()); + assertNull(config.getRecipe()); assertEquals(Settings.DEFAULT_UPDATE_CENTER_URL, config.getJenkinsUpdateCenter()); assertEquals(Settings.DEFAULT_CACHE_PATH, config.getCachePath()); assertEquals(Settings.DEFAULT_MAVEN_HOME, config.getMavenHome()); @@ -95,7 +93,7 @@ public void testConfigBuilderWithPartialValues() { assertEquals(version, config.getVersion()); assertEquals(plugins, config.getPlugins()); - assertNull(config.getRecipes()); + assertNull(config.getRecipe()); assertEquals(Settings.DEFAULT_UPDATE_CENTER_URL, config.getJenkinsUpdateCenter()); assertEquals(Settings.DEFAULT_CACHE_PATH, config.getCachePath()); assertEquals(Settings.DEFAULT_MAVEN_HOME, config.getMavenHome()); @@ -112,7 +110,7 @@ public void testConfigBuilderWithNullValues() { assertNull(config.getVersion()); assertNull(config.getPlugins()); - assertNull(config.getRecipes()); + assertNull(config.getRecipe()); assertEquals(Settings.DEFAULT_UPDATE_CENTER_URL, config.getJenkinsUpdateCenter()); assertEquals(Settings.DEFAULT_CACHE_PATH, config.getCachePath()); assertEquals(Settings.DEFAULT_MAVEN_HOME, config.getMavenHome()); diff --git a/plugin-modernizer-core/src/test/java/io/jenkins/tools/pluginmodernizer/core/github/GHServiceTest.java b/plugin-modernizer-core/src/test/java/io/jenkins/tools/pluginmodernizer/core/github/GHServiceTest.java index 5be882a1..be2812b0 100644 --- a/plugin-modernizer-core/src/test/java/io/jenkins/tools/pluginmodernizer/core/github/GHServiceTest.java +++ b/plugin-modernizer-core/src/test/java/io/jenkins/tools/pluginmodernizer/core/github/GHServiceTest.java @@ -38,6 +38,7 @@ import org.mockito.MockedStatic; import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; +import org.openrewrite.Recipe; @ExtendWith({MockitoExtension.class}) public class GHServiceTest { @@ -610,11 +611,14 @@ public void shouldFetchOriginalRepoInMetaDataOnlyModeToNewFolder() throws Except public void shouldOpenPullRequest() throws Exception { // Mocks + Recipe recipe = Mockito.mock(Recipe.class); GHRepository repository = Mockito.mock(GHRepository.class); GHPullRequest pr = Mockito.mock(GHPullRequest.class); GHPullRequestQueryBuilder prQuery = Mockito.mock(GHPullRequestQueryBuilder.class); PagedIterable prQueryList = Mockito.mock(PagedIterable.class); + doReturn(recipe).when(config).getRecipe(); + doReturn("recipe1").when(recipe).getName(); doReturn(null).when(config).getGithubAppTargetInstallationId(); doReturn(false).when(config).isDraft(); doReturn(true).when(plugin).hasChangesPushed(); @@ -638,11 +642,14 @@ public void shouldOpenPullRequest() throws Exception { public void shouldOpenDraftPullRequest() throws Exception { // Mocks + Recipe recipe = Mockito.mock(Recipe.class); GHRepository repository = Mockito.mock(GHRepository.class); GHPullRequest pr = Mockito.mock(GHPullRequest.class); GHPullRequestQueryBuilder prQuery = Mockito.mock(GHPullRequestQueryBuilder.class); PagedIterable prQueryList = Mockito.mock(PagedIterable.class); + doReturn(recipe).when(config).getRecipe(); + doReturn("recipe1").when(recipe).getName(); doReturn(null).when(config).getGithubAppTargetInstallationId(); doReturn(true).when(config).isDraft(); doReturn(true).when(plugin).hasChangesPushed();