This is an automated email from the ASF dual-hosted git repository. hboutemy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/maven-artifact-plugin.git
The following commit(s) were added to refs/heads/master by this push: new dfc962f [MARTIFACT-53] warn only if timestamp not defined in reactor dfc962f is described below commit dfc962f17d8db0c338432a001f7b2e8398b0bafc Author: Hervé Boutemy <hbout...@apache.org> AuthorDate: Sat Dec 2 19:38:35 2023 +0100 [MARTIFACT-53] warn only if timestamp not defined in reactor --- .../invoker.properties | 1 - .../pom.xml | 2 +- src/it/check-buildplan-warn/verify.groovy | 24 +++++++++ .../artifact/buildinfo/AbstractBuildinfoMojo.java | 59 +++++++++++++--------- .../artifact/buildinfo/CheckBuildPlanMojo.java | 36 +------------ src/site/apt/plugin-issues.apt | 4 +- 6 files changed, 65 insertions(+), 61 deletions(-) diff --git a/src/it/check-buildplan-fail/invoker.properties b/src/it/check-buildplan-warn/invoker.properties similarity index 96% rename from src/it/check-buildplan-fail/invoker.properties rename to src/it/check-buildplan-warn/invoker.properties index 077d077..f2191ac 100644 --- a/src/it/check-buildplan-fail/invoker.properties +++ b/src/it/check-buildplan-warn/invoker.properties @@ -16,4 +16,3 @@ # under the License. invoker.goals=artifact:check-buildplan -invoker.buildResult=failure diff --git a/src/it/check-buildplan-fail/pom.xml b/src/it/check-buildplan-warn/pom.xml similarity index 91% rename from src/it/check-buildplan-fail/pom.xml rename to src/it/check-buildplan-warn/pom.xml index f89f055..38a8085 100644 --- a/src/it/check-buildplan-fail/pom.xml +++ b/src/it/check-buildplan-warn/pom.xml @@ -28,7 +28,7 @@ <groupId>org.apache.maven.plugins.it</groupId> <artifactId>check-fail</artifactId> <version>1.0-SNAPSHOT</version> - <description>check-buildplan expected to fail because outputTimestamp is inherited form a POM outside the reactor</description> + <description>check-buildplan expected to pass with WARNING because outputTimestamp is inherited form a POM outside the reactor</description> <build> <pluginManagement> diff --git a/src/it/check-buildplan-warn/verify.groovy b/src/it/check-buildplan-warn/verify.groovy new file mode 100644 index 0000000..504e2ec --- /dev/null +++ b/src/it/check-buildplan-warn/verify.groovy @@ -0,0 +1,24 @@ + +/* + * 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. + */ + +def buildLog = new File(basedir, 'build.log').text + +// https://issues.apache.org/jira/browse/MARTIFACT-24 & MARTIFACT-53 +assert buildLog.contains('[WARNING] <project.build.outputTimestamp> property is inherited, it should be defined in pom.xml') diff --git a/src/main/java/org/apache/maven/plugins/artifact/buildinfo/AbstractBuildinfoMojo.java b/src/main/java/org/apache/maven/plugins/artifact/buildinfo/AbstractBuildinfoMojo.java index 2780115..e9543af 100644 --- a/src/main/java/org/apache/maven/plugins/artifact/buildinfo/AbstractBuildinfoMojo.java +++ b/src/main/java/org/apache/maven/plugins/artifact/buildinfo/AbstractBuildinfoMojo.java @@ -37,6 +37,7 @@ import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.logging.Log; import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; @@ -141,30 +142,7 @@ public abstract class AbstractBuildinfoMojo extends AbstractMojo { public void execute() throws MojoExecutionException { boolean mono = reactorProjects.size() == 1; - MavenArchiver archiver = new MavenArchiver(); - Date timestamp = archiver.parseOutputTimestamp(outputTimestamp); - if (timestamp == null) { - getLog().warn("Reproducible Build not activated by project.build.outputTimestamp property: " - + "see https://maven.apache.org/guides/mini/guide-reproducible-builds.html"); - } else { - if (getLog().isDebugEnabled()) { - getLog().debug("project.build.outputTimestamp = \"" + outputTimestamp + "\" => " - + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX").format(timestamp)); - } - - // check if timestamp well defined in a project from reactor - boolean parentInReactor = false; - MavenProject reactorParent = project; - while (reactorProjects.contains(reactorParent.getParent())) { - parentInReactor = true; - reactorParent = reactorParent.getParent(); - } - String prop = reactorParent.getOriginalModel().getProperties().getProperty("project.build.outputTimestamp"); - if (prop == null) { - getLog().error("project.build.outputTimestamp property should not be inherited but defined in " - + (parentInReactor ? "parent POM from reactor " : "POM ") + reactorParent.getFile()); - } - } + hasBadOutputTimestamp(outputTimestamp, getLog(), project, reactorProjects); if (!mono) { // if module skips install and/or deploy @@ -189,6 +167,39 @@ public abstract class AbstractBuildinfoMojo extends AbstractMojo { execute(artifacts); } + static boolean hasBadOutputTimestamp( + String outputTimestamp, Log log, MavenProject project, List<MavenProject> reactorProjects) { + MavenArchiver archiver = new MavenArchiver(); + Date timestamp = archiver.parseOutputTimestamp(outputTimestamp); + if (timestamp == null) { + log.error("Reproducible Build not activated by project.build.outputTimestamp property: " + + "see https://maven.apache.org/guides/mini/guide-reproducible-builds.html"); + return true; + } + + if (log.isDebugEnabled()) { + log.debug("project.build.outputTimestamp = \"" + outputTimestamp + "\" => " + + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX").format(timestamp)); + } + + // check if timestamp defined in a project from reactor: warn if it is not the case + boolean parentInReactor = false; + MavenProject reactorParent = project; + while (reactorProjects.contains(reactorParent.getParent())) { + parentInReactor = true; + reactorParent = reactorParent.getParent(); + } + String prop = reactorParent.getOriginalModel().getProperties().getProperty("project.build.outputTimestamp"); + if (prop == null) { + log.warn("<project.build.outputTimestamp> property is inherited" + + (parentInReactor ? " from outside the reactor" : "") + ", it should be defined in " + + (parentInReactor ? "parent POM from reactor " + reactorParent.getFile() : "pom.xml")); + return false; + } + + return false; + } + /** * Execute after buildinfo has been generated for current build (eventually aggregated). * diff --git a/src/main/java/org/apache/maven/plugins/artifact/buildinfo/CheckBuildPlanMojo.java b/src/main/java/org/apache/maven/plugins/artifact/buildinfo/CheckBuildPlanMojo.java index 0f5df7e..d74249a 100644 --- a/src/main/java/org/apache/maven/plugins/artifact/buildinfo/CheckBuildPlanMojo.java +++ b/src/main/java/org/apache/maven/plugins/artifact/buildinfo/CheckBuildPlanMojo.java @@ -22,15 +22,12 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; -import java.text.SimpleDateFormat; -import java.util.Date; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Properties; import java.util.Set; -import org.apache.maven.archiver.MavenArchiver; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.DefaultArtifactVersion; import org.apache.maven.execution.MavenSession; @@ -98,7 +95,8 @@ public class CheckBuildPlanMojo extends AbstractMojo { @Override public void execute() throws MojoExecutionException { - boolean fail = hasBadOutputTimestamp(); + boolean fail = AbstractBuildinfoMojo.hasBadOutputTimestamp(outputTimestamp, getLog(), project, reactorProjects); + // TODO check maven-jar-plugin module-info.class? Properties issues = loadIssues(); @@ -161,36 +159,6 @@ public class CheckBuildPlanMojo extends AbstractMojo { } } - private boolean hasBadOutputTimestamp() { - MavenArchiver archiver = new MavenArchiver(); - Date timestamp = archiver.parseOutputTimestamp(outputTimestamp); - if (timestamp == null) { - getLog().error("Reproducible Build not activated by project.build.outputTimestamp property: " - + "see https://maven.apache.org/guides/mini/guide-reproducible-builds.html"); - return true; - } else { - if (getLog().isDebugEnabled()) { - getLog().debug("project.build.outputTimestamp = \"" + outputTimestamp + "\" => " - + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX").format(timestamp)); - } - - // check if timestamp well defined in a project from reactor - boolean parentInReactor = false; - MavenProject reactorParent = project; - while (reactorProjects.contains(reactorParent.getParent())) { - parentInReactor = true; - reactorParent = reactorParent.getParent(); - } - String prop = reactorParent.getOriginalModel().getProperties().getProperty("project.build.outputTimestamp"); - if (prop == null) { - getLog().error("project.build.outputTimestamp property should not be inherited but defined in " - + (parentInReactor ? "parent POM from reactor " : "POM ") + reactorParent.getFile()); - return true; - } - } - return false; - } - private Properties loadIssues() throws MojoExecutionException { try (InputStream in = (pluginIssues == null) ? getClass().getResourceAsStream("not-reproducible-plugins.properties") diff --git a/src/site/apt/plugin-issues.apt b/src/site/apt/plugin-issues.apt index 8f02d8d..daccf6b 100644 --- a/src/site/apt/plugin-issues.apt +++ b/src/site/apt/plugin-issues.apt @@ -78,9 +78,11 @@ Usage *--------+--------------------------------------------------------------------+-------+--------------+ | org.eclipse.jetty | jetty-jspc-maven-plugin | - | no fixed release available, see {{{https://github.com/eclipse/jetty.project/}reference}} *--------+--------------------------------------------------------------------+-------+--------------+ +| org.glassfish.hk2 | hk2-inhabitant-generator | 3.0.5 | +*--------+--------------------------------------------------------------------+-------+--------------+ | org.jboss.jandex | jandex-maven-plugin | - | no fixed release available, see {{{https://github.com/wildfly/jandex-maven-plugin/pull/35}reference}} *--------+--------------------------------------------------------------------+-------+--------------+ -| org.moditect | moditect-maven-plugin | - | no fixed release available, see {{{https://github.com/moditect/moditect/pull/211}reference}} +| org.moditect | moditect-maven-plugin | 1.1.0 | *--------+--------------------------------------------------------------------+-------+--------------+ | org.springframework.boot | spring-boot-maven-plugin | 2.7.1 | *--------+--------------------------------------------------------------------+-------+--------------+