< prev index next >
src/jdk.jlink/share/classes/jdk/tools/jlink/builder/DefaultImageBuilder.java
Print this page
*** 76,107 ****
private final Path home;
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) {
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);
}
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;
}
@Override
public Path getHome() {
return home;
--- 76,102 ----
private final Path home;
private final List<String> args;
private final Set<String> modules;
! DefaultExecutableImage(Path home, Set<String> modules) {
Objects.requireNonNull(home);
if (!Files.exists(home)) {
throw new IllegalArgumentException("Invalid image home");
}
this.home = home;
this.modules = Collections.unmodifiableSet(modules);
! this.args = createArgs(home);
}
private static List<String> createArgs(Path home) {
Objects.requireNonNull(home);
List<String> javaArgs = new ArrayList<>();
! 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
public Path getHome() {
return home;
*** 128,137 ****
--- 123,133 ----
}
private final Path root;
private final Path mdir;
private final Set<String> modules = new HashSet<>();
+ private String targetOsName;
/**
* Default image builder constructor.
*
* @param root The image root directory.
*** 169,178 ****
--- 165,178 ----
}
@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 {
accept(f);
} catch (IOException ioExp) {
*** 184,194 ****
// Only add modules that contain packages
if (!m.packages().isEmpty()) {
modules.add(m.name());
}
});
! storeFiles(modules, releaseProperties(files));
if (Files.getFileStore(root).supportsFileAttributeView(PosixFileAttributeView.class)) {
// launchers in the bin directory need execute permission
Path bin = root.resolve("bin");
if (Files.isDirectory(bin)) {
--- 184,195 ----
// Only add modules that contain packages
if (!m.packages().isEmpty()) {
modules.add(m.name());
}
});
!
! storeFiles(modules, release);
if (Files.getFileStore(root).supportsFileAttributeView(PosixFileAttributeView.class)) {
// launchers in the bin directory need execute permission
Path bin = root.resolve("bin");
if (Files.isDirectory(bin)) {
*** 224,233 ****
--- 225,239 ----
desc.osVersion().ifPresent(s -> props.setProperty("OS_VERSION", s));
desc.osArch().ifPresent(s -> props.setProperty("OS_ARCH", s));
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()) {
props.load(is);
}
*** 371,381 ****
Objects.requireNonNull(target);
Files.createDirectories(Objects.requireNonNull(dstFile.getParent()));
Files.createLink(dstFile, target);
}
! private static String nativeDir(String filename) {
if (isWindows()) {
if (filename.endsWith(".dll") || filename.endsWith(".diz")
|| filename.endsWith(".pdb") || filename.endsWith(".map")) {
return "bin";
} else {
--- 377,387 ----
Objects.requireNonNull(target);
Files.createDirectories(Objects.requireNonNull(dstFile.getParent()));
Files.createLink(dstFile, target);
}
! private String nativeDir(String filename) {
if (isWindows()) {
if (filename.endsWith(".dll") || filename.endsWith(".diz")
|| filename.endsWith(".pdb") || filename.endsWith(".map")) {
return "bin";
} else {
*** 384,395 ****
} else {
return "lib";
}
}
! private static boolean isWindows() {
! return System.getProperty("os.name").startsWith("Windows");
}
/**
* chmod ugo+x file
*/
--- 390,401 ----
} else {
return "lib";
}
}
! private boolean isWindows() {
! return targetOsName.startsWith("Windows");
}
/**
* chmod ugo+x file
*/
*** 450,465 ****
}
});
}
}
- private static String getJavaProcessName() {
- return isWindows() ? "java.exe" : "java";
- }
-
public static ExecutableImage getExecutableImage(Path root) {
! if (Files.exists(root.resolve("bin").resolve(getJavaProcessName()))) {
return new DefaultExecutableImage(root, retrieveModules(root));
}
return null;
}
--- 456,469 ----
}
});
}
}
public static ExecutableImage getExecutableImage(Path root) {
! 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;
}
< prev index next >