@@ -153,7 +153,7 @@ protected AbstractBuildinfoMojo(
153
153
public void execute () throws MojoExecutionException {
154
154
boolean mono = session .getProjects ().size () == 1 ;
155
155
156
- hasBadOutputTimestamp (outputTimestamp , getLog (), project , session . getProjects () , diagnose );
156
+ hasBadOutputTimestamp (outputTimestamp , getLog (), project , session , diagnose );
157
157
158
158
if (!mono ) {
159
159
// if module skips install and/or deploy
@@ -179,17 +179,13 @@ public void execute() throws MojoExecutionException {
179
179
}
180
180
181
181
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 ) {
187
183
Instant timestamp =
188
184
MavenArchiver .parseBuildOutputTimestamp (outputTimestamp ).orElse (null );
189
185
String effective = ((timestamp == null ) ? "disabled" : DateTimeFormatter .ISO_INSTANT .format (timestamp ));
190
186
191
187
if (diagnose ) {
192
- diagnose (outputTimestamp , log , project , reactorProjects , effective );
188
+ diagnose (outputTimestamp , log , project , session , effective );
193
189
}
194
190
195
191
if (timestamp == null ) {
@@ -215,7 +211,7 @@ static boolean hasBadOutputTimestamp(
215
211
// check if timestamp defined in a project from reactor: info if it is not the case
216
212
boolean parentInReactor = false ;
217
213
MavenProject reactorParent = project ;
218
- while (reactorProjects .contains (reactorParent .getParent ())) {
214
+ while (session . getProjects () .contains (reactorParent .getParent ())) {
219
215
parentInReactor = true ;
220
216
reactorParent = reactorParent .getParent ();
221
217
}
@@ -231,11 +227,18 @@ static boolean hasBadOutputTimestamp(
231
227
}
232
228
233
229
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
+
239
242
log .info ("outputTimestamp = " + outputTimestamp
240
243
+ (effective .equals (outputTimestamp ) ? "" : (" => " + effective )));
241
244
@@ -254,14 +257,18 @@ static void diagnose(
254
257
+ " - project.build.outputTimestamp property from project original model = "
255
258
+ originalModelProperty );
256
259
260
+ if (outputTimestamp == null ) {
261
+ return ;
262
+ }
263
+
257
264
MavenProject parent = project .getParent ();
258
265
if (parent != null ) {
259
266
StringBuilder sb = new StringBuilder ("Inheritance analysis property:" + System .lineSeparator ()
260
267
+ " - current " + project .getId () + " property = " + projectProperty );
261
268
while (parent != null ) {
262
269
String parentProperty = parent .getProperties ().getProperty ("project.build.outputTimestamp" );
263
270
sb .append (System .lineSeparator ());
264
- sb .append (" - " + (reactorProjects .contains (parent ) ? "reactor" : "external" ) + " parent "
271
+ sb .append (" - " + (session . getProjects () .contains (parent ) ? "reactor" : "external" ) + " parent "
265
272
+ parent .getId () + " property = " + parentProperty );
266
273
if (!projectProperty .equals (parentProperty )) {
267
274
break ;
@@ -291,7 +298,7 @@ protected void copyAggregateToRoot(File aggregate) throws MojoExecutionException
291
298
}
292
299
293
300
// copy aggregate file to root target directory
294
- MavenProject root = getExecutionRoot ();
301
+ MavenProject root = session . getTopLevelProject ();
295
302
String extension = aggregate .getName ().substring (aggregate .getName ().lastIndexOf ('.' ));
296
303
File rootCopy =
297
304
new File (root .getBuild ().getDirectory (), root .getArtifactId () + '-' + root .getVersion () + extension );
@@ -325,7 +332,7 @@ protected BuildInfoWriter newBuildInfoWriter(PrintWriter p, boolean mono) {
325
332
* @throws MojoExecutionException if anything goes wrong
326
333
*/
327
334
protected Map <Artifact , String > generateBuildinfo (boolean mono ) throws MojoExecutionException {
328
- MavenProject root = mono ? project : getExecutionRoot ();
335
+ MavenProject root = mono ? project : session . getTopLevelProject ();
329
336
330
337
buildinfoFile .getParentFile ().mkdirs ();
331
338
@@ -355,15 +362,6 @@ protected Map<Artifact, String> generateBuildinfo(boolean mono) throws MojoExecu
355
362
}
356
363
}
357
364
358
- protected MavenProject getExecutionRoot () {
359
- for (MavenProject p : session .getAllProjects ()) {
360
- if (p .isExecutionRoot ()) {
361
- return p ;
362
- }
363
- }
364
- return null ;
365
- }
366
-
367
365
private MavenProject getLastProject () {
368
366
int i = session .getProjects ().size ();
369
367
while (i > 0 ) {
0 commit comments