You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2024/12/21 23:03:43 UTC
(maven-artifact-plugin) branch MARTIFACT-78 created (now 5b81b72)
This is an automated email from the ASF dual-hosted git repository.
hboutemy pushed a change to branch MARTIFACT-78
in repository https://gitbox.apache.org/repos/asf/maven-artifact-plugin.git
at 5b81b72 [MARTIFACT-78] diagnose reactor root and first
This branch includes the following new commits:
new 5b81b72 [MARTIFACT-78] diagnose reactor root and first
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(maven-artifact-plugin) 01/01: [MARTIFACT-78] diagnose reactor root and first
Posted by hb...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
hboutemy pushed a commit to branch MARTIFACT-78
in repository https://gitbox.apache.org/repos/asf/maven-artifact-plugin.git
commit 5b81b72cf21c80d70beac43141f81da3485a092a
Author: Hervé Boutemy <hb...@apache.org>
AuthorDate: Sun Dec 22 00:03:29 2024 +0100
[MARTIFACT-78] diagnose reactor root and first
---
.../artifact/buildinfo/AbstractBuildinfoMojo.java | 48 +++++++++++-----------
.../artifact/buildinfo/CheckBuildPlanMojo.java | 4 +-
.../plugins/artifact/buildinfo/CompareMojo.java | 4 +-
.../buildinfo/DescribeBuildOutputMojo.java | 4 +-
4 files changed, 29 insertions(+), 31 deletions(-)
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 51b0e0e..e108083 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
@@ -153,7 +153,7 @@ public abstract class AbstractBuildinfoMojo extends AbstractMojo {
public void execute() throws MojoExecutionException {
boolean mono = session.getProjects().size() == 1;
- hasBadOutputTimestamp(outputTimestamp, getLog(), project, session.getProjects(), diagnose);
+ hasBadOutputTimestamp(outputTimestamp, getLog(), project, session, diagnose);
if (!mono) {
// if module skips install and/or deploy
@@ -179,17 +179,13 @@ public abstract class AbstractBuildinfoMojo extends AbstractMojo {
}
static boolean hasBadOutputTimestamp(
- String outputTimestamp,
- Log log,
- MavenProject project,
- List<MavenProject> reactorProjects,
- boolean diagnose) {
+ String outputTimestamp, Log log, MavenProject project, MavenSession session, boolean diagnose) {
Instant timestamp =
MavenArchiver.parseBuildOutputTimestamp(outputTimestamp).orElse(null);
String effective = ((timestamp == null) ? "disabled" : DateTimeFormatter.ISO_INSTANT.format(timestamp));
if (diagnose) {
- diagnose(outputTimestamp, log, project, reactorProjects, effective);
+ diagnose(outputTimestamp, log, project, session, effective);
}
if (timestamp == null) {
@@ -215,7 +211,7 @@ public abstract class AbstractBuildinfoMojo extends AbstractMojo {
// check if timestamp defined in a project from reactor: info if it is not the case
boolean parentInReactor = false;
MavenProject reactorParent = project;
- while (reactorProjects.contains(reactorParent.getParent())) {
+ while (session.getProjects().contains(reactorParent.getParent())) {
parentInReactor = true;
reactorParent = reactorParent.getParent();
}
@@ -231,11 +227,18 @@ public abstract class AbstractBuildinfoMojo extends AbstractMojo {
}
static void diagnose(
- String outputTimestamp,
- Log log,
- MavenProject project,
- List<MavenProject> reactorProjects,
- String effective) {
+ String outputTimestamp, Log log, MavenProject project, MavenSession session, String effective) {
+ if (session.getProjects().size() > 1) {
+ log.info("reactor executionRoot = " + session.getTopLevelProject().getId());
+ log.info("reactor first = " + session.getProjects().get(0).getId());
+ MavenProject parent = session.getProjects().get(0).getParent();
+ log.info("reactor first parent = " + ((parent == null) ? parent : parent.getId()));
+ if (parent != null && session.getProjects().contains(parent)) {
+ // should not happen...
+ log.warn("reactor first parent = " + parent.getId() + " is in reactor");
+ }
+ }
+
log.info("outputTimestamp = " + outputTimestamp
+ (effective.equals(outputTimestamp) ? "" : (" => " + effective)));
@@ -254,6 +257,10 @@ public abstract class AbstractBuildinfoMojo extends AbstractMojo {
+ " - project.build.outputTimestamp property from project original model = "
+ originalModelProperty);
+ if (outputTimestamp == null) {
+ return;
+ }
+
MavenProject parent = project.getParent();
if (parent != null) {
StringBuilder sb = new StringBuilder("Inheritance analysis property:" + System.lineSeparator()
@@ -261,7 +268,7 @@ public abstract class AbstractBuildinfoMojo extends AbstractMojo {
while (parent != null) {
String parentProperty = parent.getProperties().getProperty("project.build.outputTimestamp");
sb.append(System.lineSeparator());
- sb.append(" - " + (reactorProjects.contains(parent) ? "reactor" : "external") + " parent "
+ sb.append(" - " + (session.getProjects().contains(parent) ? "reactor" : "external") + " parent "
+ parent.getId() + " property = " + parentProperty);
if (!projectProperty.equals(parentProperty)) {
break;
@@ -291,7 +298,7 @@ public abstract class AbstractBuildinfoMojo extends AbstractMojo {
}
// copy aggregate file to root target directory
- MavenProject root = getExecutionRoot();
+ MavenProject root = session.getTopLevelProject();
String extension = aggregate.getName().substring(aggregate.getName().lastIndexOf('.'));
File rootCopy =
new File(root.getBuild().getDirectory(), root.getArtifactId() + '-' + root.getVersion() + extension);
@@ -325,7 +332,7 @@ public abstract class AbstractBuildinfoMojo extends AbstractMojo {
* @throws MojoExecutionException if anything goes wrong
*/
protected Map<Artifact, String> generateBuildinfo(boolean mono) throws MojoExecutionException {
- MavenProject root = mono ? project : getExecutionRoot();
+ MavenProject root = mono ? project : session.getTopLevelProject();
buildinfoFile.getParentFile().mkdirs();
@@ -355,15 +362,6 @@ public abstract class AbstractBuildinfoMojo extends AbstractMojo {
}
}
- protected MavenProject getExecutionRoot() {
- for (MavenProject p : session.getAllProjects()) {
- if (p.isExecutionRoot()) {
- return p;
- }
- }
- return null;
- }
-
private MavenProject getLastProject() {
int i = session.getProjects().size();
while (i > 0) {
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 00a2fab..fc7eca7 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
@@ -108,8 +108,8 @@ public class CheckBuildPlanMojo extends AbstractMojo {
@Override
public void execute() throws MojoExecutionException {
- boolean fail = AbstractBuildinfoMojo.hasBadOutputTimestamp(
- outputTimestamp, getLog(), project, session.getProjects(), diagnose);
+ boolean fail =
+ AbstractBuildinfoMojo.hasBadOutputTimestamp(outputTimestamp, getLog(), project, session, diagnose);
// TODO check maven-jar-plugin module-info.class?
diff --git a/src/main/java/org/apache/maven/plugins/artifact/buildinfo/CompareMojo.java b/src/main/java/org/apache/maven/plugins/artifact/buildinfo/CompareMojo.java
index b7a4277..bda4391 100644
--- a/src/main/java/org/apache/maven/plugins/artifact/buildinfo/CompareMojo.java
+++ b/src/main/java/org/apache/maven/plugins/artifact/buildinfo/CompareMojo.java
@@ -137,7 +137,7 @@ public class CompareMojo extends AbstractBuildinfoMojo {
* @throws MojoExecutionException if anything goes wrong
*/
private void checkAgainstReference(Map<Artifact, String> artifacts, boolean mono) throws MojoExecutionException {
- MavenProject root = mono ? project : getExecutionRoot();
+ MavenProject root = mono ? project : session.getTopLevelProject();
File referenceDir = new File(root.getBuild().getDirectory(), "reference");
referenceDir.mkdirs();
@@ -301,7 +301,7 @@ public class CompareMojo extends AbstractBuildinfoMojo {
}
private String relative(File file) {
- File basedir = getExecutionRoot().getBasedir();
+ File basedir = session.getTopLevelProject().getBasedir();
int length = basedir.getPath().length();
String path = file.getPath();
return path.substring(length + 1);
diff --git a/src/main/java/org/apache/maven/plugins/artifact/buildinfo/DescribeBuildOutputMojo.java b/src/main/java/org/apache/maven/plugins/artifact/buildinfo/DescribeBuildOutputMojo.java
index ae7362f..a1d1c5f 100644
--- a/src/main/java/org/apache/maven/plugins/artifact/buildinfo/DescribeBuildOutputMojo.java
+++ b/src/main/java/org/apache/maven/plugins/artifact/buildinfo/DescribeBuildOutputMojo.java
@@ -72,7 +72,7 @@ public class DescribeBuildOutputMojo extends AbstractBuildinfoMojo {
MavenArchiver.parseBuildOutputTimestamp(outputTimestamp).orElse(null);
String effective = ((timestamp == null) ? "disabled" : DateTimeFormatter.ISO_INSTANT.format(timestamp));
- diagnose(outputTimestamp, getLog(), project, session.getProjects(), effective);
+ diagnose(outputTimestamp, getLog(), project, session, effective);
getLog().info("");
describeBuildOutput();
}
@@ -81,7 +81,7 @@ public class DescribeBuildOutputMojo extends AbstractBuildinfoMojo {
private BuildInfoWriter bi;
private void describeBuildOutput() throws MojoExecutionException {
- rootPath = getExecutionRoot().getBasedir().toPath();
+ rootPath = session.getTopLevelProject().getBasedir().toPath();
bi = newBuildInfoWriter(null, false);
Map<String, Long> groupIds = session.getProjects().stream()