This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 201350
Collapse All | Expand All

(-)a/core.startup/manifest.mf (-1 / +1 lines)
Lines 3-7 Link Here
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/core/startup/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/core/startup/Bundle.properties
4
OpenIDE-Module-Layer: org/netbeans/core/startup/layer.xml
4
OpenIDE-Module-Layer: org/netbeans/core/startup/layer.xml
5
OpenIDE-Module-Provides: org.openide.modules.InstalledFileLocator
5
OpenIDE-Module-Provides: org.openide.modules.InstalledFileLocator
6
OpenIDE-Module-Specification-Version: 1.33
6
OpenIDE-Module-Specification-Version: 1.34
7
7
(-)a/core.startup/src/org/netbeans/core/startup/CLIOptions.java (-2 / +11 lines)
Lines 85-90 Link Here
85
    private static String userDir;
85
    private static String userDir;
86
    /** The netbeans system dir - ${netbeans.user}/system */
86
    /** The netbeans system dir - ${netbeans.user}/system */
87
    private static String systemDir;
87
    private static String systemDir;
88
    private static File cacheDir;
88
89
89
    /**
90
    /**
90
     * Create a default handler.
91
     * Create a default handler.
Lines 135-141 Link Here
135
                args[i] = null;
136
                args[i] = null;
136
                try {
137
                try {
137
                    String v = args[++i];
138
                    String v = args[++i];
138
                    Places.setUserDirectory(v.equals(/*Places.MEMORY*/"memory") ? null : FileUtil.normalizeFile(new File(v)));
139
                    if (!v.equals(/*Places.MEMORY*/"memory")) {
140
                        v = FileUtil.normalizeFile(new File(v)).getPath();
141
                    }
142
                    userDir = v;
143
                    System.setProperty("netbeans.user", v);
139
                } catch(ArrayIndexOutOfBoundsException e) {
144
                } catch(ArrayIndexOutOfBoundsException e) {
140
                    System.err.println(getString("ERR_UserDirExpected"));
145
                    System.err.println(getString("ERR_UserDirExpected"));
141
                    return 2;
146
                    return 2;
Lines 143-149 Link Here
143
            } else if (isOption(args[i], "cachedir")) { // NOI18N
148
            } else if (isOption(args[i], "cachedir")) { // NOI18N
144
                args[i] = null;
149
                args[i] = null;
145
                try {
150
                try {
146
                    Places.setCacheDirectory(FileUtil.normalizeFile(new File(args[++i])));
151
                    cacheDir = FileUtil.normalizeFile(new File(args[++i]));
147
                } catch(ArrayIndexOutOfBoundsException e) {
152
                } catch(ArrayIndexOutOfBoundsException e) {
148
                    System.err.println(getString("ERR_UserDirExpected"));
153
                    System.err.println(getString("ERR_UserDirExpected"));
149
                    return 2;
154
                    return 2;
Lines 325-330 Link Here
325
        }
330
        }
326
        return userDir;
331
        return userDir;
327
    }
332
    }
333
    
334
    public static File getCacheDir() {
335
        return cacheDir;
336
    }
328
337
329
    private static void makedir (File f) {
338
    private static void makedir (File f) {
330
        if (f.isFile ()) {
339
        if (f.isFile ()) {
(-)ac91c811bd21 (+66 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common Development and
11
 * Distribution License("CDDL") (collectively, the "License"). You may not use
12
 * this file except in compliance with the License. You can obtain a copy of
13
 * the License at http://www.netbeans.org/cddl-gplv2.html or
14
 * nbbuild/licenses/CDDL-GPL-2-CP. See the License for the specific language
15
 * governing permissions and limitations under the License. When distributing
16
 * the software, include this License Header Notice in each file and include
17
 * the License file at nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
18
 * particular file as subject to the "Classpath" exception as provided by
19
 * Oracle in the GPL Version 2 section of the License file that accompanied
20
 * this code. If applicable, add the following below the License Header, with
21
 * the fields enclosed by brackets [] replaced by your own identifying
22
 * information: "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL or
25
 * only the GPL Version 2, indicate your decision by adding "[Contributor]
26
 * elects to include this software in this distribution under the [CDDL or GPL
27
 * Version 2] license." If you do not indicate a single choice of license, a
28
 * recipient has the option to distribute your version of this file under
29
 * either the CDDL, the GPL Version 2 or to extend the choice of license to its
30
 * licensees as provided above. However, if you add GPL Version 2 code and
31
 * therefore, elected the GPL Version 2 license, then the option applies only
32
 * if the new code is made subject to such option by the copyright holder.
33
 *
34
 * Contributor(s):
35
 *
36
 * Portions Copyrighted 2011 Sun Microsystems, Inc.
37
 */
38
package org.netbeans.core.startup;
39
40
import java.io.File;
41
import org.openide.modules.Places;
42
import org.openide.util.lookup.ServiceProvider;
43
44
/** Implementation of Places to deal with command line --cachedir argument.
45
 *
46
 * @author Jaroslav Tulach <jtulach@netbeans.org>
47
 */
48
@ServiceProvider(service=Places.class)
49
public final class NbPlaces extends Places {
50
51
    @Override
52
    protected File findCacheDirectory() {
53
        return CLIOptions.getCacheDir();
54
    }
55
56
    @Override
57
    protected File findUserDirectory() {
58
        String ud = CLIOptions.getUserDir();
59
        if ("memory".equals(ud)) { // NOI18N
60
            return null;
61
        } else {
62
            return new File(ud);
63
        }
64
    }
65
    
66
}
(-)a/core.startup/test/unit/src/org/netbeans/core/startup/CLIOptionsTest.java (-1 / +4 lines)
Lines 46-51 Link Here
46
import java.io.File;
46
import java.io.File;
47
import org.netbeans.junit.NbTestCase;
47
import org.netbeans.junit.NbTestCase;
48
import org.openide.filesystems.FileUtil;
48
import org.openide.filesystems.FileUtil;
49
import org.openide.modules.Places;
49
import org.openide.util.Utilities;
50
import org.openide.util.Utilities;
50
51
51
/**
52
/**
Lines 106-112 Link Here
106
        assertFalse("-userdir is not supported", "wrong".equals(System.getProperty("netbeans.user")));
107
        assertFalse("-userdir is not supported", "wrong".equals(System.getProperty("netbeans.user")));
107
        
108
        
108
        new CLIOptions().cli(new String[] { "--userdir", "correct" });
109
        new CLIOptions().cli(new String[] { "--userdir", "correct" });
109
        assertEquals("--userdir is supported", FileUtil.normalizeFile(new File("correct")).getAbsolutePath(), System.getProperty("netbeans.user"));
110
        final File exp = FileUtil.normalizeFile(new File("correct"));
111
        assertEquals("--userdir is supported via places", exp, Places.getUserDirectory());
112
        assertEquals("--userdir is supported", exp.getAbsolutePath(), System.getProperty("netbeans.user"));
110
        
113
        
111
        if (orig != null) {
114
        if (orig != null) {
112
            System.setProperty("netbeans.user", orig);
115
            System.setProperty("netbeans.user", orig);
(-)a/core.startup/test/unit/src/org/netbeans/core/startup/ModuleListTest.java (-1 / +2 lines)
Lines 110-116 Link Here
110
        MockLookup.setInstances(new IFL());
110
        MockLookup.setInstances(new IFL());
111
111
112
        File ud = new File(getWorkDir(), "ud");
112
        File ud = new File(getWorkDir(), "ud");
113
        Places.setUserDirectory(ud);
113
        ud.mkdirs();
114
        System.setProperty("netbeans.user", ud.getPath());
114
        
115
        
115
        MockModuleInstaller installer = new MockModuleInstaller();
116
        MockModuleInstaller installer = new MockModuleInstaller();
116
        MockEvents ev = new MockEvents();
117
        MockEvents ev = new MockEvents();
(-)a/core.startup/test/unit/src/org/netbeans/core/startup/NbInstallerTest9.java (-1 / +1 lines)
Lines 67-73 Link Here
67
    /** Test #26786/#28755: manifest caching can be buggy.
67
    /** Test #26786/#28755: manifest caching can be buggy.
68
     */
68
     */
69
    public void testManifestCaching() throws Exception {
69
    public void testManifestCaching() throws Exception {
70
        Places.setUserDirectory(getWorkDir());
70
        System.setProperty("netbeans.user", getWorkDirPath());
71
        ModuleInstaller inst = new org.netbeans.core.startup.NbInstaller(new MockEvents());
71
        ModuleInstaller inst = new org.netbeans.core.startup.NbInstaller(new MockEvents());
72
        File littleJar = new File(jars, "little-manifest.jar");
72
        File littleJar = new File(jars, "little-manifest.jar");
73
        //inst.loadManifest(littleJar).write(System.out);
73
        //inst.loadManifest(littleJar).write(System.out);
(-)a/csl.api/test/unit/src/org/netbeans/modules/csl/api/test/CslTestBase.java (-2 / +1 lines)
Lines 200-206 Link Here
200
import org.netbeans.spi.java.classpath.ClassPathProvider;
200
import org.netbeans.spi.java.classpath.ClassPathProvider;
201
import org.openide.loaders.DataObject;
201
import org.openide.loaders.DataObject;
202
import org.openide.loaders.DataObjectNotFoundException;
202
import org.openide.loaders.DataObjectNotFoundException;
203
import org.openide.modules.Places;
204
import org.openide.util.test.MockLookup;
203
import org.openide.util.test.MockLookup;
205
204
206
/**
205
/**
Lines 219-225 Link Here
219
        super.setUp();
218
        super.setUp();
220
219
221
        clearWorkDir();
220
        clearWorkDir();
222
        Places.setUserDirectory(getWorkDir());
221
        System.setProperty("netbeans.user", getWorkDirPath());
223
        // XXX are the following four lines actually necessary?
222
        // XXX are the following four lines actually necessary?
224
        final FileObject wd = FileUtil.toFileObject(getWorkDir());
223
        final FileObject wd = FileUtil.toFileObject(getWorkDir());
225
        assert wd != null;
224
        assert wd != null;
(-)a/maven.indexer/test/unit/src/org/netbeans/modules/maven/indexer/NexusRepositoryIndexerImplTest.java (-2 / +1 lines)
Lines 57-63 Link Here
57
import org.netbeans.modules.maven.indexer.api.RepositoryInfo;
57
import org.netbeans.modules.maven.indexer.api.RepositoryInfo;
58
import org.netbeans.modules.maven.indexer.api.RepositoryPreferences;
58
import org.netbeans.modules.maven.indexer.api.RepositoryPreferences;
59
import org.netbeans.modules.maven.indexer.spi.ClassUsageQuery.ClassUsageResult;
59
import org.netbeans.modules.maven.indexer.spi.ClassUsageQuery.ClassUsageResult;
60
import org.openide.modules.Places;
61
import org.openide.util.test.JarBuilder;
60
import org.openide.util.test.JarBuilder;
62
import org.openide.util.test.TestFileUtils;
61
import org.openide.util.test.TestFileUtils;
63
62
Lines 75-81 Link Here
75
    
74
    
76
    @Override protected void setUp() throws Exception {
75
    @Override protected void setUp() throws Exception {
77
        clearWorkDir();
76
        clearWorkDir();
78
        Places.setUserDirectory(getWorkDir());
77
        System.setProperty("netbeans.user", getWorkDirPath());
79
        File repo = new File(getWorkDir(), "repo");
78
        File repo = new File(getWorkDir(), "repo");
80
        embedder = EmbedderFactory.getProjectEmbedder();
79
        embedder = EmbedderFactory.getProjectEmbedder();
81
        defaultArtifactRepository = embedder.lookupComponent(ArtifactRepositoryFactory.class).createArtifactRepository("test", repo.toURI().toString(), "default", null, null);
80
        defaultArtifactRepository = embedder.lookupComponent(ArtifactRepositoryFactory.class).createArtifactRepository("test", repo.toURI().toString(), "default", null, null);
(-)a/o.n.bootstrap/test/unit/src/org/netbeans/StampsExtraTest.java (-1 / +1 lines)
Lines 78-84 Link Here
78
        
78
        
79
        System.setProperty("netbeans.home", platform.getPath());
79
        System.setProperty("netbeans.home", platform.getPath());
80
        System.setProperty("netbeans.dirs", ide.getPath() + File.pathSeparator + extra.getPath());
80
        System.setProperty("netbeans.dirs", ide.getPath() + File.pathSeparator + extra.getPath());
81
        Places.setUserDirectory(userdir);
81
        System.setProperty("netbeans.user", userdir.getPath());
82
82
83
        touch(platform, ".lastModified", 50000L);
83
        touch(platform, ".lastModified", 50000L);
84
        touch(ide, ".lastModified", 90000L);
84
        touch(ide, ".lastModified", 90000L);
(-)a/o.n.bootstrap/test/unit/src/org/netbeans/StampsIdeLessThanPlatformTest.java (-1 / +1 lines)
Lines 84-90 Link Here
84
        
84
        
85
        System.setProperty("netbeans.home", platform.getPath());
85
        System.setProperty("netbeans.home", platform.getPath());
86
        System.setProperty("netbeans.dirs", ide.getPath() + File.pathSeparator + nonexist.getPath());
86
        System.setProperty("netbeans.dirs", ide.getPath() + File.pathSeparator + nonexist.getPath());
87
        Places.setUserDirectory(userdir);
87
        System.setProperty("netbeans.user", userdir.getPath());
88
        
88
        
89
        StampsTest.createModule("org.openide.awt", platform, 50000L);
89
        StampsTest.createModule("org.openide.awt", platform, 50000L);
90
        StampsTest.createModule("org.openide.nodes", platform, 60000L);
90
        StampsTest.createModule("org.openide.nodes", platform, 60000L);
(-)a/openide.modules/apichanges.xml (-2 / +2 lines)
Lines 53-60 Link Here
53
    <change id="Places">
53
    <change id="Places">
54
        <api name="modules"/>
54
        <api name="modules"/>
55
        <summary>Added <code>Places</code></summary>
55
        <summary>Added <code>Places</code></summary>
56
        <version major="7" minor="25"/>
56
        <version major="7" minor="26"/>
57
        <date day="4" month="8" year="2011"/>
57
        <date day="1" month="9" year="2011"/>
58
        <author login="jglick"/>
58
        <author login="jglick"/>
59
        <compatibility>
59
        <compatibility>
60
            <p>
60
            <p>
(-)a/openide.modules/manifest.mf (-1 / +1 lines)
Lines 1-5 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.openide.modules
2
OpenIDE-Module: org.openide.modules
3
OpenIDE-Module-Localizing-Bundle: org/openide/modules/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/openide/modules/Bundle.properties
4
OpenIDE-Module-Specification-Version: 7.25
4
OpenIDE-Module-Specification-Version: 7.26
5
5
(-)a/openide.modules/src/org/openide/modules/Places.java (-30 / +36 lines)
Lines 41-46 Link Here
41
import java.io.File;
41
import java.io.File;
42
import java.util.logging.Level;
42
import java.util.logging.Level;
43
import java.util.logging.Logger;
43
import java.util.logging.Logger;
44
import org.openide.util.Lookup;
45
import org.openide.util.lookup.ServiceProvider;
44
46
45
/**
47
/**
46
 * Provides access to standard file locations.
48
 * Provides access to standard file locations.
Lines 52-73 Link Here
52
 * <li>{@code someClass.getProtectionDomain().getCodeSource().getLocation()} to find resources inside a module class loader.
54
 * <li>{@code someClass.getProtectionDomain().getCodeSource().getLocation()} to find resources inside a module class loader.
53
 * </ul>
55
 * </ul>
54
 * </div>
56
 * </div>
55
 * @since 7.25
57
 * @since 7.26
56
 */
58
 */
57
public class Places {
59
public abstract class Places {
58
60
59
    /**
61
    /**
60
     * System property key for {@link #getUserDirectory}.
62
     * System property key for {@link #getUserDirectory}. Can be used 
61
     * Should not be used by most code directly.
63
     * from a testing code to influence the location of user directory
64
     * when no {@link Places} implementation if found in {@link Lookup#getDefault()}.
62
     */
65
     */
63
    public static final String USER_DIR_PROP = "netbeans.user";
66
    public static final String USER_DIR_PROP = "netbeans.user";
64
67
65
    private static final String MEMORY = "memory";
66
67
    private static final Logger LOG = Logger.getLogger(Places.class.getName());
68
    private static final Logger LOG = Logger.getLogger(Places.class.getName());
68
69
69
    private static File cacheDir;
70
71
    /**
70
    /**
72
     * Locates the NetBeans user directory.
71
     * Locates the NetBeans user directory.
73
     * This may be used to persist valuable files for which the system filesystem
72
     * This may be used to persist valuable files for which the system filesystem
Lines 77-94 Link Here
77
     * @return a directory location (need not yet exist), or null if unconfigured
76
     * @return a directory location (need not yet exist), or null if unconfigured
78
     */
77
     */
79
    public static synchronized /*@CheckForNull*/ File getUserDirectory() {
78
    public static synchronized /*@CheckForNull*/ File getUserDirectory() {
79
        Places places = Lookup.getDefault().lookup(Places.class);
80
        if (places != null) {
81
            return places.findUserDirectory();
82
        }
80
        String p = System.getProperty(USER_DIR_PROP);
83
        String p = System.getProperty(USER_DIR_PROP);
81
        return p != null && !p.equals(MEMORY) ? new File(p) : null;
84
        return p != null ? new File(p) : null;
82
    }
83
84
    /**
85
     * Configures the NetBeans user directory.
86
     * This would be called by startup code in the NetBeans Platform,
87
     * but might also be useful to call from a unit test if tested code calls {@link #getUserDirectory} or {@link #getCacheDirectory}.
88
     * @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
89
     */
90
    public static synchronized void setUserDirectory(/*@NullAllowed*/ File dir) {
91
        System.setProperty(USER_DIR_PROP, dir != null ? dir.getAbsolutePath() : MEMORY);
92
    }
85
    }
93
86
94
    /**
87
    /**
Lines 103-110 Link Here
103
     * @see #getCacheSubfile
96
     * @see #getCacheSubfile
104
     */
97
     */
105
    public static synchronized /*@NonNull*/ File getCacheDirectory() {
98
    public static synchronized /*@NonNull*/ File getCacheDirectory() {
106
        if (cacheDir != null) {
99
        Places places = Lookup.getDefault().lookup(Places.class);
107
            return cacheDir;
100
        if (places != null) {
101
            File cache = places.findCacheDirectory();
102
            if (cache != null) {
103
                return cache;
104
            }
108
        }
105
        }
109
        File userdir = getUserDirectory();
106
        File userdir = getUserDirectory();
110
        if (userdir != null) {
107
        if (userdir != null) {
Lines 143-158 Link Here
143
        return f;
140
        return f;
144
    }
141
    }
145
142
146
    /**
143
    /** Constructor for those who believe to know 
147
     * Configures the NetBeans cache directory.
144
     * where {@link #getCacheDirectory} or
148
     * This would be called by startup code in the NetBeans Platform,
145
     * {@link #getUserDirectory()} is. Register your subclass via
149
     * but might also be useful to call from a unit test if tested code calls {@link #getCacheDirectory}.
146
     * {@link ServiceProvider} annotation. 
150
     * @param dir a directory location (need not yet exist)
151
     */
147
     */
152
    public static synchronized void setCacheDirectory(/*@NonNull*/ File dir) {
148
    protected Places() {
153
        cacheDir = dir;
154
    }
149
    }
155
150
156
    private Places() {}
151
    /** The cache directory to return from {@link #getCacheDirectory}.
157
152
     * If <code>null</code> the caches will be placed below {@link #getUserDirectory()}.
153
     * @return the file to use for caches or null 
154
     * @since 7.26
155
     */
156
    protected abstract File findCacheDirectory();
157
    
158
    /** Finds location of a user directory to return from {@link #getUserDirectory}.
159
     * @return the user directory or <code>null</code> if no user directory is
160
     *   supposed to be used
161
     * @since 7.26
162
     */
163
    protected abstract File findUserDirectory();
158
}
164
}

Return to bug 201350