Skip to content

Commit 320f599

Browse files
authored
improve summary: promote diffoscope in .buildcompare (#187)
fixes #175
1 parent 94e991c commit 320f599

2 files changed

Lines changed: 32 additions & 24 deletions

File tree

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,10 @@ protected void skip(MavenProject last) throws MojoExecutionException {
305305
getLog().info("Skipping intermediate goal run, aggregate will be " + last.getArtifactId());
306306
}
307307

308-
protected void copyAggregateToRoot(File aggregate) throws MojoExecutionException {
308+
protected File copyAggregateToRoot(File aggregate) throws MojoExecutionException {
309309
if (session.getProjects().size() == 1) {
310310
// mono-module, no aggregate file to deal with
311-
return;
311+
return aggregate;
312312
}
313313

314314
// copy aggregate file to root target directory
@@ -323,10 +323,11 @@ protected void copyAggregateToRoot(File aggregate) throws MojoExecutionException
323323
rootCopy.toPath(),
324324
LinkOption.NOFOLLOW_LINKS,
325325
StandardCopyOption.REPLACE_EXISTING);
326-
getLog().info("Aggregate " + extension.substring(1) + " copied to " + rootCopy);
326+
getLog().info("Aggregate " + extension.substring(1) + " copied to " + relative(rootCopy));
327327
} catch (IOException ioe) {
328328
throw new MojoExecutionException("Could not copy " + aggregate + " to " + rootCopy, ioe);
329329
}
330+
return rootCopy;
330331
}
331332

332333
protected BuildInfoWriter newBuildInfoWriter(PrintWriter p, boolean mono) {
@@ -413,4 +414,11 @@ private Toolchain getToolchain() {
413414

414415
return tc;
415416
}
417+
418+
protected String relative(File file) {
419+
File basedir = session.getTopLevelProject().getBasedir();
420+
int length = basedir.getPath().length();
421+
String path = file.getPath();
422+
return path.substring(length + 1);
423+
}
416424
}

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

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -195,19 +195,14 @@ private void compareWithReference(Map<Artifact, String> artifacts, File referenc
195195
int missing = reference.size() / 3 /* 3 property keys par file: filename, length and checksums.sha512 */;
196196

197197
if (ko + missing > 0) {
198-
getLog().error("Reproducible Build output summary: "
199-
+ MessageUtils.buffer().success(ok + " files ok")
200-
+ ", " + MessageUtils.buffer().failure(ko + " different")
198+
getLog().error("[Reproducible Builds] rebuild comparison result: "
199+
+ MessageUtils.buffer().success(ok + " files match")
200+
+ ", " + MessageUtils.buffer().failure(ko + " differ")
201201
+ ((missing == 0) ? "" : (", " + MessageUtils.buffer().failure(missing + " missing")))
202202
+ ((ignored.isEmpty()) ? "" : (", " + MessageUtils.buffer().warning(ignored.size() + " ignored"))));
203-
getLog().error("see "
204-
+ MessageUtils.buffer()
205-
.project("diff " + relative(referenceBuildinfo) + " " + relative(buildinfoFile))
206-
.build());
207-
getLog().error("see also https://maven.apache.org/guides/mini/guide-reproducible-builds.html");
208203
} else {
209-
getLog().info("Reproducible Build output summary: "
210-
+ MessageUtils.buffer().success(ok + " files ok")
204+
getLog().info("[Reproducible Builds] rebuild comparison result: "
205+
+ MessageUtils.buffer().success(ok + " files match")
211206
+ ((ignored.isEmpty()) ? "" : (", " + MessageUtils.buffer().warning(ignored.size() + " ignored"))));
212207
}
213208

@@ -243,15 +238,27 @@ private void compareWithReference(Map<Artifact, String> artifacts, File referenc
243238
p.print("# ");
244239
p.println(diffoscope);
245240
}
246-
getLog().info("Reproducible Build output comparison saved to " + buildcompare);
247241
} catch (IOException e) {
248242
throw new MojoExecutionException("Error creating file " + buildcompare, e);
249243
}
250244

251-
copyAggregateToRoot(buildcompare);
245+
String saved = " saved to " + relative(buildcompare);
246+
if (ko + missing > 0) {
247+
getLog().error(saved);
248+
} else {
249+
getLog().info(saved);
250+
}
251+
buildcompare = copyAggregateToRoot(buildcompare);
252+
253+
if (ko + missing > 0) {
254+
getLog().error("[Reproducible Builds] to analyze the differences, see diffoscope instructions in "
255+
+ relative(buildcompare));
256+
getLog().error(
257+
" see also https://maven.apache.org/guides/mini/guide-reproducible-builds.html");
252258

253-
if (fail && (ko + missing > 0)) {
254-
throw new MojoExecutionException("Build artifacts are different from reference");
259+
if (fail) {
260+
throw new MojoExecutionException("Rebuilt artifacts are different from reference");
261+
}
255262
}
256263
}
257264

@@ -300,13 +307,6 @@ private String getRepositoryFilename(Artifact a) {
300307
return path.substring(path.lastIndexOf('/'));
301308
}
302309

303-
private String relative(File file) {
304-
File basedir = session.getTopLevelProject().getBasedir();
305-
int length = basedir.getPath().length();
306-
String path = file.getPath();
307-
return path.substring(length + 1);
308-
}
309-
310310
private static String findPrefix(Properties reference, String actualGroupId, String actualFilename) {
311311
for (String name : reference.stringPropertyNames()) {
312312
if (name.endsWith(".filename") && actualFilename.equals(reference.getProperty(name))) {

0 commit comments

Comments
 (0)