diff --git a/README.md b/README.md index 3c86353..bb7a6a5 100644 --- a/README.md +++ b/README.md @@ -97,8 +97,9 @@ wine C:\\Program\ Files\ \(x86\)\\Inno\ Setup\ 6\\ISCC.exe $1 ### `--type zip` Mainly for debugging purposes, although can be used to bundle an RCP application -with local runtime. As the IDE launcher does not yet support relative JDK location, -this is less useful there. +with local runtime. When a runtime is bundled, the JDK location is written into +`netbeans.conf` relative to the installation using the launcher's `${BASEDIR}` +token, so it is found however the application is launched. ## Building from source diff --git a/src/main/java/org/apache/netbeans/nbpackage/AbstractPackagerTask.java b/src/main/java/org/apache/netbeans/nbpackage/AbstractPackagerTask.java index d8e65c1..d94cd81 100644 --- a/src/main/java/org/apache/netbeans/nbpackage/AbstractPackagerTask.java +++ b/src/main/java/org/apache/netbeans/nbpackage/AbstractPackagerTask.java @@ -360,9 +360,16 @@ private void copyRuntimeFromDirectory(Path runtime, Path destDir) throws IOExcep private void addRuntimeToConf(Path conf, String jdkhome) throws IOException { var contents = Files.readString(conf); - contents = contents.replace("#jdkhome=\"/path/to/jdk\"", "jdkhome=\"" + jdkhome + "\""); - // @TODO - fix this when relative links work with IDE launcher - // contents = contents.replace("#netbeans_jdkhome=\"/path/to/jdk\"", "netbeans_jdkhome=\"" + jdkhome + "\""); + // Point at the bundled JDK relative to the installation using the + // launcher's ${BASEDIR} token. Unlike passing --jdkhome via a shortcut, + // this resolves however the application is launched - eg. directly or + // via "Open With..." on a file. Forward slashes are tolerated on all + // platforms including Windows. + String basedirHome = "${BASEDIR}/" + jdkhome.replace('\\', '/'); + contents = contents.replace("#jdkhome=\"/path/to/jdk\"", + "jdkhome=\"" + basedirHome + "\""); + contents = contents.replace("#netbeans_jdkhome=\"/path/to/jdk\"", + "netbeans_jdkhome=\"" + basedirHome + "\""); Files.writeString(conf, contents); } diff --git a/src/test/java/org/apache/netbeans/nbpackage/TestUtils.java b/src/test/java/org/apache/netbeans/nbpackage/TestUtils.java index 21fc4e1..53ff41e 100644 --- a/src/test/java/org/apache/netbeans/nbpackage/TestUtils.java +++ b/src/test/java/org/apache/netbeans/nbpackage/TestUtils.java @@ -49,7 +49,9 @@ public static Path buildFakeApp(Path parent, String dirname, String branding) Files.createFile(appBin.resolve(branding)); Files.createFile(appBin.resolve(branding + ".exe")); Files.createFile(appBin.resolve(branding + "64.exe")); - Files.createFile(appEtc.resolve(branding + ".conf")); + Files.writeString(appEtc.resolve(branding + ".conf"), + "#jdkhome=\"/path/to/jdk\"\n" + + "#netbeans_jdkhome=\"/path/to/jdk\"\n"); Files.createFile(platform.resolve("module")); return dir; } diff --git a/src/test/java/org/apache/netbeans/nbpackage/innosetup/InnoSetupPackagerTest.java b/src/test/java/org/apache/netbeans/nbpackage/innosetup/InnoSetupPackagerTest.java index 9622a4e..4238f49 100644 --- a/src/test/java/org/apache/netbeans/nbpackage/innosetup/InnoSetupPackagerTest.java +++ b/src/test/java/org/apache/netbeans/nbpackage/innosetup/InnoSetupPackagerTest.java @@ -74,6 +74,11 @@ public void testImageWithX86_64Runtime() throws Exception { assertTrue(Files.exists(resolve(image, "app", "bin", "app64.exe"))); assertTrue(Files.exists(resolve(image, "app", "etc", "app.ico"))); assertTrue(Files.exists(resolve(image, "app", "jdk", "bin", "java.exe"))); + // bundled JDK is referenced in netbeans.conf relative to ${BASEDIR}, so + // it is found however the launcher is started (not just via a shortcut) + String conf = Files.readString(resolve(image, "app", "etc", "app.conf")); + assertTrue(conf.contains("jdkhome=\"${BASEDIR}/jdk\"")); + assertTrue(conf.contains("netbeans_jdkhome=\"${BASEDIR}/jdk\"")); } }