diff -r ac91c811bd21 core.startup/manifest.mf --- a/core.startup/manifest.mf Thu Aug 25 10:36:54 2011 +0200 +++ b/core.startup/manifest.mf Fri Aug 26 13:09:38 2011 +0200 @@ -3,5 +3,5 @@ OpenIDE-Module-Localizing-Bundle: org/netbeans/core/startup/Bundle.properties OpenIDE-Module-Layer: org/netbeans/core/startup/layer.xml OpenIDE-Module-Provides: org.openide.modules.InstalledFileLocator -OpenIDE-Module-Specification-Version: 1.33 +OpenIDE-Module-Specification-Version: 1.34 diff -r ac91c811bd21 core.startup/src/org/netbeans/core/startup/CLIOptions.java --- a/core.startup/src/org/netbeans/core/startup/CLIOptions.java Thu Aug 25 10:36:54 2011 +0200 +++ b/core.startup/src/org/netbeans/core/startup/CLIOptions.java Fri Aug 26 13:09:38 2011 +0200 @@ -85,6 +85,7 @@ private static String userDir; /** The netbeans system dir - ${netbeans.user}/system */ private static String systemDir; + private static File cacheDir; /** * Create a default handler. @@ -135,7 +136,11 @@ args[i] = null; try { String v = args[++i]; - Places.setUserDirectory(v.equals(/*Places.MEMORY*/"memory") ? null : FileUtil.normalizeFile(new File(v))); + if (!v.equals(/*Places.MEMORY*/"memory")) { + v = FileUtil.normalizeFile(new File(v)).getPath(); + } + userDir = v; + System.setProperty("netbeans.user", v); } catch(ArrayIndexOutOfBoundsException e) { System.err.println(getString("ERR_UserDirExpected")); return 2; @@ -143,7 +148,7 @@ } else if (isOption(args[i], "cachedir")) { // NOI18N args[i] = null; try { - Places.setCacheDirectory(FileUtil.normalizeFile(new File(args[++i]))); + cacheDir = FileUtil.normalizeFile(new File(args[++i])); } catch(ArrayIndexOutOfBoundsException e) { System.err.println(getString("ERR_UserDirExpected")); return 2; @@ -325,6 +330,10 @@ } return userDir; } + + public static File getCacheDir() { + return cacheDir; + } private static void makedir (File f) { if (f.isFile ()) { diff -r ac91c811bd21 core.startup/src/org/netbeans/core/startup/NbPlaces.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core.startup/src/org/netbeans/core/startup/NbPlaces.java Fri Aug 26 13:09:38 2011 +0200 @@ -0,0 +1,66 @@ +/* + * 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.netbeans.core.startup; + +import java.io.File; +import org.openide.modules.Places; +import org.openide.util.lookup.ServiceProvider; + +/** Implementation of Places to deal with command line --cachedir argument. + * + * @author Jaroslav Tulach + */ +@ServiceProvider(service=Places.class) +public final class NbPlaces extends Places { + + @Override + protected File findCacheDirectory() { + return CLIOptions.getCacheDir(); + } + + @Override + protected File findUserDirectory() { + String ud = CLIOptions.getUserDir(); + if ("memory".equals(ud)) { // NOI18N + return null; + } else { + return new File(ud); + } + } + +} diff -r ac91c811bd21 core.startup/test/unit/src/org/netbeans/core/startup/CLIOptionsTest.java --- a/core.startup/test/unit/src/org/netbeans/core/startup/CLIOptionsTest.java Thu Aug 25 10:36:54 2011 +0200 +++ b/core.startup/test/unit/src/org/netbeans/core/startup/CLIOptionsTest.java Fri Aug 26 13:09:38 2011 +0200 @@ -46,6 +46,7 @@ import java.io.File; import org.netbeans.junit.NbTestCase; import org.openide.filesystems.FileUtil; +import org.openide.modules.Places; import org.openide.util.Utilities; /** @@ -106,7 +107,9 @@ assertFalse("-userdir is not supported", "wrong".equals(System.getProperty("netbeans.user"))); new CLIOptions().cli(new String[] { "--userdir", "correct" }); - assertEquals("--userdir is supported", FileUtil.normalizeFile(new File("correct")).getAbsolutePath(), System.getProperty("netbeans.user")); + final File exp = FileUtil.normalizeFile(new File("correct")); + assertEquals("--userdir is supported via places", exp, Places.getUserDirectory()); + assertEquals("--userdir is supported", exp.getAbsolutePath(), System.getProperty("netbeans.user")); if (orig != null) { System.setProperty("netbeans.user", orig); diff -r ac91c811bd21 core.startup/test/unit/src/org/netbeans/core/startup/ModuleListTest.java --- a/core.startup/test/unit/src/org/netbeans/core/startup/ModuleListTest.java Thu Aug 25 10:36:54 2011 +0200 +++ b/core.startup/test/unit/src/org/netbeans/core/startup/ModuleListTest.java Fri Aug 26 13:09:38 2011 +0200 @@ -110,7 +110,8 @@ MockLookup.setInstances(new IFL()); File ud = new File(getWorkDir(), "ud"); - Places.setUserDirectory(ud); + ud.mkdirs(); + System.setProperty("netbeans.user", ud.getPath()); MockModuleInstaller installer = new MockModuleInstaller(); MockEvents ev = new MockEvents(); diff -r ac91c811bd21 core.startup/test/unit/src/org/netbeans/core/startup/NbInstallerTest9.java --- a/core.startup/test/unit/src/org/netbeans/core/startup/NbInstallerTest9.java Thu Aug 25 10:36:54 2011 +0200 +++ b/core.startup/test/unit/src/org/netbeans/core/startup/NbInstallerTest9.java Fri Aug 26 13:09:38 2011 +0200 @@ -67,7 +67,7 @@ /** Test #26786/#28755: manifest caching can be buggy. */ public void testManifestCaching() throws Exception { - Places.setUserDirectory(getWorkDir()); + System.setProperty("netbeans.user", getWorkDirPath()); ModuleInstaller inst = new org.netbeans.core.startup.NbInstaller(new MockEvents()); File littleJar = new File(jars, "little-manifest.jar"); //inst.loadManifest(littleJar).write(System.out); diff -r ac91c811bd21 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 Thu Aug 25 10:36:54 2011 +0200 +++ b/csl.api/test/unit/src/org/netbeans/modules/csl/api/test/CslTestBase.java Fri Aug 26 13:09:38 2011 +0200 @@ -200,7 +200,6 @@ 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; /** @@ -219,7 +218,7 @@ super.setUp(); clearWorkDir(); - Places.setUserDirectory(getWorkDir()); + System.setProperty("netbeans.user", getWorkDirPath()); // XXX are the following four lines actually necessary? final FileObject wd = FileUtil.toFileObject(getWorkDir()); assert wd != null; diff -r ac91c811bd21 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 Thu Aug 25 10:36:54 2011 +0200 +++ b/maven.indexer/test/unit/src/org/netbeans/modules/maven/indexer/NexusRepositoryIndexerImplTest.java Fri Aug 26 13:09:38 2011 +0200 @@ -57,7 +57,6 @@ 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; @@ -75,7 +74,7 @@ @Override protected void setUp() throws Exception { clearWorkDir(); - Places.setUserDirectory(getWorkDir()); + System.setProperty("netbeans.user", getWorkDirPath()); File repo = new File(getWorkDir(), "repo"); embedder = EmbedderFactory.getProjectEmbedder(); defaultArtifactRepository = embedder.lookupComponent(ArtifactRepositoryFactory.class).createArtifactRepository("test", repo.toURI().toString(), "default", null, null); diff -r ac91c811bd21 o.n.bootstrap/test/unit/src/org/netbeans/StampsExtraTest.java --- a/o.n.bootstrap/test/unit/src/org/netbeans/StampsExtraTest.java Thu Aug 25 10:36:54 2011 +0200 +++ b/o.n.bootstrap/test/unit/src/org/netbeans/StampsExtraTest.java Fri Aug 26 13:09:38 2011 +0200 @@ -78,7 +78,7 @@ System.setProperty("netbeans.home", platform.getPath()); System.setProperty("netbeans.dirs", ide.getPath() + File.pathSeparator + extra.getPath()); - Places.setUserDirectory(userdir); + System.setProperty("netbeans.user", userdir.getPath()); touch(platform, ".lastModified", 50000L); touch(ide, ".lastModified", 90000L); diff -r ac91c811bd21 o.n.bootstrap/test/unit/src/org/netbeans/StampsIdeLessThanPlatformTest.java --- a/o.n.bootstrap/test/unit/src/org/netbeans/StampsIdeLessThanPlatformTest.java Thu Aug 25 10:36:54 2011 +0200 +++ b/o.n.bootstrap/test/unit/src/org/netbeans/StampsIdeLessThanPlatformTest.java Fri Aug 26 13:09:38 2011 +0200 @@ -84,7 +84,7 @@ System.setProperty("netbeans.home", platform.getPath()); System.setProperty("netbeans.dirs", ide.getPath() + File.pathSeparator + nonexist.getPath()); - Places.setUserDirectory(userdir); + System.setProperty("netbeans.user", userdir.getPath()); StampsTest.createModule("org.openide.awt", platform, 50000L); StampsTest.createModule("org.openide.nodes", platform, 60000L); diff -r ac91c811bd21 openide.modules/apichanges.xml --- a/openide.modules/apichanges.xml Thu Aug 25 10:36:54 2011 +0200 +++ b/openide.modules/apichanges.xml Fri Aug 26 13:09:38 2011 +0200 @@ -53,8 +53,8 @@ Added Places - - + +

diff -r ac91c811bd21 openide.modules/manifest.mf --- a/openide.modules/manifest.mf Thu Aug 25 10:36:54 2011 +0200 +++ b/openide.modules/manifest.mf Fri Aug 26 13:09:38 2011 +0200 @@ -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.25 +OpenIDE-Module-Specification-Version: 7.26 diff -r ac91c811bd21 openide.modules/src/org/openide/modules/Places.java --- a/openide.modules/src/org/openide/modules/Places.java Thu Aug 25 10:36:54 2011 +0200 +++ b/openide.modules/src/org/openide/modules/Places.java Fri Aug 26 13:09:38 2011 +0200 @@ -41,6 +41,8 @@ import java.io.File; import java.util.logging.Level; import java.util.logging.Logger; +import org.openide.util.Lookup; +import org.openide.util.lookup.ServiceProvider; /** * Provides access to standard file locations. @@ -52,22 +54,19 @@ *

  • {@code someClass.getProtectionDomain().getCodeSource().getLocation()} to find resources inside a module class loader. * * - * @since 7.25 + * @since 7.26 */ -public class Places { +public abstract class Places { /** - * System property key for {@link #getUserDirectory}. - * Should not be used by most code directly. + * System property key for {@link #getUserDirectory}. Can be used + * from a testing code to influence the location of user directory + * when no {@link Places} implementation if found in {@link Lookup#getDefault()}. */ 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 @@ -77,18 +76,12 @@ * @return a directory location (need not yet exist), or null if unconfigured */ public static synchronized /*@CheckForNull*/ File getUserDirectory() { + Places places = Lookup.getDefault().lookup(Places.class); + if (places != null) { + return places.findUserDirectory(); + } 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); + return p != null ? new File(p) : null; } /** @@ -103,8 +96,12 @@ * @see #getCacheSubfile */ public static synchronized /*@NonNull*/ File getCacheDirectory() { - if (cacheDir != null) { - return cacheDir; + Places places = Lookup.getDefault().lookup(Places.class); + if (places != null) { + File cache = places.findCacheDirectory(); + if (cache != null) { + return cache; + } } File userdir = getUserDirectory(); if (userdir != null) { @@ -143,16 +140,25 @@ 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) + /** Constructor for those who believe to know + * where {@link #getCacheDirectory} or + * {@link #getUserDirectory()} is. Register your subclass via + * {@link ServiceProvider} annotation. */ - public static synchronized void setCacheDirectory(/*@NonNull*/ File dir) { - cacheDir = dir; + protected Places() { } - private Places() {} - + /** The cache directory to return from {@link #getCacheDirectory}. + * If null the caches will be placed below {@link #getUserDirectory()}. + * @return the file to use for caches or null + * @since 7.26 + */ + protected abstract File findCacheDirectory(); + + /** Finds location of a user directory to return from {@link #getUserDirectory}. + * @return the user directory or null if no user directory is + * supposed to be used + * @since 7.26 + */ + protected abstract File findUserDirectory(); }