Skip to content

Commit

Permalink
[MARTIFACT-53] warn only if timestamp not defined in reactor
Browse files Browse the repository at this point in the history
  • Loading branch information
hboutemy committed Dec 2, 2023
1 parent f3590ab commit dfc962f
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@
# under the License.

invoker.goals=artifact:check-buildplan
invoker.buildResult=failure
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
24 changes: 24 additions & 0 deletions src/it/check-buildplan-warn/verify.groovy
Original file line number Diff line number Diff line change
@@ -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')
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
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;
Expand Down Expand Up @@ -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
Expand All @@ -189,6 +167,39 @@ public void execute() throws MojoExecutionException {
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).
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,12 @@
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;
Expand Down Expand Up @@ -98,7 +95,8 @@ protected MavenExecutionPlan calculateExecutionPlan() throws MojoExecutionExcept

@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();
Expand Down Expand Up @@ -161,36 +159,6 @@ public void execute() throws MojoExecutionException {
}
}

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")
Expand Down
4 changes: 3 additions & 1 deletion src/site/apt/plugin-issues.apt
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
*--------+--------------------------------------------------------------------+-------+--------------+
Expand Down

0 comments on commit dfc962f

Please sign in to comment.