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

(-)projects/projectapi/apichanges.xml (+19 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="non-projects">
108
            <api name="general"/>
109
            <summary>Support for more easily replaceable projects</summary>
110
            <version major="1" minor="15"/>
111
            <date day="17" month="1" year="2008"/>
112
            <author login="jtulach"/>
113
            <compatibility addition="yes" binary="compatible" deletion="no" deprecation="no" modification="no" semantic="compatible" source="compatible">
114
            </compatibility>
115
            <description>
116
	        <p>
117
                <code>ProjectManager.clearNonProjectCache()</code> now discards
118
                also projects which are named in a special way. If their class name
119
                contains <code>NonProject</code>, then they are freed from the cache.
120
            </p>
121
            </description>
122
            <class package="org.netbeans.api.project" name="ProjectManager"/>
123
            <issue number="124975"/>
124
        </change>
125
        
107
        <change id="lookup-provider">
126
        <change id="lookup-provider">
108
            <api name="general"/>
127
            <api name="general"/>
109
            <summary>Added support for composing project's lookup from multiple sources.</summary>
128
            <summary>Added support for composing project's lookup from multiple sources.</summary>
(-)projects/projectapi/arch.xml (-3 / +5 lines)
Lines 457-465 Link Here
457
        </question>
457
        </question>
458
-->
458
-->
459
 <answer id="exec-introspection">
459
 <answer id="exec-introspection">
460
  <p>
460
   <api name="NonProject" category="devel" group="java" type="export" url="@TOP@/org/netbeans/api/project/ProjectManager.html#clearNonProjectCache()">
461
   No.
461
                <code>ProjectManager.clearNonProjectCache()</code> now discards
462
  </p>
462
                also projects which are named in a special way. If their class name
463
                contains <code>NonProject</code>, then they are freed from the cache.
464
    </api>
463
 </answer>
465
 </answer>
464
466
465
467
(-)projects/projectapi/manifest.mf (-1 / +1 lines)
Lines 1-5 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-Specification-Version: 1.14
3
OpenIDE-Module-Specification-Version: 1.15
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/projectapi/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/projectapi/Bundle.properties
5
5
(-)projects/projectapi/src/org/netbeans/api/project/ProjectManager.java (+19 lines)
Lines 48-53 Link Here
48
import java.util.HashSet;
48
import java.util.HashSet;
49
import java.util.Iterator;
49
import java.util.Iterator;
50
import java.util.Map;
50
import java.util.Map;
51
import java.util.Map.Entry;
51
import java.util.Set;
52
import java.util.Set;
52
import java.util.WeakHashMap;
53
import java.util.WeakHashMap;
53
import java.util.logging.Level;
54
import java.util.logging.Level;
Lines 466-471 Link Here
466
     * This may be useful after creating project metadata in a folder, etc.
467
     * This may be useful after creating project metadata in a folder, etc.
467
     * Cached project objects, i.e. folders that <em>are</em> known to be
468
     * Cached project objects, i.e. folders that <em>are</em> known to be
468
     * projects, are not affected.
469
     * projects, are not affected.
470
     * <p>
471
     * Since version 1.15, this method also discards
472
     * projects which are named in a special way. If their class name
473
     * contains <code>NonProject</code>, then they are freed from the cache.
469
     */
474
     */
470
    public void clearNonProjectCache() {
475
    public void clearNonProjectCache() {
471
        synchronized (dir2Proj) {
476
        synchronized (dir2Proj) {
Lines 477-482 Link Here
477
            // will stay while its delegates are changed, which does no good
482
            // will stay while its delegates are changed, which does no good
478
            // XXX should there be any way to signal that a particular
483
            // XXX should there be any way to signal that a particular
479
            // folder should be "reloaded" by a new factory?
484
            // folder should be "reloaded" by a new factory?
485
            
486
            // clearing every project that is marked as NonProject
487
            Iterator<Entry<FileObject, Union2<Reference<Project>, LoadStatus>>> it = dir2Proj.entrySet().iterator();
488
            while (it.hasNext()) {
489
                Union2<Reference<Project>, LoadStatus> union = it.next().getValue();
490
                if (union.hasFirst()) {
491
                    Reference<Project> ref = union.first();
492
                    Project prj = ref.get();
493
                    if (prj == null || prj.getClass().getSimpleName().indexOf("NonProject") == -1) { // NOI18N
494
                        continue;
495
                    }
496
                    it.remove();
497
                }
498
            }
480
        }
499
        }
481
    }
500
    }
482
    
501
    
(-)projects/projectapi/test/unit/src/org/netbeans/api/project/ProjectManagerTest.java (+58 lines)
Lines 50-58 Link Here
50
import java.util.Set;
50
import java.util.Set;
51
import java.util.logging.Level;
51
import java.util.logging.Level;
52
import org.netbeans.junit.Log;
52
import org.netbeans.junit.Log;
53
import org.netbeans.junit.MockServices;
53
import org.netbeans.junit.NbTestCase;
54
import org.netbeans.junit.NbTestCase;
54
import org.netbeans.modules.projectapi.TimedWeakReference;
55
import org.netbeans.modules.projectapi.TimedWeakReference;
56
import org.netbeans.spi.project.ProjectFactory;
57
import org.netbeans.spi.project.ProjectState;
55
import org.openide.filesystems.FileObject;
58
import org.openide.filesystems.FileObject;
59
import org.openide.util.Lookup;
56
import org.openide.util.test.MockLookup;
60
import org.openide.util.test.MockLookup;
57
61
58
/* XXX tests needed:
62
/* XXX tests needed:
Lines 174-179 Link Here
174
        assertNotNull("Can load goodproject yet again", p);
178
        assertNotNull("Can load goodproject yet again", p);
175
        assertEquals("Correct project directory set again", goodproject, p.getProjectDirectory());
179
        assertEquals("Correct project directory set again", goodproject, p.getProjectDirectory());
176
        assertEquals("ProjectFactory was called only once on new goodproject folder object", 1, TestUtil.projectLoadCount(goodproject));
180
        assertEquals("ProjectFactory was called only once on new goodproject folder object", 1, TestUtil.projectLoadCount(goodproject));
181
    }
182
    
183
    
184
    public static final class NonProjectFactory implements ProjectFactory {
185
        static FileObject recognize;
186
        
187
        public boolean isProject(FileObject projectDirectory) {
188
            return projectDirectory.equals(recognize);
189
        }
190
        public Project loadProject(FileObject projectDirectory, ProjectState state) throws IOException {
191
            if (isProject(projectDirectory)) {
192
                recognize = null;
193
                return new MyNonProject(projectDirectory);
194
            }
195
            return null;
196
        }
197
        public void saveProject(Project project) throws IOException, ClassCastException {
198
        }
199
    }
200
    static final class MyNonProject implements Project {
201
        FileObject dir;
202
203
        public MyNonProject(FileObject dir) {
204
            this.dir = dir;
205
        }
206
        
207
        public FileObject getProjectDirectory() {
208
            return dir;
209
        }
210
211
        public Lookup getLookup() {
212
            return Lookup.EMPTY;
213
        }
214
    }
215
216
    public void testProjectCanBeGCedWhenItContainsNameNonProject() throws Exception {
217
        MockLookup.setInstances(new NonProjectFactory(), TestUtil.testProjectFactory());
218
        Project prev = null;
219
        NonProjectFactory.recognize = goodproject;
220
        prev = pm.findProject(goodproject);
221
        assertNotNull("Project recognized", prev);
222
        assertEquals(MyNonProject.class, prev.getClass());
223
        pm.clearNonProjectCache();
224
        Project p = pm.findProject(goodproject);
225
        assertNotNull("Should have recognized goodproject", p);
226
        assertEquals("ProjectFactory was called once so far on goodproject", 1, TestUtil.projectLoadCount(goodproject));
227
        
228
        Reference<?> weak = new WeakReference<Object>(prev);
229
        prev = null;
230
        assertGC("NonProject can disappear", weak);
231
        
232
        // continue the normal test
233
        p = null;
234
        testFindProjectGC();
177
    }
235
    }
178
    
236
    
179
    public void testFindProjectDoesNotCacheLoadErrors() throws Exception {
237
    public void testFindProjectDoesNotCacheLoadErrors() throws Exception {

Return to bug 124975