KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > freeform > ui > ProjectModelTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.java.freeform.ui;
21
22 import java.io.File JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.Arrays JavaDoc;
25 import java.util.Collections JavaDoc;
26 import java.util.HashMap JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.List JavaDoc;
29 import java.util.Map JavaDoc;
30 import java.util.Properties JavaDoc;
31 import org.netbeans.junit.NbTestCase;
32 import org.netbeans.modules.java.freeform.JavaProjectGenerator;
33 import org.netbeans.spi.project.support.ant.PropertyEvaluator;
34 import org.netbeans.spi.project.support.ant.PropertyProvider;
35 import org.netbeans.spi.project.support.ant.PropertyUtils;
36
37 /**
38  * Tests for ProjectModel.
39  *
40  * @author David Konecny
41  */

42 public class ProjectModelTest extends NbTestCase {
43     
44     public ProjectModelTest(String JavaDoc testName) {
45         super(testName);
46     }
47     
48     public void testCreateEmptyModel() throws Exception JavaDoc {
49         File JavaDoc baseFolder = new File JavaDoc(getWorkDir(), "somefolder/");
50         File JavaDoc nbProjectFolder = new File JavaDoc(getWorkDir(), "nbprojfolder/");
51         Map JavaDoc<String JavaDoc,String JavaDoc> p = new HashMap JavaDoc<String JavaDoc,String JavaDoc>();
52         p.put("key", "value");
53         PropertyEvaluator evaluator = PropertyUtils.sequentialPropertyEvaluator(null, PropertyUtils.fixedPropertyProvider(p));
54         ProjectModel pm = ProjectModel.createEmptyModel(baseFolder, nbProjectFolder, evaluator);
55         assertNotNull(pm);
56         assertEquals("Base folder incorrect", baseFolder, pm.getBaseFolder());
57         assertEquals("NB project folder incorrect", nbProjectFolder, pm.getNBProjectFolder());
58         assertEquals("Evaluator incorrect", evaluator, pm.getEvaluator());
59         assertEquals("Evaluator is different", 1, pm.getEvaluator().getProperties().size());
60     }
61
62     // tests: addSourceFolder, removeSourceFolder, setSourceLevel, getCompilationUnit
63
public void testBasicFunctionality() throws Exception JavaDoc {
64         ProjectModel pm = createEmptyProjectModel();
65         pm.setSourceLevel("custom_source_level");
66         JavaProjectGenerator.SourceFolder sf = new JavaProjectGenerator.SourceFolder();
67         sf.location = "loc1";
68         sf.label = "label_loc1";
69         sf.type = "java";
70         pm.addSourceFolder(sf, false);
71         assertEquals("Number of source folders does not match", 1, pm.getSourceFoldersCount());
72         assertEquals("Number of comp units does not match", 1, pm.getJavaCompilationUnits().size());
73         assertEquals("Number of comp unit keys does not match", 1, pm.createCompilationUnitKeys().size());
74         List JavaDoc<ProjectModel.CompilationUnitKey> keys = generateKeys(new Object JavaDoc[]{"loc1"}, new String JavaDoc[]{"label_loc1"});
75         assertKeyEquals(keys, pm.createCompilationUnitKeys());
76         JavaProjectGenerator.JavaCompilationUnit cu1 = pm.getJavaCompilationUnits().get(0);
77         JavaProjectGenerator.JavaCompilationUnit cu2 = pm.getCompilationUnit(keys.get(0), false);
78         assertEquals("Must be the same instance", cu1, cu2);
79
80         sf = new JavaProjectGenerator.SourceFolder();
81         sf.location = "loc2";
82         sf.label = "label_loc2";
83         sf.type = "java";
84         pm.addSourceFolder(sf, false);
85         assertEquals("Number of source folders does not match", 2, pm.getSourceFoldersCount());
86         assertEquals("Number of comp units does not match", 2, pm.getJavaCompilationUnits().size());
87         assertEquals("Number of comp unit keys does not match", 2, pm.createCompilationUnitKeys().size());
88         keys = generateKeys(new Object JavaDoc[]{"loc1", "loc2"}, new String JavaDoc[]{"label_loc1", "label_loc2"});
89         assertKeyEquals(keys, pm.createCompilationUnitKeys());
90         cu1 = pm.getJavaCompilationUnits().get(0);
91         cu2 = pm.getCompilationUnit(keys.get(0), false);
92         assertEquals("Must be the same instance", cu1, cu2);
93         cu1 = pm.getJavaCompilationUnits().get(1);
94         cu2 = pm.getCompilationUnit(keys.get(1), false);
95         assertEquals("Must be the same instance", cu1, cu2);
96         
97         assertEquals("Source level does not match", "custom_source_level",
98             pm.getJavaCompilationUnits().get(0).sourceLevel);
99         assertEquals("Source level does not match", "custom_source_level",
100             pm.getJavaCompilationUnits().get(1).sourceLevel);
101         pm.setSourceLevel("jdk15");
102         assertEquals("Source level does not match", "jdk15",
103             pm.getJavaCompilationUnits().get(0).sourceLevel);
104         assertEquals("Source level does not match", "jdk15",
105             pm.getJavaCompilationUnits().get(1).sourceLevel);
106         
107         pm.removeSourceFolder(0);
108         assertEquals("Number of source folders does not match", 1, pm.getSourceFoldersCount());
109         assertEquals("Number of comp units does not match", 1, pm.getJavaCompilationUnits().size());
110         assertEquals("Number of comp unit keys does not match", 1, pm.createCompilationUnitKeys().size());
111         keys = generateKeys(new Object JavaDoc[]{"loc2"}, new String JavaDoc[]{"label_loc2"});
112         assertKeyEquals(keys, pm.createCompilationUnitKeys());
113     }
114
115     public void testAdvancedAddSourceFolder() throws Exception JavaDoc {
116         ProjectModel pm = createEmptyProjectModel();
117         pm.setSourceLevel("jdk1x");
118         JavaProjectGenerator.SourceFolder sf = new JavaProjectGenerator.SourceFolder();
119         sf.location = "loc1";
120         sf.label = "label_loc1";
121         sf.type = "java";
122         pm.addSourceFolder(sf, false);
123         assertEquals("Number of source folders does not match", 1, pm.getSourceFoldersCount());
124         assertEquals("Number of comp units does not match", 1, pm.getJavaCompilationUnits().size());
125         assertEquals("Number of comp unit keys does not match", 1, pm.createCompilationUnitKeys().size());
126         List JavaDoc keys = generateKeys(new Object JavaDoc[]{"loc1"}, new String JavaDoc[]{"label_loc1"});
127         assertKeyEquals(keys, pm.createCompilationUnitKeys());
128
129         sf = new JavaProjectGenerator.SourceFolder();
130         sf.location = "loc2";
131         sf.label = "label_loc2";
132         sf.type = "java";
133         pm.addSourceFolder(sf, false);
134         assertEquals("Number of source folders does not match", 2, pm.getSourceFoldersCount());
135         assertEquals("Number of comp units does not match", 2, pm.getJavaCompilationUnits().size());
136         assertEquals("Number of comp unit keys does not match", 2, pm.createCompilationUnitKeys().size());
137         keys = generateKeys(new Object JavaDoc[]{"loc1", "loc2"}, new String JavaDoc[]{"label_loc1", "label_loc2"});
138         assertKeyEquals(keys, pm.createCompilationUnitKeys());
139
140         sf = new JavaProjectGenerator.SourceFolder();
141         sf.location = "locWEB";
142         sf.label = "label_locWEB";
143         sf.type = "web";
144         pm.addSourceFolder(sf, false);
145         assertEquals("Number of source folders does not match", 3, pm.getSourceFoldersCount());
146         assertEquals("Number of comp units does not match", 2, pm.getJavaCompilationUnits().size());
147         assertEquals("Number of comp unit keys does not match", 2, pm.createCompilationUnitKeys().size());
148         keys = generateKeys(new Object JavaDoc[]{"loc1", "loc2"}, new String JavaDoc[]{"label_loc1", "label_loc2"});
149         assertKeyEquals(keys, pm.createCompilationUnitKeys());
150
151         pm.removeSourceFolder(2);
152         assertEquals("Number of source folders does not match", 2, pm.getSourceFoldersCount());
153         assertEquals("Number of comp units does not match", 2, pm.getJavaCompilationUnits().size());
154         assertEquals("Number of comp unit keys does not match", 2, pm.createCompilationUnitKeys().size());
155         keys = generateKeys(new Object JavaDoc[]{"loc1", "loc2"}, new String JavaDoc[]{"label_loc1", "label_loc2"});
156         assertKeyEquals(keys, pm.createCompilationUnitKeys());
157         
158         pm.updateCompilationUnits(false);
159         assertEquals("Number of source folders does not match", 2, pm.getSourceFoldersCount());
160         assertEquals("Number of comp units does not match", 1, pm.getJavaCompilationUnits().size());
161         assertEquals("Number of comp unit keys does not match", 1, pm.createCompilationUnitKeys().size());
162         keys = generateKeys(new Object JavaDoc[]{Arrays.asList("loc1", "loc2")}, new String JavaDoc[]{null});
163         assertKeyEquals(keys, pm.createCompilationUnitKeys());
164         
165         sf = new JavaProjectGenerator.SourceFolder();
166         sf.location = "loc3";
167         sf.label = "label_loc3";
168         sf.type = "java";
169         pm.addSourceFolder(sf, false);
170         assertEquals("Number of source folders does not match", 3, pm.getSourceFoldersCount());
171         assertEquals("Number of comp units does not match", 1, pm.getJavaCompilationUnits().size());
172         assertEquals("Number of comp unit keys does not match", 1, pm.createCompilationUnitKeys().size());
173         keys = generateKeys(new Object JavaDoc[]{Arrays.asList("loc1", "loc2", "loc3")}, new String JavaDoc[]{null});
174         assertKeyEquals(keys, pm.createCompilationUnitKeys());
175         
176         sf = new JavaProjectGenerator.SourceFolder();
177         sf.location = "locWEB";
178         sf.label = "label_locWEB";
179         sf.type = "web";
180         pm.addSourceFolder(sf, false);
181         assertEquals("Number of source folders does not match", 4, pm.getSourceFoldersCount());
182         assertEquals("Number of comp units does not match", 1, pm.getJavaCompilationUnits().size());
183         assertEquals("Number of comp unit keys does not match", 1, pm.createCompilationUnitKeys().size());
184         keys = generateKeys(new Object JavaDoc[]{Arrays.asList("loc1", "loc2", "loc3")}, new String JavaDoc[]{null});
185         assertKeyEquals(keys, pm.createCompilationUnitKeys());
186         
187         pm.removeSourceFolder(0);
188         pm.removeSourceFolder(0);
189         assertEquals("Number of source folders does not match", 2, pm.getSourceFoldersCount());
190         assertEquals("Number of comp units does not match", 1, pm.getJavaCompilationUnits().size());
191         assertEquals("Number of comp unit keys does not match", 1, pm.createCompilationUnitKeys().size());
192         keys = generateKeys(new Object JavaDoc[]{"loc3"}, new String JavaDoc[]{"label_loc3"});
193         assertKeyEquals(keys, pm.createCompilationUnitKeys());
194     }
195
196     public void testCreateCompilationUnitKeys() throws Exception JavaDoc {
197         List JavaDoc<JavaProjectGenerator.SourceFolder> sources;
198         List JavaDoc<JavaProjectGenerator.JavaCompilationUnit> units;
199         List JavaDoc<ProjectModel.CompilationUnitKey> keys;
200         List JavaDoc<ProjectModel.CompilationUnitKey> createdKeys;
201         
202         ProjectModel pm = createEmptyProjectModel();
203         
204         // case: some source folders; no comp unit
205
// expected result: one key for each source folder
206
sources = generateSources(new String JavaDoc[]{"src1", "src2", "src3"});
207         units = new ArrayList JavaDoc<JavaProjectGenerator.JavaCompilationUnit>();
208         keys = generateKeys(new Object JavaDoc[]{"src1", "src2", "src3"}, new String JavaDoc[]{"src1", "src2", "src3"});
209         pm.setSourceFolders(sources);
210         pm.setJavaCompilationUnits(units);
211         createdKeys = pm.createCompilationUnitKeys();
212         assertKeyEquals(keys, createdKeys);
213         
214         // case: one source folder; one comp unit for the source
215
// expected result: one key
216
sources = generateSources(new String JavaDoc[]{"src1"});
217         units = generateUnits(new Object JavaDoc[]{"src1"});
218         keys = generateKeys(new Object JavaDoc[]{"src1"}, new String JavaDoc[]{"src1"});
219         pm.setSourceFolders(sources);
220         pm.setJavaCompilationUnits(units);
221         createdKeys = pm.createCompilationUnitKeys();
222         assertKeyEquals(keys, createdKeys);
223         
224         // case: two source folders; two comp unit for the sources
225
// expected result: two key
226
sources = generateSources(new String JavaDoc[]{"src1", "src2"});
227         units = generateUnits(new Object JavaDoc[]{"src1", "src2"});
228         keys = generateKeys(new Object JavaDoc[]{"src1", "src2"}, new String JavaDoc[]{"src1", "src2"});
229         pm.setSourceFolders(sources);
230         pm.setJavaCompilationUnits(units);
231         createdKeys = pm.createCompilationUnitKeys();
232         assertKeyEquals(keys, createdKeys);
233         
234         // case: two source folders; one comp unit for both sources
235
// expected result: one key with null as location
236
sources = generateSources(new String JavaDoc[]{"src1", "src2"});
237         units = generateUnits(new Object JavaDoc[]{Arrays.asList("src1", "src2")});
238         keys = generateKeys(new Object JavaDoc[]{Arrays.asList("src1", "src2")}, new String JavaDoc[]{null});
239         pm.setSourceFolders(sources);
240         pm.setJavaCompilationUnits(units);
241         createdKeys = pm.createCompilationUnitKeys();
242         assertKeyEquals(keys, createdKeys);
243         
244         // case: mixed source folders; mixed comp units
245
sources = generateSources(new String JavaDoc[]{"src1", "src2"});
246         units = generateUnits(new Object JavaDoc[]{"src3", "src4"});
247         // XXX: impl dependency: the result will first contain comp units and then source folders:
248
keys = generateKeys(new Object JavaDoc[]{"src3", "src4", "src1", "src2"}, new String JavaDoc[]{null, null, "src1", "src2"});
249         pm.setSourceFolders(sources);
250         pm.setJavaCompilationUnits(units);
251         createdKeys = pm.createCompilationUnitKeys();
252         assertKeyEquals(keys, createdKeys);
253         
254         sources = generateSources(new String JavaDoc[]{"src1", "src2"});
255         units = generateUnits(new Object JavaDoc[]{Arrays.asList("src2", "src3")});
256         // XXX: impl dependency: the result will first contain comp units and then source folders:
257
keys = generateKeys(new Object JavaDoc[]{Arrays.asList("src2", "src3"), "src1"}, new String JavaDoc[]{null, "src1"});
258         pm.setSourceFolders(sources);
259         pm.setJavaCompilationUnits(units);
260         createdKeys = pm.createCompilationUnitKeys();
261         assertKeyEquals(keys, createdKeys);
262     }
263     
264     public void testUpdateCompilationUnits() throws Exception JavaDoc {
265         List JavaDoc sources;
266         List JavaDoc units = new ArrayList JavaDoc();
267         List JavaDoc expectedUnits;
268         
269         ProjectModel pm = createEmptyProjectModel();
270         
271         sources = generateSources(new String JavaDoc[]{"src1", "src2"});
272         JavaProjectGenerator.JavaCompilationUnit cu = new JavaProjectGenerator.JavaCompilationUnit();
273         cu.packageRoots = Collections.singletonList("src1");
274         JavaProjectGenerator.JavaCompilationUnit.CP cp = new JavaProjectGenerator.JavaCompilationUnit.CP();
275         cp.classpath = "cp1"+File.pathSeparatorChar+"cp2";
276         cp.mode = "compile";
277         cu.classpath = Collections.singletonList(cp);
278         cu.output = Arrays.asList(new String JavaDoc[]{"out1", "out2"});
279         units.add(cu);
280         cu = new JavaProjectGenerator.JavaCompilationUnit();
281         cu.packageRoots = Collections.singletonList("src2");
282         cp = new JavaProjectGenerator.JavaCompilationUnit.CP();
283         cp.classpath = "cp2"+File.pathSeparatorChar+"cp3";
284         cp.mode = "compile";
285         cu.classpath = Collections.singletonList(cp);
286         cu.output = Arrays.asList(new String JavaDoc[]{"out3"});
287         units.add(cu);
288         pm.setSourceFolders(sources);
289         pm.setJavaCompilationUnits(units);
290         pm.setSourceLevel("S_L_14");
291         pm.updateCompilationUnits(false);
292         assertEquals("Compilation units has to be merged into one", 1, units.size());
293         cu = (JavaProjectGenerator.JavaCompilationUnit)units.get(0);
294         assertEquals("Compilation unit has to have two package roots", 2, cu.packageRoots.size());
295         assertTrue("Missing expected package root: src1", cu.packageRoots.contains("src1"));
296         assertTrue("Missing expected package root: src2", cu.packageRoots.contains("src2"));
297         assertEquals("Compilation unit has to have three classpath items",
298             "cp1"+File.pathSeparatorChar+"cp2"+File.pathSeparatorChar+"cp3",
299             cu.classpath.get(0).classpath);
300         assertEquals("Compilation unit has to have three output items", 3, cu.output.size());
301         assertTrue("Missing expected package root: out1", cu.output.contains("out1"));
302         assertTrue("Missing expected package root: out2", cu.output.contains("out2"));
303         assertTrue("Missing expected package root: out2", cu.output.contains("out2"));
304         assertTrue("Missing expected source level: S_L_14", cu.sourceLevel.equals("S_L_14"));
305         
306         pm.setSourceFolders(sources);
307         pm.setJavaCompilationUnits(units);
308         pm.setSourceLevel("S_L_15");
309         pm.updateCompilationUnits(true);
310         assertEquals("Compilation units has to be cloned into two", 2, units.size());
311         cu = (JavaProjectGenerator.JavaCompilationUnit)units.get(0);
312         assertEquals("Compilation unit has to have one package root", 1, cu.packageRoots.size());
313         assertTrue("Missing expected package root", cu.packageRoots.contains("src1"));
314         assertEquals("Compilation unit has to have three classpath items",
315             "cp1"+File.pathSeparatorChar+"cp2"+File.pathSeparatorChar+"cp3",
316             cu.classpath.get(0).classpath);
317         assertEquals("Compilation unit has to have three output items", 3, cu.output.size());
318         assertTrue("Missing expected package root: out1", cu.output.contains("out1"));
319         assertTrue("Missing expected package root: out2", cu.output.contains("out2"));
320         assertTrue("Missing expected package root: out2", cu.output.contains("out2"));
321         assertTrue("Missing expected source level: S_L_14", cu.sourceLevel.equals("S_L_15"));
322         cu = (JavaProjectGenerator.JavaCompilationUnit)units.get(1);
323         assertEquals("Compilation unit has to have one package root", 1, cu.packageRoots.size());
324         assertTrue("Missing expected package root", cu.packageRoots.contains("src2"));
325         assertEquals("Compilation unit has to have three classpath items",
326             "cp1"+File.pathSeparatorChar+"cp2"+File.pathSeparatorChar+"cp3",
327             cu.classpath.get(0).classpath);
328         assertEquals("Compilation unit has to have three output items", 3, cu.output.size());
329         assertTrue("Missing expected package root: out1", cu.output.contains("out1"));
330         assertTrue("Missing expected package root: out2", cu.output.contains("out2"));
331         assertTrue("Missing expected package root: out2", cu.output.contains("out2"));
332         assertTrue("Missing expected source level: S_L_14", cu.sourceLevel.equals("S_L_15"));
333         
334     }
335     
336     public void testUpdatePrincipalSourceFolders() throws Exception JavaDoc {
337         ProjectModel pm = createEmptyProjectModel();
338         List JavaDoc<JavaProjectGenerator.SourceFolder> l = pm.getSourceFolders();
339         // base folder and proj folder are different
340
List JavaDoc<JavaProjectGenerator.SourceFolder> l2 = pm.updatePrincipalSourceFolders(l, true);
341         assertEquals("Principal source for base directory must be added", 1, l2.size());
342         l2 = pm.updatePrincipalSourceFolders(l, false);
343         assertEquals("There are no external java source folders", 0, l2.size());
344         
345         pm = createEmptyProjectModel();
346         JavaProjectGenerator.SourceFolder sf = new JavaProjectGenerator.SourceFolder();
347         sf.location = "..\\something";
348         sf.label = "something";
349         sf.type = "java";
350         l = pm.getSourceFolders();
351         pm.addSourceFolder(sf, false);
352         l2 = pm.updatePrincipalSourceFolders(l, false);
353         assertEquals("One principal source must be added", 2, l2.size());
354         
355         pm = createEmptyProjectModel();
356         JavaProjectGenerator.SourceFolder sf2 = new JavaProjectGenerator.SourceFolder();
357         sf2.location = "..\\something2";
358         sf2.label = "something2";
359         sf2.type = "java";
360         pm.addSourceFolder(sf, false);
361         pm.addSourceFolder(sf2, false);
362         pm.removeSourceFolder(0);
363         pm.removeSourceFolder(0);
364         pm.addSourceFolder(sf, false);
365         pm.addSourceFolder(sf2, false);
366         pm.removeSourceFolder(0);
367         pm.addSourceFolder(sf, false);
368         l = pm.getSourceFolders();
369         l2 = pm.updatePrincipalSourceFolders(l, false);
370         assertEquals("Two principal sources must be added", 4, l2.size());
371         JavaProjectGenerator.SourceFolder addedSF = l2.get(2);
372         assertEquals("Added principal source must have the same label", addedSF.label, sf.label);
373         assertEquals("Added principal source must have the same location", addedSF.location, sf.location);
374         assertNull("Added principal source must have type==null", addedSF.type);
375         addedSF = l2.get(3);
376         assertEquals("Added principal source must have the same label", addedSF.label, sf2.label);
377         assertEquals("Added principal source must have the same location", addedSF.location, sf2.location);
378         assertNull("Added principal source must have type==null", addedSF.type);
379         pm.removeSourceFolder(0);
380         l = pm.getSourceFolders();
381         l2 = pm.updatePrincipalSourceFolders(l, false);
382         assertEquals("One principal source must be removed", 2, l2.size());
383
384         JavaProjectGenerator.SourceFolder sf2_ = new JavaProjectGenerator.SourceFolder();
385         sf2_.location = "..\\something2";
386         sf2_.label = "something2";
387         sf2_.type = null;
388         pm = createEmptyProjectModel();
389         pm.addSourceFolder(sf2, false);
390         pm.addSourceFolder(sf2_, false);
391         l = pm.getSourceFolders();
392         l2 = pm.updatePrincipalSourceFolders(l, false);
393         assertEquals("No principal sources added in this case because it already exist", l.size(), l2.size());
394     }
395     
396     private List JavaDoc<JavaProjectGenerator.SourceFolder> generateSources(String JavaDoc[] locations) {
397         List JavaDoc<JavaProjectGenerator.SourceFolder> l = new ArrayList JavaDoc<JavaProjectGenerator.SourceFolder>(locations.length);
398         for (String JavaDoc loc : locations) {
399             JavaProjectGenerator.SourceFolder sf = new JavaProjectGenerator.SourceFolder();
400             sf.location = loc;
401             sf.label = loc;
402             sf.type = "java";
403             l.add(sf);
404         }
405         return l;
406     }
407
408     /**
409      * @param locations can be either String or List instance
410      */

411     private List JavaDoc generateUnits(Object JavaDoc[] locations) {
412         List JavaDoc l = new ArrayList JavaDoc(locations.length);
413         for (int i=0; i<locations.length; i++) {
414             JavaProjectGenerator.JavaCompilationUnit cu = new JavaProjectGenerator.JavaCompilationUnit();
415             if (locations[i] instanceof List JavaDoc) { // XXX use Union2
416
cu.packageRoots = (List JavaDoc)locations[i];
417             } else {
418                 cu.packageRoots = Collections.singletonList((String JavaDoc) locations[i]);
419             }
420             l.add(cu);
421         }
422         return l;
423     }
424     
425     /**
426      * @param locations can be either String or List instance
427      */

428     private List JavaDoc<ProjectModel.CompilationUnitKey> generateKeys(Object JavaDoc[] locations, String JavaDoc[] labels) {
429         List JavaDoc<ProjectModel.CompilationUnitKey> l = new ArrayList JavaDoc<ProjectModel.CompilationUnitKey>(locations.length);
430         for (int i=0; i<locations.length; i++) {
431             ProjectModel.CompilationUnitKey key = new ProjectModel.CompilationUnitKey();
432             if (locations[i] instanceof List JavaDoc) {
433                 key.locations = (List JavaDoc)locations[i];
434             } else {
435                 key.locations = Collections.singletonList((String JavaDoc) locations[i]);
436             }
437             key.label = labels[i];
438             l.add(key);
439         }
440         return l;
441     }
442     
443     private void assertKeyEquals(List JavaDoc<ProjectModel.CompilationUnitKey> l1, List JavaDoc<ProjectModel.CompilationUnitKey> l2) throws Exception JavaDoc {
444         String JavaDoc param = "Keys do not match: Expected: "+l1+" Result:"+l2; // NOI18N
445
assertEquals(param, l1, l2);
446         Iterator JavaDoc<ProjectModel.CompilationUnitKey> i1 = l1.iterator();
447         Iterator JavaDoc<ProjectModel.CompilationUnitKey> i2 = l2.iterator();
448         while (i1.hasNext()) {
449             ProjectModel.CompilationUnitKey k1 = i1.next();
450             ProjectModel.CompilationUnitKey k2 = i2.next();
451             assertEquals(param, k1.label, k2.label);
452         }
453     }
454
455     private ProjectModel createEmptyProjectModel() throws Exception JavaDoc {
456         File JavaDoc baseFolder = new File JavaDoc(getWorkDir(), "somefolder/");
457         File JavaDoc nbProjectFolder = new File JavaDoc(getWorkDir(), "nbprojfolder/");
458         Map JavaDoc<String JavaDoc,String JavaDoc> p = new HashMap JavaDoc<String JavaDoc,String JavaDoc>();
459         p.put("key", "value");
460         PropertyEvaluator evaluator = PropertyUtils.sequentialPropertyEvaluator(null, PropertyUtils.fixedPropertyProvider(p));
461         return ProjectModel.createEmptyModel(baseFolder, nbProjectFolder, evaluator);
462     }
463     
464 }
465
Popular Tags