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

(-)projects/projectapi/src/org/netbeans/api/project/ProjectManager.java (-1 / +36 lines)
Lines 41-46 Link Here
41
41
42
package org.netbeans.api.project;
42
package org.netbeans.api.project;
43
43
44
import java.io.File;
44
import java.io.IOException;
45
import java.io.IOException;
45
import java.lang.ref.Reference;
46
import java.lang.ref.Reference;
46
import java.util.Arrays;
47
import java.util.Arrays;
Lines 50-55 Link Here
50
import java.util.Map;
51
import java.util.Map;
51
import java.util.Set;
52
import java.util.Set;
52
import java.util.WeakHashMap;
53
import java.util.WeakHashMap;
54
import java.util.concurrent.Executor;
53
import java.util.logging.Level;
55
import java.util.logging.Level;
54
import java.util.logging.Logger;
56
import java.util.logging.Logger;
55
import org.netbeans.modules.projectapi.SimpleFileOwnerQueryImplementation;
57
import org.netbeans.modules.projectapi.SimpleFileOwnerQueryImplementation;
Lines 61-67 Link Here
61
import org.openide.filesystems.FileChangeListener;
63
import org.openide.filesystems.FileChangeListener;
62
import org.openide.filesystems.FileEvent;
64
import org.openide.filesystems.FileEvent;
63
import org.openide.filesystems.FileObject;
65
import org.openide.filesystems.FileObject;
66
import org.openide.filesystems.FileStateInvalidException;
67
import org.openide.filesystems.FileSystem;
64
import org.openide.filesystems.FileUtil;
68
import org.openide.filesystems.FileUtil;
69
import org.openide.util.Exceptions;
65
import org.openide.util.Lookup;
70
import org.openide.util.Lookup;
66
import org.openide.util.LookupEvent;
71
import org.openide.util.LookupEvent;
67
import org.openide.util.LookupListener;
72
import org.openide.util.LookupListener;
Lines 107-113 Link Here
107
        return DEFAULT;
112
        return DEFAULT;
108
    }
113
    }
109
    
114
    
110
    private static final Mutex MUTEX = new Mutex();
115
    private static final Executor FS_EXEC = new Executor() {
116
        public void execute(final Runnable command) {
117
            FileSystem fs = null;
118
            for (File f : File.listRoots()) {
119
                FileObject fo = FileUtil.toFileObject(f);
120
                if (fo != null) {
121
                    try {
122
                        fs = fo.getFileSystem();
123
                        break;
124
                    } catch (FileStateInvalidException ex) {
125
                        LOG.log(Level.WARNING, "Cannot find filesystem for " + f, ex); // NOI18N
126
                    }
127
                }
128
            }
129
            
130
            if (fs != null) {
131
                try {
132
                    fs.runAtomicAction(new FileSystem.AtomicAction() {
133
                        public void run() throws IOException {
134
                            command.run();
135
                        }
136
                    });
137
                } catch (IOException ex) {
138
                    throw (IllegalStateException)new IllegalStateException().initCause(ex);
139
                }
140
            } else {
141
                command.run();
142
            }
143
        }
144
    };
145
    private static final Mutex MUTEX = new Mutex(new Mutex.Privileged(), FS_EXEC);
111
    /**
146
    /**
112
     * Get a read/write lock to be used for all project metadata accesses.
147
     * Get a read/write lock to be used for all project metadata accesses.
113
     * All methods relating to recognizing and loading projects, saving them,
148
     * All methods relating to recognizing and loading projects, saving them,
(-)projects/projectapi/test/unit/src/org/netbeans/api/project/ProjectManagerTest.java (-1 / +56 lines)
Lines 51-57 Link Here
51
import java.util.logging.Level;
51
import java.util.logging.Level;
52
import org.netbeans.junit.NbTestCase;
52
import org.netbeans.junit.NbTestCase;
53
import org.netbeans.modules.projectapi.TimedWeakReference;
53
import org.netbeans.modules.projectapi.TimedWeakReference;
54
import org.openide.filesystems.FileAttributeEvent;
55
import org.openide.filesystems.FileChangeListener;
56
import org.openide.filesystems.FileEvent;
54
import org.openide.filesystems.FileObject;
57
import org.openide.filesystems.FileObject;
58
import org.openide.filesystems.FileRenameEvent;
59
import org.openide.util.Mutex;
55
import org.openide.util.test.MockLookup;
60
import org.openide.util.test.MockLookup;
56
61
57
/* XXX tests needed:
62
/* XXX tests needed:
Lines 67-73 Link Here
67
 * Test ProjectManager find and save functionality.
72
 * Test ProjectManager find and save functionality.
68
 * @author Jesse Glick
73
 * @author Jesse Glick
69
 */
74
 */
70
public class ProjectManagerTest extends NbTestCase {
75
public class ProjectManagerTest extends NbTestCase 
76
implements FileChangeListener {
71
    
77
    
72
    static {
78
    static {
73
        // For easier testing.
79
        // For easier testing.
Lines 92-97 Link Here
92
    protected void setUp() throws Exception {
98
    protected void setUp() throws Exception {
93
        super.setUp();
99
        super.setUp();
94
        scratch = TestUtil.makeScratchDir(this);
100
        scratch = TestUtil.makeScratchDir(this);
101
        
102
        scratch.getFileSystem().addFileChangeListener(this);
103
        
95
        goodproject = scratch.createFolder("good");
104
        goodproject = scratch.createFolder("good");
96
        goodproject.createFolder("testproject");
105
        goodproject.createFolder("testproject");
97
        goodproject2 = scratch.createFolder("good2");
106
        goodproject2 = scratch.createFolder("good2");
Lines 106-111 Link Here
106
    }
115
    }
107
    
116
    
108
    protected void tearDown() throws Exception {
117
    protected void tearDown() throws Exception {
118
        scratch.getFileSystem().removeFileChangeListener(this);
119
        
109
        scratch = null;
120
        scratch = null;
110
        goodproject = null;
121
        goodproject = null;
111
        badproject = null;
122
        badproject = null;
Lines 343-348 Link Here
343
        assertNotNull("now p3 is recognized as a non-broken project", pm.findProject(p3));
354
        assertNotNull("now p3 is recognized as a non-broken project", pm.findProject(p3));
344
        assertEquals("p1 still recognized as a project", proj1, pm.findProject(p1));
355
        assertEquals("p1 still recognized as a project", proj1, pm.findProject(p1));
345
    }
356
    }
357
    public void testClearNonProjectCacheInWriteAccess() throws Exception {
358
        ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<Void>() {
359
            public Void run() throws Exception {
360
                testClearNonProjectCache();
361
                return null;
362
            }
363
        });
364
    }
365
    public void testClearNonProjectCacheInReadAccess() throws Exception {
366
        ProjectManager.mutex().readAccess(new Mutex.ExceptionAction<Void>() {
367
            public Void run() throws Exception {
368
                testClearNonProjectCache();
369
                return null;
370
            }
371
        });
372
    }
346
    
373
    
347
    public void testLoadExceptionWithConcurrentLoad() throws Exception {
374
    public void testLoadExceptionWithConcurrentLoad() throws Exception {
348
        TestUtil.BROKEN_PROJECT_LOAD_LOCK = new Object();
375
        TestUtil.BROKEN_PROJECT_LOAD_LOCK = new Object();
Lines 473-476 Link Here
473
        assertTrue("An IllegalStateException was thrown when calling notifyDeleted twice.", wasException);
500
        assertTrue("An IllegalStateException was thrown when calling notifyDeleted twice.", wasException);
474
    }
501
    }
475
    
502
    
503
    private void assertNoAccess() {
504
        assertFalse("No read access", ProjectManager.mutex().isReadAccess());
505
        assertFalse("No write access", ProjectManager.mutex().isWriteAccess());
476
}
506
}
507
    
508
    public void fileFolderCreated(FileEvent fe) {
509
        assertNoAccess();
510
    }
511
512
    public void fileDataCreated(FileEvent fe) {
513
        assertNoAccess();
514
    }
515
516
    public void fileChanged(FileEvent fe) {
517
        assertNoAccess();
518
    }
519
520
    public void fileDeleted(FileEvent fe) {
521
        assertNoAccess();
522
    }
523
524
    public void fileRenamed(FileRenameEvent fe) {
525
        assertNoAccess();
526
    }
527
528
    public void fileAttributeChanged(FileAttributeEvent fe) {
529
        assertNoAccess();
530
    }
531
}

Return to bug 123832