Skip to content

Commit 5b81b72

Browse files
committed
[MARTIFACT-78] diagnose reactor root and first
1 parent 1a30172 commit 5b81b72

File tree

4 files changed

+29
-31
lines changed

4 files changed

+29
-31
lines changed

src/main/java/org/apache/maven/plugins/artifact/buildinfo/AbstractBuildinfoMojo.java

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ protected AbstractBuildinfoMojo(
153153
public void execute() throws MojoExecutionException {
154154
boolean mono = session.getProjects().size() == 1;
155155

156-
hasBadOutputTimestamp(outputTimestamp, getLog(), project, session.getProjects(), diagnose);
156+
hasBadOutputTimestamp(outputTimestamp, getLog(), project, session, diagnose);
157157

158158
if (!mono) {
159159
// if module skips install and/or deploy
@@ -179,17 +179,13 @@ public void execute() throws MojoExecutionException {
179179
}
180180

181181
static boolean hasBadOutputTimestamp(
182-
String outputTimestamp,
183-
Log log,
184-
MavenProject project,
185-
List<MavenProject> reactorProjects,
186-
boolean diagnose) {
182+
String outputTimestamp, Log log, MavenProject project, MavenSession session, boolean diagnose) {
187183
Instant timestamp =
188184
MavenArchiver.parseBuildOutputTimestamp(outputTimestamp).orElse(null);
189185
String effective = ((timestamp == null) ? "disabled" : DateTimeFormatter.ISO_INSTANT.format(timestamp));
190186

191187
if (diagnose) {
192-
diagnose(outputTimestamp, log, project, reactorProjects, effective);
188+
diagnose(outputTimestamp, log, project, session, effective);
193189
}
194190

195191
if (timestamp == null) {
@@ -215,7 +211,7 @@ static boolean hasBadOutputTimestamp(
215211
// check if timestamp defined in a project from reactor: info if it is not the case
216212
boolean parentInReactor = false;
217213
MavenProject reactorParent = project;
218-
while (reactorProjects.contains(reactorParent.getParent())) {
214+
while (session.getProjects().contains(reactorParent.getParent())) {
219215
parentInReactor = true;
220216
reactorParent = reactorParent.getParent();
221217
}
@@ -231,11 +227,18 @@ static boolean hasBadOutputTimestamp(
231227
}
232228

233229
static void diagnose(
234-
String outputTimestamp,
235-
Log log,
236-
MavenProject project,
237-
List<MavenProject> reactorProjects,
238-
String effective) {
230+
String outputTimestamp, Log log, MavenProject project, MavenSession session, String effective) {
231+
if (session.getProjects().size() > 1) {
232+
log.info("reactor executionRoot = " + session.getTopLevelProject().getId());
233+
log.info("reactor first = " + session.getProjects().get(0).getId());
234+
MavenProject parent = session.getProjects().get(0).getParent();
235+
log.info("reactor first parent = " + ((parent == null) ? parent : parent.getId()));
236+
if (parent != null && session.getProjects().contains(parent)) {
237+
// should not happen...
238+
log.warn("reactor first parent = " + parent.getId() + " is in reactor");
239+
}
240+
}
241+
239242
log.info("outputTimestamp = " + outputTimestamp
240243
+ (effective.equals(outputTimestamp) ? "" : (" => " + effective)));
241244

@@ -254,14 +257,18 @@ static void diagnose(
254257
+ " - project.build.outputTimestamp property from project original model = "
255258
+ originalModelProperty);
256259

260+
if (outputTimestamp == null) {
261+
return;
262+
}
263+
257264
MavenProject parent = project.getParent();
258265
if (parent != null) {
259266
StringBuilder sb = new StringBuilder("Inheritance analysis property:" + System.lineSeparator()
260267
+ " - current " + project.getId() + " property = " + projectProperty);
261268
while (parent != null) {
262269
String parentProperty = parent.getProperties().getProperty("project.build.outputTimestamp");
263270
sb.append(System.lineSeparator());
264-
sb.append(" - " + (reactorProjects.contains(parent) ? "reactor" : "external") + " parent "
271+
sb.append(" - " + (session.getProjects().contains(parent) ? "reactor" : "external") + " parent "
265272
+ parent.getId() + " property = " + parentProperty);
266273
if (!projectProperty.equals(parentProperty)) {
267274
break;
@@ -291,7 +298,7 @@ protected void copyAggregateToRoot(File aggregate) throws MojoExecutionException
291298
}
292299

293300
// copy aggregate file to root target directory
294-
MavenProject root = getExecutionRoot();
301+
MavenProject root = session.getTopLevelProject();
295302
String extension = aggregate.getName().substring(aggregate.getName().lastIndexOf('.'));
296303
File rootCopy =
297304
new File(root.getBuild().getDirectory(), root.getArtifactId() + '-' + root.getVersion() + extension);
@@ -325,7 +332,7 @@ protected BuildInfoWriter newBuildInfoWriter(PrintWriter p, boolean mono) {
325332
* @throws MojoExecutionException if anything goes wrong
326333
*/
327334
protected Map<Artifact, String> generateBuildinfo(boolean mono) throws MojoExecutionException {
328-
MavenProject root = mono ? project : getExecutionRoot();
335+
MavenProject root = mono ? project : session.getTopLevelProject();
329336

330337
buildinfoFile.getParentFile().mkdirs();
331338

@@ -355,15 +362,6 @@ protected Map<Artifact, String> generateBuildinfo(boolean mono) throws MojoExecu
355362
}
356363
}
357364

358-
protected MavenProject getExecutionRoot() {
359-
for (MavenProject p : session.getAllProjects()) {
360-
if (p.isExecutionRoot()) {
361-
return p;
362-
}
363-
}
364-
return null;
365-
}
366-
367365
private MavenProject getLastProject() {
368366
int i = session.getProjects().size();
369367
while (i > 0) {

src/main/java/org/apache/maven/plugins/artifact/buildinfo/CheckBuildPlanMojo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ protected MavenExecutionPlan calculateExecutionPlan() throws MojoExecutionExcept
108108

109109
@Override
110110
public void execute() throws MojoExecutionException {
111-
boolean fail = AbstractBuildinfoMojo.hasBadOutputTimestamp(
112-
outputTimestamp, getLog(), project, session.getProjects(), diagnose);
111+
boolean fail =
112+
AbstractBuildinfoMojo.hasBadOutputTimestamp(outputTimestamp, getLog(), project, session, diagnose);
113113

114114
// TODO check maven-jar-plugin module-info.class?
115115

src/main/java/org/apache/maven/plugins/artifact/buildinfo/CompareMojo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ protected void skip(MavenProject last) throws MojoExecutionException {
137137
* @throws MojoExecutionException if anything goes wrong
138138
*/
139139
private void checkAgainstReference(Map<Artifact, String> artifacts, boolean mono) throws MojoExecutionException {
140-
MavenProject root = mono ? project : getExecutionRoot();
140+
MavenProject root = mono ? project : session.getTopLevelProject();
141141
File referenceDir = new File(root.getBuild().getDirectory(), "reference");
142142
referenceDir.mkdirs();
143143

@@ -301,7 +301,7 @@ private String getRepositoryFilename(Artifact a) {
301301
}
302302

303303
private String relative(File file) {
304-
File basedir = getExecutionRoot().getBasedir();
304+
File basedir = session.getTopLevelProject().getBasedir();
305305
int length = basedir.getPath().length();
306306
String path = file.getPath();
307307
return path.substring(length + 1);

src/main/java/org/apache/maven/plugins/artifact/buildinfo/DescribeBuildOutputMojo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public void execute() throws MojoExecutionException {
7272
MavenArchiver.parseBuildOutputTimestamp(outputTimestamp).orElse(null);
7373
String effective = ((timestamp == null) ? "disabled" : DateTimeFormatter.ISO_INSTANT.format(timestamp));
7474

75-
diagnose(outputTimestamp, getLog(), project, session.getProjects(), effective);
75+
diagnose(outputTimestamp, getLog(), project, session, effective);
7676
getLog().info("");
7777
describeBuildOutput();
7878
}
@@ -81,7 +81,7 @@ public void execute() throws MojoExecutionException {
8181
private BuildInfoWriter bi;
8282

8383
private void describeBuildOutput() throws MojoExecutionException {
84-
rootPath = getExecutionRoot().getBasedir().toPath();
84+
rootPath = session.getTopLevelProject().getBasedir().toPath();
8585
bi = newBuildInfoWriter(null, false);
8686

8787
Map<String, Long> groupIds = session.getProjects().stream()

0 commit comments

Comments
 (0)