From de4e0fee897c1b83bf68700bea8e9f6300f35d06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Volkan=20Yaz=C4=B1c=C4=B1?= Date: Wed, 8 May 2024 10:02:41 +0200 Subject: [PATCH 1/2] Add `skip` parameter to all Maven goals --- .../maven/AbstractChangelogMojo.java | 39 +++++++++++++++++++ .../log4j/changelog/maven/ExportMojo.java | 15 ++----- .../log4j/changelog/maven/ImportMojo.java | 15 ++----- .../log4j/changelog/maven/ReleaseMojo.java | 16 ++------ ...ratorMojo.java => AbstractDocgenMojo.java} | 8 +++- .../maven/DocumentationGeneratorMojo.java | 5 ++- .../docgen/maven/SchemaGeneratorMojo.java | 5 ++- src/changelog/.0.x.x/add-maven-skip.xml | 8 ++++ .../pages/log4j-changelog-maven-plugin.adoc | 8 ++++ .../ROOT/pages/log4j-docgen-maven-plugin.adoc | 12 ++++++ 10 files changed, 94 insertions(+), 37 deletions(-) create mode 100644 log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/AbstractChangelogMojo.java rename log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/{AbstractGeneratorMojo.java => AbstractDocgenMojo.java} (90%) create mode 100644 src/changelog/.0.x.x/add-maven-skip.xml diff --git a/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/AbstractChangelogMojo.java b/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/AbstractChangelogMojo.java new file mode 100644 index 00000000..223cf82e --- /dev/null +++ b/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/AbstractChangelogMojo.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to you 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 + * + * http://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.apache.logging.log4j.changelog.maven; + +import java.io.File; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugins.annotations.Parameter; + +abstract class AbstractChangelogMojo extends AbstractMojo { + + /** + * Indicates if the execution should be skipped or not. + */ + @Parameter(property = "log4j.changelog.skip") + boolean skip; + + /** + * Directory containing release folders composed of changelog entry XML files. + */ + @Parameter( + defaultValue = "${project.basedir}/src/changelog", + property = "log4j.changelog.directory", + required = true) + File changelogDirectory; +} diff --git a/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ExportMojo.java b/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ExportMojo.java index d051f37e..4c5877df 100644 --- a/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ExportMojo.java +++ b/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ExportMojo.java @@ -25,7 +25,6 @@ import org.apache.logging.log4j.changelog.exporter.ChangelogExporter; import org.apache.logging.log4j.changelog.exporter.ChangelogExporterArgs; import org.apache.logging.log4j.changelog.exporter.ChangelogExporterTemplate; -import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; @@ -36,20 +35,11 @@ * @see ChangelogExporter */ @Mojo(name = "export", defaultPhase = LifecyclePhase.PRE_SITE, threadSafe = true) -public final class ExportMojo extends AbstractMojo { +public final class ExportMojo extends AbstractChangelogMojo { private static final String SOURCE_TARGET_TEMPLATE_PATTERN = "^\\.(.*)\\." + ChangelogFiles.templateFileNameExtension() + '$'; - /** - * Directory containing release folders composed of changelog entry XML files. - */ - @Parameter( - defaultValue = "${project.basedir}/src/changelog", - property = "log4j.changelog.directory", - required = true) - private File changelogDirectory; - /** * Templates that will be rendered with the release information of all releases, e.g., to generate an index page. */ @@ -73,6 +63,9 @@ public final class ExportMojo extends AbstractMojo { @Override public void execute() { + if (skip) { + return; + } final Set translatedIndexTemplates = toExporterTemplates(indexTemplates); final Set translatedReleaseChangelogTemplates = toExporterTemplates(changelogTemplates); diff --git a/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ImportMojo.java b/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ImportMojo.java index 05249bf9..64a5a83c 100644 --- a/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ImportMojo.java +++ b/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ImportMojo.java @@ -20,7 +20,6 @@ import org.apache.logging.log4j.changelog.importer.MavenChangesImporter; import org.apache.logging.log4j.changelog.importer.MavenChangesImporterArgs; import org.apache.logging.log4j.changelog.releaser.ChangelogReleaser; -import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; @@ -30,16 +29,7 @@ * @see ChangelogReleaser */ @Mojo(name = "import", threadSafe = true) -public final class ImportMojo extends AbstractMojo { - - /** - * Directory containing release folders composed of changelog entry XML files. - */ - @Parameter( - defaultValue = "${project.basedir}/src/changelog", - property = "log4j.changelog.directory", - required = true) - private File changelogDirectory; +public final class ImportMojo extends AbstractChangelogMojo { /** * maven-changes-plugin source XML, {@code changes.xml}, location. @@ -58,6 +48,9 @@ public final class ImportMojo extends AbstractMojo { @Override public void execute() { + if (skip) { + return; + } final MavenChangesImporterArgs args = new MavenChangesImporterArgs(changelogDirectory.toPath(), changesXmlFile.toPath(), releaseVersionMajor); MavenChangesImporter.performImport(args); diff --git a/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ReleaseMojo.java b/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ReleaseMojo.java index 01204b6d..aa4c8e52 100644 --- a/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ReleaseMojo.java +++ b/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ReleaseMojo.java @@ -16,13 +16,11 @@ */ package org.apache.logging.log4j.changelog.maven; -import java.io.File; import java.time.LocalDate; import java.time.ZoneId; import java.util.regex.Pattern; import org.apache.logging.log4j.changelog.releaser.ChangelogReleaser; import org.apache.logging.log4j.changelog.releaser.ChangelogReleaserArgs; -import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; @@ -33,16 +31,7 @@ * @see ChangelogReleaser */ @Mojo(name = "release", defaultPhase = LifecyclePhase.VALIDATE, threadSafe = true) -public final class ReleaseMojo extends AbstractMojo { - - /** - * Directory containing release folders composed of changelog entry XML files. - */ - @Parameter( - defaultValue = "${project.basedir}/src/changelog", - property = "log4j.changelog.directory", - required = true) - private File changelogDirectory; +public final class ReleaseMojo extends AbstractChangelogMojo { /** * The version to be released, e.g., {@code 2.19.0}. @@ -66,6 +55,9 @@ public final class ReleaseMojo extends AbstractMojo { @Override public void execute() { + if (skip) { + return; + } Pattern compiledVersionPattern = versionPattern != null ? Pattern.compile(versionPattern) : null; final ChangelogReleaserArgs args = new ChangelogReleaserArgs( changelogDirectory.toPath(), diff --git a/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/AbstractGeneratorMojo.java b/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/AbstractDocgenMojo.java similarity index 90% rename from log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/AbstractGeneratorMojo.java rename to log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/AbstractDocgenMojo.java index 36603baf..4831e763 100644 --- a/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/AbstractGeneratorMojo.java +++ b/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/AbstractDocgenMojo.java @@ -21,7 +21,13 @@ import org.apache.maven.plugins.annotations.Parameter; import org.jspecify.annotations.Nullable; -abstract class AbstractGeneratorMojo extends AbstractMojo { +abstract class AbstractDocgenMojo extends AbstractMojo { + + /** + * Indicates if the execution should be skipped or not. + */ + @Parameter(property = "log4j.docgen.skip") + boolean skip; /** * The paths of the plugin descriptor XML files. diff --git a/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/DocumentationGeneratorMojo.java b/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/DocumentationGeneratorMojo.java index 86c55742..aa230d66 100644 --- a/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/DocumentationGeneratorMojo.java +++ b/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/DocumentationGeneratorMojo.java @@ -33,7 +33,7 @@ * @see DocumentationGenerator */ @Mojo(name = "generate-documentation", defaultPhase = LifecyclePhase.GENERATE_RESOURCES, threadSafe = true) -public class DocumentationGeneratorMojo extends AbstractGeneratorMojo { +public class DocumentationGeneratorMojo extends AbstractDocgenMojo { /** * The path to the FreeMarker template directory. @@ -55,6 +55,9 @@ public class DocumentationGeneratorMojo extends AbstractGeneratorMojo { @Override public void execute() { + if (skip) { + return; + } final Set pluginSets = PluginSets.ofDescriptorFilesAndFileMatchers(descriptorFiles, descriptorFileMatchers); final Predicate classNameFilter = typeFilter != null ? typeFilter.createPredicate() : ignored -> true; diff --git a/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/SchemaGeneratorMojo.java b/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/SchemaGeneratorMojo.java index 7f16de8a..5fe8edbe 100644 --- a/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/SchemaGeneratorMojo.java +++ b/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/SchemaGeneratorMojo.java @@ -34,7 +34,7 @@ * @see SchemaGenerator */ @Mojo(name = "generate-schema", defaultPhase = LifecyclePhase.GENERATE_RESOURCES, threadSafe = true) -public class SchemaGeneratorMojo extends AbstractGeneratorMojo { +public class SchemaGeneratorMojo extends AbstractDocgenMojo { /** * The version of the XSD @@ -50,6 +50,9 @@ public class SchemaGeneratorMojo extends AbstractGeneratorMojo { @Override public void execute() throws MojoExecutionException { + if (skip) { + return; + } final Set pluginSets = PluginSets.ofDescriptorFilesAndFileMatchers(descriptorFiles, descriptorFileMatchers); final Predicate classNameFilter = typeFilter != null ? typeFilter.createPredicate() : ignored -> true; diff --git a/src/changelog/.0.x.x/add-maven-skip.xml b/src/changelog/.0.x.x/add-maven-skip.xml new file mode 100644 index 00000000..0c23cad0 --- /dev/null +++ b/src/changelog/.0.x.x/add-maven-skip.xml @@ -0,0 +1,8 @@ + + + + Add `skip` parameter to all Maven goals + diff --git a/src/site/antora/modules/ROOT/pages/log4j-changelog-maven-plugin.adoc b/src/site/antora/modules/ROOT/pages/log4j-changelog-maven-plugin.adoc index b93b2486..c4d9a473 100644 --- a/src/site/antora/modules/ROOT/pages/log4j-changelog-maven-plugin.adoc +++ b/src/site/antora/modules/ROOT/pages/log4j-changelog-maven-plugin.adoc @@ -86,6 +86,10 @@ You can use the `export` goal as follows: `export` goal by default runs during the `pre-site` phase and accepts the following configuration: +`skip` (parameter):: +Indicates if the execution should be skipped or not. +It defaults to `false` and can be set using the `log4j.changelog.skip` property. + `changelogDirectory` (parameter):: Directory containing release folders composed of changelog entry XML files. It defaults to `${project.basedir}/src/changelog` and can be set using the `log4j.changelog.directory` property. @@ -135,6 +139,10 @@ Note that above we are using `-N` (`--non-recursive`) to avoid visiting submodul `release` goal does not have default phase and accepts the following configuration parameters: +`skip` (parameter):: +Indicates if the execution should be skipped or not. +It defaults to `false` and can be set using the `log4j.changelog.skip` property. + `changelogDirectory` (parameter):: Directory containing release folders composed of changelog entry XML files. It defaults to `${project.basedir}/src/changelog` and can be set using the `log4j.changelog.directory` property. diff --git a/src/site/antora/modules/ROOT/pages/log4j-docgen-maven-plugin.adoc b/src/site/antora/modules/ROOT/pages/log4j-docgen-maven-plugin.adoc index 7b824b40..7b7f6231 100644 --- a/src/site/antora/modules/ROOT/pages/log4j-docgen-maven-plugin.adoc +++ b/src/site/antora/modules/ROOT/pages/log4j-docgen-maven-plugin.adoc @@ -69,6 +69,12 @@ The `generate-documentation` goal generates an AsciiDoc-formatted documentation ---- +The `generate-documentation` goal configuration also accepts the following parameters: + +`skip` (parameter):: +Indicates if the execution should be skipped or not. +It defaults to `false` and can be set using the `log4j.docgen.skip` property. + [#generate-schema] == Generate schema @@ -96,3 +102,9 @@ The `generate-schema` goal generates an XSD derived from the types loaded using ---- + +The `generate-schema` goal configuration also accepts the following parameters: + +`skip` (parameter):: +Indicates if the execution should be skipped or not. +It defaults to `false` and can be set using the `log4j.docgen.skip` property. From 842e23fae62ba1ad217626fcd5c40d0983b15cdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Volkan=20Yaz=C4=B1c=C4=B1?= Date: Wed, 8 May 2024 10:16:48 +0200 Subject: [PATCH 2/2] Log when execution is skipped --- .../org/apache/logging/log4j/changelog/maven/ExportMojo.java | 1 + .../org/apache/logging/log4j/changelog/maven/ImportMojo.java | 1 + .../org/apache/logging/log4j/changelog/maven/ReleaseMojo.java | 1 + .../logging/log4j/docgen/maven/DocumentationGeneratorMojo.java | 1 + .../apache/logging/log4j/docgen/maven/SchemaGeneratorMojo.java | 1 + 5 files changed, 5 insertions(+) diff --git a/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ExportMojo.java b/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ExportMojo.java index 4c5877df..37bf582d 100644 --- a/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ExportMojo.java +++ b/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ExportMojo.java @@ -64,6 +64,7 @@ public final class ExportMojo extends AbstractChangelogMojo { @Override public void execute() { if (skip) { + getLog().info("Skipping changelog export"); return; } final Set translatedIndexTemplates = toExporterTemplates(indexTemplates); diff --git a/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ImportMojo.java b/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ImportMojo.java index 64a5a83c..8fd7b89a 100644 --- a/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ImportMojo.java +++ b/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ImportMojo.java @@ -49,6 +49,7 @@ public final class ImportMojo extends AbstractChangelogMojo { @Override public void execute() { if (skip) { + getLog().info("Skipping changelog import"); return; } final MavenChangesImporterArgs args = diff --git a/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ReleaseMojo.java b/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ReleaseMojo.java index aa4c8e52..1ea8eaaa 100644 --- a/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ReleaseMojo.java +++ b/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ReleaseMojo.java @@ -56,6 +56,7 @@ public final class ReleaseMojo extends AbstractChangelogMojo { @Override public void execute() { if (skip) { + getLog().info("Skipping changelog release"); return; } Pattern compiledVersionPattern = versionPattern != null ? Pattern.compile(versionPattern) : null; diff --git a/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/DocumentationGeneratorMojo.java b/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/DocumentationGeneratorMojo.java index aa230d66..bbb5c66b 100644 --- a/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/DocumentationGeneratorMojo.java +++ b/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/DocumentationGeneratorMojo.java @@ -56,6 +56,7 @@ public class DocumentationGeneratorMojo extends AbstractDocgenMojo { @Override public void execute() { if (skip) { + getLog().info("Skipping documentation generation"); return; } final Set pluginSets = diff --git a/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/SchemaGeneratorMojo.java b/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/SchemaGeneratorMojo.java index 5fe8edbe..5f4e8846 100644 --- a/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/SchemaGeneratorMojo.java +++ b/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/SchemaGeneratorMojo.java @@ -51,6 +51,7 @@ public class SchemaGeneratorMojo extends AbstractDocgenMojo { @Override public void execute() throws MojoExecutionException { if (skip) { + getLog().info("Skipping schema generation"); return; } final Set pluginSets =