xdg-basedir-compliant-userPrefs.patch 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # TODO: consider changing system-wide preferences
  2. # consider removing dot in front of 'lock' files (both system and user)
  3. --- a/src/java.prefs/unix/classes/java/util/prefs/FileSystemPreferences.java
  4. +++ b/src/java.prefs/unix/classes/java/util/prefs/FileSystemPreferences.java
  5. @@ -114,9 +114,30 @@
  6. private static void setupUserRoot() {
  7. AccessController.doPrivileged(new PrivilegedAction<Void>() {
  8. public Void run() {
  9. - userRootDir =
  10. - new File(System.getProperty("java.util.prefs.userRoot",
  11. - System.getProperty("user.home")), ".java/.userPrefs");
  12. + /* On Linux systems, put the userPrefs dir into
  13. + * ${XDG_CONFIG_HOME:-$HOME/.config}/java/userPrefs in order to
  14. + * follow the XDG Base Directory Specification.
  15. + */
  16. + if (System.getProperty("os.name").equals("Linux")) {
  17. + /* assume findable homedir, which the jvm already does */
  18. + String xdgDefaultConfigHome = System.getenv("HOME") +
  19. + "/.config";
  20. + String xdgConfigHomeEnvVar = "XDG_CONFIG_HOME";
  21. + String xdgConfigDir;
  22. +
  23. + String xdgSetConfigDir = System.getenv(xdgConfigHomeEnvVar);
  24. +
  25. + if (xdgSetConfigDir == null)
  26. + xdgConfigDir = xdgDefaultConfigHome;
  27. + else
  28. + xdgConfigDir = xdgSetConfigDir;
  29. +
  30. + userRootDir = new File(xdgConfigDir, "java/userPrefs");
  31. + } else {
  32. + userRootDir =
  33. + new File(System.getProperty("java.util.prefs.userRoot",
  34. + System.getProperty("user.home")), ".java/.userPrefs");
  35. + }
  36. // Attempt to create root dir if it does not yet exist.
  37. if (!userRootDir.exists()) {
  38. if (userRootDir.mkdirs()) {