--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/builder/DefaultImageBuilder.java Fri Aug 26 08:33:28 2016 -0700
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/builder/DefaultImageBuilder.java Fri Aug 26 21:31:47 2016 +0530
@@ -78,28 +78,23 @@
private final List<String> args;
private final Set<String> modules;
- public DefaultExecutableImage(Path home, Set<String> modules) {
- this(home, modules, createArgs(home));
- }
-
- private DefaultExecutableImage(Path home, Set<String> modules,
- List<String> args) {
+ DefaultExecutableImage(Path home, Set<String> modules) {
Objects.requireNonNull(home);
- Objects.requireNonNull(args);
if (!Files.exists(home)) {
throw new IllegalArgumentException("Invalid image home");
}
this.home = home;
this.modules = Collections.unmodifiableSet(modules);
- this.args = Collections.unmodifiableList(args);
+ this.args = createArgs(home);
}
private static List<String> createArgs(Path home) {
Objects.requireNonNull(home);
List<String> javaArgs = new ArrayList<>();
- javaArgs.add(home.resolve("bin").
- resolve(getJavaProcessName()).toString());
- return javaArgs;
+ Path binDir = home.resolve("bin");
+ String java = Files.exists(binDir.resolve("java"))? "java" : "java.exe";
+ javaArgs.add(binDir.resolve(java).toString());
+ return Collections.unmodifiableList(javaArgs);
}
@Override
@@ -130,6 +125,7 @@
private final Path root;
private final Path mdir;
private final Set<String> modules = new HashSet<>();
+ private String targetOsName;
/**
* Default image builder constructor.
@@ -171,6 +167,10 @@
@Override
public void storeFiles(ResourcePool files) {
try {
+ // populate release properties up-front. targetOsName
+ // field is assigned from there and used elsewhere.
+ Properties release = releaseProperties(files);
+
files.entries().forEach(f -> {
if (!f.type().equals(ResourcePoolEntry.Type.CLASS_OR_RESOURCE)) {
try {
@@ -186,7 +186,8 @@
modules.add(m.name());
}
});
- storeFiles(modules, releaseProperties(files));
+
+ storeFiles(modules, release);
if (Files.getFileStore(root).supportsFileAttributeView(PosixFileAttributeView.class)) {
// launchers in the bin directory need execute permission
@@ -226,6 +227,11 @@
props.setProperty("JAVA_VERSION", System.getProperty("java.version"));
});
+ this.targetOsName = props.getProperty("OS_NAME");
+ if (this.targetOsName == null) {
+ throw new RuntimeException("can't determine target OS from java.base descriptor");
+ }
+
Optional<ResourcePoolEntry> release = pool.findEntry("/java.base/release");
if (release.isPresent()) {
try (InputStream is = release.get().content()) {
@@ -373,7 +379,7 @@
Files.createLink(dstFile, target);
}
- private static String nativeDir(String filename) {
+ private String nativeDir(String filename) {
if (isWindows()) {
if (filename.endsWith(".dll") || filename.endsWith(".diz")
|| filename.endsWith(".pdb") || filename.endsWith(".map")) {
@@ -386,8 +392,8 @@
}
}
- private static boolean isWindows() {
- return System.getProperty("os.name").startsWith("Windows");
+ private boolean isWindows() {
+ return targetOsName.startsWith("Windows");
}
/**
@@ -452,12 +458,10 @@
}
}
- private static String getJavaProcessName() {
- return isWindows() ? "java.exe" : "java";
- }
-
public static ExecutableImage getExecutableImage(Path root) {
- if (Files.exists(root.resolve("bin").resolve(getJavaProcessName()))) {
+ Path binDir = root.resolve("bin");
+ if (Files.exists(binDir.resolve("java")) ||
+ Files.exists(binDir.resolve("java.exe"))) {
return new DefaultExecutableImage(root, retrieveModules(root));
}
return null;