From 7c2c91ac28048cd403a156d89f10dcbcfc8449a8 Mon Sep 17 00:00:00 2001 From: Mike Sol Date: Thu, 27 Jul 2023 09:32:21 -0700 Subject: [PATCH 1/3] Remove unnecessary goal + grammar fixes for other goals --- .../maven/AbstractRewriteDryRunMojo.java | 10 ++--- .../maven/AbstractRewriteRunMojo.java | 4 +- .../org/openrewrite/maven/RemoveMojo.java | 5 ++- .../maven/RewriteDiscoverMojo.java | 5 ++- .../maven/RewriteDumpMavenSettings.java | 42 ------------------- 5 files changed, 13 insertions(+), 53 deletions(-) delete mode 100644 src/main/java/org/openrewrite/maven/RewriteDumpMavenSettings.java diff --git a/src/main/java/org/openrewrite/maven/AbstractRewriteDryRunMojo.java b/src/main/java/org/openrewrite/maven/AbstractRewriteDryRunMojo.java index dc341cf7..cb3ad0a2 100644 --- a/src/main/java/org/openrewrite/maven/AbstractRewriteDryRunMojo.java +++ b/src/main/java/org/openrewrite/maven/AbstractRewriteDryRunMojo.java @@ -52,8 +52,8 @@ public void execute() throws MojoExecutionException { return; } - //If the plugin is configured to run over all projects (at the end of the build) only proceed if the plugin - //is being run on the last project. + // If the plugin is configured to run over all projects (at the end of the build) only proceed if the plugin + // is being run on the last project. if (!runPerSubmodule && !project.getId().equals(mavenSession.getProjects().get(mavenSession.getProjects().size() - 1).getId())) { return; } @@ -70,14 +70,14 @@ public void execute() throws MojoExecutionException { if (results.isNotEmpty()) { for (Result result : results.generated) { assert result.getAfter() != null; - getLog().warn("These recipes would generate new file " + + getLog().warn("These recipes would generate a new file " + result.getAfter().getSourcePath() + ":"); logRecipesThatMadeChanges(result); } for (Result result : results.deleted) { assert result.getBefore() != null; - getLog().warn("These recipes would delete file " + + getLog().warn("These recipes would delete a file " + result.getBefore().getSourcePath() + ":"); logRecipesThatMadeChanges(result); @@ -85,7 +85,7 @@ public void execute() throws MojoExecutionException { for (Result result : results.moved) { assert result.getBefore() != null; assert result.getAfter() != null; - getLog().warn("These recipes would move file from " + + getLog().warn("These recipes would move a file from " + result.getBefore().getSourcePath() + " to " + result.getAfter().getSourcePath() + ":"); logRecipesThatMadeChanges(result); diff --git a/src/main/java/org/openrewrite/maven/AbstractRewriteRunMojo.java b/src/main/java/org/openrewrite/maven/AbstractRewriteRunMojo.java index 21e05534..c40669f7 100644 --- a/src/main/java/org/openrewrite/maven/AbstractRewriteRunMojo.java +++ b/src/main/java/org/openrewrite/maven/AbstractRewriteRunMojo.java @@ -43,8 +43,8 @@ public void execute() throws MojoExecutionException { return; } - //If the plugin is configured to run over all projects (at the end of the build) only proceed if the plugin - //is being run on the last project. + // If the plugin is configured to run over all projects (at the end of the build) only proceed if the plugin + // is being run on the last project. if (!runPerSubmodule && !project.getId().equals(mavenSession.getProjects().get(mavenSession.getProjects().size() - 1).getId())) { return; } diff --git a/src/main/java/org/openrewrite/maven/RemoveMojo.java b/src/main/java/org/openrewrite/maven/RemoveMojo.java index beee1dbe..e9c2f424 100644 --- a/src/main/java/org/openrewrite/maven/RemoveMojo.java +++ b/src/main/java/org/openrewrite/maven/RemoveMojo.java @@ -36,9 +36,10 @@ import java.util.List; /** - * Remove rewrite-maven-plugin (or any other plugin) from the project.
+ * Remove the specified plugin from the project. If no groupId or artifactId is specified, this will default to + * removing the rewrite-maven-plugin.
* For example:
- * {@code ./mvnw rewrite:remove} + * {@code ./mvnw rewrite:remove -DgroupId=foo -DartifactId=bar} */ @Mojo(name = "remove", threadSafe = true) @Execute diff --git a/src/main/java/org/openrewrite/maven/RewriteDiscoverMojo.java b/src/main/java/org/openrewrite/maven/RewriteDiscoverMojo.java index aea51b2b..cdb0adf0 100644 --- a/src/main/java/org/openrewrite/maven/RewriteDiscoverMojo.java +++ b/src/main/java/org/openrewrite/maven/RewriteDiscoverMojo.java @@ -32,8 +32,9 @@ import java.util.HashSet; /** - * Generate a report of available recipes found on the classpath.
- * {@code ./mvnw rewrite:discover -Ddetail=true -Drecipe=} to display recipe configuration details. For example:
+ * Generate a report of the available recipes and styles found on the classpath.
+ *
+ * Can also be used to display information about a specific recipe. For example:
* {@code ./mvnw rewrite:discover -Ddetail=true -Drecipe=org.openrewrite.java.format.AutoFormat} */ @Mojo(name = "discover", threadSafe = true, requiresProject = false, aggregator = true) diff --git a/src/main/java/org/openrewrite/maven/RewriteDumpMavenSettings.java b/src/main/java/org/openrewrite/maven/RewriteDumpMavenSettings.java deleted file mode 100644 index b8aaf95c..00000000 --- a/src/main/java/org/openrewrite/maven/RewriteDumpMavenSettings.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2023 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.openrewrite.maven; - -import com.fasterxml.jackson.core.JsonProcessingException; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugins.annotations.Mojo; -import org.openrewrite.maven.internal.MavenXmlMapper; - -import java.nio.file.Path; - -@Mojo(name = "dumpMavenSettings", threadSafe = true, requiresProject = false, aggregator = true) -public class RewriteDumpMavenSettings extends AbstractRewriteMojo { - - @Override - public void execute() throws MojoExecutionException, MojoFailureException { - Path baseDir = getBuildRoot(); - MavenMojoProjectParser projectParser = new MavenMojoProjectParser(getLog(), baseDir, pomCacheEnabled, pomCacheDirectory, runtime, skipMavenParsing, getExclusions(), getPlainTextMasks(), sizeThresholdMb, mavenSession, settingsDecrypter, runPerSubmodule); - MavenSettings mavenSettings = projectParser.buildSettings(); - - try { - getLog().info("The effective Maven settings in use by rewrite-maven-plugin are:"); - getLog().info(MavenXmlMapper.writeMapper().writer().writeValueAsString(mavenSettings)); - } catch (JsonProcessingException e) { - throw new MojoExecutionException("Failed to dump maven settings.", e); - } - } -} From b431fb41e95497b8c20ac423514e18ae4355a727 Mon Sep 17 00:00:00 2001 From: Mike Sol Date: Thu, 27 Jul 2023 09:42:30 -0700 Subject: [PATCH 2/3] Delete unnecessary RemoveMojo mojo --- .../org/openrewrite/maven/RemoveMojo.java | 81 ------------------- 1 file changed, 81 deletions(-) delete mode 100644 src/main/java/org/openrewrite/maven/RemoveMojo.java diff --git a/src/main/java/org/openrewrite/maven/RemoveMojo.java b/src/main/java/org/openrewrite/maven/RemoveMojo.java deleted file mode 100644 index e9c2f424..00000000 --- a/src/main/java/org/openrewrite/maven/RemoveMojo.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.openrewrite.maven; - -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugins.annotations.Execute; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; -import org.openrewrite.ExecutionContext; -import org.openrewrite.LargeSourceSet; -import org.openrewrite.Result; -import org.openrewrite.internal.InMemoryLargeSourceSet; -import org.openrewrite.xml.tree.Xml; - -import java.io.BufferedWriter; -import java.io.IOException; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Collections; -import java.util.List; - -/** - * Remove the specified plugin from the project. If no groupId or artifactId is specified, this will default to - * removing the rewrite-maven-plugin.
- * For example:
- * {@code ./mvnw rewrite:remove -DgroupId=foo -DartifactId=bar} - */ -@Mojo(name = "remove", threadSafe = true) -@Execute -@SuppressWarnings("unused") -public class RemoveMojo extends AbstractRewriteMojo { - - @SuppressWarnings("NotNullFieldNotInitialized") - @Parameter(property = "groupId", defaultValue = "org.openrewrite.maven") - protected String groupId; - - @SuppressWarnings("NotNullFieldNotInitialized") - @Parameter(property = "artifactId", defaultValue = "rewrite-maven-plugin") - protected String artifactId; - - @Override - public void execute() throws MojoExecutionException, MojoFailureException { - Path baseDir = getBuildRoot(); - ExecutionContext ctx = executionContext(); - Xml.Document maven = new MavenMojoProjectParser(getLog(), baseDir, pomCacheEnabled, pomCacheDirectory, runtime, skipMavenParsing, getExclusions(), getPlainTextMasks(), sizeThresholdMb, mavenSession, settingsDecrypter, runPerSubmodule).parseMaven(project, Collections.emptyList(), ctx); - LargeSourceSet poms = new InMemoryLargeSourceSet(Collections.singletonList(maven)); - List results = new RemovePlugin(groupId, artifactId) - .run(poms, ctx) - .getChangeset() - .getAllResults(); - if (!results.isEmpty()) { - Result result = results.get(0); - assert result.getBefore() != null; - assert result.getAfter() != null; - Charset charset = result.getAfter().getCharset() == null ? StandardCharsets.UTF_8 : result.getAfter().getCharset(); - try (BufferedWriter sourceFileWriter = Files.newBufferedWriter( - baseDir.resolve(result.getBefore().getSourcePath()), charset)) { - sourceFileWriter.write(new String(result.getAfter().printAll().getBytes(charset), charset)); - } catch (IOException e) { - throw new RuntimeException(e); - } - getLog().info("Removed " + artifactId + " from " + project.getFile().getPath()); - } - } -} From b6b0d7716abe8bc5969839e173db3942f1e4370d Mon Sep 17 00:00:00 2001 From: Mike Sol Date: Thu, 27 Jul 2023 09:49:52 -0700 Subject: [PATCH 3/3] Delete test for removed mojo --- .../org/openrewrite/maven/RemoveMojoIT.java | 39 ------------------- 1 file changed, 39 deletions(-) delete mode 100644 src/test/java/org/openrewrite/maven/RemoveMojoIT.java diff --git a/src/test/java/org/openrewrite/maven/RemoveMojoIT.java b/src/test/java/org/openrewrite/maven/RemoveMojoIT.java deleted file mode 100644 index 448f27a4..00000000 --- a/src/test/java/org/openrewrite/maven/RemoveMojoIT.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.openrewrite.maven; - -import com.soebes.itf.jupiter.extension.*; -import com.soebes.itf.jupiter.maven.MavenExecutionResult; - -import static com.soebes.itf.extension.assertj.MavenITAssertions.assertThat; - -@MavenJupiterExtension -@MavenOption(MavenCLIOptions.NO_TRANSFER_PROGRESS) -@MavenOption(MavenCLIExtra.MUTE_PLUGIN_VALIDATION_WARNING) -@MavenGoal("${project.groupId}:${project.artifactId}:${project.version}:remove") -@SuppressWarnings("NewClassNamingConvention") -class RemoveMojoIT { - - @MavenTest - void single_project(MavenExecutionResult result) { - assertThat(result) - .isSuccessful() - .out() - .info() - .anySatisfy(line -> assertThat(line).contains("Removed rewrite-maven-plugin from")); - } - -}