Lines 22-27
Link Here
|
22 |
import java.beans.PropertyChangeEvent; |
22 |
import java.beans.PropertyChangeEvent; |
23 |
import java.beans.PropertyChangeListener; |
23 |
import java.beans.PropertyChangeListener; |
24 |
import java.beans.PropertyChangeSupport; |
24 |
import java.beans.PropertyChangeSupport; |
|
|
25 |
import java.io.IOException; |
25 |
import java.net.MalformedURLException; |
26 |
import java.net.MalformedURLException; |
26 |
import java.net.URL; |
27 |
import java.net.URL; |
27 |
import java.util.ArrayList; |
28 |
import java.util.ArrayList; |
Lines 32-41
Link Here
|
32 |
import java.util.List; |
33 |
import java.util.List; |
33 |
import java.util.Map; |
34 |
import java.util.Map; |
34 |
import java.util.Set; |
35 |
import java.util.Set; |
|
|
36 |
import java.util.StringTokenizer; |
35 |
import org.netbeans.api.project.TestUtil; |
37 |
import org.netbeans.api.project.TestUtil; |
36 |
import org.netbeans.junit.NbTestCase; |
38 |
import org.netbeans.junit.NbTestCase; |
|
|
39 |
import org.netbeans.modules.project.libraries.WriteableLibraryProvider; |
40 |
import org.netbeans.spi.project.libraries.LibraryFactory; |
37 |
import org.netbeans.spi.project.libraries.LibraryImplementation; |
41 |
import org.netbeans.spi.project.libraries.LibraryImplementation; |
38 |
import org.netbeans.spi.project.libraries.LibraryProvider; |
42 |
import org.netbeans.spi.project.libraries.LibraryTypeProvider; |
|
|
43 |
import org.netbeans.spi.project.libraries.support.LibrariesSupport; |
44 |
import org.openide.filesystems.FileObject; |
45 |
import org.openide.filesystems.Repository; |
46 |
import org.openide.loaders.DataFolder; |
47 |
import org.openide.loaders.InstanceDataObject; |
48 |
import org.openide.util.lookup.Lookups; |
39 |
import org.openide.util.lookup.Lookups; |
49 |
import org.openide.util.lookup.Lookups; |
40 |
/** |
50 |
/** |
41 |
* |
51 |
* |
Lines 45-50
Link Here
|
45 |
|
55 |
|
46 |
private TestLibraryProvider lp; |
56 |
private TestLibraryProvider lp; |
47 |
|
57 |
|
|
|
58 |
private static final String LIBRARY_TYPE = "j2se"; //NOI18N |
59 |
private static final String[] VOLUME_TYPES = new String[] { |
60 |
"bin", |
61 |
"src", |
62 |
"doc" |
63 |
}; |
64 |
|
48 |
/** Creates a new instance of LibraryManagerTest */ |
65 |
/** Creates a new instance of LibraryManagerTest */ |
49 |
public LibraryManagerTest (String testName) { |
66 |
public LibraryManagerTest (String testName) { |
50 |
super (testName); |
67 |
super (testName); |
Lines 53-59
Link Here
|
53 |
protected void setUp() throws Exception { |
70 |
protected void setUp() throws Exception { |
54 |
super.setUp(); |
71 |
super.setUp(); |
55 |
lp = new TestLibraryProvider (); |
72 |
lp = new TestLibraryProvider (); |
56 |
TestUtil.setLookup (Lookups.fixed(new Object[] {lp})); |
73 |
TestUtil.setLookup (Lookups.fixed(new Object[] { |
|
|
74 |
lp |
75 |
})); |
76 |
registerLibraryTypeProvider(); |
77 |
} |
78 |
|
79 |
|
80 |
private static void registerLibraryTypeProvider () throws Exception { |
81 |
StringTokenizer tk = new StringTokenizer("org-netbeans-api-project-libraries/LibraryTypeProviders","/"); |
82 |
FileObject root = Repository.getDefault().getDefaultFileSystem().getRoot(); |
83 |
while (tk.hasMoreElements()) { |
84 |
String pathElement = tk.nextToken(); |
85 |
FileObject tmp = root.getFileObject(pathElement); |
86 |
if (tmp == null) { |
87 |
tmp = root.createFolder(pathElement); |
88 |
} |
89 |
root = tmp; |
90 |
} |
91 |
if (root.getChildren().length == 0) { |
92 |
InstanceDataObject.create (DataFolder.findFolder(root),"TestLibraryTypeProvider",TestLibraryTypeProvider.class); |
93 |
} |
57 |
} |
94 |
} |
58 |
|
95 |
|
59 |
public void testGetLibraries () throws Exception { |
96 |
public void testGetLibraries () throws Exception { |
Lines 93-98
Link Here
|
93 |
assertNull ("Nonexisting library", lib); |
130 |
assertNull ("Nonexisting library", lib); |
94 |
} |
131 |
} |
95 |
|
132 |
|
|
|
133 |
public void testAddRemoveLibrary () throws Exception { |
134 |
final LibraryImplementation[] impls = createTestLibs(); |
135 |
lp.setLibraries(impls); |
136 |
final LibraryManager lm = LibraryManager.getDefault(); |
137 |
Library[] libs = lm.getLibraries(); |
138 |
assertEquals ("Libraries count", 2, libs.length); |
139 |
assertLibsEquals (libs, impls); |
140 |
final LibraryTypeProvider provider = LibrariesSupport.getLibraryTypeProvider(LIBRARY_TYPE); |
141 |
assertNotNull (provider); |
142 |
final LibraryImplementation newLibImplementation = provider.createLibrary(); |
143 |
newLibImplementation.setName("NewLib"); |
144 |
final Library newLibrary = LibraryFactory.createLibrary(newLibImplementation); |
145 |
lm.addLibrary(newLibrary); |
146 |
libs = lm.getLibraries(); |
147 |
assertEquals ("Libraries count", 3, libs.length); |
148 |
List newLibs = new ArrayList (Arrays.asList(impls)); |
149 |
newLibs.add (newLibImplementation); |
150 |
assertLibsEquals (libs, (LibraryImplementation[])newLibs.toArray(new LibraryImplementation[newLibs.size()])); |
151 |
lm.removeLibrary(newLibrary); |
152 |
libs = lm.getLibraries(); |
153 |
assertEquals("Libraries count",2,libs.length); |
154 |
assertLibsEquals (libs, impls); |
155 |
} |
156 |
|
96 |
static LibraryImplementation[] createTestLibs () throws MalformedURLException { |
157 |
static LibraryImplementation[] createTestLibs () throws MalformedURLException { |
97 |
LibraryImplementation[] impls = new LibraryImplementation[] { |
158 |
LibraryImplementation[] impls = new LibraryImplementation[] { |
98 |
new TestLibraryImplementation (), |
159 |
new TestLibraryImplementation (), |
Lines 129-142
Link Here
|
129 |
} |
190 |
} |
130 |
|
191 |
|
131 |
|
192 |
|
132 |
static class TestLibraryProvider implements LibraryProvider { |
193 |
static class TestLibraryProvider implements WriteableLibraryProvider { |
133 |
|
194 |
|
134 |
private PropertyChangeSupport support; |
195 |
private PropertyChangeSupport support; |
135 |
private LibraryImplementation[] libraries; |
196 |
private List libraries; |
136 |
|
197 |
|
137 |
public TestLibraryProvider () { |
198 |
public TestLibraryProvider () { |
138 |
this.support = new PropertyChangeSupport (this); |
199 |
this.support = new PropertyChangeSupport (this); |
139 |
this.libraries = new LibraryImplementation[0]; |
200 |
this.libraries = new ArrayList(); |
140 |
} |
201 |
} |
141 |
|
202 |
|
142 |
public void removePropertyChangeListener(PropertyChangeListener listener) { |
203 |
public void removePropertyChangeListener(PropertyChangeListener listener) { |
Lines 148-158
Link Here
|
148 |
} |
209 |
} |
149 |
|
210 |
|
150 |
public LibraryImplementation[] getLibraries() { |
211 |
public LibraryImplementation[] getLibraries() { |
151 |
return this.libraries; |
212 |
return (LibraryImplementation[]) this.libraries.toArray(new LibraryImplementation[libraries.size()]); |
152 |
} |
213 |
} |
153 |
|
214 |
|
154 |
public void setLibraries (LibraryImplementation[] libraries) { |
215 |
public void setLibraries (LibraryImplementation[] libraries) { |
155 |
this.libraries = libraries; |
216 |
this.libraries = new ArrayList(Arrays.asList(libraries)); |
|
|
217 |
this.support.firePropertyChange(PROP_LIBRARIES,null,null); |
218 |
} |
219 |
|
220 |
public void addLibrary(LibraryImplementation library) throws IOException { |
221 |
this.libraries.add (library); |
222 |
this.support.firePropertyChange(PROP_LIBRARIES,null,null); |
223 |
} |
224 |
|
225 |
public void removeLibrary(LibraryImplementation library) throws IOException { |
226 |
this.libraries.remove (library); |
227 |
this.support.firePropertyChange(PROP_LIBRARIES,null,null); |
228 |
} |
229 |
|
230 |
public void updateLibrary(LibraryImplementation oldLibrary, LibraryImplementation newLibrary) throws IOException { |
231 |
this.libraries.remove(oldLibrary); |
232 |
this.libraries.add (newLibrary); |
156 |
this.support.firePropertyChange(PROP_LIBRARIES,null,null); |
233 |
this.support.firePropertyChange(PROP_LIBRARIES,null,null); |
157 |
} |
234 |
} |
158 |
|
235 |
|
Lines 175-180
Link Here
|
175 |
} |
252 |
} |
176 |
} |
253 |
} |
177 |
|
254 |
|
|
|
255 |
|
256 |
public static class TestLibraryTypeProvider implements LibraryTypeProvider { |
257 |
|
258 |
|
259 |
public String getDisplayName() { |
260 |
return LIBRARY_TYPE; |
261 |
} |
262 |
|
263 |
public String getLibraryType() { |
264 |
return LIBRARY_TYPE; |
265 |
} |
266 |
|
267 |
public String[] getSupportedVolumeTypes() { |
268 |
return VOLUME_TYPES; |
269 |
} |
270 |
|
271 |
public LibraryImplementation createLibrary() { |
272 |
return LibrariesSupport.createLibraryImplementation(LIBRARY_TYPE, VOLUME_TYPES); |
273 |
} |
274 |
|
275 |
public void libraryDeleted(LibraryImplementation library) { |
276 |
} |
277 |
|
278 |
public void libraryCreated(LibraryImplementation library) { |
279 |
} |
280 |
|
281 |
public java.beans.Customizer getCustomizer(String volumeType) { |
282 |
return null; |
283 |
} |
284 |
|
285 |
public org.openide.util.Lookup getLookup() { |
286 |
return null; |
287 |
} |
288 |
} |
289 |
|
178 |
static class TestLibraryImplementation implements LibraryImplementation { |
290 |
static class TestLibraryImplementation implements LibraryImplementation { |
179 |
|
291 |
|
180 |
private static final Set supportedTypes; |
292 |
private static final Set supportedTypes; |
Lines 184-195
Link Here
|
184 |
private Map contents; |
296 |
private Map contents; |
185 |
private PropertyChangeSupport support; |
297 |
private PropertyChangeSupport support; |
186 |
|
298 |
|
187 |
static { |
299 |
static { |
188 |
Set st = new HashSet (); |
300 |
supportedTypes = Collections.unmodifiableSet(new HashSet(Arrays.asList(VOLUME_TYPES))); |
189 |
st.add ("bin"); |
|
|
190 |
st.add ("src"); |
191 |
st.add ("doc"); |
192 |
supportedTypes = Collections.unmodifiableSet(st); |
193 |
} |
301 |
} |
194 |
|
302 |
|
195 |
public TestLibraryImplementation () { |
303 |
public TestLibraryImplementation () { |
Lines 198-204
Link Here
|
198 |
} |
306 |
} |
199 |
|
307 |
|
200 |
public String getType() { |
308 |
public String getType() { |
201 |
return "TestLibraryType"; |
309 |
return LIBRARY_TYPE; |
202 |
} |
310 |
} |
203 |
|
311 |
|
204 |
public String getName() { |
312 |
public String getName() { |