Skip to content

Commit 399a976

Browse files
authored
compare show missing reference files (#189)
1 parent 5e08b94 commit 399a976

1 file changed

Lines changed: 23 additions & 7 deletions

File tree

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

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ private void compareWithReference(Map<Artifact, String> artifacts, File referenc
166166
int ok = 0;
167167
List<String> okFilenames = new ArrayList<>();
168168
List<String> koFilenames = new ArrayList<>();
169+
List<String> missingFilenames = new ArrayList<>();
169170
List<String> diffoscopes = new ArrayList<>();
170171
List<String> ignored = new ArrayList<>();
171172
File referenceDir = referenceBuildinfo.getParentFile();
@@ -180,19 +181,19 @@ private void compareWithReference(Map<Artifact, String> artifacts, File referenc
180181

181182
String[] checkResult = checkArtifact(artifact, prefix, reference, actual, referenceDir);
182183
String filename = checkResult[0];
183-
String diffoscope = checkResult[1];
184+
String diffoscope = checkResult[1]; // diffoscope or wget
184185

185186
if (diffoscope == null) {
186187
ok++;
187188
okFilenames.add(filename);
188189
} else {
189-
koFilenames.add(filename);
190+
(diffoscope.startsWith("wget") ? missingFilenames : koFilenames).add(filename);
190191
diffoscopes.add(diffoscope);
191192
}
192193
}
193194

194195
int ko = artifacts.size() - ok - ignored.size();
195-
int missing = reference.size() / 3 /* 3 property keys par file: filename, length and checksums.sha512 */;
196+
int missing = missingFilenames.size();
196197

197198
if (ko + missing > 0) {
198199
getLog().error("[Reproducible Builds] rebuild comparison result: "
@@ -218,6 +219,10 @@ private void compareWithReference(Map<Artifact, String> artifacts, File referenc
218219
p.println("okFiles=\"" + String.join(" ", okFilenames) + '"');
219220
p.println("koFiles=\"" + String.join(" ", koFilenames) + '"');
220221
p.println("ignoredFiles=\"" + String.join(" ", ignored) + '"');
222+
if (missing > 0) {
223+
p.println("missing=" + missing);
224+
p.println("missingFiles=\"" + String.join(" ", missingFilenames) + '"');
225+
}
221226
Properties ref = new Properties();
222227
if (referenceBuildinfo != null) {
223228
try (InputStream in = Files.newInputStream(referenceBuildinfo.toPath())) {
@@ -267,9 +272,10 @@ private void compareWithReference(Map<Artifact, String> artifacts, File referenc
267272
}
268273
}
269274

270-
// { filename, diffoscope }
275+
// { filename, diffoscope or wget }
271276
private String[] checkArtifact(
272-
Artifact artifact, String prefix, Properties reference, Properties actual, File referenceDir) {
277+
Artifact artifact, String prefix, Properties reference, Properties actual, File referenceDir)
278+
throws MojoExecutionException {
273279
String actualFilename = (String) actual.remove(prefix + ".filename");
274280
String actualLength = (String) actual.remove(prefix + ".length");
275281
String actualSha512 = (String) actual.remove(prefix + ".checksums.sha512");
@@ -280,7 +286,9 @@ private String[] checkArtifact(
280286
reference.remove(referencePrefix + ".groupId");
281287

282288
String issue = null;
283-
if (!actualLength.equals(referenceLength)) {
289+
if (referenceLength == null) {
290+
issue = "missing reference file";
291+
} else if (!actualLength.equals(referenceLength)) {
284292
issue = "size";
285293
} else if (!actualSha512.equals(referenceSha512)) {
286294
issue = "sha512";
@@ -295,7 +303,7 @@ private String[] checkArtifact(
295303
return new String[] {actualFilename, null};
296304
}
297305

298-
private String diffoscope(Artifact a, File referenceDir) {
306+
private String diffoscope(Artifact a, File referenceDir) throws MojoExecutionException {
299307
File actual = a.getFile();
300308
// notice: actual file name may have been defined in pom
301309
// reference file name is taken from repository format
@@ -304,6 +312,14 @@ private String diffoscope(Artifact a, File referenceDir) {
304312
return "missing file for " + ArtifactIdUtils.toId(a) + " reference = " + relative(reference)
305313
+ " actual = null";
306314
}
315+
if (!reference.exists()) {
316+
RemoteRepository repo = createReferenceRepo();
317+
String url = repo.getUrl() + "/"
318+
+ session.getRepositorySession()
319+
.getLocalRepositoryManager()
320+
.getPathForRemoteArtifact(a, repo, null);
321+
return "wget " + url + "; ls -l " + relative(actual);
322+
}
307323
return "diffoscope " + relative(reference) + " " + relative(actual);
308324
}
309325

0 commit comments

Comments
 (0)