Add documentation for installation detection

This commit is contained in:
crschnick 2023-12-09 12:08:04 +00:00
parent 83435b0642
commit 575cea68e3

View file

@ -75,14 +75,18 @@ public class XPipeInstallation {
@SneakyThrows @SneakyThrows
public static Path getCurrentInstallationBasePath() { public static Path getCurrentInstallationBasePath() {
Path path = // We should always have a command associated with the current process, otherwise something went seriously wrong
Path.of(ProcessHandle.current().info().command().orElseThrow()).toRealPath(); // Resolve any possible links to a real path
Path path = Path.of(ProcessHandle.current().info().command().orElseThrow()).toRealPath();
// Check if the process was started using a relative path, and adapt it if necessary
if (!path.isAbsolute()) { if (!path.isAbsolute()) {
path = Path.of(System.getProperty("user.dir")).resolve(path).toRealPath(); path = Path.of(System.getProperty("user.dir")).resolve(path).toRealPath();
} }
var name = path.getFileName().toString(); var name = path.getFileName().toString();
// Check if we launched the JVM via a start script instead of the native executable
if (name.endsWith("java") || name.endsWith("java.exe")) { if (name.endsWith("java") || name.endsWith("java.exe")) {
// If we are not an image, we are probably running in a development environment where we want to use the working directory
var isImage = ModuleHelper.isImage(); var isImage = ModuleHelper.isImage();
if (!isImage) { if (!isImage) {
return Path.of(System.getProperty("user.dir")); return Path.of(System.getProperty("user.dir"));
@ -138,6 +142,7 @@ public class XPipeInstallation {
} }
private static Path getLocalInstallationBasePathForJavaExecutable(Path executable) { private static Path getLocalInstallationBasePathForJavaExecutable(Path executable) {
// Resolve root path of installation relative to the java executable in a JPackage installation
if (OsType.getLocal().equals(OsType.MACOS)) { if (OsType.getLocal().equals(OsType.MACOS)) {
return executable return executable
.getParent() .getParent()
@ -154,6 +159,7 @@ public class XPipeInstallation {
} }
private static Path getLocalInstallationBasePathForDaemonExecutable(Path executable) { private static Path getLocalInstallationBasePathForDaemonExecutable(Path executable) {
// Resolve root path of installation relative to executable in a JPackage installation
if (OsType.getLocal().equals(OsType.MACOS)) { if (OsType.getLocal().equals(OsType.MACOS)) {
return executable.getParent().getParent().getParent(); return executable.getParent().getParent().getParent();
} else if (OsType.getLocal().equals(OsType.LINUX)) { } else if (OsType.getLocal().equals(OsType.LINUX)) {