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

(-)src/org/netbeans/api/java/classpath/GlobalPathRegistry.java (+16 lines)
Lines 13-18 Link Here
13
13
14
package org.netbeans.api.java.classpath;
14
package org.netbeans.api.java.classpath;
15
15
16
import java.beans.PropertyChangeEvent;
17
import java.beans.PropertyChangeListener;
16
import java.util.ArrayList;
18
import java.util.ArrayList;
17
import java.util.Arrays;
19
import java.util.Arrays;
18
import java.util.Collection;
20
import java.util.Collection;
Lines 97-102 Link Here
97
            }
99
            }
98
        }
100
        }
99
    };
101
    };
102
    private PropertyChangeListener classpathListener = new PropertyChangeListener() {
103
        public void propertyChange(PropertyChangeEvent evt) {
104
            synchronized (GlobalPathRegistry.this) {
105
                //Reset cache
106
                GlobalPathRegistry.this.resetSourceRootsCache ();
107
            }
108
        }
109
    };
100
    
110
    
101
    private GlobalPathRegistry() {}
111
    private GlobalPathRegistry() {}
102
    
112
    
Lines 148-153 Link Here
148
                if (added != null && !added.contains(paths[i]) && !l.contains(paths[i])) {
158
                if (added != null && !added.contains(paths[i]) && !l.contains(paths[i])) {
149
                    added.add(paths[i]);
159
                    added.add(paths[i]);
150
                }
160
                }
161
                if (!l.contains(paths[i])) {
162
                    paths[i].addPropertyChangeListener(classpathListener);
163
                }
151
                l.add(paths[i]);
164
                l.add(paths[i]);
152
            }
165
            }
153
            if (added != null && !added.isEmpty()) {
166
            if (added != null && !added.isEmpty()) {
Lines 193-198 Link Here
193
                }
206
                }
194
                if (removed != null && !removed.contains(paths[i]) && !l2.contains(paths[i])) {
207
                if (removed != null && !removed.contains(paths[i]) && !l2.contains(paths[i])) {
195
                    removed.add(paths[i]);
208
                    removed.add(paths[i]);
209
                }
210
                if (!l2.contains(paths[i])) {
211
                    paths[i].removePropertyChangeListener(classpathListener);
196
                }
212
                }
197
            }
213
            }
198
            this.paths.put(id, l2);
214
            this.paths.put(id, l2);
(-)test/unit/src/org/netbeans/api/java/classpath/ClassPathTest.java (-1 / +1 lines)
Lines 252-258 Link Here
252
        cp = null;
252
        cp = null;
253
    }
253
    }
254
    
254
    
255
    private static final class TestClassPathImplementation implements ClassPathImplementation, PropertyChangeListener {
255
    static final class TestClassPathImplementation implements ClassPathImplementation, PropertyChangeListener {
256
256
257
        private PropertyChangeSupport support = new PropertyChangeSupport (this);
257
        private PropertyChangeSupport support = new PropertyChangeSupport (this);
258
        private List resources = new ArrayList ();
258
        private List resources = new ArrayList ();
(-)test/unit/src/org/netbeans/api/java/classpath/GlobalPathRegistryTest.java (-4 / +19 lines)
Lines 13-18 Link Here
13
13
14
package org.netbeans.api.java.classpath;
14
package org.netbeans.api.java.classpath;
15
15
16
import java.beans.PropertyChangeListener;
17
import java.beans.PropertyChangeSupport;
16
import java.net.URL;
18
import java.net.URL;
17
import java.util.ArrayList;
19
import java.util.ArrayList;
18
import java.util.Arrays;
20
import java.util.Arrays;
Lines 20-37 Link Here
20
import java.util.HashMap;
22
import java.util.HashMap;
21
import java.util.HashSet;
23
import java.util.HashSet;
22
import java.util.Iterator;
24
import java.util.Iterator;
23
import java.util.List;
24
import java.util.Set;
25
import java.util.Set;
25
import java.util.Map;
26
import java.util.Map;
26
import javax.swing.event.ChangeEvent;
27
import javax.swing.event.ChangeEvent;
27
import javax.swing.event.ChangeListener;
28
import javax.swing.event.ChangeListener;
28
import org.netbeans.api.java.queries.SourceForBinaryQuery;
29
import org.netbeans.api.java.queries.SourceForBinaryQuery;
29
import org.netbeans.junit.NbTestCase;
30
import org.netbeans.junit.NbTestCase;
31
import org.netbeans.spi.java.classpath.ClassPathImplementation;
30
import org.netbeans.spi.java.classpath.support.ClassPathSupport;
32
import org.netbeans.spi.java.classpath.support.ClassPathSupport;
31
import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation;
33
import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation;
32
import org.openide.filesystems.FileObject;
34
import org.openide.filesystems.FileObject;
33
import org.netbeans.api.project.TestUtil;
35
import org.netbeans.api.project.TestUtil;
34
import org.openide.filesystems.FileStateInvalidException;
36
import org.netbeans.spi.java.classpath.ClassPathFactory;
35
import org.openide.filesystems.FileUtil;
37
import org.openide.filesystems.FileUtil;
36
import org.openide.util.Lookup;
38
import org.openide.util.Lookup;
37
import org.openide.util.lookup.Lookups;
39
import org.openide.util.lookup.Lookups;
Lines 133-148 Link Here
133
    }
135
    }
134
    
136
    
135
    
137
    
136
    public void testGetSourceRoots () throws FileStateInvalidException {
138
    public void testGetSourceRoots () throws Exception {
137
        SFBQImpl query = (SFBQImpl) Lookup.getDefault().lookup(SFBQImpl.class);
139
        SFBQImpl query = (SFBQImpl) Lookup.getDefault().lookup(SFBQImpl.class);
138
        assertNotNull ("SourceForBinaryQueryImplementation not found in lookup",query);                
140
        assertNotNull ("SourceForBinaryQueryImplementation not found in lookup",query);                
139
        query.addPair(cp3.getRoots()[0].getURL(),new FileObject[0]);
141
        query.addPair(cp3.getRoots()[0].getURL(),new FileObject[0]);
140
        r.register(ClassPath.SOURCE, new ClassPath[] {cp1, cp2});
142
        ClassPathTest.TestClassPathImplementation cpChangingImpl = new ClassPathTest.TestClassPathImplementation();
143
        ClassPath cpChanging = ClassPathFactory.createClassPath(cpChangingImpl);
144
        assertEquals("cpChangingImpl is empty", 0, cpChanging.getRoots().length);
145
        r.register(ClassPath.SOURCE, new ClassPath[] {cp1, cp2, cpChanging});
141
        r.register (ClassPath.COMPILE, new ClassPath[] {cp3});
146
        r.register (ClassPath.COMPILE, new ClassPath[] {cp3});
142
        Set result = r.getSourceRoots();
147
        Set result = r.getSourceRoots();
143
        assertEquals ("Wrong number of source roots",result.size(),cp1.getRoots().length + cp2.getRoots().length);
148
        assertEquals ("Wrong number of source roots",result.size(),cp1.getRoots().length + cp2.getRoots().length);
144
        assertTrue ("Missing roots from cp1",result.containsAll (Arrays.asList(cp1.getRoots())));
149
        assertTrue ("Missing roots from cp1",result.containsAll (Arrays.asList(cp1.getRoots())));
145
        assertTrue ("Missing roots from cp2",result.containsAll (Arrays.asList(cp2.getRoots())));                
150
        assertTrue ("Missing roots from cp2",result.containsAll (Arrays.asList(cp2.getRoots())));                
151
        // simulate classpath change:
152
        URL u = ((ClassPath.Entry)cp5.entries().get(0)).getURL();
153
        cpChangingImpl.addResource(u);
154
        assertEquals("cpChangingImpl is not empty", 1, cpChanging.getRoots().length);
155
        result = r.getSourceRoots();
156
        assertEquals ("Wrong number of source roots",result.size(),cp1.getRoots().length + cp2.getRoots().length + cpChanging.getRoots().length);
157
        assertTrue ("Missing roots from cp1",result.containsAll (Arrays.asList(cp1.getRoots())));
158
        assertTrue ("Missing roots from cp2",result.containsAll (Arrays.asList(cp2.getRoots())));                
159
        cpChangingImpl.removeResource(u);
160
        
146
        query.addPair(cp3.getRoots()[0].getURL(),cp4.getRoots());       
161
        query.addPair(cp3.getRoots()[0].getURL(),cp4.getRoots());       
147
        result = r.getSourceRoots();
162
        result = r.getSourceRoots();
148
        assertEquals ("Wrong number of source roots",result.size(),cp1.getRoots().length + cp2.getRoots().length+cp4.getRoots().length);
163
        assertEquals ("Wrong number of source roots",result.size(),cp1.getRoots().length + cp2.getRoots().length+cp4.getRoots().length);

Return to bug 51545