Skip to content
This repository was archived by the owner on Aug 27, 2022. It is now read-only.
/ lanai Public archive

Commit 79904c1

Browse files
Ian GravesAlan Bateman
Ian Graves
authored and
Alan Bateman
committedSep 26, 2020
8252730: jlink does not create reproducible builds on different servers
Reviewed-by: mchung, alanb
1 parent ea7c47c commit 79904c1

File tree

3 files changed

+122
-8
lines changed

3 files changed

+122
-8
lines changed
 

‎src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImageFileCreator.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -262,14 +262,14 @@ public String getString(int id) {
262262
return writer.getString(id);
263263
}
264264
});
265-
266-
for (Archive archive : archives) {
267-
String mn = archive.moduleName();
268-
entriesForModule.get(mn).stream()
269-
.map(e -> new ArchiveEntryResourcePoolEntry(mn,
270-
e.getResourcePoolEntryName(), e))
265+
archives.stream()
266+
.map(Archive::moduleName)
267+
.sorted()
268+
.flatMap(mn ->
269+
entriesForModule.get(mn).stream()
270+
.map(e -> new ArchiveEntryResourcePoolEntry(mn,
271+
e.getResourcePoolEntryName(), e)))
271272
.forEach(resources::add);
272-
}
273273
return resources;
274274
}
275275

‎test/jdk/tools/jlink/JLinkReproducible2Test.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
* @bug 8241602
3333
* @modules jdk.jlink
3434
* java.se
35+
* jdk.management
36+
* jdk.unsupported
37+
* jdk.charsets
3538
* @run main JLinkReproducible2Test
3639
*/
3740
public class JLinkReproducible2Test {
@@ -48,7 +51,17 @@ public static void main(String[] args) throws Exception {
4851
JLINK_TOOL.run(System.out, System.err, "--add-modules", "java.se", "--output", image2.toString());
4952

5053
if (Files.mismatch(image1.resolve("lib").resolve("modules"), image2.resolve("lib").resolve("modules")) != -1L) {
51-
new RuntimeException("jlink producing inconsistent result");
54+
throw new RuntimeException("jlink producing inconsistent result");
55+
}
56+
57+
Path image3 = Paths.get("./image3");
58+
Path image4 = Paths.get("./image4");
59+
60+
JLINK_TOOL.run(System.out, System.err, "--add-modules", "java.base,jdk.management,jdk.unsupported,jdk.charsets", "--output", image3.toString());
61+
JLINK_TOOL.run(System.out, System.err, "--add-modules", "java.base,jdk.management,jdk.unsupported,jdk.charsets", "--output", image4.toString());
62+
63+
if (Files.mismatch(image3.resolve("lib").resolve("modules"), image4.resolve("lib").resolve("modules")) != -1L) {
64+
throw new RuntimeException("jlink producing inconsistent result with multiple named modules");
5265
}
5366
}
5467
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
import jdk.test.lib.process.ProcessTools;
25+
26+
import java.io.File;
27+
import java.io.IOException;
28+
import java.io.UncheckedIOException;
29+
import java.nio.file.*;
30+
31+
import java.nio.file.attribute.BasicFileAttributes;
32+
import java.util.Optional;
33+
34+
/*
35+
* @test
36+
* @summary Make sure that jimages are consistent when created by jlink. Copies test jdk and runs against original.
37+
* @bug 8252730
38+
* @modules jdk.jlink
39+
* jdk.management
40+
* jdk.unsupported
41+
* jdk.charsets
42+
* @library /test/lib
43+
* @run main JLinkReproducible3Test
44+
*/
45+
public class JLinkReproducible3Test {
46+
47+
public static void main(String[] args) throws Exception {
48+
Path image1 = Paths.get("./image1");
49+
Path image2 = Paths.get("./image2");
50+
51+
Path copyJdk1Dir = Path.of("./copy-jdk1-tmpdir");
52+
Files.createDirectory(copyJdk1Dir);
53+
54+
Path copyJdk2Dir = Path.of("./copy-jdk2-tmpdir");
55+
Files.createDirectory(copyJdk2Dir);
56+
57+
Path jdkTestDir = Path.of(
58+
Optional.of(
59+
System.getProperty("test.jdk"))
60+
.orElseThrow(() -> new RuntimeException("Couldn't load JDK Test Dir"))
61+
);
62+
63+
copyJDK(jdkTestDir, copyJdk1Dir);
64+
copyJDK(jdkTestDir, copyJdk2Dir);
65+
66+
Path copiedJlink1 = Optional.of(
67+
Paths.get(copyJdk1Dir.toString(), "bin", "jlink"))
68+
.orElseThrow(() -> new RuntimeException("Unable to load copied jlink")
69+
);
70+
71+
Path copiedJlink2 = Optional.of(
72+
Paths.get(copyJdk2Dir.toString(), "bin", "jlink"))
73+
.orElseThrow(() -> new RuntimeException("Unable to load copied jlink")
74+
);
75+
76+
runCopiedJlink(copiedJlink1.toString(), "--add-modules", "java.base,jdk.management,jdk.unsupported,jdk.charsets", "--output", image1.toString());
77+
runCopiedJlink(copiedJlink2.toString(), "--add-modules", "java.base,jdk.management,jdk.unsupported,jdk.charsets", "--output", image2.toString());
78+
79+
long mismatch = Files.mismatch(image1.resolve("lib").resolve("modules"), image2.resolve("lib").resolve("modules"));
80+
if (mismatch != -1L) {
81+
throw new RuntimeException("jlink producing inconsistent result in modules. Mismatch in modules file occurred at byte position " + mismatch);
82+
}
83+
}
84+
85+
private static void runCopiedJlink(String... args) throws Exception {
86+
var process = new ProcessBuilder(args);
87+
var res = ProcessTools.executeProcess(process);
88+
res.shouldHaveExitValue(0);
89+
}
90+
91+
private static void copyJDK(Path src, Path dst) throws Exception {
92+
Files.walk(src).skip(1).forEach(file -> {
93+
try {
94+
Files.copy(file, dst.resolve(src.relativize(file)), StandardCopyOption.COPY_ATTRIBUTES);
95+
} catch (IOException ioe) {
96+
throw new UncheckedIOException(ioe);
97+
}
98+
});
99+
}
100+
}
101+

0 commit comments

Comments
 (0)
This repository has been archived.