--- a/apisupport.ant/nbproject/project.xml +++ a/apisupport.ant/nbproject/project.xml @@ -261,7 +261,7 @@ - 7.22 + 7.25 --- a/apisupport.ant/src/org/netbeans/modules/apisupport/project/universe/PlatformLayersCacheManager.java +++ a/apisupport.ant/src/org/netbeans/modules/apisupport/project/universe/PlatformLayersCacheManager.java @@ -79,6 +79,7 @@ import org.netbeans.modules.apisupport.project.universe.PlatformLayersCacheManager.PLFSCacheEntry; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileSystem; +import org.openide.modules.Places; import org.openide.util.NbBundle.Messages; import org.openide.util.Parameters; import org.openide.util.RequestProcessor; @@ -88,7 +89,7 @@ * @author Richard Michalsky */ public class PlatformLayersCacheManager { - static final String CACHE_PATH = "var/cache/nbplfsc"; + static final String CACHE_PATH = "nbplfsc"; static class PLFSCacheEntry { private File jarFile; @@ -182,11 +183,7 @@ } private static void resetCacheLocation() { - cacheLocation = new File(System.getProperty("netbeans.user"),CACHE_PATH); - if (! cacheLocation.exists()) { - if (! cacheLocation.mkdirs()) - throw new RuntimeException("Cannot create cache dir " + System.getProperty("netbeans.user") + CACHE_PATH); - } + cacheLocation = Places.getCacheSubdirectory(CACHE_PATH); } /** --- a/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/universe/PlatformLayersCacheManagerTest.java +++ a/apisupport.ant/test/unit/src/org/netbeans/modules/apisupport/project/universe/PlatformLayersCacheManagerTest.java @@ -54,6 +54,7 @@ import org.netbeans.modules.apisupport.project.TestBase; import org.openide.filesystems.FileSystem; import org.openide.filesystems.FileUtil; +import org.openide.modules.Places; /** * @@ -73,8 +74,7 @@ protected void setUp() throws Exception { super.setUp(); - File userdir = new File(System.getProperty("netbeans.user")); - cacheDir = new File(userdir, PlatformLayersCacheManager.CACHE_PATH); + cacheDir = new File(Places.getCacheDirectory(), PlatformLayersCacheManager.CACHE_PATH); assertFalse("Cache not yet saved", cacheDir.isDirectory()); plaf = NbPlatform.getDefaultPlatform(); jarNames = new HashSet(); --- a/autoupdate.services/nbproject/project.xml +++ a/autoupdate.services/nbproject/project.xml @@ -45,7 +45,7 @@ - 7.15 + 7.25 --- a/autoupdate.services/src/org/netbeans/modules/autoupdate/services/Utilities.java +++ a/autoupdate.services/src/org/netbeans/modules/autoupdate/services/Utilities.java @@ -98,6 +98,7 @@ import org.openide.modules.Dependency; import org.openide.modules.InstalledFileLocator; import org.openide.modules.ModuleInfo; +import org.openide.modules.Places; import org.openide.modules.SpecificationVersion; import org.openide.util.Exceptions; import org.openide.util.Lookup; @@ -1274,16 +1275,7 @@ } private static File getCacheDirectory () { - File cacheDir = null; - String userDir = System.getProperty ("netbeans.user"); // NOI18N - if (userDir != null) { - cacheDir = new File (new File (new File (userDir, "var"), "cache"), "catalogcache"); // NOI18N - } else { - File dir = FileUtil.toFile (FileUtil.getConfigRoot()); - cacheDir = new File (dir, "catalogcache"); // NOI18N - } - cacheDir.mkdirs(); - return cacheDir; + return Places.getCacheSubdirectory("catalogcache"); } private static Preferences getPreferences() { --- a/autoupdate.services/src/org/netbeans/modules/autoupdate/updateprovider/AutoupdateCatalogCache.java +++ a/autoupdate.services/src/org/netbeans/modules/autoupdate/updateprovider/AutoupdateCatalogCache.java @@ -55,7 +55,7 @@ import java.util.logging.Logger; import org.netbeans.modules.autoupdate.services.AutoupdateSettings; import org.openide.filesystems.FileUtil; -import org.openide.util.Exceptions; +import org.openide.modules.Places; /** * @@ -85,15 +85,7 @@ private void initCacheDirectory () { assert cacheDir == null : "Do initCacheDirectory only once!"; - String userDir = System.getProperty("netbeans.user"); // NOI18N - if (userDir != null) { - cacheDir = new File (new File (new File (userDir, "var"), "cache"), "catalogcache"); // NOI18N - } else { - File dir = FileUtil.toFile (FileUtil.getConfigRoot()); - assert dir != null : "Provide netbeans.user so we know where to store catalogcache!"; - cacheDir = new File(dir, "catalogcache"); // NOI18N - } - cacheDir.mkdirs(); + cacheDir = Places.getCacheSubdirectory("catalogcache"); // NOI18N getLicenseDir().mkdirs(); err.log (Level.FINE, "getCacheDirectory: {0}", cacheDir.getPath ()); return; --- a/cnd.completion/nbproject/project.xml +++ a/cnd.completion/nbproject/project.xml @@ -213,6 +213,14 @@ + org.openide.modules + + + + 7.25 + + + org.openide.nodes --- a/cnd.completion/src/org/netbeans/modules/cnd/completion/doxygensupport/ManDocumentation.java +++ a/cnd.completion/src/org/netbeans/modules/cnd/completion/doxygensupport/ManDocumentation.java @@ -69,6 +69,7 @@ import org.netbeans.modules.cnd.api.project.NativeProject; import org.netbeans.spi.editor.completion.CompletionDocumentation; import org.openide.filesystems.FileUtil; +import org.openide.modules.Places; import org.openide.util.Exceptions; import org.openide.util.NbBundle; @@ -179,15 +180,6 @@ // // return ""; // } - private static File getCacheDir() { - String nbuser = System.getProperty("netbeans.user"); //XXX // NOI18N - File cache = new File(nbuser, "var/cache/cnd/manpages"); // NOI18N - - cache.mkdirs(); - - return cache; - } - private static File getCacheFile(String name, int chapter, String platformName) { // name might look like "operator /=", so we need to escape it String safeName; @@ -197,7 +189,7 @@ // UTF-8 should always be supported, but anyway... safeName = name; } - return new File(getCacheDir(), safeName + "." + platformName + "." + chapter); // NOI18N + return Places.getCacheSubfile("cnd/manpages/" + safeName + "." + platformName + "." + chapter); // NOI18N } static NativeProject getNativeProject(CsmFile csmFile) { --- a/cnd.repository/nbproject/project.xml +++ a/cnd.repository/nbproject/project.xml @@ -23,6 +23,14 @@ + org.openide.modules + + + + 7.25 + + + org.openide.util --- a/cnd.repository/src/org/netbeans/modules/cnd/repository/disk/StorageAllocator.java +++ a/cnd.repository/src/org/netbeans/modules/cnd/repository/disk/StorageAllocator.java @@ -50,6 +50,7 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import org.netbeans.modules.cnd.repository.testbench.Stats; +import org.openide.modules.Places; /** * @@ -57,20 +58,14 @@ */ public class StorageAllocator { private final static StorageAllocator instance = new StorageAllocator(); - private String diskRepositoryPath; + private final File diskRepository; private StorageAllocator() { - diskRepositoryPath = System.getProperty("cnd.repository.cache.path"); - if (diskRepositoryPath == null) { - diskRepositoryPath = System.getProperty("netbeans.user") + //NOI18N - File.separator + "var" + File.separator + "cache" + //NOI18N - File.separator + "cnd" + File.separator + "model"; //NOI18N - // create directory if needed - File diskRepositoryFile = new File(diskRepositoryPath); - if (!diskRepositoryFile.exists()) { - diskRepositoryFile.mkdirs(); - } - diskRepositoryPath = diskRepositoryFile.getAbsolutePath(); + String diskRepositoryPath = System.getProperty("cnd.repository.cache.path"); + if (diskRepositoryPath != null) { + diskRepository = new File(diskRepositoryPath); + } else { + diskRepository = Places.getCacheSubdirectory("cnd/model"); // NOI18N } }; @@ -80,10 +75,6 @@ private Map unit2path = new ConcurrentHashMap(); - public String getCachePath() { - return diskRepositoryPath; - } - public String reduceString (String name) { if (name.length() > 128) { int hashCode = name.hashCode(); @@ -105,9 +96,9 @@ prefix = reduceString(prefix); - path = getCachePath() + File.separator + prefix + File.separator; // NOI18N - - File pathFile = new File (path); + File pathFile = new File(diskRepository, prefix); + + path = pathFile + File.separator; if (!pathFile.exists()) { pathFile.mkdirs(); @@ -151,8 +142,7 @@ } } public void cleanRepositoryCaches() { - File repositoryPath = new File(diskRepositoryPath); - deleteDirectory(repositoryPath, false); + deleteDirectory(diskRepository, false); } /** @@ -160,8 +150,7 @@ * have not been modified within last 2 weeks are considered outdated. */ public void purgeCaches() { - File repositoryDir = new File(diskRepositoryPath); - File[] unitDirs = repositoryDir.listFiles(); + File[] unitDirs = diskRepository.listFiles(); if (unitDirs != null && 0 < unitDirs.length) { long now = System.currentTimeMillis(); for (File unitDir : unitDirs) { --- a/cnd.repository/src/org/netbeans/modules/cnd/repository/translator/RepositoryTranslatorImpl.java +++ a/cnd.repository/src/org/netbeans/modules/cnd/repository/translator/RepositoryTranslatorImpl.java @@ -68,6 +68,7 @@ import org.netbeans.modules.cnd.repository.disk.StorageAllocator; import org.netbeans.modules.cnd.repository.testbench.Stats; import org.netbeans.modules.cnd.repository.util.IntToStringCache; +import org.openide.modules.Places; import org.openide.util.CharSequences; /** @@ -116,10 +117,7 @@ private static boolean loaded = false; private static final int DEFAULT_VERSION_OF_PERSISTENCE_MECHANIZM = 0; private static int version = DEFAULT_VERSION_OF_PERSISTENCE_MECHANIZM; - private final static String MASTER_INDEX_FILE_NAME = System.getProperty("netbeans.user") + //NOI18N - File.separator + "var" + File.separator + "cache" + //NOI18N - File.separator + "cnd" + File.separator + "model" + //NOI18N - File.separator + "index"; //NOI18N + private final static File MASTER_INDEX_FILE = Places.getCacheSubfile("cnd/model/index"); // NOI18N private final static String PROJECT_INDEX_FILE_NAME = "project-index"; //NOI18N /** Creates a new instance of RepositoryTranslatorImpl */ @@ -344,7 +342,7 @@ InputStream bis = null; DataInputStream dis = null; try { - fis = new FileInputStream(MASTER_INDEX_FILE_NAME); + fis = new FileInputStream(MASTER_INDEX_FILE); bis = new BufferedInputStream(fis); dis = new DataInputStream(bis); readMasterIndex(dis); @@ -379,7 +377,7 @@ DataOutputStream dos = null; try { - fos = new FileOutputStream(MASTER_INDEX_FILE_NAME, false); + fos = new FileOutputStream(MASTER_INDEX_FILE, false); bos = new BufferedOutputStream(fos); dos = new DataOutputStream(bos); writeUnitsCache(dos); --- a/core.browser.xulrunner/nbproject/project.xml +++ a/core.browser.xulrunner/nbproject/project.xml @@ -103,7 +103,7 @@ - 7.11 + 7.25 --- a/core.browser.xulrunner/src/org/netbeans/core/browser/xulrunner/BrowserManager.java +++ a/core.browser.xulrunner/src/org/netbeans/core/browser/xulrunner/BrowserManager.java @@ -53,8 +53,8 @@ import javax.swing.event.ChangeListener; import org.mozilla.browser.MozillaConfig; import org.netbeans.core.IDESettings; -import org.openide.filesystems.FileUtil; import org.openide.modules.InstalledFileLocator; +import org.openide.modules.Places; import org.openide.util.ChangeSupport; import org.openide.util.NbPreferences; @@ -157,16 +157,7 @@ } private void initProfileDir() { - File profileDir; - String userDir = System.getProperty("netbeans.user"); // NOI18N - if (userDir != null) { - profileDir = new File(new File(new File (userDir, "var"), "cache"), "mozillaprofilev1"); // NOI18N - } else { - profileDir = FileUtil.toFile(FileUtil.getConfigRoot()); - profileDir = new File(profileDir, "mozillaprofilev1"); // NOI18N - } - profileDir.mkdirs(); - MozillaConfig.setProfileDir(profileDir); + MozillaConfig.setProfileDir(Places.getCacheSubdirectory("mozillaprofilev1")); // NOI18N } private static class Holder { --- a/core.netigso/nbproject/project.xml +++ a/core.netigso/nbproject/project.xml @@ -80,7 +80,7 @@ - 7.8 + 7.25 --- a/core.netigso/src/org/netbeans/core/netigso/Netigso.java +++ a/core.netigso/src/org/netbeans/core/netigso/Netigso.java @@ -66,6 +66,7 @@ import org.netbeans.ProxyClassLoader; import org.netbeans.Stamps; import org.openide.modules.ModuleInfo; +import org.openide.modules.Places; import org.openide.util.Lookup; import org.openide.util.lookup.ServiceProvider; import org.openide.util.lookup.ServiceProviders; @@ -312,12 +313,7 @@ private File getNetigsoCache() throws IllegalStateException { // Explicitly specify the directory to use for caching bundles. - String ud = System.getProperty("netbeans.user"); - if (ud == null) { - throw new IllegalStateException(); - } - File udf = new File(ud); - return new File(new File(new File(udf, "var"), "cache"), "netigso"); + return Places.getCacheSubdirectory("netigso"); } private void deleteRec(File dir) { --- a/core.startup/nbproject/project.xml +++ a/core.startup/nbproject/project.xml @@ -71,7 +71,7 @@ - 7.19 + 7.25 --- a/core.startup/src/org/netbeans/core/startup/Bundle.properties +++ a/core.startup/src/org/netbeans/core/startup/Bundle.properties @@ -102,7 +102,7 @@ # error messages ERR_UIExpected=UI class name expected, using default UI... -ERR_UserDirExpected=Directory expected after --userdir switch +ERR_UserDirExpected=Directory expected after --userdir or --cachedir switch ERR_UINotFound=UI class not found, using default UI... ERR_FontSizeExpected=Font size expected, using default font size... ERR_BadFontSize=Bad format of the font size, using default font size... --- a/core.startup/src/org/netbeans/core/startup/CLIOptions.java +++ a/core.startup/src/org/netbeans/core/startup/CLIOptions.java @@ -51,6 +51,7 @@ import java.util.MissingResourceException; import org.netbeans.CLIHandler; import org.openide.filesystems.FileUtil; +import org.openide.modules.Places; import org.openide.util.NbBundle; /** @@ -133,7 +134,16 @@ } else if (isOption (args[i], "userdir")) { // NOI18N args[i] = null; try { - System.setProperty ("netbeans.user", args[++i]); + String v = args[++i]; + Places.setUserDirectory(v.equals(/*Places.MEMORY*/"memory") ? null : FileUtil.normalizeFile(new File(v))); + } catch(ArrayIndexOutOfBoundsException e) { + System.err.println(getString("ERR_UserDirExpected")); + return 2; + } + } else if (isOption(args[i], "cachedir")) { // NOI18N + args[i] = null; + try { + Places.setCacheDirectory(FileUtil.normalizeFile(new File(args[++i]))); } catch(ArrayIndexOutOfBoundsException e) { System.err.println(getString("ERR_UserDirExpected")); return 2; @@ -236,6 +246,7 @@ w.println(" --fontsize set the base font size of the user interface, in points"); w.println(" --locale use specified locale"); w.println(" --userdir use specified directory to store user settings"); + w.println(" --cachedir use specified directory to store user cache"); w.println(" --nosplash do not show the splash screen"); w.println(""); // \ --branding use specified branding (- for default) --- a/core.startup/src/org/netbeans/core/startup/InstalledFileLocatorImpl.java +++ a/core.startup/src/org/netbeans/core/startup/InstalledFileLocatorImpl.java @@ -66,6 +66,7 @@ import org.netbeans.Util; import org.openide.filesystems.FileUtil; import org.openide.modules.InstalledFileLocator; +import org.openide.modules.Places; import org.openide.util.lookup.ServiceProvider; /** @@ -82,7 +83,7 @@ private final File[] dirs; public InstalledFileLocatorImpl() { List _dirs = new ArrayList(); - addDir(_dirs, System.getProperty("netbeans.user")); + addDir(_dirs, System.getProperty(Places.USER_DIR_PROP)); String nbdirs = System.getProperty("netbeans.dirs"); // #27151 if (nbdirs != null) { StringTokenizer tok = new StringTokenizer(nbdirs, File.pathSeparator); --- a/core.startup/src/org/netbeans/core/startup/ModuleLifecycleManager.java +++ a/core.startup/src/org/netbeans/core/startup/ModuleLifecycleManager.java @@ -49,6 +49,7 @@ import org.netbeans.TopSecurityManager; import org.netbeans.core.startup.layers.SessionManager; import org.openide.LifecycleManager; +import org.openide.modules.Places; import org.openide.util.Exceptions; import org.openide.util.lookup.ServiceProvider; @@ -98,7 +99,7 @@ if (!TopSecurityManager.class.getClassLoader().getClass().getName().endsWith(".Launcher$AppClassLoader")) { throw new UnsupportedOperationException("not running in regular module system, cannot restart"); // NOI18N } - String userdir = System.getProperty("netbeans.user"); // NOI18N + File userdir = Places.getUserDirectory(); if (userdir == null) { throw new UnsupportedOperationException("no userdir"); // NOI18N } --- a/core.startup/src/org/netbeans/core/startup/TopLogging.java +++ a/core.startup/src/org/netbeans/core/startup/TopLogging.java @@ -87,6 +87,7 @@ import java.util.regex.PatternSyntaxException; import org.netbeans.TopSecurityManager; import org.openide.filesystems.FileUtil; +import org.openide.modules.Places; import org.openide.util.Lookup; import org.openide.util.LookupEvent; import org.openide.util.LookupListener; @@ -186,12 +187,12 @@ public static void initializeQuietly() { initialize(false); } - private static String previousUser; + private static File previousUser; static final void initialize() { initialize(true); } private static void initialize(boolean verbose) { - if (previousUser == null || previousUser.equals(System.getProperty("netbeans.user"))) { + if (previousUser == null || previousUser.equals(Places.getUserDirectory())) { // useful from tests streamHandler = null; defaultHandler = null; @@ -307,6 +308,7 @@ ps.println(" Current Directory = " + System.getProperty("user.dir", "unknown")); ps.print( " User Directory = "); // NOI18N ps.println(CLIOptions.getUserDir()); // NOI18N + ps.println(" Cache Directory = " + Places.getCacheDirectory()); // NOI18N ps.print( " Installation = "); // NOI18N for (File cluster : clusters) { ps.print(cluster + "\n "); // NOI18N @@ -393,10 +395,10 @@ private static synchronized NonClose defaultHandler() { if (defaultHandler != null) return defaultHandler; - String home = System.getProperty("netbeans.user"); - if (home != null && !"memory".equals(home) && !CLIOptions.noLogging) { + File home = Places.getUserDirectory(); + if (home != null && !CLIOptions.noLogging) { try { - File dir = new File(new File(new File(home), "var"), "log"); + File dir = new File(new File(home, "var"), "log"); dir.mkdirs (); File f = new File(dir, "messages.log"); File f1 = new File(dir, "messages.log.1"); --- a/core.startup/test/unit/src/org/netbeans/core/startup/CLIOptionsTest.java +++ a/core.startup/test/unit/src/org/netbeans/core/startup/CLIOptionsTest.java @@ -43,7 +43,9 @@ */ package org.netbeans.core.startup; +import java.io.File; import org.netbeans.junit.NbTestCase; +import org.openide.filesystems.FileUtil; import org.openide.util.Utilities; /** @@ -104,7 +106,7 @@ assertFalse("-userdir is not supported", "wrong".equals(System.getProperty("netbeans.user"))); new CLIOptions().cli(new String[] { "--userdir", "correct" }); - assertTrue("--userdir is supported", "correct".equals(System.getProperty("netbeans.user"))); + assertEquals("--userdir is supported", FileUtil.normalizeFile(new File("correct")).getAbsolutePath(), System.getProperty("netbeans.user")); if (orig != null) { System.setProperty("netbeans.user", orig); --- a/core.startup/test/unit/src/org/netbeans/core/startup/ModuleListTest.java +++ a/core.startup/test/unit/src/org/netbeans/core/startup/ModuleListTest.java @@ -71,6 +71,7 @@ import org.openide.filesystems.FileUtil; import org.openide.filesystems.LocalFileSystem; import org.openide.modules.InstalledFileLocator; +import org.openide.modules.Places; import org.openide.util.test.MockLookup; /** Test the functions of the module list, i.e. finding modules on @@ -79,8 +80,6 @@ */ public class ModuleListTest extends SetupHid { - private File ud; - private static final String PREFIX = "wherever/"; private LocalFileSystem fs; @@ -110,9 +109,8 @@ MockLookup.setInstances(new IFL()); - ud = new File(getWorkDir(), "ud"); - ud.mkdirs(); - System.setProperty("netbeans.user", ud.getPath()); + File ud = new File(getWorkDir(), "ud"); + Places.setUserDirectory(ud); MockModuleInstaller installer = new MockModuleInstaller(); MockEvents ev = new MockEvents(); @@ -204,7 +202,7 @@ Stamps.getModulesJARs().flush(0); Stamps.getModulesJARs().shutdown(); - File f = new File(new File(new File(System.getProperty("netbeans.user"), "var"), "cache"), "all-modules.dat"); + File f = Places.getCacheSubfile("all-modules.dat"); assertTrue("Cache exists", f.exists()); FileObject mf = fs.findResource(modulesfolder.getPath()); --- a/core.startup/test/unit/src/org/netbeans/core/startup/NbInstallerTest9.java +++ a/core.startup/test/unit/src/org/netbeans/core/startup/NbInstallerTest9.java @@ -52,6 +52,7 @@ import java.util.jar.Manifest; import org.netbeans.ModuleInstaller; import org.netbeans.Stamps; +import org.openide.modules.Places; /** Test the NetBeans module installer implementation. * Broken into pieces to ensure each runs in its own VM. @@ -66,7 +67,7 @@ /** Test #26786/#28755: manifest caching can be buggy. */ public void testManifestCaching() throws Exception { - System.setProperty("netbeans.user", getWorkDirPath()); + Places.setUserDirectory(getWorkDir()); ModuleInstaller inst = new org.netbeans.core.startup.NbInstaller(new MockEvents()); File littleJar = new File(jars, "little-manifest.jar"); //inst.loadManifest(littleJar).write(System.out); @@ -76,7 +77,7 @@ File bigJar = new File(jars, "big-manifest.jar"); assertEquals(getManifest(bigJar), inst.loadManifest(bigJar)); Stamps.getModulesJARs().shutdown(); - File allManifestsDat = new File(new File(new File(getWorkDir(), "var"), "cache"), "all-manifest.dat"); + File allManifestsDat = Places.getCacheSubfile("all-manifest.dat"); assertTrue("File " + allManifestsDat + " exists", allManifestsDat.isFile()); // Create a new NbInstaller, since otherwise it turns off caching... inst = new org.netbeans.core.startup.NbInstaller(new MockEvents()); --- a/csl.api/test/unit/src/org/netbeans/modules/csl/api/test/CslTestBase.java +++ a/csl.api/test/unit/src/org/netbeans/modules/csl/api/test/CslTestBase.java @@ -200,6 +200,7 @@ import org.netbeans.spi.java.classpath.ClassPathProvider; import org.openide.loaders.DataObject; import org.openide.loaders.DataObjectNotFoundException; +import org.openide.modules.Places; import org.openide.util.test.MockLookup; /** @@ -218,7 +219,8 @@ super.setUp(); clearWorkDir(); - System.setProperty("netbeans.user", getWorkDirPath()); + Places.setUserDirectory(getWorkDir()); + // XXX are the following four lines actually necessary? final FileObject wd = FileUtil.toFileObject(getWorkDir()); assert wd != null; FileObject cache = FileUtil.createFolder(wd, "var/cache"); --- a/dlight.remote.impl/nbproject/project.xml +++ a/dlight.remote.impl/nbproject/project.xml @@ -89,6 +89,14 @@ + org.openide.modules + + + + 7.25 + + + org.openide.util --- a/dlight.remote.impl/src/org/netbeans/modules/remote/impl/fs/FileSystemCacheProviderImpl.java +++ a/dlight.remote.impl/src/org/netbeans/modules/remote/impl/fs/FileSystemCacheProviderImpl.java @@ -45,6 +45,7 @@ import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment; import org.netbeans.modules.nativeexecution.api.util.EnvUtils; import org.netbeans.modules.remote.spi.FileSystemCacheProvider; +import org.openide.modules.Places; import org.openide.util.lookup.ServiceProvider; /** @@ -58,7 +59,6 @@ protected String getCacheImpl(ExecutionEnvironment executionEnvironment) { String hostId = EnvUtils.toHostID(executionEnvironment); String userId = executionEnvironment.getUser(); - String root = System.getProperty("netbeans.user") == null ? null : System.getProperty("netbeans.user").replace('\\', '/') + "/var/cache/remote-files/"; //NOI18N; - return (root == null) ? null : root + hostId + '_' + userId + '/'; + return Places.getCacheSubdirectory("remote-files").getAbsolutePath().replace('\\', '/') + '/' + hostId + '_' + userId + '/'; // NOI18N } } --- a/dlight.remote/src/org/netbeans/modules/remote/spi/FileSystemCacheProvider.java +++ a/dlight.remote/src/org/netbeans/modules/remote/spi/FileSystemCacheProvider.java @@ -58,6 +58,7 @@ protected abstract String getCacheImpl(ExecutionEnvironment executionEnvironment); + // XXX reconsider API - why not File? why /-separated on Windows? public static String getCacheRoot(ExecutionEnvironment executionEnvironment) { FileSystemCacheProvider provider = Lookup.getDefault().lookup(FileSystemCacheProvider.class); RemoteLogger.assertTrue(provider != null, "No FileSystemCacheProvider found"); // NOI18N --- a/java.source.ant/nbproject/project.xml +++ a/java.source.ant/nbproject/project.xml @@ -119,6 +119,14 @@ + org.openide.modules + + + + 7.25 + + + org.openide.nodes --- a/java.source.ant/src/org/netbeans/modules/java/source/ant/ProjectRunnerImpl.java +++ a/java.source.ant/src/org/netbeans/modules/java/source/ant/ProjectRunnerImpl.java @@ -80,6 +80,7 @@ import org.openide.filesystems.FileObject; import org.openide.filesystems.FileStateInvalidException; import org.openide.filesystems.FileUtil; +import org.openide.modules.Places; import org.openide.util.ChangeSupport; import org.openide.util.Exceptions; import org.openide.util.NbBundle; @@ -384,7 +385,7 @@ URL thisClassSource = ProjectRunnerImpl.class.getProtectionDomain().getCodeSource().getLocation(); File jarFile = FileUtil.archiveOrDirForURL(thisClassSource); - File scriptFile = new File(getCacheFolder(), actionName + ".xml"); + File scriptFile = Places.getCacheSubfile("executor-snippets/" + actionName + ".xml"); if (!scriptFile.canRead() || (jarFile != null && jarFile.lastModified() > scriptFile.lastModified())) { try { @@ -404,34 +405,6 @@ return FileUtil.toFileObject(scriptFile); } - private static final String NB_USER_DIR = "netbeans.user"; //NOI18N - private static final String SNIPPETS_CACHE_DIR = "var"+File.separatorChar+"cache"+File.separatorChar+"executor-snippets"; //NOI18N - - - private static String getNbUserDir () { - final String nbUserProp = System.getProperty(NB_USER_DIR); - return nbUserProp; - } - - private static File cacheFolder; - - private static synchronized File getCacheFolder () { - if (cacheFolder == null) { - final String nbUserDirProp = getNbUserDir(); - assert nbUserDirProp != null; - final File nbUserDir = new File (nbUserDirProp); - cacheFolder = FileUtil.normalizeFile(new File (nbUserDir, SNIPPETS_CACHE_DIR)); - if (!cacheFolder.exists()) { - boolean created = cacheFolder.mkdirs(); - assert created : "Cannot create cache folder"; //NOI18N - } - else { - assert cacheFolder.isDirectory() && cacheFolder.canRead() && cacheFolder.canWrite(); - } - } - return cacheFolder; - } - private static void copyFile(URLConnection source, FileObject target) throws IOException { InputStream ins = null; OutputStream out = null; --- a/languages/nbproject/project.xml +++ a/languages/nbproject/project.xml @@ -161,7 +161,7 @@ - 6.4 + 7.25 --- a/languages/src/org/netbeans/modules/languages/features/Index.java +++ a/languages/src/org/netbeans/modules/languages/features/Index.java @@ -70,6 +70,7 @@ import org.netbeans.modules.languages.Utils; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; +import org.openide.modules.Places; import org.openide.util.Exceptions; @@ -197,17 +198,7 @@ private static synchronized File getCacheFolder () { if (cacheFolder == null) { - String userDir = System.getProperty ("netbeans.user"); - assert userDir != null; - String cacheDir = userDir + File.separatorChar + - "var" + File.separatorChar + "cache" + File.separatorChar + - "sindex" + File.separatorChar + "1.0"; - cacheFolder = FileUtil.normalizeFile (new File (cacheDir)); - if (!cacheFolder.exists ()) { - boolean created = cacheFolder.mkdirs (); - assert created : "Cannot create cache folder"; //NOI18N - } else - assert cacheFolder.isDirectory () && cacheFolder.canRead () && cacheFolder.canWrite (); + cacheFolder = Places.getCacheSubdirectory("sindex/1.0"); } return cacheFolder; } --- a/maven.indexer/nbproject/project.xml +++ a/maven.indexer/nbproject/project.xml @@ -124,7 +124,7 @@ - 7.7 + 7.25 --- a/maven.indexer/src/org/netbeans/modules/maven/indexer/NexusRepositoryIndexerImpl.java +++ a/maven.indexer/src/org/netbeans/modules/maven/indexer/NexusRepositoryIndexerImpl.java @@ -51,7 +51,6 @@ import org.codehaus.plexus.util.FileUtils; import java.util.Map; import org.apache.lucene.document.Document; -import org.netbeans.api.annotations.common.SuppressWarnings; import org.netbeans.modules.maven.indexer.api.QueryField; import org.netbeans.modules.maven.indexer.api.NBVersionInfo; import java.io.File; @@ -163,6 +162,7 @@ import org.openide.awt.StatusDisplayer; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; +import org.openide.modules.Places; import org.openide.util.Exceptions; import org.openide.util.Lookup; import org.openide.util.Mutex; @@ -179,7 +179,6 @@ public class NexusRepositoryIndexerImpl implements RepositoryIndexerImplementation, BaseQueries, ChecksumQueries, ArchetypeQueries, DependencyInfoQueries, ClassesQuery, ClassUsageQuery, GenericFindQuery, ContextLoadedQuery { - private static final String MAVENINDEX_PATH = "mavenindex"; private PlexusContainer embedder; private ArtifactRepository repository; @@ -760,18 +759,8 @@ repo.fireChangeIndex(); } - @SuppressWarnings("RV_RETURN_VALUE_IGNORED_BAD_PRACTICE") // if mkdirs fails, indexing will just fail later anyway private File getDefaultIndexLocation() { - String userdir = System.getProperty("netbeans.user"); //NOI18N - File cacheDir; - if (userdir != null) { - cacheDir = new File(new File(new File(userdir, "var"), "cache"), MAVENINDEX_PATH);//NOI18N - } else { - File root = FileUtil.toFile(FileUtil.getConfigRoot()); - cacheDir = new File(root, MAVENINDEX_PATH);//NOI18N - } - cacheDir.mkdirs(); - return cacheDir; + return Places.getCacheSubdirectory("mavenindex"); } @Override --- a/maven.indexer/test/unit/src/org/netbeans/modules/maven/indexer/NexusRepositoryIndexerImplTest.java +++ a/maven.indexer/test/unit/src/org/netbeans/modules/maven/indexer/NexusRepositoryIndexerImplTest.java @@ -57,6 +57,7 @@ import org.netbeans.modules.maven.indexer.api.RepositoryInfo; import org.netbeans.modules.maven.indexer.api.RepositoryPreferences; import org.netbeans.modules.maven.indexer.spi.ClassUsageQuery.ClassUsageResult; +import org.openide.modules.Places; import org.openide.util.test.JarBuilder; import org.openide.util.test.TestFileUtils; @@ -74,7 +75,7 @@ @Override protected void setUp() throws Exception { clearWorkDir(); - System.setProperty("netbeans.user", getWorkDirPath()); + Places.setUserDirectory(getWorkDir()); File repo = new File(getWorkDir(), "repo"); embedder = EmbedderFactory.getProjectEmbedder(); defaultArtifactRepository = embedder.lookupComponent(ArtifactRepositoryFactory.class).createArtifactRepository("test", repo.toURI().toString(), "default", null, null); --- a/maven/nbproject/project.xml +++ a/maven/nbproject/project.xml @@ -332,7 +332,7 @@ - 7.7 + 7.25 --- a/maven/src/org/netbeans/modules/maven/CacheDirProvider.java +++ a/maven/src/org/netbeans/modules/maven/CacheDirProvider.java @@ -42,12 +42,12 @@ package org.netbeans.modules.maven; -import java.io.File; import java.io.IOException; import org.netbeans.api.annotations.common.SuppressWarnings; import org.netbeans.spi.project.CacheDirectoryProvider; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; +import org.openide.modules.Places; /** * implementation of CacheDirectoryProvider that places the cache directory in the user @@ -64,7 +64,7 @@ @SuppressWarnings("RV_ABSOLUTE_VALUE_OF_HASHCODE") // for compatibility, use this decimal scheme public @Override FileObject getCacheDirectory() throws IOException { int code = Math.abs(project.getProjectDirectory().getPath().hashCode()); - return FileUtil.createFolder(FileUtil.createFolder(new File(System.getProperty("netbeans.user"))), "var/cache/mavencachedirs/" + code); // NOI18N + return FileUtil.createFolder(Places.getCacheSubdirectory("mavencachedirs/" + code)); // NOI18N } } --- a/maven/src/org/netbeans/modules/maven/ProjectOpenedHookImpl.java +++ a/maven/src/org/netbeans/modules/maven/ProjectOpenedHookImpl.java @@ -73,6 +73,7 @@ import org.netbeans.modules.maven.options.MavenSettings; import org.netbeans.spi.project.ui.ProjectOpenedHook; import org.openide.filesystems.FileUtil; +import org.openide.modules.Places; import org.openide.util.Exceptions; import org.openide.util.NbBundle; import org.openide.util.RequestProcessor; @@ -199,11 +200,7 @@ } } private boolean existsDefaultIndexLocation() { - String userdir = System.getProperty("netbeans.user"); //NOI18N - if (userdir == null) { - return false; // from a unit test - } - File cacheDir = new File(new File(new File(userdir, "var"), "cache"), "mavenindex");//NOI18N + File cacheDir = new File(Places.getCacheDirectory(), "mavenindex");//NOI18N return cacheDir.exists() && cacheDir.isDirectory(); } private boolean checkDiff(String repoid, long amount) { --- a/o.n.bootstrap/arch.xml +++ a/o.n.bootstrap/arch.xml @@ -499,11 +499,6 @@
  • - - NetBeans user directory. - -
  • -
  • Additional secondary NetBeans installation directories, if applicable. --- a/o.n.bootstrap/nbproject/project.xml +++ a/o.n.bootstrap/nbproject/project.xml @@ -54,7 +54,7 @@ - 7.19 + 7.25 --- a/o.n.bootstrap/src/org/netbeans/CLIHandler.java +++ a/o.n.bootstrap/src/org/netbeans/CLIHandler.java @@ -74,6 +74,7 @@ import java.util.Random; import java.util.logging.Level; import java.util.logging.Logger; +import org.openide.modules.Places; import org.openide.util.RequestProcessor; import org.openide.util.Task; @@ -523,13 +524,13 @@ } // get the value - String home = System.getProperty("netbeans.user"); // NOI18N + String home = System.getProperty(Places.USER_DIR_PROP); // NOI18N if (home == null) { home = System.getProperty("user.home"); // NOI18N - System.setProperty ("netbeans.user", home); // NOI18N + System.setProperty(Places.USER_DIR_PROP, home); // NOI18N } - if ("memory".equals(home)) { // NOI18N + if (/*Places.MEMORY*/"memory".equals(home)) { // NOI18N int execCode = processInitLevelCLI(args, handlers, failOnUnknownOptions); return new Status(execCode); } --- a/o.n.bootstrap/src/org/netbeans/Stamps.java +++ a/o.n.bootstrap/src/org/netbeans/Stamps.java @@ -68,6 +68,7 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.logging.Level; import java.util.logging.Logger; +import org.openide.modules.Places; import org.openide.util.Exceptions; /** @@ -164,19 +165,14 @@ return asByteBuffer(cache, true, false); } final File file(String cache, int[] len) { - String ud = getUserDir(); - if (ud == null) { - LOG.log(Level.FINE, "No userdir when asking for {0}", cache); // NOI18N - return null; - } synchronized (this) { if (worker.isProcessing(cache)) { LOG.log(Level.FINE, "Worker processing when asking for {0}", cache); // NOI18N return null; } } - - File cacheFile = new File(new File(new File(ud, "var"), "cache"), cache.replace('/', File.separatorChar)); // NOI18N + + File cacheFile = Places.getCacheSubfile(cache); long last = cacheFile.lastModified(); if (last <= 0) { LOG.log(Level.FINE, "Cache does not exist when asking for {0}", cache); // NOI18N @@ -265,7 +261,7 @@ } private static void discardCachesImpl(AtomicLong al) { - String user = getUserDir(); + File user = Places.getUserDirectory(); long now = System.currentTimeMillis(); if (user != null) { File f = new File(user, ".lastModified"); @@ -316,11 +312,6 @@ // This will be called externally from a launcher. // - private static String getUserDir() { - String ud = System.getProperty("netbeans.user"); // NOI18N - return "memory".equals(ud) ? null : ud; - } - private static AtomicLong stamp(boolean checkStampFile) { AtomicLong result = new AtomicLong(); AtomicReference newestFile = new AtomicReference(); @@ -348,15 +339,14 @@ } } } - String user = getUserDir(); + File user = Places.getUserDirectory(); if (user != null) { AtomicInteger crc = new AtomicInteger(); - stampForCluster (new File (user), result, newestFile, new HashSet (), false, false, crc); + stampForCluster(user, result, newestFile, new HashSet(), false, false, crc); sb.append(user).append('=').append(result.longValue()).append('\n'); sb.append("crc=").append(crc.intValue()).append('\n'); - File userDir = new File(user); - File checkSum = new File(new File(new File(new File(userDir, "var"), "cache"), "lastModified"), "all-checksum.txt"); + File checkSum = new File(Places.getCacheDirectory(), "lastModified/all-checksum.txt"); if (!compareAndUpdateFile(checkSum, sb.toString(), result)) { discardCachesImpl(result); } @@ -376,10 +366,8 @@ } return time; } - String user = getUserDir(); - if (user != null) { - File userDir = new File(user); - stamp = new File(new File(new File(new File(userDir, "var"), "cache"), "lastModified"), clusterLocalStamp(cluster)); + if (Places.getUserDirectory() != null) { + stamp = new File(new File(Places.getCacheDirectory(), "lastModified"), clusterLocalStamp(cluster)); if (checkStampFile && (time = stamp.lastModified()) > 0) { if (time > result.longValue()) { newestFile.set(stamp); @@ -568,12 +556,12 @@ public boolean store(AtomicInteger delay) { assert os == null; - String ud = getUserDir(); - if (ud == null) { - LOG.warning("No 'netbeans.user' property to store: " + cache); // NOI18N + File cacheDir = Places.getCacheDirectory(); + if (!cacheDir.isDirectory()) { + LOG.log(Level.WARNING, "Nonexistent cache directory: {0}", cacheDir); // NOI18N return false; } - File cacheFile = new File(new File(new File(ud, "var"), "cache"), cache); // NOI18N + File cacheFile = new File(cacheDir, cache); // NOI18N boolean delete = false; try { LOG.log(Level.FINE, "Cleaning cache {0}", cacheFile); --- a/o.n.bootstrap/src/org/netbeans/TopSecurityManager.java +++ a/o.n.bootstrap/src/org/netbeans/TopSecurityManager.java @@ -65,6 +65,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import java.util.logging.LoggingPermission; +import org.openide.modules.Places; import org.openide.util.Lookup; /** NetBeans security manager implementation. @@ -271,7 +272,7 @@ } } } - if ("netbeans.home".equals(x)) { // NOI18N + if ("netbeans.home".equals(x) || Places.USER_DIR_PROP.equals(x)) { // NOI18N // Control access to this system property. for (Class c : getClassContext()) { if (c != TopSecurityManager.class && @@ -299,6 +300,7 @@ private final Set warnedClassesNDE = new HashSet(25); private static final Set warnedClassesNH = new HashSet(25); static { + warnedClassesNH.add("org.openide.modules.Places"); warnedClassesNH.add("org.netbeans.MainImpl"); // NOI18N warnedClassesNH.add("org.netbeans.Stamps"); // NOI18N warnedClassesNH.add("org.netbeans.core.startup.InstalledFileLocatorImpl"); // NOI18N --- a/o.n.bootstrap/test/unit/src/org/netbeans/StampsExtraTest.java +++ a/o.n.bootstrap/test/unit/src/org/netbeans/StampsExtraTest.java @@ -47,6 +47,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import org.netbeans.junit.NbTestCase; +import org.openide.modules.Places; /** * @@ -77,7 +78,7 @@ System.setProperty("netbeans.home", platform.getPath()); System.setProperty("netbeans.dirs", ide.getPath() + File.pathSeparator + extra.getPath()); - System.setProperty("netbeans.user", userdir.getPath()); + Places.setUserDirectory(userdir); touch(platform, ".lastModified", 50000L); touch(ide, ".lastModified", 90000L); @@ -103,9 +104,7 @@ CountingSecurityManager.assertCounts("Just few accesses to installation", 6); assertEquals("Stamps are the same", stamp, newStamp); - File lastModifiedDir = new File(new File(new File(userdir, "var"), "cache"), "lastModified"); - File extraLM = new File(lastModifiedDir, "extra"); - assertFalse("File has not been created for non-existing cluster", extraLM.canRead()); + assertFalse("File has not been created for non-existing cluster", Places.getCacheSubfile("lastModified/extra").canRead()); extra.mkdirs(); File lastModified = new File(extra, ".lastModified"); --- a/o.n.bootstrap/test/unit/src/org/netbeans/StampsIdeLessThanPlatformTest.java +++ a/o.n.bootstrap/test/unit/src/org/netbeans/StampsIdeLessThanPlatformTest.java @@ -47,11 +47,10 @@ import java.io.FileInputStream; import java.io.FileReader; import java.io.IOException; -import java.util.Enumeration; -import java.util.Properties; import java.util.logging.Level; import java.util.logging.Logger; import org.netbeans.junit.NbTestCase; +import org.openide.modules.Places; /** * @@ -85,7 +84,7 @@ System.setProperty("netbeans.home", platform.getPath()); System.setProperty("netbeans.dirs", ide.getPath() + File.pathSeparator + nonexist.getPath()); - System.setProperty("netbeans.user", userdir.getPath()); + Places.setUserDirectory(userdir); StampsTest.createModule("org.openide.awt", platform, 50000L); StampsTest.createModule("org.openide.nodes", platform, 60000L); @@ -110,7 +109,7 @@ StampsTest.assertStamp(-1L, userdir, false, false); - File checkSum = new File(new File(new File(new File(userdir, "var"), "cache"), "lastModified"), "all-checksum.txt"); + File checkSum = Places.getCacheSubfile("lastModified/all-checksum.txt"); assertTrue("Checksum created" , checkSum.isFile()); byte[] arr = new byte[30000]; --- a/o.n.core/nbproject/project.xml +++ a/o.n.core/nbproject/project.xml @@ -144,7 +144,7 @@ - 7.19 + 7.25 --- a/o.n.core/src/org/netbeans/core/actions/LogAction.java +++ a/o.n.core/src/org/netbeans/core/actions/LogAction.java @@ -47,6 +47,7 @@ import java.io.File; import java.util.logging.Level; import java.util.logging.Logger; +import org.openide.modules.Places; import org.openide.util.actions.CallableSystemAction; import org.openide.util.HelpCtx; import org.openide.util.NbBundle; @@ -61,12 +62,11 @@ public void performAction() { - // FIXME This may not be used this way anymore. - String userDir = System.getProperty("netbeans.user"); - if (userDir == null) + File userDir = Places.getUserDirectory(); + if (userDir == null) { return; - // FIXME the same as above - File f = new File(userDir + "/var/log/messages.log"); // TEMP + } + File f = new File(userDir, "/var/log/messages.log"); LogViewerSupport p = new LogViewerSupport(f, NbBundle.getMessage(LogAction.class, "MSG_ShortLogTab_name")); try { p.showLogViewer(); --- a/o.n.core/src/org/netbeans/core/ui/Bundle.properties +++ a/o.n.core/src/org/netbeans/core/ui/Bundle.properties @@ -41,8 +41,6 @@ # made subject to such option by the copyright holder. # Product Information panel -LBL_Description=
    \ -

    Product Version\: {0}

    \n

    Java\: {1}; {2}

    \n

    System\: {3}; {4}; {5}

    \n

    Userdir: {6}

    LBL_Copyright=
    \ NetBeans IDE and NetBeans Platform are based on software from netbeans.org, \ which has been dual licensed under the Common Development and Distribution License (CDDL) \ --- a/o.n.core/src/org/netbeans/core/ui/ProductInformationPanel.java +++ a/o.n.core/src/org/netbeans/core/ui/ProductInformationPanel.java @@ -68,19 +68,36 @@ import org.openide.awt.HtmlBrowser; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; +import org.openide.modules.Places; import org.openide.util.NbBundle; +import static org.netbeans.core.ui.Bundle.*; +import org.openide.util.NbBundle.Messages; public class ProductInformationPanel extends JPanel implements HyperlinkListener { URL url = null; Icon about; + @Messages({ + "# {0} - product version", + "# {1} - Java version", + "# {2} - VM version", + "# {3} - OS", + "# {4} - encoding", + "# {5} - locale", + "# {6} - user dir", + "# {7} - cache dir", + "LBL_description=
    " + + "

    Product Version: {0}

    \n " + + "

    Java: {1}; {2}

    \n " + + "

    System: {3}; {4}; {5}

    \n " + + "

    User directory: {6}

    \n " + + "

    Cache directory: {7}

    " + }) public ProductInformationPanel() { initComponents(); imageLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); - description.setText(org.openide.util.NbBundle.getMessage(ProductInformationPanel.class, - "LBL_Description", new Object[] {getProductVersionValue(), getJavaValue(), getVMValue(), - getOperatingSystemValue(), getEncodingValue(), getSystemLocaleValue(), getUserDirValue()})); + description.setText(LBL_description(getProductVersionValue(), getJavaValue(), getVMValue(), getOperatingSystemValue(), getEncodingValue(), getSystemLocaleValue(), getUserDirValue(), Places.getCacheDirectory().getAbsolutePath())); description.setCaretPosition(0); // so that text is not scrolled down description.addHyperlinkListener(this); copyright.addHyperlinkListener(this); --- a/openide.modules/apichanges.xml +++ a/openide.modules/apichanges.xml @@ -50,6 +50,26 @@ Modules API + + + Added Places + + + + +

    + Modules using system properties such as netbeans.user + should use this new API instead. +

    +
    + +

    + Introduced a structured API for accessing well-known file locations. +

    +
    + + +
    Module names can contain Java keywords --- a/openide.modules/manifest.mf +++ a/openide.modules/manifest.mf @@ -1,5 +1,5 @@ Manifest-Version: 1.0 OpenIDE-Module: org.openide.modules OpenIDE-Module-Localizing-Bundle: org/openide/modules/Bundle.properties -OpenIDE-Module-Specification-Version: 7.24 +OpenIDE-Module-Specification-Version: 7.25 --- a/openide.modules/src/org/openide/modules/Places.java +++ a/openide.modules/src/org/openide/modules/Places.java @@ -0,0 +1,158 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2011 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development and + * Distribution License("CDDL") (collectively, the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy of + * the License at http://www.netbeans.org/cddl-gplv2.html or + * nbbuild/licenses/CDDL-GPL-2-CP. See the License for the specific language + * governing permissions and limitations under the License. When distributing + * the software, include this License Header Notice in each file and include + * the License file at nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided by + * Oracle in the GPL Version 2 section of the License file that accompanied + * this code. If applicable, add the following below the License Header, with + * the fields enclosed by brackets [] replaced by your own identifying + * information: "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you do not indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to its + * licensees as provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the option applies only + * if the new code is made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2011 Sun Microsystems, Inc. + */ + +package org.openide.modules; + +import java.io.File; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * Provides access to standard file locations. + *
    + * This class should be used for limited purposes only. You might instead want to use:
      + *
    • FileUtil.getConfigFile + * to find a file declared in an XML layer or created or overridden in the {@code config} subdirectory of the user directory. + *
    • {@link InstalledFileLocator} to find modules installed as part of an NBM. + *
    • {@code someClass.getProtectionDomain().getCodeSource().getLocation()} to find resources inside a module class loader. + *
    + *
    + * @since 7.25 + */ +public class Places { + + /** + * System property key for {@link #getUserDirectory}. + * Should not be used by most code directly. + */ + public static final String USER_DIR_PROP = "netbeans.user"; + + private static final String MEMORY = "memory"; + + private static final Logger LOG = Logger.getLogger(Places.class.getName()); + + private static File cacheDir; + + /** + * Locates the NetBeans user directory. + * This may be used to persist valuable files for which the system filesystem + * ({@code FileUtil.getConfigFile}) is inappropriate due its being virtual. + * Each module is responsible for using sufficiently unique filenames within this directory. + * The system property {@link #USER_DIR_PROP} is used for compatibility. + * @return a directory location (need not yet exist), or null if unconfigured + */ + public static synchronized /*@CheckForNull*/ File getUserDirectory() { + String p = System.getProperty(USER_DIR_PROP); + return p != null && !p.equals(MEMORY) ? new File(p) : null; + } + + /** + * Configures the NetBeans user directory. + * This would be called by startup code in the NetBeans Platform, + * but might also be useful to call from a unit test if tested code calls {@link #getUserDirectory} or {@link #getCacheDirectory}. + * @param dir a directory location (need not yet exist); null be passed but means the same as {@code memory} for the system property, interpreted by the module system + */ + public static synchronized void setUserDirectory(/*@NullAllowed*/ File dir) { + System.setProperty(USER_DIR_PROP, dir != null ? dir.getAbsolutePath() : MEMORY); + } + + /** + * Locates the NetBeans cache directory. + * This may be used to store pure performance caches - files which could be safely deleted, + * since they would be automatically recreated on demand. + * Each module is responsible for using sufficiently unique filenames within this directory. + * {@code $userdir/var/cache/} is used as a default when {@link #getUserDirectory} is configured. + * As a final fallback, a location in the system temporary directory will be returned. + * @return a directory location (never null but need not yet exist) + * @see #getCacheSubdirectory + * @see #getCacheSubfile + */ + public static synchronized /*@NonNull*/ File getCacheDirectory() { + if (cacheDir != null) { + return cacheDir; + } + File userdir = getUserDirectory(); + if (userdir != null) { + return new File(new File(userdir, "var"), "cache"); + } + return new File(System.getProperty("java.io.tmpdir"), "nbcache"); + } + + /** + * Convenience method to get a particular subdirectory within {@link #getCacheDirectory}. + * The directory will be created if it does not yet exist (but a warning logged if permissions do not allow this). + * @param path a subdirectory path such as {@code stuff} or {@code mymodule/stuff} ({@code /} permitted even on Windows) + * @return a directory of that name within the general cache directory + */ + public static /*@NonNull*/ File getCacheSubdirectory(String path) { + File d = new File(getCacheDirectory(), path); + if (!d.isDirectory() && !d.mkdirs()) { + LOG.log(Level.WARNING, "could not create {0}", d); + } + return d; + } + + /** + * Convenience method to get a particular file within {@link #getCacheDirectory}. + * The parent directory will be created if it does not yet exist (but a warning logged if permissions do not allow this); + * the file itself will not be automatically created. + * @param path a file path such as {@code stuff.ser} or {@code mymodule/stuff.ser} ({@code /} permitted even on Windows) + * @return a file of that name within the general cache directory + */ + public static /*@NonNull*/ File getCacheSubfile(String path) { + File f = new File(getCacheDirectory(), path); + File d = f.getParentFile(); + if (!d.isDirectory() && !d.mkdirs()) { + LOG.log(Level.WARNING, "could not create {0}", d); + } + return f; + } + + /** + * Configures the NetBeans cache directory. + * This would be called by startup code in the NetBeans Platform, + * but might also be useful to call from a unit test if tested code calls {@link #getCacheDirectory}. + * @param dir a directory location (need not yet exist) + */ + public static synchronized void setCacheDirectory(/*@NonNull*/ File dir) { + cacheDir = dir; + } + + private Places() {} + +} --- a/parsing.api/nbproject/project.xml +++ a/parsing.api/nbproject/project.xml @@ -178,7 +178,7 @@ - 7.6 + 7.25 --- a/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/CacheFolder.java +++ a/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/CacheFolder.java @@ -59,6 +59,7 @@ import org.openide.filesystems.FileSystem; import org.openide.filesystems.FileUtil; import org.openide.filesystems.URLMapper; +import org.openide.modules.Places; /** * @@ -68,8 +69,6 @@ private static final Logger LOG = Logger.getLogger(CacheFolder.class.getName()); - private static final String NB_USER_DIR = "netbeans.user"; //NOI18N - private static final String INDEX_DIR = "var"+File.separatorChar+"cache"+File.separatorChar+"index"; //NOI18N private static final String SEGMENTS_FILE = "segments"; //NOI18N private static final String SLICE_PREFIX = "s"; //NOI18N @@ -198,20 +197,7 @@ public static synchronized FileObject getCacheFolder () { if (cacheFolder == null) { - final String nbUserDirProp = System.getProperty(NB_USER_DIR); - if (nbUserDirProp == null) { - throw new IllegalStateException("No " + NB_USER_DIR + " system property"); //NOI18N - } - - final File nbUserDir = new File (nbUserDirProp); - File cache = FileUtil.normalizeFile(new File (nbUserDir, INDEX_DIR)); - if (!cache.exists()) { - cache.mkdirs(); - if (!cache.exists()) { - throw new IllegalStateException("Can't create indices cache folder " + cache.getAbsolutePath()); //NOI18N - } - } - + File cache = Places.getCacheSubdirectory("index"); // NOI18N if (!cache.isDirectory()) { throw new IllegalStateException("Indices cache folder " + cache.getAbsolutePath() + " is not a folder"); //NOI18N } --- a/spellchecker/nbproject/project.xml +++ a/spellchecker/nbproject/project.xml @@ -149,7 +149,7 @@ - 7.15 + 7.25 --- a/spellchecker/src/org/netbeans/modules/spellchecker/TrieDictionary.java +++ a/spellchecker/src/org/netbeans/modules/spellchecker/TrieDictionary.java @@ -69,6 +69,7 @@ import java.util.logging.Logger; import org.netbeans.modules.spellchecker.spi.dictionary.Dictionary; import org.netbeans.modules.spellchecker.spi.dictionary.ValidityType; +import org.openide.modules.Places; import org.openide.util.CharSequences; import org.openide.util.Exceptions; import org.openide.util.RequestProcessor; @@ -225,10 +226,8 @@ private static final int CURRENT_TRIE_DICTIONARY_VERSION = 1; - private static final File CACHE_DIR = new File(new File(new File(System.getProperty("netbeans.user"), "var"), "cache"), "dict"); - public static Dictionary getDictionary(String suffix, List sources) throws IOException { - File trie = new File(CACHE_DIR, "dictionary" + suffix + ".trie" + CURRENT_TRIE_DICTIONARY_VERSION); + File trie = Places.getCacheSubfile("dict/dictionary" + suffix + ".trie" + CURRENT_TRIE_DICTIONARY_VERSION); return getDictionary(trie, sources); } --- a/subversion/nbproject/project.xml +++ a/subversion/nbproject/project.xml @@ -229,7 +229,7 @@ - 6.6 + 7.25 --- a/subversion/src/org/netbeans/modules/subversion/DiskMapTurboProvider.java +++ a/subversion/src/org/netbeans/modules/subversion/DiskMapTurboProvider.java @@ -48,11 +48,11 @@ import org.netbeans.modules.turbo.CacheIndex; import org.netbeans.modules.subversion.util.*; import org.netbeans.modules.turbo.TurboProvider; -import org.openide.filesystems.FileUtil; import java.io.*; import java.util.*; import java.util.logging.Level; import org.netbeans.modules.proxy.Base64Encoder; +import org.openide.modules.Places; /** * Storage of file attributes with shortcut to retrieve all stored values. @@ -481,14 +481,7 @@ } private void initCacheStore() { - String userDir = System.getProperty("netbeans.user"); // NOI18N - if (userDir != null) { - cacheStore = new File(new File(new File (userDir, "var"), "cache"), CACHE_DIRECTORY); // NOI18N - } else { - File cachedir = FileUtil.toFile(FileUtil.getConfigRoot()); - cacheStore = new File(cachedir, CACHE_DIRECTORY); // NOI18N - } - cacheStore.mkdirs(); + cacheStore = Places.getCacheSubdirectory(CACHE_DIRECTORY); } private static void copyStreams(OutputStream out, InputStream in, int len) throws IOException { --- a/versioning.system.cvss/nbproject/project.xml +++ a/versioning.system.cvss/nbproject/project.xml @@ -253,7 +253,7 @@ - 6.0 + 7.25 --- a/versioning.system.cvss/src/org/netbeans/modules/versioning/system/cvss/DiskMapTurboProvider.java +++ a/versioning.system.cvss/src/org/netbeans/modules/versioning/system/cvss/DiskMapTurboProvider.java @@ -45,12 +45,12 @@ package org.netbeans.modules.versioning.system.cvss; import org.netbeans.modules.turbo.TurboProvider; -import org.openide.filesystems.FileUtil; import org.openide.ErrorManager; import java.io.*; import java.util.*; import java.util.logging.Level; +import org.openide.modules.Places; /** * Storage of file attributes with shortcut to retrieve all stored values. @@ -306,13 +306,7 @@ } private void initCacheStore() { - String userDir = System.getProperty("netbeans.user"); // NOI18N - if (userDir != null) { - cacheStore = new File(new File(new File (userDir, "var"), "cache"), "cvscache"); // NOI18N - } else { - File cachedir = FileUtil.toFile(FileUtil.getConfigRoot()); - cacheStore = new File(cachedir, "cvscache"); // NOI18N - } + cacheStore = Places.getCacheSubdirectory("cvscache"); // NOI18N } private void makeSureCacheStoreExists() { --- a/versioning.util/nbproject/project.xml +++ a/versioning.util/nbproject/project.xml @@ -210,6 +210,14 @@ + org.openide.modules + + + + 7.25 + + + org.openide.nodes --- a/versioning.util/src/org/netbeans/modules/versioning/historystore/StorageManager.java +++ a/versioning.util/src/org/netbeans/modules/versioning/historystore/StorageManager.java @@ -48,6 +48,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import org.netbeans.modules.versioning.util.Utils; +import org.openide.modules.Places; import org.openide.util.NbPreferences; /** @@ -99,8 +100,7 @@ } private File getBaseFolder() { - String userDir = System.getProperty("netbeans.user"); // NOI18N - return new File(new File(new File(userDir, "var"), "cache"), "vcshistory"); // NOI18N + return Places.getCacheSubdirectory("vcshistory"); // NOI18N } private void cleanUp() { --- a/welcome/nbproject/project.xml +++ a/welcome/nbproject/project.xml @@ -68,6 +68,14 @@ + org.netbeans.modules.projectui + + + + 1.12 + + + org.netbeans.modules.projectuiapi @@ -77,14 +85,6 @@ - org.netbeans.modules.projectui - - - - 1.12 - - - org.openide.awt @@ -119,7 +119,7 @@ - 7.0 + 7.25 --- a/welcome/src/org/netbeans/modules/welcome/content/RSSFeed.java +++ a/welcome/src/org/netbeans/modules/welcome/content/RSSFeed.java @@ -92,7 +92,7 @@ import javax.xml.parsers.ParserConfigurationException; import org.openide.ErrorManager; import org.openide.awt.Mnemonics; -import org.openide.filesystems.FileUtil; +import org.openide.modules.Places; import org.openide.util.NbPreferences; import org.openide.util.RequestProcessor; import org.openide.util.WeakListeners; @@ -135,16 +135,7 @@ * Enclosing folder is created if it does not exist yet. */ private static File initCacheStore(String path) throws IOException { - File cacheStore; - String userDir = System.getProperty("netbeans.user"); // NOI18N - if (userDir != null) { - cacheStore = new File(new File(new File (userDir, "var"), "cache"), "welcome"); // NOI18N - } else { - File cachedir = FileUtil.toFile(FileUtil.getConfigRoot()); - cacheStore = new File(cachedir, "welcome"); // NOI18N - } - cacheStore = new File(cacheStore, path); - cacheStore.getParentFile().mkdirs(); + File cacheStore = Places.getCacheSubfile("welcome/" + path); // NOI18N cacheStore.createNewFile(); return cacheStore; } --- a/welcome/src/org/netbeans/modules/welcome/content/Utils.java +++ a/welcome/src/org/netbeans/modules/welcome/content/Utils.java @@ -64,7 +64,7 @@ import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.loaders.DataObject; -import org.openide.util.Lookup; +import org.openide.modules.Places; import org.openide.util.NbBundle; /** @@ -144,15 +144,7 @@ } public static File getCacheStore() throws IOException { - File cacheStore; - String userDir = System.getProperty("netbeans.user"); // NOI18N - if (userDir != null) { - cacheStore = new File(new File(new File (userDir, "var"), "cache"), "welcome"); // NOI18N - } else { - File cachedir = FileUtil.toFile(FileUtil.getConfigRoot()); - cacheStore = new File(cachedir, "welcome"); // NOI18N - } - return cacheStore; + return Places.getCacheSubdirectory("welcome"); // NOI18N } /**