From e29969244c8e4c736d5b129ff37d02f9c7bd22b1 Mon Sep 17 00:00:00 2001 From: Smaarn Date: Thu, 9 May 2024 17:22:51 +0200 Subject: [PATCH 1/5] Add support for `pomFile` parameter --- src/it/check-separate-fails/invalid-pom.xml | 34 +++ .../check-separate-fails/invoker.properties | 2 + src/it/check-separate-fails/pom.xml | 38 +++ .../invoker.properties | 2 + src/it/check-separate-succeeds/pom.xml | 37 +++ src/it/check-separate-succeeds/valid-pom.xml | 35 +++ src/it/separate-pom/invoker.properties | 2 + src/it/separate-pom/pom.xml | 17 ++ src/it/separate-pom/separate-pom-expected.xml | 231 +++++++++++++++++ src/it/separate-pom/separate-pom.xml | 232 ++++++++++++++++++ src/it/separate-pom/verify.groovy | 4 + .../java/org/codehaus/mojo/tidy/TidyMojo.java | 16 +- 12 files changed, 649 insertions(+), 1 deletion(-) create mode 100644 src/it/check-separate-fails/invalid-pom.xml create mode 100644 src/it/check-separate-fails/invoker.properties create mode 100644 src/it/check-separate-fails/pom.xml create mode 100644 src/it/check-separate-succeeds/invoker.properties create mode 100644 src/it/check-separate-succeeds/pom.xml create mode 100644 src/it/check-separate-succeeds/valid-pom.xml create mode 100644 src/it/separate-pom/invoker.properties create mode 100644 src/it/separate-pom/pom.xml create mode 100644 src/it/separate-pom/separate-pom-expected.xml create mode 100644 src/it/separate-pom/separate-pom.xml create mode 100644 src/it/separate-pom/verify.groovy diff --git a/src/it/check-separate-fails/invalid-pom.xml b/src/it/check-separate-fails/invalid-pom.xml new file mode 100644 index 0000000..b57556b --- /dev/null +++ b/src/it/check-separate-fails/invalid-pom.xml @@ -0,0 +1,34 @@ + + + + pom-check-fails + org.codehaus.mojo.tidy.its + + org.codehaus + codehaus-parent + 4 + + 4.0.0 + 1.0-SNAPSHOT + + Test that check fails for a POM that is not tidy. + + + + + org.codehaus.mojo + tidy-maven-plugin + @pom.version@ + + + validate + validate + + check + + + + + + + diff --git a/src/it/check-separate-fails/invoker.properties b/src/it/check-separate-fails/invoker.properties new file mode 100644 index 0000000..0d92d95 --- /dev/null +++ b/src/it/check-separate-fails/invoker.properties @@ -0,0 +1,2 @@ +invoker.goals = verify +invoker.buildResult = failure diff --git a/src/it/check-separate-fails/pom.xml b/src/it/check-separate-fails/pom.xml new file mode 100644 index 0000000..0944610 --- /dev/null +++ b/src/it/check-separate-fails/pom.xml @@ -0,0 +1,38 @@ + + + 4.0.0 + + + org.codehaus + codehaus-parent + 4 + + + org.codehaus.mojo.tidy.its + pom-check-separate-fails + 1.0-SNAPSHOT + + Test that check fails for an external invalid POM + + + + + org.codehaus.mojo + tidy-maven-plugin + @pom.version@ + + + validate + validate + + check + + + ${project.basedir}/invalid-pom.xml + + + + + + + diff --git a/src/it/check-separate-succeeds/invoker.properties b/src/it/check-separate-succeeds/invoker.properties new file mode 100644 index 0000000..1f6e992 --- /dev/null +++ b/src/it/check-separate-succeeds/invoker.properties @@ -0,0 +1,2 @@ +invoker.goals = verify +invoker.buildResult = success diff --git a/src/it/check-separate-succeeds/pom.xml b/src/it/check-separate-succeeds/pom.xml new file mode 100644 index 0000000..1d76724 --- /dev/null +++ b/src/it/check-separate-succeeds/pom.xml @@ -0,0 +1,37 @@ + + + + pom-check-fails + org.codehaus.mojo.tidy.its + + org.codehaus + codehaus-parent + 4 + + 4.0.0 + 1.0-SNAPSHOT + + Test that check passes for a separate POM that is tidy. + + + + + org.codehaus.mojo + tidy-maven-plugin + @pom.version@ + + + validate + validate + + check + + + ${project.basedir}/valid-pom.xml + + + + + + + diff --git a/src/it/check-separate-succeeds/valid-pom.xml b/src/it/check-separate-succeeds/valid-pom.xml new file mode 100644 index 0000000..3665f50 --- /dev/null +++ b/src/it/check-separate-succeeds/valid-pom.xml @@ -0,0 +1,35 @@ + + + 4.0.0 + + + org.codehaus + codehaus-parent + 4 + + + org.codehaus.mojo.tidy.its + pom-check-succeeds + 1.0-SNAPSHOT + + Test that check doesn't fail for a tidy separate POM + + + + + org.codehaus.mojo + tidy-maven-plugin + @pom.version@ + + + validate + validate + + check + + + + + + + diff --git a/src/it/separate-pom/invoker.properties b/src/it/separate-pom/invoker.properties new file mode 100644 index 0000000..c8b5542 --- /dev/null +++ b/src/it/separate-pom/invoker.properties @@ -0,0 +1,2 @@ +invoker.goals = org.codehaus.mojo:tidy-maven-plugin:${project.version}:pom -Dtidy.pomFile=separate-pom.xml +invoker.buildResult = success diff --git a/src/it/separate-pom/pom.xml b/src/it/separate-pom/pom.xml new file mode 100644 index 0000000..1e90c22 --- /dev/null +++ b/src/it/separate-pom/pom.xml @@ -0,0 +1,17 @@ + + + + pom + + pom-space-indent + org.codehaus.mojo.tidy.its + + org.codehaus + codehaus-parent + 4 + + 4.0.0 + 1.0-SNAPSHOT + Test of tidy:pom on a separate pom with all elements. + + diff --git a/src/it/separate-pom/separate-pom-expected.xml b/src/it/separate-pom/separate-pom-expected.xml new file mode 100644 index 0000000..6998901 --- /dev/null +++ b/src/it/separate-pom/separate-pom-expected.xml @@ -0,0 +1,231 @@ + + + 4.0.0 + + + org.codehaus + codehaus-parent + 4 + + + org.codehaus.mojo.tidy.its + pom-space-indent + 1.0-SNAPSHOT + pom + + Complete POM test + Test of tidy:pom on a separate pom with all elements. + http://maven.apache.org + 2011 + + MojoHaus + http://www.mojohaus.org + + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + + + John Doe + john.doe@acme.org + + Lead Developer + + 0 + + + + + Jane Doe + jone.doe@acme.org + + + + + + MojoHaus Development List + mojohaus-dev+subscribe@googlegroups.com + mojohaus-dev+unsubscribe@googlegroups.com + mojohaus-dev@googlegroups.com + https://groups.google.com/forum/#!forum/mojohaus-dev + + + Maven Users List + users-subscribe@maven.apache.org + users-unsubscribe@maven.apache.org + users@maven.apache.org + http://mail-archives.apache.org/mod_mbox/maven-users/ + + http://maven.40175.n5.nabble.com/Maven-Users-f40176.html + + + + + + 2.2.1 + + + + scm:git:https://github.com/mojohaus/tidy-maven-plugin.git + scm:git:ssh://git@github.com/mojohaus/tidy-maven-plugin.git + https://github.com/mojohaus/tidy-maven-plugin + + + GitHub + https://github.com/mojohaus/tidy-maven-plugin/issues + + + travis + https://travis-ci.org/mojohaus/tidy-maven-plugin + + + + ossrh-staging + https://oss.sonatype.org/service/local/staging/deploy/maven2 + + + ossrh-snapshots + https://oss.sonatype.org/content/repositories/snapshots + + + github + scm:git:git@github.com:mojohaus/tidy-maven-plugin.git + + + + + UTF-8 + 5.7.2 + + + + + + org.codehaus.plexus + plexus-utils + 3.0.24 + jar + compile + + + + + + org.junit.jupiter + junit-jupiter-engine + ${junit.version} + test + + + org.junit.vintage + junit-vintage-engine + ${junit.version} + test + + + org.apache.logging.log4j + log4j-api + 2.19.0 + bundle + + + + + + ossrh-snapshots + ossrh-snapshots + https://oss.sonatype.org/content/repositories/snapshots + + false + + + true + + + + + + ossrh-snapshots + ossrh-snapshots + https://oss.sonatype.org/content/repositories/snapshots + + false + + + true + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.5.1 + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.16 + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.8 + + + build-helper + generate-sources + + add-source + + + + + dummy + + + + + + org.apache.maven.wagon + wagon-ssh-external + 1.0-beta-6 + + + + + + + + org.apache.maven.plugins + maven-project-info-reports-plugin + 2.7 + + + + + + + run-its + + + skipTests + !true + + + + + diff --git a/src/it/separate-pom/separate-pom.xml b/src/it/separate-pom/separate-pom.xml new file mode 100644 index 0000000..6adcae4 --- /dev/null +++ b/src/it/separate-pom/separate-pom.xml @@ -0,0 +1,232 @@ + + + + pom + + pom-space-indent + org.codehaus.mojo.tidy.its + + org.codehaus + codehaus-parent + 4 + + 4.0.0 + 1.0-SNAPSHOT + Test of tidy:pom on a separate pom with all elements. + + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + Complete POM test + 2011 + http://maven.apache.org + + + UTF-8 + 5.7.2 + + + + ossrh-snapshots + ossrh-snapshots + https://oss.sonatype.org/content/repositories/snapshots + + false + + + true + + + + + MojoHaus + http://www.mojohaus.org + + + + + ossrh-snapshots + ossrh-snapshots + https://oss.sonatype.org/content/repositories/snapshots + + false + + + true + + + + + + + + MojoHaus Development List + mojohaus-dev+subscribe@googlegroups.com + mojohaus-dev+unsubscribe@googlegroups.com + mojohaus-dev@googlegroups.com + https://groups.google.com/forum/#!forum/mojohaus-dev + + + Maven Users List + users-subscribe@maven.apache.org + users-unsubscribe@maven.apache.org + users@maven.apache.org + http://mail-archives.apache.org/mod_mbox/maven-users/ + + http://maven.40175.n5.nabble.com/Maven-Users-f40176.html + + + + + scm:git:https://github.com/mojohaus/tidy-maven-plugin.git + scm:git:ssh://git@github.com/mojohaus/tidy-maven-plugin.git + https://github.com/mojohaus/tidy-maven-plugin + + + + 2.2.1 + + + + GitHub + https://github.com/mojohaus/tidy-maven-plugin/issues + + + + Jane Doe + jone.doe@acme.org + + + + + John Doe + john.doe@acme.org + + Lead Developer + + 0 + + + + + + ossrh-staging + https://oss.sonatype.org/service/local/staging/deploy/maven2 + + + ossrh-snapshots + https://oss.sonatype.org/content/repositories/snapshots + + + github + scm:git:git@github.com:mojohaus/tidy-maven-plugin.git + + + + + + + org.codehaus.plexus + plexus-utils + 3.0.24 + jar + compile + + + + + + + org.apache.maven.wagon + wagon-ssh-external + 1.0-beta-6 + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.5.1 + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.16 + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.8 + + + build-helper + generate-sources + + add-source + + + + + dummy + + + + + + travis + https://travis-ci.org/mojohaus/tidy-maven-plugin + + + + org.junit.jupiter + junit-jupiter-engine + ${junit.version} + test + + + org.junit.vintage + junit-vintage-engine + ${junit.version} + test + + + org.apache.logging.log4j + log4j-api + 2.19.0 + bundle + + + + + + + org.apache.maven.plugins + maven-project-info-reports-plugin + 2.7 + + + + + + run-its + + + skipTests + !true + + + + + diff --git a/src/it/separate-pom/verify.groovy b/src/it/separate-pom/verify.groovy new file mode 100644 index 0000000..c7170b1 --- /dev/null +++ b/src/it/separate-pom/verify.groovy @@ -0,0 +1,4 @@ +File pomFile = new File( basedir, 'separate-pom.xml' ) +File expectedPomFile = new File( basedir, 'separate-pom-expected.xml' ) + +assert pomFile.getText() == expectedPomFile.getText() diff --git a/src/main/java/org/codehaus/mojo/tidy/TidyMojo.java b/src/main/java/org/codehaus/mojo/tidy/TidyMojo.java index c0c2af2..cc52cea 100644 --- a/src/main/java/org/codehaus/mojo/tidy/TidyMojo.java +++ b/src/main/java/org/codehaus/mojo/tidy/TidyMojo.java @@ -46,6 +46,16 @@ public abstract class TidyMojo extends AbstractMojo { @Parameter(defaultValue = "${project}", required = true, readonly = true) protected MavenProject project; + /** + * The path of the pom file to process. + * + *

If unset, the value of project.file will be used instead.

+ * + * @since 1.3.0 + */ + @Parameter(property = "tidy.pomFile") + private File pomFile; + /** * Set this to 'true' to skip execution. */ @@ -88,7 +98,11 @@ private String getProjectPom() throws MojoExecutionException { * Returns the file of the POM. */ protected File getPomFile() { - return project.getFile(); + File result = this.pomFile; + if (null == result) { + result = this.project.getFile(); + } + return result; } /** From 865629ffd0f413085980e5951fa6fdbd68d20d5e Mon Sep 17 00:00:00 2001 From: Smaarn Date: Thu, 9 May 2024 17:28:59 +0200 Subject: [PATCH 2/5] Make invalid and valid pom minimalistic (e.g. without plugin configuration) --- src/it/check-separate-fails/invalid-pom.xml | 19 ------------------- src/it/check-separate-succeeds/valid-pom.xml | 19 ------------------- 2 files changed, 38 deletions(-) diff --git a/src/it/check-separate-fails/invalid-pom.xml b/src/it/check-separate-fails/invalid-pom.xml index b57556b..e9a7e4a 100644 --- a/src/it/check-separate-fails/invalid-pom.xml +++ b/src/it/check-separate-fails/invalid-pom.xml @@ -12,23 +12,4 @@ 1.0-SNAPSHOT Test that check fails for a POM that is not tidy. - - - - - org.codehaus.mojo - tidy-maven-plugin - @pom.version@ - - - validate - validate - - check - - - - - - diff --git a/src/it/check-separate-succeeds/valid-pom.xml b/src/it/check-separate-succeeds/valid-pom.xml index 3665f50..5ec7a30 100644 --- a/src/it/check-separate-succeeds/valid-pom.xml +++ b/src/it/check-separate-succeeds/valid-pom.xml @@ -13,23 +13,4 @@ 1.0-SNAPSHOT Test that check doesn't fail for a tidy separate POM - - - - - org.codehaus.mojo - tidy-maven-plugin - @pom.version@ - - - validate - validate - - check - - - - - - From cfa7e299ee5529ad6275f64320289dd5e4156574 Mon Sep 17 00:00:00 2001 From: Smaarn Date: Thu, 9 May 2024 17:29:51 +0200 Subject: [PATCH 3/5] Fix formatting --- src/main/java/org/codehaus/mojo/tidy/TidyMojo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/codehaus/mojo/tidy/TidyMojo.java b/src/main/java/org/codehaus/mojo/tidy/TidyMojo.java index cc52cea..cd2a77d 100644 --- a/src/main/java/org/codehaus/mojo/tidy/TidyMojo.java +++ b/src/main/java/org/codehaus/mojo/tidy/TidyMojo.java @@ -50,7 +50,7 @@ public abstract class TidyMojo extends AbstractMojo { * The path of the pom file to process. * *

If unset, the value of project.file will be used instead.

- * + * * @since 1.3.0 */ @Parameter(property = "tidy.pomFile") From 130abcf6bb75f9f760ebe5025756a8a2033ae344 Mon Sep 17 00:00:00 2001 From: Smaarn Date: Sat, 11 May 2024 14:09:04 +0200 Subject: [PATCH 4/5] Use explicit default property --- src/main/java/org/codehaus/mojo/tidy/TidyMojo.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/codehaus/mojo/tidy/TidyMojo.java b/src/main/java/org/codehaus/mojo/tidy/TidyMojo.java index cd2a77d..faa6f8b 100644 --- a/src/main/java/org/codehaus/mojo/tidy/TidyMojo.java +++ b/src/main/java/org/codehaus/mojo/tidy/TidyMojo.java @@ -49,11 +49,9 @@ public abstract class TidyMojo extends AbstractMojo { /** * The path of the pom file to process. * - *

If unset, the value of project.file will be used instead.

- * * @since 1.3.0 */ - @Parameter(property = "tidy.pomFile") + @Parameter(property = "tidy.pomFile", defaultValue = "${project.file}") private File pomFile; /** @@ -98,11 +96,7 @@ private String getProjectPom() throws MojoExecutionException { * Returns the file of the POM. */ protected File getPomFile() { - File result = this.pomFile; - if (null == result) { - result = this.project.getFile(); - } - return result; + return this.pomFile; } /** From fa051951fbf1d12d74f8091402ec1d432e3f01c9 Mon Sep 17 00:00:00 2001 From: Smaarn Date: Sat, 11 May 2024 18:01:31 +0200 Subject: [PATCH 5/5] Bump version to 1.3.0-SNAPSHOT --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2ab50a9..679d2ce 100644 --- a/pom.xml +++ b/pom.xml @@ -28,7 +28,7 @@ tidy-maven-plugin - 1.2.1-SNAPSHOT + 1.3.0-SNAPSHOT maven-plugin Tidy Maven Plugin