This is an automated email from the ASF dual-hosted git repository. ebakke pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push: new a4807c0ec0 [NETBEANS-1914] Fix startup problems on Windows after moving NetBeans install directory. a4807c0ec0 is described below commit a4807c0ec0a64ca6d5dcd0a39fde4a8fe9b50170 Author: Eirik Bakke <eba...@ultorg.com> AuthorDate: Wed Nov 23 00:25:36 2022 -0500 [NETBEANS-1914] Fix startup problems on Windows after moving NetBeans install directory. On Windows, renaming or moving the NetBeans installation directory caused errors on startup, due to references to old paths in all-layers.dat in the cache directory. The bug did not seem to happen on Linux or MacOS; I'm not sure why. See https://issues.apache.org/jira/browse/NETBEANS-1914 for an example stack trace. The solution in this patch is to include the netbeans.home path in the all-checksum.txt file, on Windows. This will invalidate the cache if the installation directory is changed. Some tests had to be modified to permit this change. --- .../startup/layers/CachingPreventsFileTouchesTest.java | 15 ++++++++++++--- .../modules/netbinox/CachingPreventsFileTouchesTest.java | 3 ++- platform/o.n.bootstrap/src/org/netbeans/Stamps.java | 10 ++++++++++ .../test/unit/src/org/netbeans/StampsRenameTest.java | 7 +++++++ 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/platform/core.startup/test/unit/src/org/netbeans/core/startup/layers/CachingPreventsFileTouchesTest.java b/platform/core.startup/test/unit/src/org/netbeans/core/startup/layers/CachingPreventsFileTouchesTest.java index 1df60a00d3..8470cd7977 100644 --- a/platform/core.startup/test/unit/src/org/netbeans/core/startup/layers/CachingPreventsFileTouchesTest.java +++ b/platform/core.startup/test/unit/src/org/netbeans/core/startup/layers/CachingPreventsFileTouchesTest.java @@ -161,9 +161,18 @@ public class CachingPreventsFileTouchesTest extends NbTestCase { Collections.shuffle(Arrays.asList(arr)); for (File f : arr) { if (!f.isDirectory()) { - System.err.println("checking " + f); - cnt++; - assertFileDoesNotContain(f, install); + if (f.getName().equals("all-checksum.txt")) { + /* In org.netbeans.Stamps, we intentionally include the full netbeans.home path + on Windows as a workaround for NETBEANS-1914. This is meant to invalidate the + cache on changes to netbeans.home in case, despite the intentions of those who + implemented the cache directory system, an absolute path to netbeas.home did end + up in the cache directory. */ + System.err.println("skipping checksum file " + f); + } else { + System.err.println("checking " + f); + cnt++; + assertFileDoesNotContain(f, install); + } } } assertTrue("Some cache files found", cnt > 4); diff --git a/platform/netbinox/test/unit/src/org/netbeans/modules/netbinox/CachingPreventsFileTouchesTest.java b/platform/netbinox/test/unit/src/org/netbeans/modules/netbinox/CachingPreventsFileTouchesTest.java index f56e35c35d..1afe0a8815 100644 --- a/platform/netbinox/test/unit/src/org/netbeans/modules/netbinox/CachingPreventsFileTouchesTest.java +++ b/platform/netbinox/test/unit/src/org/netbeans/modules/netbinox/CachingPreventsFileTouchesTest.java @@ -238,7 +238,8 @@ public class CachingPreventsFileTouchesTest extends NbTestCase { final File[] arr = recursiveFiles(cacheDir, new ArrayList<File>()); Collections.shuffle(Arrays.asList(arr)); for (File f : arr) { - if (!f.isDirectory()) { + // Same as in o.n.core.startup.layers.CachingPreventsFileTouchesTest + if (!f.isDirectory() && !f.getName().equals("all-checksum.txt")) { cnt++; assertFileDoesNotContain(f, install); } diff --git a/platform/o.n.bootstrap/src/org/netbeans/Stamps.java b/platform/o.n.bootstrap/src/org/netbeans/Stamps.java index f274d5d0ab..c2632cd5ca 100644 --- a/platform/o.n.bootstrap/src/org/netbeans/Stamps.java +++ b/platform/o.n.bootstrap/src/org/netbeans/Stamps.java @@ -55,6 +55,7 @@ import java.util.logging.Logger; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import org.openide.modules.Places; +import org.openide.util.BaseUtilities; import org.openide.util.Exceptions; import org.openide.util.NbBundle; @@ -337,6 +338,15 @@ public final class Stamps { sb.append("branding=").append(NbBundle.getBranding()).append('\n'); sb.append("java.version=").append(System.getProperty("java.version")).append('\n'); sb.append("java.vm.version=").append(System.getProperty("java.vm.version")).append('\n'); + if (BaseUtilities.isWindows()) { + /* NETBEANS-1914: On Windows (but not on Linux or MacOS), the cache directory has been + observed to contain absolute paths to the NetBeans install directory (netbeans.home). + This can cause errors on startup if said directory is later moved. As a workaround, + include the netbeans.home path among the values that will cause the cache to be + invalidated if changed. (A better solution would be to get rid of the absolute paths; + but after some investigation, I could not figure out how to do this.) */ + sb.append("netbeans.home=").append(home == null ? "" : home).append('\n'); + } File checkSum = new File(Places.getCacheDirectory(), "lastModified/all-checksum.txt"); if (!compareAndUpdateFile(checkSum, sb.toString(), result)) { diff --git a/platform/o.n.bootstrap/test/unit/src/org/netbeans/StampsRenameTest.java b/platform/o.n.bootstrap/test/unit/src/org/netbeans/StampsRenameTest.java index fc87f34418..baf7c24388 100644 --- a/platform/o.n.bootstrap/test/unit/src/org/netbeans/StampsRenameTest.java +++ b/platform/o.n.bootstrap/test/unit/src/org/netbeans/StampsRenameTest.java @@ -24,6 +24,7 @@ import java.io.File; import java.io.IOException; import java.util.logging.Level; import org.netbeans.junit.NbTestCase; +import org.openide.util.BaseUtilities; /** * @@ -70,6 +71,12 @@ public class StampsRenameTest extends NbTestCase implements Stamps.Updater{ File i2 = new File(getWorkDir(), "inst2"); assertTrue("Rename of the dir successful", install.renameTo(i2)); + if (BaseUtilities.isWindows()) { + // See comment in org.netbeans.Stamps. + assertTrue("Renamed back to install to permit workaround for NETBEANS-1914", + i2.renameTo(install)); + i2 = install; + } setNetBeansProperties(i2, userdir, Stamps.moduleJARs()); --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org For additional commands, e-mail: commits-h...@netbeans.apache.org For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists