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 168414
Collapse All | Expand All

(-)a/project.ant/src/org/netbeans/spi/project/support/ant/ExtensibleMetadataProviderImpl.java (-1 / +1 lines)
Lines 57-63 Link Here
57
    /**
57
    /**
58
     * Relative path from project directory to the required private cache directory.
58
     * Relative path from project directory to the required private cache directory.
59
     */
59
     */
60
    private static final String CACHE_PATH = "nbproject/private/cache"; // NOI18N
60
    private static final String CACHE_PATH = "nbproject/private"; // NOI18N
61
    
61
    
62
    private final AntProjectHelper helper;
62
    private final AntProjectHelper helper;
63
    
63
    
(-)a/projectapi/apichanges.xml (+17 lines)
Lines 104-109 Link Here
104
    <!-- ACTUAL CHANGES BEGIN HERE: -->
104
    <!-- ACTUAL CHANGES BEGIN HERE: -->
105
105
106
    <changes>
106
    <changes>
107
        <change id="ProjectUtils.getCacheDirectory">
108
            <api name="general"/>
109
            <summary>API complement to <code>CacheDirectoryProvider</code></summary>
110
            <version major="1" minor="26"/>
111
            <date day="21" month="7" year="2009"/>
112
            <author login="jglick"/>
113
            <compatibility addition="yes"/>
114
            <description>
115
                <p>
116
                    Added <code>ProjectUtils.getCacheDirectory</code> to complement
117
                    the SPI interface <code>CacheDirectoryProvider</code>.
118
                </p>
119
            </description>
120
            <class package="org.netbeans.api.project" name="ProjectUtils"/>
121
            <issue number="168414"/>
122
        </change>
123
107
        <change id="source-group-modifier">
124
        <change id="source-group-modifier">
108
            <api name="general"/>
125
            <api name="general"/>
109
            <summary>introduction of SourceGroupModifier, a way to create SourceGroup if missing</summary>
126
            <summary>introduction of SourceGroupModifier, a way to create SourceGroup if missing</summary>
(-)a/projectapi/manifest.mf (-1 / +1 lines)
Lines 1-7 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.modules.projectapi/1
2
OpenIDE-Module: org.netbeans.modules.projectapi/1
3
OpenIDE-Module-Install: org/netbeans/modules/projectapi/Installer.class
3
OpenIDE-Module-Install: org/netbeans/modules/projectapi/Installer.class
4
OpenIDE-Module-Specification-Version: 1.25
4
OpenIDE-Module-Specification-Version: 1.26
5
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/projectapi/Bundle.properties
5
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/projectapi/Bundle.properties
6
OpenIDE-Module-Layer: org/netbeans/modules/projectapi/layer.xml
6
OpenIDE-Module-Layer: org/netbeans/modules/projectapi/layer.xml
7
7
(-)a/projectapi/src/org/netbeans/api/project/ProjectUtils.java (-2 / +30 lines)
Lines 42-47 Link Here
42
package org.netbeans.api.project;
42
package org.netbeans.api.project;
43
43
44
import java.beans.PropertyChangeListener;
44
import java.beans.PropertyChangeListener;
45
import java.io.IOException;
45
import java.util.Collections;
46
import java.util.Collections;
46
import java.util.HashMap;
47
import java.util.HashMap;
47
import java.util.HashSet;
48
import java.util.HashSet;
Lines 49-67 Link Here
49
import java.util.Set;
50
import java.util.Set;
50
import java.util.prefs.Preferences;
51
import java.util.prefs.Preferences;
51
import javax.swing.Icon;
52
import javax.swing.Icon;
52
import javax.swing.ImageIcon;
53
import org.netbeans.modules.projectapi.AuxiliaryConfigBasedPreferencesProvider;
53
import org.netbeans.modules.projectapi.AuxiliaryConfigBasedPreferencesProvider;
54
import org.netbeans.modules.projectapi.AuxiliaryConfigImpl;
54
import org.netbeans.modules.projectapi.AuxiliaryConfigImpl;
55
import org.netbeans.spi.project.AuxiliaryConfiguration;
55
import org.netbeans.spi.project.AuxiliaryConfiguration;
56
import org.netbeans.spi.project.AuxiliaryProperties;
56
import org.netbeans.spi.project.AuxiliaryProperties;
57
import org.netbeans.spi.project.CacheDirectoryProvider;
57
import org.netbeans.spi.project.SubprojectProvider;
58
import org.netbeans.spi.project.SubprojectProvider;
58
import org.netbeans.spi.project.support.GenericSources;
59
import org.netbeans.spi.project.support.GenericSources;
59
import org.openide.filesystems.FileObject;
60
import org.openide.filesystems.FileObject;
60
import org.openide.filesystems.FileStateInvalidException;
61
import org.openide.filesystems.FileStateInvalidException;
62
import org.openide.filesystems.FileUtil;
61
import org.openide.util.ImageUtilities;
63
import org.openide.util.ImageUtilities;
62
import org.openide.util.Mutex;
64
import org.openide.util.Mutex;
63
import org.openide.util.Parameters;
65
import org.openide.util.Parameters;
64
import org.openide.util.Utilities;
65
66
66
/**
67
/**
67
 * Utility methods to get information about {@link Project}s.
68
 * Utility methods to get information about {@link Project}s.
Lines 263-266 Link Here
263
        return new AuxiliaryConfigImpl(project);
264
        return new AuxiliaryConfigImpl(project);
264
    }
265
    }
265
266
267
    /**
268
     * Gets a directory in which modules may store arbitrary extra unversioned files
269
     * associated with a project.
270
     * These could be caches of information found in sources, logs or snapshots
271
     * from activities associated with developing the project, etc.
272
     * <p>
273
     * If the project supplies a {@link CacheDirectoryProvider}, that will be used
274
     * for the parent directory. Otherwise an unspecified storage area will be used.
275
     * @param project a project
276
     * @param owner a class from the calling module (each module or package will get its own space)
277
     * @return a directory available for storing miscellaneous files
278
     * @throws IOException if no such directory could be created
279
     * @since org.netbeans.modules.projectapi/1 1.26
280
     */
281
    public static FileObject getCacheDirectory(Project project, Class<?> owner) throws IOException {
282
        FileObject d;
283
        CacheDirectoryProvider cdp = project.getLookup().lookup(CacheDirectoryProvider.class);
284
        if (cdp != null) {
285
            d = cdp.getCacheDirectory();
286
        } else {
287
            d = FileUtil.createFolder(FileUtil.getConfigRoot(),
288
                    String.format("Projects/extra/%s-%08x", getInformation(project).getName(), // NOI18N
289
                                  project.getProjectDirectory().getPath().hashCode()));
290
        }
291
        return FileUtil.createFolder(d, AuxiliaryConfigBasedPreferencesProvider.findCNBForClass(owner));
292
    }
293
266
}
294
}
(-)a/projectapi/src/org/netbeans/modules/projectapi/AuxiliaryConfigBasedPreferencesProvider.java (-1 / +1 lines)
Lines 316-322 Link Here
316
        modified = true;
316
        modified = true;
317
    }
317
    }
318
    
318
    
319
    private static String findCNBForClass(Class cls) {
319
    public static String findCNBForClass(Class cls) {
320
        String absolutePath = null;
320
        String absolutePath = null;
321
        ClassLoader cl = cls.getClassLoader();
321
        ClassLoader cl = cls.getClassLoader();
322
        for (ModuleInfo module : Lookup.getDefault().lookupAll(ModuleInfo.class)) {
322
        for (ModuleInfo module : Lookup.getDefault().lookupAll(ModuleInfo.class)) {
(-)a/projectapi/test/unit/src/org/netbeans/api/project/ProjectUtilsTest.java (-1 / +57 lines)
Lines 41-52 Link Here
41
41
42
package org.netbeans.api.project;
42
package org.netbeans.api.project;
43
43
44
import java.beans.PropertyChangeListener;
44
import java.io.File;
45
import java.io.File;
46
import java.io.IOException;
45
import java.util.Arrays;
47
import java.util.Arrays;
46
import java.util.HashSet;
48
import java.util.HashSet;
47
import java.util.Set;
49
import java.util.Set;
50
import javax.swing.Icon;
48
import javax.swing.event.ChangeListener;
51
import javax.swing.event.ChangeListener;
49
import org.netbeans.junit.NbTestCase;
52
import org.netbeans.junit.NbTestCase;
53
import org.netbeans.spi.project.CacheDirectoryProvider;
50
import org.netbeans.spi.project.SubprojectProvider;
54
import org.netbeans.spi.project.SubprojectProvider;
51
import org.openide.filesystems.FileObject;
55
import org.openide.filesystems.FileObject;
52
import org.openide.filesystems.FileUtil;
56
import org.openide.filesystems.FileUtil;
Lines 209-218 Link Here
209
        
213
        
210
        public void removeChangeListener(ChangeListener l) {}
214
        public void removeChangeListener(ChangeListener l) {}
211
        
215
        
212
        public String toString() {
216
        public @Override String toString() {
213
            return name;
217
            return name;
214
        }
218
        }
215
219
216
    }
220
    }
221
222
    public void testGetCacheDirectory() throws Exception {
223
        final FileObject pdir = FileUtil.createMemoryFileSystem().getRoot().createFolder("foo");
224
        final ProjectInformation info = new ProjectInformation() {
225
            public String getName() {
226
                return "foo-project";
227
            }
228
            public String getDisplayName() {
229
                return getName();
230
            }
231
            public Icon getIcon() {
232
                return null;
233
            }
234
            public Project getProject() {
235
                return null;
236
            }
237
            public void addPropertyChangeListener(PropertyChangeListener listener) {}
238
            public void removePropertyChangeListener(PropertyChangeListener listener) {}
239
        };
240
        Project p = new Project() {
241
            public FileObject getProjectDirectory() {
242
                return pdir;
243
            }
244
            public Lookup getLookup() {
245
                return Lookups.fixed(info);
246
            }
247
        };
248
        FileObject d = ProjectUtils.getCacheDirectory(p, Object.class);
249
        assertEquals(FileUtil.getConfigRoot().getFileSystem(), d.getFileSystem());
250
        assertEquals("Projects/extra/foo-project-00018cc6/java-lang", d.getPath());
251
        d = ProjectUtils.getCacheDirectory(p, Object.class);
252
        assertEquals("Projects/extra/foo-project-00018cc6/java-lang", d.getPath());
253
        final FileObject cache = FileUtil.createMemoryFileSystem().getRoot();
254
        p = new Project() {
255
            public FileObject getProjectDirectory() {
256
                return pdir;
257
            }
258
            public Lookup getLookup() {
259
                return Lookups.fixed(info, new CacheDirectoryProvider() {
260
                    public FileObject getCacheDirectory() throws IOException {
261
                        return cache;
262
                    }
263
                });
264
            }
265
        };
266
        d = ProjectUtils.getCacheDirectory(p, Object.class);
267
        assertEquals("java-lang", d.getNameExt());
268
        assertEquals(cache, d.getParent());
269
        d = ProjectUtils.getCacheDirectory(p, Object.class);
270
        assertEquals("java-lang", d.getNameExt());
271
        assertEquals(cache, d.getParent());
272
    }
217
    
273
    
218
}
274
}

Return to bug 168414