Source Code Cross Referenced for SingleModulePropertiesTest.java in  » IDE-Netbeans » api » org » netbeans » modules » apisupport » project » ui » customizer » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » api » org.netbeans.modules.apisupport.project.ui.customizer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:
042:        package org.netbeans.modules.apisupport.project.ui.customizer;
043:
044:        import java.io.File;
045:        import java.io.FileInputStream;
046:        import java.io.FileOutputStream;
047:        import java.io.IOException;
048:        import java.io.InputStream;
049:        import java.io.OutputStream;
050:        import java.util.ArrayList;
051:        import java.util.Arrays;
052:        import java.util.HashMap;
053:        import java.util.Map;
054:        import java.util.Set;
055:        import java.util.jar.Manifest;
056:        import org.netbeans.api.project.Project;
057:        import org.netbeans.api.project.ProjectManager;
058:        import org.netbeans.api.project.ProjectUtils;
059:        import org.netbeans.modules.apisupport.project.EditableManifest;
060:        import org.netbeans.modules.apisupport.project.ManifestManager;
061:        import org.netbeans.modules.apisupport.project.NbModuleProject;
062:        import org.netbeans.modules.apisupport.project.NbModuleProjectGenerator;
063:        import org.netbeans.modules.apisupport.project.spi.NbModuleProvider;
064:        import org.netbeans.modules.apisupport.project.ProjectXMLManager;
065:        import org.netbeans.modules.apisupport.project.SuiteProvider;
066:        import org.netbeans.modules.apisupport.project.TestBase;
067:        import org.netbeans.modules.apisupport.project.Util;
068:        import org.netbeans.modules.apisupport.project.suite.SuiteProject;
069:        import org.netbeans.modules.apisupport.project.ui.customizer.CustomizerComponentFactory.PublicPackagesTableModel;
070:        import org.netbeans.modules.apisupport.project.universe.LocalizedBundleInfo;
071:        import org.netbeans.modules.apisupport.project.universe.ModuleEntry;
072:        import org.netbeans.modules.apisupport.project.universe.ModuleList;
073:        import org.netbeans.modules.apisupport.project.universe.NbPlatform;
074:        import org.netbeans.spi.project.support.ant.EditableProperties;
075:        import org.openide.filesystems.FileLock;
076:        import org.openide.filesystems.FileObject;
077:        import org.openide.filesystems.FileUtil;
078:        import org.openide.util.Mutex;
079:
080:        // XXX mkrauskopf: don't use libs/xerces for testing purposes of apisupport
081:        // since it could fail with a new version of xerces lib! Generate or create some
082:        // testing modules in apisupport testing data section instead.
083:
084:        /**
085:         * Tests {@link SingleModuleProperties}. Actually also for some classes which
086:         * SingleModuleProperties utilizes - which doesn't mean they shouldn't be tested
087:         * individually :)
088:         *
089:         * @author Martin Krauskopf
090:         */
091:        public class SingleModulePropertiesTest extends TestBase {
092:
093:            public SingleModulePropertiesTest(String name) {
094:                super (name);
095:            }
096:
097:            protected void setUp() throws Exception {
098:                clearWorkDir();
099:                super .setUp();
100:            }
101:
102:            /** Tests few basic properties to be sure that loading works. */
103:            public void testThatBasicPropertiesAreLoaded() throws Exception {
104:                NbModuleProject p = generateStandaloneModule("module1");
105:                SingleModuleProperties props = loadProperties(p);
106:                assertNotNull(props.getActivePlatform());
107:                assertNotNull("loading bundle info", props.getBundleInfo());
108:                assertEquals("display name", "Testing Module", props
109:                        .getBundleInfo().getDisplayName());
110:                assertEquals("cnb", "org.example.module1", props
111:                        .getCodeNameBase());
112:                assertNull("no impl. version", props.getImplementationVersion());
113:                assertTrue("jar file", props.getJarFile().endsWith(
114:                        "org-example-module1.jar"));
115:                assertEquals("major release version", null, props
116:                        .getMajorReleaseVersion());
117:                assertEquals("spec. version", "1.0", props
118:                        .getSpecificationVersion());
119:            }
120:
121:            public void testThatPropertiesAreRefreshed() throws Exception {
122:                NbModuleProject p = generateStandaloneModule("module1");
123:                SingleModuleProperties props = loadProperties(p);
124:                assertEquals("spec. version", "1.0", props
125:                        .getSpecificationVersion());
126:                assertEquals("display name", "Testing Module", props
127:                        .getBundleInfo().getDisplayName());
128:                assertEquals("number of dependencies", 0, props
129:                        .getDependenciesListModel().getSize());
130:
131:                // silently change manifest
132:                InputStream is = new FileInputStream(props.getManifestFile());
133:                EditableManifest em = new EditableManifest();
134:                try {
135:                    em = new EditableManifest(is);
136:                } finally {
137:                    is.close();
138:                }
139:                em.setAttribute(
140:                        ManifestManager.OPENIDE_MODULE_SPECIFICATION_VERSION,
141:                        "1.1", null);
142:                OutputStream os = new FileOutputStream(props.getManifestFile());
143:                try {
144:                    em.write(os);
145:                } finally {
146:                    os.close();
147:                }
148:
149:                // silently change bundle
150:                EditableProperties ep = new EditableProperties();
151:                is = new FileInputStream(props.getBundleInfo().getPaths()[0]);
152:                try {
153:                    ep.load(is);
154:                } finally {
155:                    is.close();
156:                }
157:                ep.setProperty(LocalizedBundleInfo.NAME, "Miscellaneous");
158:                os = new FileOutputStream(props.getBundleInfo().getPaths()[0]);
159:                try {
160:                    ep.store(os);
161:                } finally {
162:                    os.close();
163:                }
164:
165:                // modify project.xml
166:                Util.addDependency(p, "org.netbeans.modules.java.project", "1",
167:                        null, false);
168:                ProjectManager.getDefault().saveProject(p);
169:
170:                simulatePropertiesOpening(props, p);
171:
172:                // check that manifest and bundle has been reloaded
173:                assertEquals("spec. version", "1.1", props
174:                        .getSpecificationVersion());
175:                assertEquals("display name should be changed", "Miscellaneous",
176:                        props.getBundleInfo().getDisplayName());
177:                assertEquals("number of dependencies", 1, props
178:                        .getDependenciesListModel().getSize());
179:            }
180:
181:            public void testThatPropertiesListen() throws Exception {
182:                NbModuleProject p = generateStandaloneModule("module1");
183:                SingleModuleProperties props = loadProperties(p);
184:                assertEquals("display name from ProjectInformation",
185:                        "Testing Module", ProjectUtils.getInformation(p)
186:                                .getDisplayName());
187:                assertEquals("display name from LocalizedBundleInfo",
188:                        "Testing Module", props.getBundleInfo()
189:                                .getDisplayName());
190:
191:                FileObject bundleFO = FileUtil.toFileObject(props
192:                        .getBundleInfo().getPaths()[0]);
193:                EditableProperties bundleEP = Util.loadProperties(bundleFO);
194:                bundleEP.setProperty(LocalizedBundleInfo.NAME, "Miscellaneous");
195:                // let's fire a change
196:                Util.storeProperties(bundleFO, bundleEP);
197:
198:                // display name should be refreshed
199:                assertEquals(
200:                        "display name was refreshed in ProjectInformation",
201:                        "Miscellaneous", ProjectUtils.getInformation(p)
202:                                .getDisplayName());
203:                assertEquals(
204:                        "display name was refreshed in LocalizedBundleInfo",
205:                        "Miscellaneous", props.getBundleInfo().getDisplayName());
206:            }
207:
208:            public void testGetPublicPackages() throws Exception {
209:                final NbModuleProject p = generateStandaloneModule("module1");
210:                FileUtil.createData(p.getSourceDirectory(),
211:                        "org/example/module1/One.java");
212:                FileUtil.createData(p.getSourceDirectory(),
213:                        "org/example/module1/resources/Two.java");
214:
215:                // apply and save project
216:                boolean result = ProjectManager.mutex().writeAccess(
217:                        new Mutex.ExceptionAction<Boolean>() {
218:                            public Boolean run() throws IOException {
219:                                ProjectXMLManager pxm = new ProjectXMLManager(p);
220:                                String[] newPP = new String[] { "org.example.module1" };
221:                                pxm.replacePublicPackages(newPP);
222:                                return true;
223:                            }
224:                        });
225:                assertTrue("replace public packages", result);
226:                ProjectManager.getDefault().saveProject(p);
227:
228:                SingleModuleProperties props = loadProperties(p);
229:                PublicPackagesTableModel pptm = props.getPublicPackagesModel();
230:                assertEquals("number of available public packages", 2, pptm
231:                        .getRowCount());
232:                assertEquals("number of selected public packages", 1, pptm
233:                        .getSelectedPackages().length);
234:
235:                // libs.xerces properties
236:                NbModuleProject libP = (NbModuleProject) ProjectManager
237:                        .getDefault().findProject(
238:                                nbRoot().getFileObject("libs.xerces"));
239:                props = loadProperties(libP);
240:                pptm = props.getPublicPackagesModel();
241:                assertEquals("number of available public packages", 38, pptm
242:                        .getRowCount());
243:                assertEquals("number of selected public packages", 38, pptm
244:                        .getSelectedPackages().length);
245:            }
246:
247:            public void testThatProjectWithoutBundleDoesNotThrowNPE_61469()
248:                    throws Exception {
249:                FileObject pFO = TestBase.generateStandaloneModuleDirectory(
250:                        getWorkDir(), "module1");
251:                FileObject propsFO = FileUtil
252:                        .toFileObject(new File(getWorkDir(),
253:                                "module1/src/org/example/module1/resources/Bundle.properties"));
254:                propsFO.delete();
255:                NbModuleProject p = (NbModuleProject) ProjectManager
256:                        .getDefault().findProject(pFO);
257:                SingleModuleProperties props = loadProperties(p);
258:                simulatePropertiesOpening(props, p);
259:            }
260:
261:            public void testThatManifestFormattingIsNotMessedUp_61248()
262:                    throws Exception {
263:                NbModuleProject p = generateStandaloneModule("module1");
264:                EditableManifest em = Util.loadManifest(p.getManifestFile());
265:                em.setAttribute(ManifestManager.OPENIDE_MODULE_REQUIRES, "\n"
266:                        + "  org.openide.execution.ExecutionEngine,\n"
267:                        + "  org.openide.windows.IOProvider", null);
268:                Util.storeManifest(p.getManifestFile(), em);
269:                String before = TestBase.slurp(p.getManifestFile());
270:
271:                SingleModuleProperties props = loadProperties(p);
272:                // two lines below are ensured by CustomizerVersioning - let's simulate it
273:                props.setImplementationVersion("");
274:                props.setProvidedTokens("");
275:                props.storeProperties();
276:                ProjectManager.getDefault().saveProject(p);
277:                String after = TestBase.slurp(p.getManifestFile());
278:
279:                assertEquals("the same content", before, after);
280:            }
281:
282:            public void testNiceFormattingForRequiredTokensInManifest_63516()
283:                    throws Exception {
284:                NbModuleProject p = generateStandaloneModule("module1");
285:                EditableManifest em = Util.loadManifest(p.getManifestFile());
286:                em.setAttribute(ManifestManager.OPENIDE_MODULE_REQUIRES, "\n"
287:                        + "  org.openide.execution.ExecutionEngine,\n"
288:                        + "  org.openide.windows.IOProvider", null);
289:                Util.storeManifest(p.getManifestFile(), em);
290:
291:                SingleModuleProperties props = loadProperties(p);
292:                props.getRequiredTokenListModel().addToken(
293:                        "org.netbeans.api.javahelp.Help");
294:                // two lines below are ensured by CustomizerVersioning - let's simulate it
295:                props.setImplementationVersion("");
296:                props.setProvidedTokens("");
297:                props.storeProperties();
298:                ProjectManager.getDefault().saveProject(p);
299:                String real = TestBase.slurp(p.getManifestFile());
300:                String expected = "Manifest-Version: 1.0\n"
301:                        + "OpenIDE-Module: org.example.module1\n"
302:                        + "OpenIDE-Module-Layer: org/example/module1/resources/layer.xml\n"
303:                        + "OpenIDE-Module-Localizing-Bundle: org/example/module1/resources/Bundle.properties\n"
304:                        + "OpenIDE-Module-Requires: \n"
305:                        + "  org.netbeans.api.javahelp.Help,\n"
306:                        + "  org.openide.execution.ExecutionEngine,\n"
307:                        + "  org.openide.windows.IOProvider\n"
308:                        + "OpenIDE-Module-Specification-Version: 1.0\n\n";
309:
310:                assertEquals("expected content", expected, real);
311:
312:                props.getRequiredTokenListModel().removeToken(
313:                        "org.openide.execution.ExecutionEngine");
314:                props.getRequiredTokenListModel().removeToken(
315:                        "org.netbeans.api.javahelp.Help");
316:                props.storeProperties();
317:                ProjectManager.getDefault().saveProject(p);
318:                real = TestBase.slurp(p.getManifestFile());
319:                expected = "Manifest-Version: 1.0\n"
320:                        + "OpenIDE-Module: org.example.module1\n"
321:                        + "OpenIDE-Module-Layer: org/example/module1/resources/layer.xml\n"
322:                        + "OpenIDE-Module-Localizing-Bundle: org/example/module1/resources/Bundle.properties\n"
323:                        + "OpenIDE-Module-Requires: org.openide.windows.IOProvider\n"
324:                        + "OpenIDE-Module-Specification-Version: 1.0\n\n";
325:
326:                assertEquals("expected content", expected, real);
327:            }
328:
329:            public void testAvailablePublicPackages() throws Exception {
330:                Map<String, String> contents = new HashMap<String, String>();
331:                contents.put("lib/pkg/Clazz3.class", "");
332:                contents.put("lib/pkg2/Clazz4.class", "");
333:                contents.put("1.0/oldlib/Clazz5.class", ""); // #72669
334:                File jar = new File(getWorkDir(), "some.jar");
335:                createJar(jar, contents, new Manifest());
336:                SuiteProject sweet = generateSuite("sweet");
337:                File moduleDir = new File(getWorkDir(), "module");
338:                NbModuleProjectGenerator.createSuiteLibraryModule(moduleDir,
339:                        "module", "Module", "module/Bundle.properties", sweet
340:                                .getProjectDirectoryFile(), null,
341:                        new File[] { jar });
342:                NbModuleProject p = (NbModuleProject) ProjectManager
343:                        .getDefault().findProject(
344:                                FileUtil.toFileObject(moduleDir));
345:                FileObject srcDir = p.getProjectDirectory()
346:                        .getFileObject("src");
347:                FileUtil.createData(srcDir, "pkg1/Clazz1.java");
348:                FileUtil.createData(srcDir, "pkg1/Clazz2.java");
349:                FileUtil.createData(srcDir, "pkg2/CVS/#1.20#Clazz1.java");
350:                FileUtil.createData(srcDir, "pkg2/Clazz1.java");
351:                FileUtil.createData(srcDir, "pkg2/deeper/Clazz1.java");
352:                FileUtil.createData(srcDir,
353:                        "pkg2/deeper/and/deeper/Clazz1.java");
354:                FileUtil.createData(srcDir, ".broken/Clazz.java"); // #72669
355:                assertEquals(Arrays.asList("lib.pkg", "lib.pkg2", "pkg1",
356:                        "pkg2", "pkg2.deeper", "pkg2.deeper.and.deeper"),
357:                        new ArrayList<String>(SingleModuleProperties
358:                                .getInstance(p).getAvailablePublicPackages()));
359:            }
360:
361:            public void testPublicPackagesAreUpToDate_63561() throws Exception {
362:                SuiteProject suite1 = generateSuite("suite1");
363:                final NbModuleProject p = TestBase.generateSuiteComponent(
364:                        suite1, "module1a");
365:                FileUtil.createData(p.getSourceDirectory(),
366:                        "org/example/module1a/Dummy.java");
367:                SingleModuleProperties props = loadProperties(p);
368:                PublicPackagesTableModel pptm = props.getPublicPackagesModel();
369:                assertEquals("number of available public packages", 1, pptm
370:                        .getRowCount());
371:                assertEquals("number of selected public packages", 0, pptm
372:                        .getSelectedPackages().length);
373:                assertEquals("no public packages in the ModuleEntry", 0, props
374:                        .getModuleList().getEntry("org.example.module1a")
375:                        .getPublicPackages().length);
376:
377:                // apply and save project
378:                boolean result = ProjectManager.mutex().writeAccess(
379:                        new Mutex.ExceptionAction<Boolean>() {
380:                            public Boolean run() throws IOException {
381:                                ProjectXMLManager pxm = new ProjectXMLManager(p);
382:                                String[] newPP = new String[] { "org.example.module1a" };
383:                                pxm.replacePublicPackages(newPP);
384:                                return true;
385:                            }
386:                        });
387:                assertTrue("replace public packages", result);
388:                ProjectManager.getDefault().saveProject(p);
389:
390:                simulatePropertiesOpening(props, p);
391:
392:                pptm = props.getPublicPackagesModel();
393:                assertEquals("number of available public packages", 1, pptm
394:                        .getRowCount());
395:                assertEquals("number of selected public packages", 1, pptm
396:                        .getSelectedPackages().length);
397:                assertEquals("one public packages in the ModuleEntry", 1, props
398:                        .getModuleList().getEntry("org.example.module1a")
399:                        .getPublicPackages().length);
400:            }
401:
402:            /** Test that a module doesn't offer itself in its dependency list. */
403:            public void testThatTheModuleDoesNotOfferItself_61232()
404:                    throws Exception {
405:                NbModuleProject p = generateStandaloneModule("module1");
406:                SingleModuleProperties props = loadProperties(p);
407:                for (ModuleDependency dependency : props
408:                        .getUniverseDependencies(true)) {
409:                    ModuleEntry me = dependency.getModuleEntry();
410:                    assertFalse(
411:                            "module doesn't offer itself in its dependency list: "
412:                                    + p.getCodeNameBase(), p.getCodeNameBase()
413:                                    .equals(me.getCodeNameBase()));
414:                }
415:            }
416:
417:            public void testGetAvailableFriends() throws Exception {
418:                // standalone
419:                NbModuleProject standAlone = generateStandaloneModule("module1");
420:                SingleModuleProperties props = loadProperties(standAlone);
421:                assertEquals("There are no friends for standalone module.", 0,
422:                        props.getAvailableFriends().length);
423:
424:                // suitecomponent
425:                SuiteProject suite1 = generateSuite("suite1");
426:                TestBase.generateSuiteComponent(suite1, "component1");
427:                NbModuleProject component2 = TestBase.generateSuiteComponent(
428:                        suite1, "component2");
429:                TestBase.generateSuiteComponent(suite1, "component3");
430:                props = loadProperties(component2);
431:                assertEquals("There are two available friends for component2.",
432:                        2, props.getAvailableFriends().length);
433:
434:                // netbeans.org
435:                Project javaProject = ProjectManager.getDefault().findProject(
436:                        nbRoot().getFileObject("java.project"));
437:                props = loadProperties((NbModuleProject) javaProject);
438:                assertTrue("There are two available friends for component2.",
439:                        props.getAvailableFriends().length > 50);
440:            }
441:
442:            public void testSimulateLocalizedBundlePackageRefactoring()
443:                    throws Exception {
444:                NbModuleProject p = generateStandaloneModule("module1");
445:                SingleModuleProperties props = loadProperties(p);
446:                assertEquals("display name from ProjectInformation",
447:                        "Testing Module", ProjectUtils.getInformation(p)
448:                                .getDisplayName());
449:                assertEquals("display name from LocalizedBundleInfo",
450:                        "Testing Module", props.getBundleInfo()
451:                                .getDisplayName());
452:
453:                // rename package
454:                FileObject pDir = p.getProjectDirectory();
455:                FileObject pkg = pDir.getFileObject("src/org/example/module1");
456:                FileLock lock = pkg.lock();
457:                pkg.rename(lock, "module1Renamed", null);
458:                lock.releaseLock();
459:                FileObject manifestFO = pDir.getFileObject("manifest.mf");
460:
461:                // change manifest
462:                EditableManifest mf = Util.loadManifest(manifestFO);
463:                mf
464:                        .setAttribute(
465:                                ManifestManager.OPENIDE_MODULE_LOCALIZING_BUNDLE,
466:                                "org/example/module1Renamed/resources/Bundle.properties",
467:                                null);
468:                Util.storeManifest(manifestFO, mf);
469:
470:                simulatePropertiesOpening(props, p);
471:
472:                // make sure that properties are not damaged
473:                assertEquals(
474:                        "display name was refreshed in ProjectInformation",
475:                        "Testing Module", ProjectUtils.getInformation(p)
476:                                .getDisplayName());
477:                assertEquals(
478:                        "display name was refreshed in LocalizedBundleInfo",
479:                        "Testing Module", props.getBundleInfo()
480:                                .getDisplayName());
481:            }
482:
483:            public void testSimulateIllLocalizedBundlePackageRefactoring_67961()
484:                    throws Exception {
485:                NbModuleProject p = generateStandaloneModule("module1");
486:                SingleModuleProperties props = loadProperties(p);
487:                assertEquals("display name from ProjectInformation",
488:                        "Testing Module", ProjectUtils.getInformation(p)
489:                                .getDisplayName());
490:                assertEquals("display name from LocalizedBundleInfo",
491:                        "Testing Module", props.getBundleInfo()
492:                                .getDisplayName());
493:
494:                // change manifest (will fire a change event before the package is actually renamed)
495:                FileObject pDir = p.getProjectDirectory();
496:                FileObject manifestFO = pDir.getFileObject("manifest.mf");
497:                EditableManifest mf = Util.loadManifest(manifestFO);
498:                mf
499:                        .setAttribute(
500:                                ManifestManager.OPENIDE_MODULE_LOCALIZING_BUNDLE,
501:                                "org/example/module1Renamed/resources/Bundle.properties",
502:                                null);
503:                Util.storeManifest(manifestFO, mf);
504:
505:                // rename package
506:                FileObject pkg = pDir.getFileObject("src/org/example/module1");
507:                FileLock lock = pkg.lock();
508:                pkg.rename(lock, "module1Renamed", null);
509:                lock.releaseLock();
510:
511:                simulatePropertiesOpening(props, p);
512:
513:                // make sure that properties are not damaged
514:                assertEquals(
515:                        "display name was refreshed in ProjectInformation",
516:                        "Testing Module", ProjectUtils.getInformation(p)
517:                                .getDisplayName());
518:                assertEquals(
519:                        "display name was refreshed in LocalizedBundleInfo",
520:                        "Testing Module", props.getBundleInfo()
521:                                .getDisplayName());
522:            }
523:
524:            public void testResolveFile() throws Exception {
525:                NbModuleProject p = generateStandaloneModule("module1");
526:                SingleModuleProperties props = loadProperties(p);
527:                assertTrue("manifest exist", props.evaluateFile("manifest.mf")
528:                        .exists());
529:                assertTrue("manifest exist", props.evaluateFile(
530:                        props.getProjectDirectory() + "/manifest.mf").exists());
531:                assertTrue("manifest exist", props.evaluateFile(
532:                        "${basedir}/manifest.mf").exists());
533:                assertFalse("non-existing file", props.evaluateFile(
534:                        "non-existing").exists());
535:                assertFalse("invalid reference", props.evaluateFile(
536:                        "${invalid-reference}/manifest.mf").exists());
537:            }
538:
539:            public void testThatFilesAreNotTouched_67249() throws Exception {
540:                NbModuleProject p = generateStandaloneModule("module1");
541:                FileUtil.createData(p.getSourceDirectory(),
542:                        "org/example/module1/One.java");
543:                FileUtil.createData(p.getSourceDirectory(),
544:                        "org/example/module1/resources/Two.java");
545:                SingleModuleProperties props = loadProperties(p);
546:
547:                // times before change
548:                FileObject bundle = FileUtil.toFileObject(props.getBundleInfo()
549:                        .getPaths()[0]);
550:                FileObject mf = p.getManifestFile();
551:                long mfTime = mf.lastModified().getTime();
552:                long bundleTime = bundle.lastModified().getTime();
553:
554:                // be sure we are not too fast
555:                Thread.sleep(2000);
556:
557:                // select a package
558:                props.getPublicPackagesModel().setValueAt(Boolean.TRUE, 0, 0);
559:                props.storeProperties();
560:
561:                // compare with times after change
562:                assertEquals("time for manifest has not changed", mfTime, mf
563:                        .lastModified().getTime());
564:                assertEquals("time for bundle has not changed", bundleTime,
565:                        bundle.lastModified().getTime());
566:            }
567:
568:            public void testGetUniverseDependencies() throws Exception {
569:                SuiteProject suite = generateSuite("suite");
570:
571:                NbModuleProject testPrj = generateSuiteComponent(suite,
572:                        "testPrj");
573:
574:                NbModuleProject apiPrj = generateSuiteComponent(suite, "apiPrj");
575:                FileUtil.createData(apiPrj.getProjectDirectory(),
576:                        "src/api/Util.java");
577:                SingleModuleProperties apiPrjProps = SingleModulePropertiesTest
578:                        .loadProperties(apiPrj);
579:                apiPrjProps.getPublicPackagesModel().setValueAt(Boolean.TRUE,
580:                        0, 0);
581:                apiPrjProps.storeProperties();
582:                ProjectManager.getDefault().saveProject(apiPrj);
583:
584:                NbModuleProject friendPrj = generateSuiteComponent(suite,
585:                        "friendPrj");
586:                FileUtil.createData(friendPrj.getProjectDirectory(),
587:                        "src/friend/Karel.java");
588:                SingleModuleProperties friendPrjProps = SingleModulePropertiesTest
589:                        .loadProperties(friendPrj);
590:                friendPrjProps.getPublicPackagesModel().setValueAt(
591:                        Boolean.TRUE, 0, 0);
592:                friendPrjProps.getFriendListModel().addFriend(
593:                        "org.example.testPrj");
594:                friendPrjProps.storeProperties();
595:                ProjectManager.getDefault().saveProject(friendPrj);
596:
597:                generateSuiteComponent(suite, "nonApiPrj");
598:                ModuleEntry apiPrjME = ModuleList.getModuleList(
599:                        testPrj.getProjectDirectoryFile()).getEntry(
600:                        "org.example.apiPrj");
601:                ModuleDependency apiPrjDep = new ModuleDependency(apiPrjME);
602:                ModuleEntry friendPrjME = ModuleList.getModuleList(
603:                        testPrj.getProjectDirectoryFile()).getEntry(
604:                        "org.example.friendPrj");
605:                ModuleDependency friendPrjDep = new ModuleDependency(
606:                        friendPrjME);
607:                ModuleEntry nonApiPrjME = ModuleList.getModuleList(
608:                        testPrj.getProjectDirectoryFile()).getEntry(
609:                        "org.example.nonApiPrj");
610:                ModuleDependency nonApiPrjDep = new ModuleDependency(
611:                        nonApiPrjME);
612:
613:                SingleModuleProperties testProps = SingleModulePropertiesTest
614:                        .loadProperties(testPrj);
615:                Set allDeps = testProps.getUniverseDependencies(false);
616:                Set allDepsFilterExcluded = testProps
617:                        .getUniverseDependencies(true);
618:                Set apiDeps = testProps.getUniverseDependencies(false, true);
619:                Set apiDepsFilterExcluded = testProps.getUniverseDependencies(
620:                        true, true);
621:
622:                assertTrue(allDeps.contains(apiPrjDep));
623:                assertTrue(allDeps.contains(friendPrjDep));
624:                assertTrue(allDeps.contains(nonApiPrjDep));
625:
626:                assertTrue(allDepsFilterExcluded.contains(apiPrjDep));
627:                assertTrue(allDepsFilterExcluded.contains(friendPrjDep));
628:                assertTrue(allDepsFilterExcluded.contains(nonApiPrjDep));
629:
630:                assertTrue(apiDeps.contains(apiPrjDep));
631:                assertTrue(apiDeps.contains(friendPrjDep));
632:                assertFalse(apiDeps.contains(nonApiPrjDep));
633:
634:                assertTrue(apiDepsFilterExcluded.contains(apiPrjDep));
635:                assertTrue(apiDepsFilterExcluded.contains(friendPrjDep));
636:                assertFalse(apiDepsFilterExcluded.contains(nonApiPrjDep));
637:
638:                // #72124: check that cluster include/exclude lists do not affect suite components:
639:                EditableProperties ep = suite.getHelper().getProperties(
640:                        "nbproject/platform.properties");
641:                ep.setProperty(SuiteProperties.ENABLED_CLUSTERS_PROPERTY,
642:                        "crazy99"); // should not match any platform modules
643:                suite.getHelper().putProperties(
644:                        "nbproject/platform.properties", ep);
645:                ProjectManager.getDefault().saveProject(suite);
646:                allDepsFilterExcluded = testProps.getUniverseDependencies(true);
647:                assertTrue(allDepsFilterExcluded.contains(apiPrjDep));
648:                assertTrue(allDepsFilterExcluded.contains(friendPrjDep));
649:                assertTrue(allDepsFilterExcluded.contains(nonApiPrjDep));
650:            }
651:
652:            public void testDefaultPackageIsNotOffered_71532() throws Exception {
653:                NbModuleProject p = generateStandaloneModule("module1");
654:                FileUtil.createData(p.getProjectDirectory(),
655:                        "src/BadInDefault.java");
656:                FileUtil.createData(p.getProjectDirectory(),
657:                        "src/org/example/module1/GoodOne.java");
658:                assertEquals("one non-default valid package", 1,
659:                        loadProperties(p).getPublicPackagesModel()
660:                                .getRowCount());
661:            }
662:
663:            //    public void testReloadNetBeansModulueListSpeedHid() throws Exception {
664:            //        long startTotal = System.currentTimeMillis();
665:            //        SingleModuleProperties props = loadProperties(nbCVSRoot().getFileObject("apisupport/project"),
666:            //                "src/org/netbeans/modules/apisupport/project/Bundle.properties");
667:            //        long start = System.currentTimeMillis();
668:            //        props.reloadModuleListInfo();
669:            //        System.err.println("Reloading of module list: " + (System.currentTimeMillis() - start) + "msec");
670:            //        System.err.println("Total time: " + (System.currentTimeMillis() - startTotal) + "msec");
671:            //    }
672:            //
673:            //    public void testReloadBinaryModulueListSpeedHid() throws Exception {
674:            //        long startTotal = System.currentTimeMillis();
675:            //        SingleModuleProperties props = loadProperties(suite2FO.getFileObject("misc-project"),
676:            //                "src/org/netbeans/examples/modules/misc/Bundle.properties");
677:            //        long start = System.currentTimeMillis();
678:            //        props.reloadModuleListInfo();
679:            //        System.err.println("Time to reload module list: " + (System.currentTimeMillis() - start) + "msec");
680:            //        System.err.println("Total time: " + (System.currentTimeMillis() - startTotal) + "msec");
681:            //    }
682:
683:            public void testGetActivePlatform() throws Exception {
684:                SuiteProject suite = generateSuite("suite");
685:                NbModuleProject module = generateSuiteComponent(suite, "module");
686:                File plaf = new File(getWorkDir(), "plaf");
687:                makePlatform(plaf);
688:                FileObject platformPropertiesFO = suite.getProjectDirectory()
689:                        .getFileObject("nbproject/platform.properties");
690:                EditableProperties platformProperties = Util
691:                        .loadProperties(platformPropertiesFO);
692:                platformProperties.put("suite.dir", "${basedir}");
693:                platformProperties.put("netbeans.dest.dir",
694:                        "${suite.dir}/../plaf");
695:                Util.storeProperties(platformPropertiesFO, platformProperties);
696:                SingleModuleProperties props = loadProperties(module);
697:                NbPlatform platform = props.getActivePlatform();
698:                assertEquals(plaf, platform.getDestDir());
699:            }
700:
701:            static SingleModuleProperties loadProperties(NbModuleProject project)
702:                    throws IOException {
703:                return new SingleModuleProperties(project.getHelper(), project
704:                        .evaluator(), getSuiteProvider(project),
705:                        getModuleType(project), project.getLookup().lookup(
706:                                LocalizedBundleInfo.Provider.class));
707:            }
708:
709:            private static NbModuleProvider.NbModuleType getModuleType(Project p) {
710:                return p.getLookup().lookup(NbModuleProvider.class)
711:                        .getModuleType();
712:            }
713:
714:            private static SuiteProvider getSuiteProvider(Project p) {
715:                return p.getLookup().lookup(SuiteProvider.class);
716:            }
717:
718:            private static void simulatePropertiesOpening(
719:                    final SingleModuleProperties props, final NbModuleProject p) {
720:                props.refresh(getModuleType(p), getSuiteProvider(p));
721:            }
722:
723:        }
www_.j_a_v__a__2___s__.___c___o___m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.