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); |