KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ui > customizer > SingleModulePropertiesTest


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.apisupport.project.ui.customizer;
21
22 import java.io.File JavaDoc;
23 import java.io.FileInputStream JavaDoc;
24 import java.io.FileOutputStream JavaDoc;
25 import java.io.IOException JavaDoc;
26 import java.io.InputStream JavaDoc;
27 import java.io.OutputStream JavaDoc;
28 import java.util.ArrayList JavaDoc;
29 import java.util.Arrays JavaDoc;
30 import java.util.HashMap JavaDoc;
31 import java.util.Iterator JavaDoc;
32 import java.util.Map JavaDoc;
33 import java.util.Set JavaDoc;
34 import java.util.jar.Manifest JavaDoc;
35 import org.netbeans.api.project.Project;
36 import org.netbeans.api.project.ProjectManager;
37 import org.netbeans.api.project.ProjectUtils;
38 import org.netbeans.modules.apisupport.project.EditableManifest;
39 import org.netbeans.modules.apisupport.project.ManifestManager;
40 import org.netbeans.modules.apisupport.project.NbModuleProject;
41 import org.netbeans.modules.apisupport.project.NbModuleProjectGenerator;
42 import org.netbeans.modules.apisupport.project.spi.NbModuleProvider;
43 import org.netbeans.modules.apisupport.project.ProjectXMLManager;
44 import org.netbeans.modules.apisupport.project.SuiteProvider;
45 import org.netbeans.modules.apisupport.project.TestBase;
46 import org.netbeans.modules.apisupport.project.Util;
47 import org.netbeans.modules.apisupport.project.suite.SuiteProject;
48 import org.netbeans.modules.apisupport.project.ui.customizer.CustomizerComponentFactory.PublicPackagesTableModel;
49 import org.netbeans.modules.apisupport.project.universe.LocalizedBundleInfo;
50 import org.netbeans.modules.apisupport.project.universe.ModuleEntry;
51 import org.netbeans.modules.apisupport.project.universe.ModuleList;
52 import org.netbeans.spi.project.support.ant.EditableProperties;
53 import org.openide.filesystems.FileLock;
54 import org.openide.filesystems.FileObject;
55 import org.openide.filesystems.FileUtil;
56 import org.openide.util.Mutex;
57
58 // XXX mkrauskopf: don't use libs/xerces for testing purposes of apisupport
59
// since it could fail with a new version of xerces lib! Generate or create some
60
// testing modules in apisupport testing data section instead.
61

62 /**
63  * Tests {@link SingleModuleProperties}. Actually also for some classes which
64  * SingleModuleProperties utilizes - which doesn't mean they shouldn't be tested
65  * individually :)
66  *
67  * @author Martin Krauskopf
68  */

69 public class SingleModulePropertiesTest extends TestBase {
70     
71     public SingleModulePropertiesTest(String JavaDoc name) {
72         super(name);
73     }
74     
75     protected void setUp() throws Exception JavaDoc {
76         clearWorkDir();
77         super.setUp();
78     }
79     
80     /** Tests few basic properties to be sure that loading works. */
81     public void testThatBasicPropertiesAreLoaded() throws Exception JavaDoc {
82         NbModuleProject p = generateStandaloneModule("module1");
83         SingleModuleProperties props = loadProperties(p);
84         assertNotNull(props.getActivePlatform());
85         assertNotNull("loading bundle info", props.getBundleInfo());
86         assertEquals("display name", "Testing Module", props.getBundleInfo().getDisplayName());
87         assertEquals("cnb", "org.example.module1", props.getCodeNameBase());
88         assertNull("no impl. version", props.getImplementationVersion());
89         assertTrue("jar file", props.getJarFile().endsWith("org-example-module1.jar"));
90         assertEquals("major release version", null, props.getMajorReleaseVersion());
91         assertEquals("spec. version", "1.0", props.getSpecificationVersion());
92     }
93     
94     public void testThatPropertiesAreRefreshed() throws Exception JavaDoc {
95         NbModuleProject p = generateStandaloneModule("module1");
96         SingleModuleProperties props = loadProperties(p);
97         assertEquals("spec. version", "1.0", props.getSpecificationVersion());
98         assertEquals("display name", "Testing Module", props.getBundleInfo().getDisplayName());
99         assertEquals("number of dependencies", 0, props.getDependenciesListModel().getSize());
100         
101         // silently change manifest
102
InputStream JavaDoc is = new FileInputStream JavaDoc(props.getManifestFile());
103         EditableManifest em = new EditableManifest();
104         try {
105             em = new EditableManifest(is);
106         } finally {
107             is.close();
108         }
109         em.setAttribute(ManifestManager.OPENIDE_MODULE_SPECIFICATION_VERSION, "1.1", null);
110         OutputStream JavaDoc os = new FileOutputStream JavaDoc(props.getManifestFile());
111         try {
112             em.write(os);
113         } finally {
114             os.close();
115         }
116         
117         // silently change bundle
118
EditableProperties ep = new EditableProperties();
119         is = new FileInputStream JavaDoc(props.getBundleInfo().getPaths()[0]);
120         try {
121             ep.load(is);
122         } finally {
123             is.close();
124         }
125         ep.setProperty(LocalizedBundleInfo.NAME, "Miscellaneous");
126         os = new FileOutputStream JavaDoc(props.getBundleInfo().getPaths()[0]);
127         try {
128             ep.store(os);
129         } finally {
130             os.close();
131         }
132         
133         // modify project.xml
134
Util.addDependency(p, "org.netbeans.modules.java.project", "1", null, false);
135         ProjectManager.getDefault().saveProject(p);
136         
137         simulatePropertiesOpening(props, p);
138         
139         // check that manifest and bundle has been reloaded
140
assertEquals("spec. version", "1.1", props.getSpecificationVersion());
141         assertEquals("display name should be changed", "Miscellaneous", props.getBundleInfo().getDisplayName());
142         assertEquals("number of dependencies", 1, props.getDependenciesListModel().getSize());
143     }
144     
145     public void testThatPropertiesListen() throws Exception JavaDoc {
146         NbModuleProject p = generateStandaloneModule("module1");
147         SingleModuleProperties props = loadProperties(p);
148         assertEquals("display name from ProjectInformation", "Testing Module",
149                 ProjectUtils.getInformation(p).getDisplayName());
150         assertEquals("display name from LocalizedBundleInfo", "Testing Module",
151                 props.getBundleInfo().getDisplayName());
152         
153         FileObject bundleFO = FileUtil.toFileObject(props.getBundleInfo().getPaths()[0]);
154         EditableProperties bundleEP = Util.loadProperties(bundleFO);
155         bundleEP.setProperty(LocalizedBundleInfo.NAME, "Miscellaneous");
156         // let's fire a change
157
Util.storeProperties(bundleFO, bundleEP);
158         
159         // display name should be refreshed
160
assertEquals("display name was refreshed in ProjectInformation", "Miscellaneous",
161                 ProjectUtils.getInformation(p).getDisplayName());
162         assertEquals("display name was refreshed in LocalizedBundleInfo", "Miscellaneous",
163                 props.getBundleInfo().getDisplayName());
164     }
165     
166     public void testGetPublicPackages() throws Exception JavaDoc {
167         final NbModuleProject p = generateStandaloneModule("module1");
168         FileUtil.createData(p.getSourceDirectory(), "org/example/module1/One.java");
169         FileUtil.createData(p.getSourceDirectory(), "org/example/module1/resources/Two.java");
170         
171         // apply and save project
172
Boolean JavaDoc result = (Boolean JavaDoc) ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction() {
173             public Object JavaDoc run() throws IOException JavaDoc {
174                 ProjectXMLManager pxm = new ProjectXMLManager(p);
175                 String JavaDoc[] newPP = new String JavaDoc[] { "org.example.module1" };
176                 pxm.replacePublicPackages(newPP);
177                 return Boolean.TRUE;
178             }
179         });
180         assertTrue("replace public packages", result.booleanValue());
181         ProjectManager.getDefault().saveProject(p);
182         
183         SingleModuleProperties props = loadProperties(p);
184         PublicPackagesTableModel pptm = props.getPublicPackagesModel();
185         assertEquals("number of available public packages", 2, pptm.getRowCount());
186         assertEquals("number of selected public packages", 1, pptm.getSelectedPackages().length);
187         
188         // libs/xerces properties
189
NbModuleProject libP = (NbModuleProject) ProjectManager.getDefault().findProject(nbCVSRoot().getFileObject("libs/xerces"));
190         props = loadProperties(libP);
191         pptm = props.getPublicPackagesModel();
192         assertEquals("number of available public packages", 39, pptm.getRowCount());
193         assertEquals("number of selected public packages", 39, pptm.getSelectedPackages().length);
194     }
195     
196     public void testThatProjectWithoutBundleDoesNotThrowNPE_61469() throws Exception JavaDoc {
197         FileObject pFO = TestBase.generateStandaloneModuleDirectory(getWorkDir(), "module1");
198         FileObject propsFO = FileUtil.toFileObject(new File JavaDoc(getWorkDir(),
199                 "module1/src/org/example/module1/resources/Bundle.properties"));
200         propsFO.delete();
201         NbModuleProject p = (NbModuleProject) ProjectManager.getDefault().findProject(pFO);
202         SingleModuleProperties props = loadProperties(p);
203         simulatePropertiesOpening(props, p);
204     }
205     
206     public void testThatManifestFormattingIsNotMessedUp_61248() throws Exception JavaDoc {
207         NbModuleProject p = generateStandaloneModule("module1");
208         EditableManifest em = Util.loadManifest(p.getManifestFile());
209         em.setAttribute(ManifestManager.OPENIDE_MODULE_REQUIRES, "\n" +
210                 " org.openide.execution.ExecutionEngine,\n" +
211                 " org.openide.windows.IOProvider", null);
212         Util.storeManifest(p.getManifestFile(), em);
213         String JavaDoc before = TestBase.slurp(p.getManifestFile());
214         
215         SingleModuleProperties props = loadProperties(p);
216         // two lines below are ensured by CustomizerVersioning - let's simulate it
217
props.setImplementationVersion("");
218         props.setProvidedTokens("");
219         props.storeProperties();
220         ProjectManager.getDefault().saveProject(p);
221         String JavaDoc after = TestBase.slurp(p.getManifestFile());
222         
223         assertEquals("the same content", before, after);
224     }
225     
226     public void testNiceFormattingForRequiredTokensInManifest_63516() throws Exception JavaDoc {
227         NbModuleProject p = generateStandaloneModule("module1");
228         EditableManifest em = Util.loadManifest(p.getManifestFile());
229         em.setAttribute(ManifestManager.OPENIDE_MODULE_REQUIRES, "\n" +
230                 " org.openide.execution.ExecutionEngine,\n" +
231                 " org.openide.windows.IOProvider", null);
232         Util.storeManifest(p.getManifestFile(), em);
233         
234         SingleModuleProperties props = loadProperties(p);
235         props.getRequiredTokenListModel().addToken("org.netbeans.api.javahelp.Help");
236         // two lines below are ensured by CustomizerVersioning - let's simulate it
237
props.setImplementationVersion("");
238         props.setProvidedTokens("");
239         props.storeProperties();
240         ProjectManager.getDefault().saveProject(p);
241         String JavaDoc real = TestBase.slurp(p.getManifestFile());
242         String JavaDoc expected = "Manifest-Version: 1.0\n" +
243                 "OpenIDE-Module: org.example.module1\n" +
244                 "OpenIDE-Module-Layer: org/example/module1/resources/layer.xml\n" +
245                 "OpenIDE-Module-Localizing-Bundle: org/example/module1/resources/Bundle.properties\n" +
246                 "OpenIDE-Module-Requires: \n" +
247                 " org.netbeans.api.javahelp.Help,\n" +
248                 " org.openide.execution.ExecutionEngine,\n" +
249                 " org.openide.windows.IOProvider\n" +
250                 "OpenIDE-Module-Specification-Version: 1.0\n\n";
251         
252         assertEquals("expected content", expected, real);
253         
254         props.getRequiredTokenListModel().removeToken("org.openide.execution.ExecutionEngine");
255         props.getRequiredTokenListModel().removeToken("org.netbeans.api.javahelp.Help");
256         props.storeProperties();
257         ProjectManager.getDefault().saveProject(p);
258         real = TestBase.slurp(p.getManifestFile());
259         expected = "Manifest-Version: 1.0\n" +
260                 "OpenIDE-Module: org.example.module1\n" +
261                 "OpenIDE-Module-Layer: org/example/module1/resources/layer.xml\n" +
262                 "OpenIDE-Module-Localizing-Bundle: org/example/module1/resources/Bundle.properties\n" +
263                 "OpenIDE-Module-Requires: org.openide.windows.IOProvider\n" +
264                 "OpenIDE-Module-Specification-Version: 1.0\n\n";
265         
266         assertEquals("expected content", expected, real);
267     }
268     
269     public void testAvailablePublicPackages() throws Exception JavaDoc {
270         Map JavaDoc/*<String,String>*/ contents = new HashMap JavaDoc();
271         contents.put("lib/pkg/Clazz3.class", "");
272         contents.put("lib/pkg2/Clazz4.class", "");
273         contents.put("1.0/oldlib/Clazz5.class", ""); // #72669
274
File JavaDoc jar = new File JavaDoc(getWorkDir(), "some.jar");
275         createJar(jar, contents, new Manifest JavaDoc());
276         SuiteProject sweet = generateSuite("sweet");
277         File JavaDoc moduleDir = new File JavaDoc(getWorkDir(), "module");
278         NbModuleProjectGenerator.createSuiteLibraryModule(
279                 moduleDir, "module", "Module", "module/Bundle.properties",
280                 sweet.getProjectDirectoryFile(), null, new File JavaDoc[] {jar});
281         NbModuleProject p = (NbModuleProject) ProjectManager.getDefault().findProject(FileUtil.toFileObject(moduleDir));
282         FileObject srcDir = p.getProjectDirectory().getFileObject("src");
283         FileUtil.createData(srcDir, "pkg1/Clazz1.java");
284         FileUtil.createData(srcDir, "pkg1/Clazz2.java");
285         FileUtil.createData(srcDir, "pkg2/CVS/#1.20#Clazz1.java");
286         FileUtil.createData(srcDir, "pkg2/Clazz1.java");
287         FileUtil.createData(srcDir, "pkg2/deeper/Clazz1.java");
288         FileUtil.createData(srcDir, "pkg2/deeper/and/deeper/Clazz1.java");
289         FileUtil.createData(srcDir, ".broken/Clazz.java"); // #72669
290
assertEquals(Arrays.asList(new String JavaDoc[] {"lib.pkg", "lib.pkg2", "pkg1", "pkg2", "pkg2.deeper", "pkg2.deeper.and.deeper"}),
291                 new ArrayList JavaDoc(SingleModuleProperties.getInstance(p).getAvailablePublicPackages()));
292     }
293     
294     public void testPublicPackagesAreUpToDate_63561() throws Exception JavaDoc {
295         SuiteProject suite1 = generateSuite("suite1");
296         final NbModuleProject p = TestBase.generateSuiteComponent(suite1, "module1a");
297         FileUtil.createData(p.getSourceDirectory(), "org/example/module1a/Dummy.java");
298         SingleModuleProperties props = loadProperties(p);
299         PublicPackagesTableModel pptm = props.getPublicPackagesModel();
300         assertEquals("number of available public packages", 1, pptm.getRowCount());
301         assertEquals("number of selected public packages", 0, pptm.getSelectedPackages().length);
302         assertEquals("no public packages in the ModuleEntry", 0, props.getModuleList().getEntry("org.example.module1a").getPublicPackages().length);
303         
304         // apply and save project
305
Boolean JavaDoc result = (Boolean JavaDoc) ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction() {
306             public Object JavaDoc run() throws IOException JavaDoc {
307                 ProjectXMLManager pxm = new ProjectXMLManager(p);
308                 String JavaDoc[] newPP = new String JavaDoc[] { "org.example.module1a" };
309                 pxm.replacePublicPackages(newPP);
310                 return Boolean.TRUE;
311             }
312         });
313         assertTrue("replace public packages", result.booleanValue());
314         ProjectManager.getDefault().saveProject(p);
315         
316         simulatePropertiesOpening(props, p);
317         
318         pptm = props.getPublicPackagesModel();
319         assertEquals("number of available public packages", 1, pptm.getRowCount());
320         assertEquals("number of selected public packages", 1, pptm.getSelectedPackages().length);
321         assertEquals("one public packages in the ModuleEntry", 1, props.getModuleList().getEntry("org.example.module1a").getPublicPackages().length);
322     }
323     
324     /** Test that a module doesn't offer itself in its dependency list. */
325     public void testThatTheModuleDoesNotOfferItself_61232() throws Exception JavaDoc {
326         NbModuleProject p = generateStandaloneModule("module1");
327         SingleModuleProperties props = loadProperties(p);
328         Set JavaDoc set = props.getUniverseDependencies(true);
329         for (Iterator JavaDoc it = set.iterator() ; it.hasNext() ; ) {
330             ModuleDependency dependency = (ModuleDependency) it.next();
331             ModuleEntry me = dependency.getModuleEntry();
332             assertFalse("module doesn't offer itself in its dependency list: " + p.getCodeNameBase(),
333                     p.getCodeNameBase().equals(me.getCodeNameBase()));
334         }
335     }
336     
337     public void testGetAvailableFriends() throws Exception JavaDoc {
338         // standalone
339
NbModuleProject standAlone = generateStandaloneModule("module1");
340         SingleModuleProperties props = loadProperties(standAlone);
341         assertEquals("There are no friends for standalone module.", 0, props.getAvailableFriends().length);
342         
343         // suitecomponent
344
SuiteProject suite1 = generateSuite("suite1");
345         TestBase.generateSuiteComponent(suite1, "component1");
346         NbModuleProject component2 = TestBase.generateSuiteComponent(suite1, "component2");
347         TestBase.generateSuiteComponent(suite1, "component3");
348         props = loadProperties(component2);
349         assertEquals("There are two available friends for component2.", 2, props.getAvailableFriends().length);
350         
351         // netbeans.org
352
Project javaProject = ProjectManager.getDefault().findProject(nbCVSRoot().getFileObject("java/project"));
353         props = loadProperties((NbModuleProject) javaProject);
354         assertTrue("There are two available friends for component2.", props.getAvailableFriends().length > 50);
355     }
356     
357     public void testSimulateLocalizedBundlePackageRefactoring() throws Exception JavaDoc {
358         NbModuleProject p = generateStandaloneModule("module1");
359         SingleModuleProperties props = loadProperties(p);
360         assertEquals("display name from ProjectInformation", "Testing Module",
361                 ProjectUtils.getInformation(p).getDisplayName());
362         assertEquals("display name from LocalizedBundleInfo", "Testing Module",
363                 props.getBundleInfo().getDisplayName());
364         
365         // rename package
366
FileObject pDir = p.getProjectDirectory();
367         FileObject pkg = pDir.getFileObject("src/org/example/module1");
368         FileLock lock = pkg.lock();
369         pkg.rename(lock, "module1Renamed", null);
370         lock.releaseLock();
371         FileObject manifestFO = pDir.getFileObject("manifest.mf");
372         
373         // change manifest
374
EditableManifest mf = Util.loadManifest(manifestFO);
375         mf.setAttribute(ManifestManager.OPENIDE_MODULE_LOCALIZING_BUNDLE, "org/example/module1Renamed/resources/Bundle.properties", null);
376         Util.storeManifest(manifestFO, mf);
377         
378         simulatePropertiesOpening(props, p);
379         
380         // make sure that properties are not damaged
381
assertEquals("display name was refreshed in ProjectInformation", "Testing Module",
382                 ProjectUtils.getInformation(p).getDisplayName());
383         assertEquals("display name was refreshed in LocalizedBundleInfo", "Testing Module",
384                 props.getBundleInfo().getDisplayName());
385     }
386     
387     public void testSimulateIllLocalizedBundlePackageRefactoring_67961() throws Exception JavaDoc {
388         NbModuleProject p = generateStandaloneModule("module1");
389         SingleModuleProperties props = loadProperties(p);
390         assertEquals("display name from ProjectInformation", "Testing Module",
391                 ProjectUtils.getInformation(p).getDisplayName());
392         assertEquals("display name from LocalizedBundleInfo", "Testing Module",
393                 props.getBundleInfo().getDisplayName());
394         
395         // change manifest (will fire a change event before the package is actually renamed)
396
FileObject pDir = p.getProjectDirectory();
397         FileObject manifestFO = pDir.getFileObject("manifest.mf");
398         EditableManifest mf = Util.loadManifest(manifestFO);
399         mf.setAttribute(ManifestManager.OPENIDE_MODULE_LOCALIZING_BUNDLE, "org/example/module1Renamed/resources/Bundle.properties", null);
400         Util.storeManifest(manifestFO, mf);
401         
402         // rename package
403
FileObject pkg = pDir.getFileObject("src/org/example/module1");
404         FileLock lock = pkg.lock();
405         pkg.rename(lock, "module1Renamed", null);
406         lock.releaseLock();
407         
408         simulatePropertiesOpening(props, p);
409         
410         // make sure that properties are not damaged
411
assertEquals("display name was refreshed in ProjectInformation", "Testing Module",
412                 ProjectUtils.getInformation(p).getDisplayName());
413         assertEquals("display name was refreshed in LocalizedBundleInfo", "Testing Module",
414                 props.getBundleInfo().getDisplayName());
415     }
416     
417     public void testResolveFile() throws Exception JavaDoc {
418         NbModuleProject p = generateStandaloneModule("module1");
419         SingleModuleProperties props = loadProperties(p);
420         assertTrue("manifest exist", props.evaluateFile("manifest.mf").exists());
421         assertTrue("manifest exist", props.evaluateFile(props.getProjectDirectory() + "/manifest.mf").exists());
422         assertTrue("manifest exist", props.evaluateFile("${basedir}/manifest.mf").exists());
423         assertFalse("non-existing file", props.evaluateFile("non-existing").exists());
424         assertFalse("invalid reference", props.evaluateFile("${invalid-reference}/manifest.mf").exists());
425     }
426     
427     public void testThatFilesAreNotTouched_67249() throws Exception JavaDoc {
428         NbModuleProject p = generateStandaloneModule("module1");
429         FileUtil.createData(p.getSourceDirectory(), "org/example/module1/One.java");
430         FileUtil.createData(p.getSourceDirectory(), "org/example/module1/resources/Two.java");
431         SingleModuleProperties props = loadProperties(p);
432         
433         // times before change
434
FileObject bundle = FileUtil.toFileObject(props.getBundleInfo().getPaths()[0]);
435         FileObject mf = p.getManifestFile();
436         long mfTime = mf.lastModified().getTime();
437         long bundleTime = bundle.lastModified().getTime();
438         
439         // be sure we are not too fast
440
Thread.sleep(2000);
441         
442         // select a package
443
props.getPublicPackagesModel().setValueAt(Boolean.TRUE, 0, 0);
444         props.storeProperties();
445         
446         // compare with times after change
447
assertEquals("time for manifest has not changed", mfTime, mf.lastModified().getTime());
448         assertEquals("time for bundle has not changed", bundleTime, bundle.lastModified().getTime());
449     }
450     
451     public void testGetUniverseDependencies() throws Exception JavaDoc {
452         SuiteProject suite = generateSuite("suite");
453         
454         NbModuleProject testPrj = generateSuiteComponent(suite, "testPrj");
455         
456         NbModuleProject apiPrj = generateSuiteComponent(suite, "apiPrj");
457         FileUtil.createData(apiPrj.getProjectDirectory(), "src/api/Util.java");
458         SingleModuleProperties apiPrjProps = SingleModulePropertiesTest.loadProperties(apiPrj);
459         apiPrjProps.getPublicPackagesModel().setValueAt(Boolean.TRUE, 0, 0);
460         apiPrjProps.storeProperties();
461         ProjectManager.getDefault().saveProject(apiPrj);
462         
463         NbModuleProject friendPrj = generateSuiteComponent(suite, "friendPrj");
464         FileUtil.createData(friendPrj.getProjectDirectory(), "src/friend/Karel.java");
465         SingleModuleProperties friendPrjProps = SingleModulePropertiesTest.loadProperties(friendPrj);
466         friendPrjProps.getPublicPackagesModel().setValueAt(Boolean.TRUE, 0, 0);
467         friendPrjProps.getFriendListModel().addFriend("org.example.testPrj");
468         friendPrjProps.storeProperties();
469         ProjectManager.getDefault().saveProject(friendPrj);
470         
471         generateSuiteComponent(suite, "nonApiPrj");
472         ModuleEntry apiPrjME = ModuleList.getModuleList(testPrj.getProjectDirectoryFile()).getEntry("org.example.apiPrj");
473         ModuleDependency apiPrjDep = new ModuleDependency(apiPrjME);
474         ModuleEntry friendPrjME = ModuleList.getModuleList(testPrj.getProjectDirectoryFile()).getEntry("org.example.friendPrj");
475         ModuleDependency friendPrjDep = new ModuleDependency(friendPrjME);
476         ModuleEntry nonApiPrjME = ModuleList.getModuleList(testPrj.getProjectDirectoryFile()).getEntry("org.example.nonApiPrj");
477         ModuleDependency nonApiPrjDep = new ModuleDependency(nonApiPrjME);
478         
479         SingleModuleProperties testProps = SingleModulePropertiesTest.loadProperties(testPrj);
480         Set JavaDoc allDeps = testProps.getUniverseDependencies(false);
481         Set JavaDoc allDepsFilterExcluded = testProps.getUniverseDependencies(true);
482         Set JavaDoc apiDeps = testProps.getUniverseDependencies(false, true);
483         Set JavaDoc apiDepsFilterExcluded = testProps.getUniverseDependencies(true, true);
484         
485         assertTrue(allDeps.contains(apiPrjDep));
486         assertTrue(allDeps.contains(friendPrjDep));
487         assertTrue(allDeps.contains(nonApiPrjDep));
488         
489         assertTrue(allDepsFilterExcluded.contains(apiPrjDep));
490         assertTrue(allDepsFilterExcluded.contains(friendPrjDep));
491         assertTrue(allDepsFilterExcluded.contains(nonApiPrjDep));
492         
493         assertTrue(apiDeps.contains(apiPrjDep));
494         assertTrue(apiDeps.contains(friendPrjDep));
495         assertFalse(apiDeps.contains(nonApiPrjDep));
496         
497         assertTrue(apiDepsFilterExcluded.contains(apiPrjDep));
498         assertTrue(apiDepsFilterExcluded.contains(friendPrjDep));
499         assertFalse(apiDepsFilterExcluded.contains(nonApiPrjDep));
500         
501         // #72124: check that cluster include/exclude lists do not affect suite components:
502
EditableProperties ep = suite.getHelper().getProperties("nbproject/platform.properties");
503         ep.setProperty(SuiteProperties.ENABLED_CLUSTERS_PROPERTY, "crazy99"); // should not match any platform modules
504
suite.getHelper().putProperties("nbproject/platform.properties", ep);
505         ProjectManager.getDefault().saveProject(suite);
506         allDepsFilterExcluded = testProps.getUniverseDependencies(true);
507         assertTrue(allDepsFilterExcluded.contains(apiPrjDep));
508         assertTrue(allDepsFilterExcluded.contains(friendPrjDep));
509         assertTrue(allDepsFilterExcluded.contains(nonApiPrjDep));
510     }
511     
512     public void testDefaultPackageIsNotOffered_71532() throws Exception JavaDoc {
513         NbModuleProject p = generateStandaloneModule("module1");
514         FileUtil.createData(p.getProjectDirectory(), "src/BadInDefault.java");
515         FileUtil.createData(p.getProjectDirectory(), "src/org/example/module1/GoodOne.java");
516         assertEquals("one non-default valid package", 1, loadProperties(p).getPublicPackagesModel().getRowCount());
517     }
518     
519 // public void testReloadNetBeansModulueListSpeedHid() throws Exception {
520
// long startTotal = System.currentTimeMillis();
521
// SingleModuleProperties props = loadProperties(nbCVSRoot().getFileObject("apisupport/project"),
522
// "src/org/netbeans/modules/apisupport/project/Bundle.properties");
523
// long start = System.currentTimeMillis();
524
// props.reloadModuleListInfo();
525
// System.err.println("Reloading of module list: " + (System.currentTimeMillis() - start) + "msec");
526
// System.err.println("Total time: " + (System.currentTimeMillis() - startTotal) + "msec");
527
// }
528
//
529
// public void testReloadBinaryModulueListSpeedHid() throws Exception {
530
// long startTotal = System.currentTimeMillis();
531
// SingleModuleProperties props = loadProperties(suite2FO.getFileObject("misc-project"),
532
// "src/org/netbeans/examples/modules/misc/Bundle.properties");
533
// long start = System.currentTimeMillis();
534
// props.reloadModuleListInfo();
535
// System.err.println("Time to reload module list: " + (System.currentTimeMillis() - start) + "msec");
536
// System.err.println("Total time: " + (System.currentTimeMillis() - startTotal) + "msec");
537
// }
538

539     static SingleModuleProperties loadProperties(NbModuleProject project) throws IOException JavaDoc {
540         return new SingleModuleProperties(project.getHelper(), project.evaluator(),
541                 getSuiteProvider(project), getModuleType(project),
542                 (LocalizedBundleInfo.Provider) project.getLookup().lookup(LocalizedBundleInfo.Provider.class));
543     }
544     
545     private static NbModuleProvider.NbModuleType getModuleType(Project p) {
546         NbModuleProvider nmtp = (NbModuleProvider) p.getLookup().lookup(NbModuleProvider.class);
547         return nmtp.getModuleType();
548     }
549     
550     private static SuiteProvider getSuiteProvider(Project p) {
551         return (SuiteProvider) p.getLookup().lookup(SuiteProvider.class);
552     }
553     
554     private static void simulatePropertiesOpening(
555             final SingleModuleProperties props, final NbModuleProject p) {
556         props.refresh(getModuleType(p), getSuiteProvider(p));
557     }
558     
559 }
560
Popular Tags