Source Code Cross Referenced for ModuleDependenciesTest.java in  » IDE-Netbeans » nbbuild » org » netbeans » nbbuild » 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 » nbbuild » org.netbeans.nbbuild 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003:         *
0004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005:         *
0006:         * The contents of this file are subject to the terms of either the GNU
0007:         * General Public License Version 2 only ("GPL") or the Common
0008:         * Development and Distribution License("CDDL") (collectively, the
0009:         * "License"). You may not use this file except in compliance with the
0010:         * License. You can obtain a copy of the License at
0011:         * http://www.netbeans.org/cddl-gplv2.html
0012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013:         * specific language governing permissions and limitations under the
0014:         * License.  When distributing the software, include this License Header
0015:         * Notice in each file and include the License file at
0016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
0017:         * particular file as subject to the "Classpath" exception as provided
0018:         * by Sun in the GPL Version 2 section of the License file that
0019:         * accompanied this code. If applicable, add the following below the
0020:         * License Header, with the fields enclosed by brackets [] replaced by
0021:         * your own identifying information:
0022:         * "Portions Copyrighted [year] [name of copyright owner]"
0023:         *
0024:         * Contributor(s):
0025:         *
0026:         * The Original Software is NetBeans. The Initial Developer of the Original
0027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
0028:         * Microsystems, Inc. All Rights Reserved.
0029:         *
0030:         * If you wish your version of this file to be governed by only the CDDL
0031:         * or only the GPL Version 2, indicate your decision by adding
0032:         * "[Contributor] elects to include this software in this distribution
0033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034:         * single choice of license, a recipient has the option to distribute
0035:         * your version of this file under either the CDDL, the GPL Version 2 or
0036:         * to extend the choice of license to its licensees as provided above.
0037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
0038:         * Version 2 license, then the option applies only if the new code is
0039:         * made subject to such option by the copyright holder.
0040:         */
0041:
0042:        package org.netbeans.nbbuild;
0043:
0044:        import java.io.File;
0045:        import java.io.FileOutputStream;
0046:        import java.io.FileReader;
0047:        import java.io.IOException;
0048:        import java.util.StringTokenizer;
0049:        import java.util.jar.JarEntry;
0050:        import java.util.jar.JarOutputStream;
0051:        import java.util.jar.Manifest;
0052:        import java.util.regex.Matcher;
0053:        import java.util.regex.Pattern;
0054:        import org.netbeans.junit.NbTestCase;
0055:
0056:        /** Check the behaviour ModuleDependencies task that prints out info about
0057:         * module dependencies, etc.
0058:         *
0059:         * @author Jaroslav Tulach
0060:         */
0061:        public class ModuleDependenciesTest extends NbTestCase {
0062:            public ModuleDependenciesTest(String name) {
0063:                super (name);
0064:            }
0065:
0066:            /*
0067:            public void testJustMakeSureWeAreAbleToParseTheStructure () throws Exception {
0068:                java.io.File f = PublicPackagesInProjectizedXMLTest.extractString (
0069:                    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
0070:                    "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >" +
0071:                    "  <taskdef name=\"deps\" classname=\"org.netbeans.nbbuild.ModuleDependencies\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>" +
0072:                    "<target name=\"all\" >" +
0073:                    "  <deps>" +
0074:                    "    <input name=\"ahoj\" >" +
0075:                    "      <jars dir=\"${nb_all}/nbbuild\" > " +
0076:                    "        <include name=\"nbantext.jar\" />" +
0077:                    "      </jars>" +
0078:                    "    </input>" +
0079:                    "    <output type=\"public-packages\" file=\"file.txt\" />" +
0080:                    "  </deps >" +
0081:                    "  " +
0082:                    "</target>" +
0083:                    "</project>"
0084:
0085:                );
0086:                PublicPackagesInProjectizedXMLTest.execute (f, new String[] { });
0087:            }*/
0088:
0089:            public void testPublicPackagesOfAModuleThatDoesNotDefineThem()
0090:                    throws Exception {
0091:                File notAModule = generateJar(new String[] { "not/X.class",
0092:                        "not/resource/X.html" }, createManifest());
0093:
0094:                Manifest m = createManifest();
0095:                m.getMainAttributes().putValue("OpenIDE-Module", "my.module/3");
0096:                File withoutPkgs = generateJar(
0097:                        new String[] { "DefaultPkg.class", "is/X.class",
0098:                                "is/too/MyClass.class",
0099:                                "not/as/it/is/resource/X.xml" }, m);
0100:
0101:                m = createManifest();
0102:                m.getMainAttributes().putValue("OpenIDE-Module",
0103:                        "my.another.module/3");
0104:                m.getMainAttributes().putValue(
0105:                        "OpenIDE-Module-Public-Packages",
0106:                        "is.there.*, is.recursive.**");
0107:                File withPkgs = generateJar(new String[] { "is/there/A.class",
0108:                        "not/there/B.class", "is/recursive/Root.class",
0109:                        "is/recursive/sub/Under.class", "not/res/X.jpg" }, m);
0110:
0111:                m = createManifest();
0112:                m.getMainAttributes().putValue("OpenIDE-Module",
0113:                        "my.very.public.module/10");
0114:                m.getMainAttributes().putValue(
0115:                        "OpenIDE-Module-Public-Packages", "-");
0116:                File allPkgs = generateJar(new String[] { "not/very/A.class",
0117:                        "not/very/B.class", "not/very/sub/Root.class",
0118:                        "not/res/X.jpg" }, m);
0119:
0120:                File parent = notAModule.getParentFile();
0121:                assertEquals("All parents are the same 1", parent, withoutPkgs
0122:                        .getParentFile());
0123:                assertEquals("All parents are the same 2", parent, withPkgs
0124:                        .getParentFile());
0125:                assertEquals("All parents are the same 3", parent, allPkgs
0126:                        .getParentFile());
0127:
0128:                File output = PublicPackagesInProjectizedXMLTest
0129:                        .extractString("");
0130:                output.delete();
0131:                assertFalse("Is gone", output.exists());
0132:                java.io.File f = PublicPackagesInProjectizedXMLTest
0133:                        .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
0134:                                + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
0135:                                + "  <taskdef name=\"deps\" classname=\"org.netbeans.nbbuild.ModuleDependencies\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
0136:                                + "<target name=\"all\" >"
0137:                                + "  <deps>"
0138:                                + "    <input name=\"ahoj\" >"
0139:                                + "      <jars dir=\""
0140:                                + parent
0141:                                + "\" > "
0142:                                + "        <include name=\""
0143:                                + notAModule.getName()
0144:                                + "\" />"
0145:                                + "        <include name=\""
0146:                                + withoutPkgs.getName()
0147:                                + "\" />"
0148:                                + "        <include name=\""
0149:                                + withPkgs.getName()
0150:                                + "\" />"
0151:                                + "        <include name=\""
0152:                                + allPkgs.getName()
0153:                                + "\" />"
0154:                                + "      </jars>"
0155:                                + "    </input>"
0156:                                + "    <output type=\"public-packages\" file=\""
0157:                                + output
0158:                                + "\" />"
0159:                                + "  </deps >"
0160:                                + "</target>"
0161:                                + "</project>");
0162:                PublicPackagesInProjectizedXMLTest.execute(f,
0163:                        new String[] { "-verbose" });
0164:
0165:                assertTrue("Result generated", output.exists());
0166:
0167:                String res = readFile(output);
0168:
0169:                assertEquals("No not package", -1, res.indexOf("not"));
0170:                assertTrue("Some of is pkgs: " + res, res.indexOf("is\n") >= 0);
0171:                assertEquals("No default pkg", -1, res.indexOf("\n\n"));
0172:                assertTrue("is there resursive: " + res, res
0173:                        .indexOf("is.recursive\n") >= 0);
0174:                assertTrue("is there too: " + res, res.indexOf("is.too\n") >= 0);
0175:            }
0176:
0177:            public void testPublicPackagesInAModuleThatDeclaresFriendsAreNotCounted()
0178:                    throws Exception {
0179:                File notAModule = generateJar(new String[] { "not/X.class",
0180:                        "not/resource/X.html" }, createManifest());
0181:
0182:                Manifest m = createManifest();
0183:                m.getMainAttributes().putValue("OpenIDE-Module", "my.module/3");
0184:                m.getMainAttributes().putValue("OpenIDE-Module-Friends",
0185:                        "my.very.public.module");
0186:                File withoutPkgs = generateJar(new String[] {
0187:                        "DefaultPkg.class", "just/friend/X.class",
0188:                        "just/friend/MyClass.class",
0189:                        "not/as/it/is/resource/X.xml" }, m);
0190:
0191:                m = createManifest();
0192:                m.getMainAttributes().putValue("OpenIDE-Module",
0193:                        "my.another.module/3");
0194:                m.getMainAttributes().putValue(
0195:                        "OpenIDE-Module-Public-Packages",
0196:                        "friend.there.*, friend.recursive.**");
0197:                m.getMainAttributes().putValue("OpenIDE-Module-Friends",
0198:                        "my.very.public.module");
0199:                File withPkgs = generateJar(new String[] {
0200:                        "friend/there/A.class", "not/there/B.class",
0201:                        "friend/recursive/Root.class",
0202:                        "friend/recursive/sub/Under.class", "not/res/X.jpg" },
0203:                        m);
0204:
0205:                m = createManifest();
0206:                m.getMainAttributes().putValue("OpenIDE-Module",
0207:                        "my.very.public.module/10");
0208:                m.getMainAttributes().putValue(
0209:                        "OpenIDE-Module-Public-Packages", "-");
0210:                File allPkgs = generateJar(new String[] { "not/very/A.class",
0211:                        "not/very/B.class", "not/very/sub/Root.class",
0212:                        "not/res/X.jpg" }, m);
0213:
0214:                File parent = notAModule.getParentFile();
0215:                assertEquals("All parents are the same 1", parent, withoutPkgs
0216:                        .getParentFile());
0217:                assertEquals("All parents are the same 2", parent, withPkgs
0218:                        .getParentFile());
0219:                assertEquals("All parents are the same 3", parent, allPkgs
0220:                        .getParentFile());
0221:
0222:                File output = PublicPackagesInProjectizedXMLTest
0223:                        .extractString("");
0224:                output.delete();
0225:                File friendPkg = PublicPackagesInProjectizedXMLTest
0226:                        .extractString("");
0227:                friendPkg.delete();
0228:                assertFalse("Is gone", output.exists());
0229:                java.io.File f = PublicPackagesInProjectizedXMLTest
0230:                        .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
0231:                                + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
0232:                                + "  <taskdef name=\"deps\" classname=\"org.netbeans.nbbuild.ModuleDependencies\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
0233:                                + "<target name=\"all\" >"
0234:                                + "  <deps>"
0235:                                + "    <input name=\"ahoj\" >"
0236:                                + "      <jars dir=\""
0237:                                + parent
0238:                                + "\" > "
0239:                                + "        <include name=\""
0240:                                + notAModule.getName()
0241:                                + "\" />"
0242:                                + "        <include name=\""
0243:                                + withoutPkgs.getName()
0244:                                + "\" />"
0245:                                + "        <include name=\""
0246:                                + withPkgs.getName()
0247:                                + "\" />"
0248:                                + "        <include name=\""
0249:                                + allPkgs.getName()
0250:                                + "\" />"
0251:                                + "      </jars>"
0252:                                + "    </input>"
0253:                                + "    <output type=\"public-packages\" file=\""
0254:                                + output
0255:                                + "\" />"
0256:                                + "    <output type=\"friend-packages\" file=\""
0257:                                + friendPkg
0258:                                + "\" />"
0259:                                + "  </deps >"
0260:                                + "</target>" + "</project>");
0261:                PublicPackagesInProjectizedXMLTest.execute(f,
0262:                        new String[] { "-verbose" });
0263:
0264:                assertTrue("Result generated", output.exists());
0265:
0266:                String res = readFile(output);
0267:
0268:                if (!res.equals("\n")) {
0269:                    fail("No public packages:\n" + res);
0270:                }
0271:
0272:                // now friend packages
0273:                res = readFile(friendPkg);
0274:
0275:                Matcher match = Pattern.compile("MODULE ([^ ]*)").matcher(res);
0276:                assertTrue("One MODULE is there: " + res, match.find());
0277:                int fst = match.start();
0278:                assertEquals("my.another.module", match.group(1));
0279:
0280:                assertTrue("Second MODULE is there: " + res, match.find());
0281:                int snd = match.start();
0282:                assertEquals("my.module", match.group(1));
0283:
0284:                match = Pattern.compile(
0285:                        "  FRIEND my.very.public.module \\(ahoj\\)").matcher(
0286:                        res);
0287:                assertTrue("One FRIEND is there: " + res, match.find());
0288:                assertTrue("Second FRIEND is there: " + res, match.find());
0289:
0290:                assertTrue("FriendPkg1\n" + res,
0291:                        res.indexOf("just.friend") >= snd);
0292:                assertTrue("FriendPkg2\n" + res,
0293:                        res.indexOf("friend.there") >= fst);
0294:
0295:            }
0296:
0297:            public void testThereCanBeLimitOnNumberOfFriends() throws Exception {
0298:                File notAModule = generateJar(new String[] { "not/X.class",
0299:                        "not/resource/X.html" }, createManifest());
0300:
0301:                Manifest m = createManifest();
0302:                m.getMainAttributes().putValue("OpenIDE-Module", "my.module/3");
0303:                m.getMainAttributes().putValue("OpenIDE-Module-Friends",
0304:                        "my.very.public.module");
0305:                File withoutPkgs = generateJar(new String[] {
0306:                        "DefaultPkg.class", "just/friend/X.class",
0307:                        "just/friend/MyClass.class",
0308:                        "not/as/it/is/resource/X.xml" }, m);
0309:
0310:                m = createManifest();
0311:                m.getMainAttributes().putValue("OpenIDE-Module",
0312:                        "my.another.module/3");
0313:                m.getMainAttributes().putValue(
0314:                        "OpenIDE-Module-Public-Packages",
0315:                        "friend.there.*, friend.recursive.**");
0316:                m.getMainAttributes().putValue("OpenIDE-Module-Friends",
0317:                        "my.very.public.module, my.module");
0318:                File withPkgs = generateJar(new String[] {
0319:                        "friend/there/A.class", "not/there/B.class",
0320:                        "friend/recursive/Root.class",
0321:                        "friend/recursive/sub/Under.class", "not/res/X.jpg" },
0322:                        m);
0323:
0324:                m = createManifest();
0325:                m.getMainAttributes().putValue("OpenIDE-Module",
0326:                        "my.very.public.module/10");
0327:                m.getMainAttributes().putValue(
0328:                        "OpenIDE-Module-Public-Packages", "-");
0329:                File allPkgs = generateJar(new String[] { "not/very/A.class",
0330:                        "not/very/B.class", "not/very/sub/Root.class",
0331:                        "not/res/X.jpg" }, m);
0332:
0333:                File parent = notAModule.getParentFile();
0334:                assertEquals("All parents are the same 1", parent, withoutPkgs
0335:                        .getParentFile());
0336:                assertEquals("All parents are the same 2", parent, withPkgs
0337:                        .getParentFile());
0338:                assertEquals("All parents are the same 3", parent, allPkgs
0339:                        .getParentFile());
0340:
0341:                File output = PublicPackagesInProjectizedXMLTest
0342:                        .extractString("");
0343:                output.delete();
0344:                File friendPkg = PublicPackagesInProjectizedXMLTest
0345:                        .extractString("");
0346:                friendPkg.delete();
0347:                assertFalse("Is gone", output.exists());
0348:                java.io.File f = PublicPackagesInProjectizedXMLTest
0349:                        .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
0350:                                + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
0351:                                + "  <taskdef name=\"deps\" classname=\"org.netbeans.nbbuild.ModuleDependencies\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
0352:                                + "<target name=\"all\" >"
0353:                                + "  <property name='deps.max.friends' value='1'/>"
0354:                                + "  <deps>"
0355:                                + "    <input name=\"ahoj\" >"
0356:                                + "      <jars dir=\""
0357:                                + parent
0358:                                + "\" > "
0359:                                + "        <include name=\""
0360:                                + notAModule.getName()
0361:                                + "\" />"
0362:                                + "        <include name=\""
0363:                                + withoutPkgs.getName()
0364:                                + "\" />"
0365:                                + "        <include name=\""
0366:                                + withPkgs.getName()
0367:                                + "\" />"
0368:                                + "        <include name=\""
0369:                                + allPkgs.getName()
0370:                                + "\" />"
0371:                                + "      </jars>"
0372:                                + "    </input>"
0373:                                + "    <output type=\"public-packages\" file=\""
0374:                                + output
0375:                                + "\" />"
0376:                                + "    <output type=\"friend-packages\" file=\""
0377:                                + friendPkg
0378:                                + "\" />"
0379:                                + "  </deps >"
0380:                                + "</target>" + "</project>");
0381:                // this should succeed now, as the limit applies only to intercluster relations - #87076
0382:                PublicPackagesInProjectizedXMLTest.execute(f,
0383:                        new String[] { "-verbose" });
0384:            }
0385:
0386:            public void testThereCanBeLimitOnNumberOfFriendsAmongGroups()
0387:                    throws Exception {
0388:                File notAModule = generateJar(new String[] { "not/X.class",
0389:                        "not/resource/X.html" }, createManifest());
0390:
0391:                Manifest m = createManifest();
0392:                m.getMainAttributes().putValue("OpenIDE-Module", "my.module/3");
0393:                m.getMainAttributes().putValue("OpenIDE-Module-Friends",
0394:                        "my.very.public.module");
0395:                File myModule = generateJar(new String[] { "DefaultPkg.class",
0396:                        "just/friend/X.class", "just/friend/MyClass.class",
0397:                        "not/as/it/is/resource/X.xml" }, m);
0398:
0399:                m = createManifest();
0400:                m.getMainAttributes().putValue("OpenIDE-Module",
0401:                        "my.another.module/3");
0402:                m.getMainAttributes().putValue(
0403:                        "OpenIDE-Module-Public-Packages",
0404:                        "friend.there.*, friend.recursive.**");
0405:                m.getMainAttributes().putValue("OpenIDE-Module-Friends",
0406:                        "my.very.public.module, my.module");
0407:                File myAnotherModule = generateJar(new String[] {
0408:                        "friend/there/A.class", "not/there/B.class",
0409:                        "friend/recursive/Root.class",
0410:                        "friend/recursive/sub/Under.class", "not/res/X.jpg" },
0411:                        m);
0412:
0413:                m = createManifest();
0414:                m.getMainAttributes().putValue("OpenIDE-Module",
0415:                        "my.very.public.module/10");
0416:                m.getMainAttributes().putValue(
0417:                        "OpenIDE-Module-Public-Packages", "-");
0418:                File myVeryPublicModule = generateJar(new String[] {
0419:                        "not/very/A.class", "not/very/B.class",
0420:                        "not/very/sub/Root.class", "not/res/X.jpg" }, m);
0421:
0422:                File parent = notAModule.getParentFile();
0423:                assertEquals("All parents are the same 1", parent, myModule
0424:                        .getParentFile());
0425:                assertEquals("All parents are the same 2", parent,
0426:                        myAnotherModule.getParentFile());
0427:                assertEquals("All parents are the same 3", parent,
0428:                        myVeryPublicModule.getParentFile());
0429:
0430:                File friendPkg = PublicPackagesInProjectizedXMLTest
0431:                        .extractString("");
0432:                friendPkg.delete();
0433:                assertFalse("Is gone", friendPkg.exists());
0434:                java.io.File f = PublicPackagesInProjectizedXMLTest
0435:                        .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
0436:                                + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
0437:                                + "  <taskdef name=\"deps\" classname=\"org.netbeans.nbbuild.ModuleDependencies\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
0438:                                + "<target name=\"all\" >"
0439:                                + "  <property name='deps.max.friends' value='${limit}'/>"
0440:                                + "  <deps>"
0441:                                + "    <input name=\"base\" >"
0442:                                + "      <jars dir=\""
0443:                                + parent
0444:                                + "\" > "
0445:                                + "        <include name=\""
0446:                                + notAModule.getName()
0447:                                + "\" />"
0448:                                + "        <include name=\""
0449:                                + myAnotherModule.getName()
0450:                                + "\" />"
0451:                                + "      </jars>"
0452:                                + "    </input>"
0453:                                + "    <input name=\"extra\" >"
0454:                                + "      <jars dir=\""
0455:                                + parent
0456:                                + "\" > "
0457:                                + "        <include name=\""
0458:                                + myModule.getName()
0459:                                + "\" />"
0460:                                + "        <include name=\""
0461:                                + myVeryPublicModule.getName()
0462:                                + "\" />"
0463:                                + "      </jars>"
0464:                                + "    </input>"
0465:                                + "    <output type=\"group-friend-packages\" file=\""
0466:                                + friendPkg
0467:                                + "\" />"
0468:                                + "  </deps >"
0469:                                + "</target>" + "</project>");
0470:
0471:                // this will succeed, limit of 5 is ok
0472:                PublicPackagesInProjectizedXMLTest.execute(f, new String[] {
0473:                        "-verbose", "-Dlimit=5" });
0474:
0475:                String res = readFile(friendPkg);
0476:
0477:                if (!res.equals("MODULE my.another.module (base)\n"
0478:                        + "  FRIEND my.module (extra)\n"
0479:                        + "  FRIEND my.very.public.module (extra)\n"
0480:                        + "  PACKAGE friend.recursive\n"
0481:                        + "  PACKAGE friend.recursive.sub\n"
0482:                        + "  PACKAGE friend.there\n" + "")) {
0483:                    fail("Unexpected res:\n" + res);
0484:                }
0485:
0486:                friendPkg.delete();
0487:
0488:                try {
0489:                    PublicPackagesInProjectizedXMLTest.execute(f, new String[] {
0490:                            "-verbose", "-Dlimit=1" });
0491:                    fail("This should fail");
0492:                } catch (PublicPackagesInProjectizedXMLTest.ExecutionError ex) {
0493:                    if (PublicPackagesInProjectizedXMLTest.getStdErr().indexOf(
0494:                            "Too many intercluster friends") == -1) {
0495:                        fail("There should be a message about too many friends:\n"
0496:                                + PublicPackagesInProjectizedXMLTest
0497:                                        .getStdErr());
0498:                    }
0499:                }
0500:            }
0501:
0502:            public void testThereExternalsAreCountedAsWell() throws Exception {
0503:                File notAModule = generateJar(new String[] { "not/X.class",
0504:                        "not/resource/X.html" }, createManifest());
0505:
0506:                Manifest m = createManifest();
0507:                m.getMainAttributes().putValue("OpenIDE-Module", "my.module/3");
0508:                m.getMainAttributes().putValue("OpenIDE-Module-Friends",
0509:                        "my.very.public.module");
0510:                File myModule = generateJar(new String[] { "DefaultPkg.class",
0511:                        "just/friend/X.class", "just/friend/MyClass.class",
0512:                        "not/as/it/is/resource/X.xml" }, m);
0513:
0514:                m = createManifest();
0515:                m.getMainAttributes().putValue("OpenIDE-Module",
0516:                        "my.another.module/3");
0517:                m.getMainAttributes().putValue(
0518:                        "OpenIDE-Module-Public-Packages",
0519:                        "friend.there.*, friend.recursive.**");
0520:                m.getMainAttributes().putValue("OpenIDE-Module-Friends",
0521:                        "my.very.public.module, my.module");
0522:                File myAnotherModule = generateJar(new String[] {
0523:                        "friend/there/A.class", "not/there/B.class",
0524:                        "friend/recursive/Root.class",
0525:                        "friend/recursive/sub/Under.class", "not/res/X.jpg" },
0526:                        m);
0527:
0528:                m = createManifest();
0529:                m.getMainAttributes().putValue("OpenIDE-Module",
0530:                        "my.very.public.module/10");
0531:                m.getMainAttributes().putValue(
0532:                        "OpenIDE-Module-Public-Packages", "-");
0533:                File myVeryPublicModule = generateJar(new String[] {
0534:                        "not/very/A.class", "not/very/B.class",
0535:                        "not/very/sub/Root.class", "not/res/X.jpg" }, m);
0536:
0537:                File parent = notAModule.getParentFile();
0538:                assertEquals("All parents are the same 1", parent, myModule
0539:                        .getParentFile());
0540:                assertEquals("All parents are the same 2", parent,
0541:                        myAnotherModule.getParentFile());
0542:                assertEquals("All parents are the same 3", parent,
0543:                        myVeryPublicModule.getParentFile());
0544:
0545:                File friendPkg = PublicPackagesInProjectizedXMLTest
0546:                        .extractString("");
0547:                friendPkg.delete();
0548:                assertFalse("Is gone", friendPkg.exists());
0549:                java.io.File f = PublicPackagesInProjectizedXMLTest
0550:                        .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
0551:                                + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
0552:                                + "  <taskdef name=\"deps\" classname=\"org.netbeans.nbbuild.ModuleDependencies\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
0553:                                + "<target name=\"all\" >"
0554:                                + "  <property name='deps.max.friends' value='${limit}'/>"
0555:                                + "  <deps>"
0556:                                + "    <input name=\"base\" >"
0557:                                + "      <jars dir=\""
0558:                                + parent
0559:                                + "\" > "
0560:                                + "        <include name=\""
0561:                                + notAModule.getName()
0562:                                + "\" />"
0563:                                + "        <include name=\""
0564:                                + myAnotherModule.getName()
0565:                                + "\" />"
0566:                                + "      </jars>"
0567:                                + "    </input>"
0568:                                + "    <output type=\"group-friend-packages\" file=\""
0569:                                + friendPkg
0570:                                + "\" />"
0571:                                + "  </deps >"
0572:                                + "</target>" + "</project>");
0573:
0574:                // this will succeed, limit of 5 is ok
0575:                PublicPackagesInProjectizedXMLTest.execute(f, new String[] {
0576:                        "-verbose", "-Dlimit=5" });
0577:
0578:                String res = readFile(friendPkg);
0579:
0580:                if (!res.equals("MODULE my.another.module (base)\n"
0581:                        + "  EXTERNAL my.module\n"
0582:                        + "  EXTERNAL my.very.public.module\n"
0583:                        + "  PACKAGE friend.recursive\n"
0584:                        + "  PACKAGE friend.recursive.sub\n"
0585:                        + "  PACKAGE friend.there\n" + "")) {
0586:                    fail("Unexpected res:\n" + res);
0587:                }
0588:
0589:                friendPkg.delete();
0590:
0591:                try {
0592:                    PublicPackagesInProjectizedXMLTest.execute(f, new String[] {
0593:                            "-verbose", "-Dlimit=1" });
0594:                    fail("This should fail");
0595:                } catch (PublicPackagesInProjectizedXMLTest.ExecutionError ex) {
0596:                    if (PublicPackagesInProjectizedXMLTest.getStdErr().indexOf(
0597:                            "Too many intercluster friends") == -1) {
0598:                        fail("There should be a message about too many friends:\n"
0599:                                + PublicPackagesInProjectizedXMLTest
0600:                                        .getStdErr());
0601:                    }
0602:                }
0603:            }
0604:
0605:            public void testPublicPackagesOfAModuleThatDoesNotDefineThemButTheyAreProvidedByModuleTheModuleDependsOn()
0606:                    throws Exception {
0607:                File notAModule = generateJar(new String[] { "is/cp/X.class",
0608:                        "not/cp/resource/X.html" }, createManifest());
0609:
0610:                Manifest m = createManifest();
0611:                m.getMainAttributes().putValue("OpenIDE-Module", "my.module/3");
0612:                m.getMainAttributes().putValue("Class-Path",
0613:                        notAModule.getName());
0614:                File withoutPkgs = generateJar(
0615:                        new String[] { "DefaultPkg.class", "is/X.class",
0616:                                "is/too/MyClass.class",
0617:                                "not/as/it/is/resource/X.xml" }, m);
0618:
0619:                File parent = notAModule.getParentFile();
0620:                assertEquals("All parents are the same 1", parent, withoutPkgs
0621:                        .getParentFile());
0622:
0623:                File output = PublicPackagesInProjectizedXMLTest
0624:                        .extractString("");
0625:                output.delete();
0626:                assertFalse("Is gone", output.exists());
0627:                java.io.File f = PublicPackagesInProjectizedXMLTest
0628:                        .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
0629:                                + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
0630:                                + "  <taskdef name=\"deps\" classname=\"org.netbeans.nbbuild.ModuleDependencies\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
0631:                                + "<target name=\"all\" >"
0632:                                + "  <deps>"
0633:                                + "    <input name=\"ahoj\" >"
0634:                                + "      <jars dir='"
0635:                                + parent
0636:                                + "' > "
0637:                                + "        <include name='"
0638:                                + notAModule.getName()
0639:                                + "' />"
0640:                                + "        <include name='"
0641:                                + withoutPkgs.getName()
0642:                                + "' />"
0643:                                + "      </jars>"
0644:                                + "    </input>"
0645:                                + "    <output type=\"public-packages\" file=\""
0646:                                + output
0647:                                + "\" />"
0648:                                + "  </deps >"
0649:                                + "</target>"
0650:                                + "</project>");
0651:                PublicPackagesInProjectizedXMLTest.execute(f,
0652:                        new String[] { "-verbose" });
0653:
0654:                assertTrue("Result generated", output.exists());
0655:
0656:                String res = readFile(output);
0657:
0658:                assertEquals("No not package", -1, res.indexOf("not"));
0659:                assertTrue("Some of is pkgs: " + res, res.indexOf("is\n") >= 0);
0660:                assertTrue("is/too pkgs: " + res, res.indexOf("is.too\n") >= 0);
0661:                assertEquals("No default pkg", -1, res.indexOf("\n\n"));
0662:                assertTrue(
0663:                        "is/cp is there as well as the withoutPkgs module depends on notAModule: "
0664:                                + res, res.indexOf("is.cp\n") >= 0);
0665:            }
0666:
0667:            public void testPublicPackagesForOneCluster() throws Exception {
0668:                Manifest m1 = createManifest();
0669:                m1.getMainAttributes().putValue("OpenIDE-Module",
0670:                        "my.ignored.module/3");
0671:                File ignoreModule = generateJar(
0672:                        new String[] { "DefaultPkg.class", "is2/X.class",
0673:                                "is2/too/MyClass.class",
0674:                                "not/as/it/is/resource/X.xml" }, m1);
0675:
0676:                Manifest m = createManifest();
0677:                m.getMainAttributes().putValue("OpenIDE-Module", "my.module/3");
0678:                File withoutPkgs = generateJar(
0679:                        new String[] { "DefaultPkg.class", "is/X.class",
0680:                                "is/too/MyClass.class",
0681:                                "not/as/it/is/resource/X.xml" }, m);
0682:
0683:                File parent = ignoreModule.getParentFile();
0684:                assertEquals("All parents are the same 1", parent, withoutPkgs
0685:                        .getParentFile());
0686:
0687:                File output = PublicPackagesInProjectizedXMLTest
0688:                        .extractString("");
0689:                output.delete();
0690:                assertFalse("Is gone", output.exists());
0691:                java.io.File f = PublicPackagesInProjectizedXMLTest
0692:                        .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
0693:                                + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
0694:                                + "  <taskdef name=\"deps\" classname=\"org.netbeans.nbbuild.ModuleDependencies\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
0695:                                + "<target name=\"all\" >"
0696:                                + "  <deps generate='ahoj'>"
0697:                                + "    <input name=\"ignore\" >"
0698:                                + "      <jars dir='"
0699:                                + parent
0700:                                + "' > "
0701:                                + "        <include name='"
0702:                                + ignoreModule.getName()
0703:                                + "' />"
0704:                                + "      </jars>"
0705:                                + "    </input>"
0706:                                + "    <input name=\"ahoj\" >"
0707:                                + "      <jars dir='"
0708:                                + parent
0709:                                + "' > "
0710:                                + "        <include name='"
0711:                                + withoutPkgs.getName()
0712:                                + "' />"
0713:                                + "      </jars>"
0714:                                + "    </input>"
0715:                                + "    <output type=\"public-packages\" file=\""
0716:                                + output
0717:                                + "\" />"
0718:                                + "  </deps >"
0719:                                + "</target>"
0720:                                + "</project>");
0721:                PublicPackagesInProjectizedXMLTest.execute(f,
0722:                        new String[] { "-verbose" });
0723:
0724:                assertTrue("Result generated", output.exists());
0725:
0726:                String res = readFile(output);
0727:
0728:                assertEquals("No not package", -1, res.indexOf("not"));
0729:                assertEquals("No is2 package", -1, res.indexOf("is2"));
0730:                assertTrue("Some of is pkgs: " + res, res.indexOf("is\n") >= 0);
0731:                assertTrue("is/too pkgs: " + res, res.indexOf("is.too\n") >= 0);
0732:                assertEquals("No default pkg", -1, res.indexOf("\n\n"));
0733:            }
0734:
0735:            public void testSharedPackagesForOneCluster() throws Exception {
0736:                Manifest m0 = createManifest();
0737:                m0.getMainAttributes().putValue("OpenIDE-Module",
0738:                        "my.huge.module/3");
0739:                File hugeModule = generateJar(new String[] { "not/X.class",
0740:                        "is/too/MyClass.class", }, m0);
0741:
0742:                Manifest m1 = createManifest();
0743:                m1.getMainAttributes().putValue("OpenIDE-Module",
0744:                        "my.ignored.module/3");
0745:                File ignoreModule = generateJar(new String[] { "not/X.class" },
0746:                        m1);
0747:
0748:                Manifest m = createManifest();
0749:                m.getMainAttributes().putValue("OpenIDE-Module", "my.module/3");
0750:                File withoutPkgs = generateJar(
0751:                        new String[] { "is/too/MyClass.class" }, m);
0752:
0753:                File parent = ignoreModule.getParentFile();
0754:                assertEquals("All parents are the same 1", parent, withoutPkgs
0755:                        .getParentFile());
0756:
0757:                File output = PublicPackagesInProjectizedXMLTest
0758:                        .extractString("");
0759:                output.delete();
0760:                assertFalse("Is gone", output.exists());
0761:                java.io.File f = PublicPackagesInProjectizedXMLTest
0762:                        .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
0763:                                + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
0764:                                + "  <taskdef name=\"deps\" classname=\"org.netbeans.nbbuild.ModuleDependencies\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
0765:                                + "<target name=\"all\" >"
0766:                                + "  <deps generate='ahoj'>"
0767:                                + "    <input name=\"ignore\" >"
0768:                                + "      <jars dir='"
0769:                                + parent
0770:                                + "' > "
0771:                                + "        <include name='"
0772:                                + ignoreModule.getName()
0773:                                + "' />"
0774:                                + "        <include name='"
0775:                                + hugeModule.getName()
0776:                                + "' />"
0777:                                + "      </jars>"
0778:                                + "    </input>"
0779:                                + "    <input name=\"ahoj\" >"
0780:                                + "      <jars dir='"
0781:                                + parent
0782:                                + "' > "
0783:                                + "        <include name='"
0784:                                + withoutPkgs.getName()
0785:                                + "' />"
0786:                                + "      </jars>"
0787:                                + "    </input>"
0788:                                + "    <output type=\"shared-packages\" file=\""
0789:                                + output
0790:                                + "\" />"
0791:                                + "  </deps >"
0792:                                + "</target>"
0793:                                + "</project>");
0794:                PublicPackagesInProjectizedXMLTest.execute(f,
0795:                        new String[] { "-verbose" });
0796:
0797:                assertTrue("Result generated", output.exists());
0798:
0799:                String res = readFile(output);
0800:
0801:                assertEquals("No not package:\n" + res, -1, res.indexOf("not"));
0802:                assertTrue("is/too pkgs: " + res, res.indexOf("is.too\n") >= 0);
0803:                assertEquals("No default pkg:\n" + res, -1, res.indexOf("\n\n"));
0804:            }
0805:
0806:            public void testNameOfModuleWithoutMajorVersionDoesNotContainSlash()
0807:                    throws Exception {
0808:                Manifest m = createManifest();
0809:                m.getMainAttributes().putValue("OpenIDE-Module", "my.module");
0810:                File module = generateJar(new String[] { "something" }, m);
0811:
0812:                File parent = module.getParentFile();
0813:
0814:                File output = PublicPackagesInProjectizedXMLTest
0815:                        .extractString("");
0816:                output.delete();
0817:                assertFalse("Is gone", output.exists());
0818:                java.io.File f = PublicPackagesInProjectizedXMLTest
0819:                        .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
0820:                                + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
0821:                                + "  <taskdef name=\"deps\" classname=\"org.netbeans.nbbuild.ModuleDependencies\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
0822:                                + "<target name=\"all\" >"
0823:                                + "  <deps>"
0824:                                + "    <input name=\"ahoj\" >"
0825:                                + "      <jars dir=\""
0826:                                + parent
0827:                                + "\" > "
0828:                                + "        <include name=\""
0829:                                + module.getName()
0830:                                + "\" />"
0831:                                + "      </jars>"
0832:                                + "    </input>"
0833:                                + "    <output type=\"modules\" file=\""
0834:                                + output
0835:                                + "\" />"
0836:                                + "  </deps >"
0837:                                + "</target>"
0838:                                + "</project>");
0839:                PublicPackagesInProjectizedXMLTest.execute(f,
0840:                        new String[] { "-verbose" });
0841:
0842:                assertTrue("Result generated", output.exists());
0843:
0844:                String res = readFile(output);
0845:
0846:                assertEquals("Starts with MODULE", 0, res.indexOf("MODULE"));
0847:                assertTrue("module name is there" + res, res
0848:                        .indexOf("my.module") > 0);
0849:                assertEquals("no slash is there", -1, res.indexOf('/'));
0850:            }
0851:
0852:            public void testGenerateListOfModules() throws Exception {
0853:                File notAModule = generateJar(new String[] { "not/X.class",
0854:                        "not/resource/X.html" }, createManifest());
0855:
0856:                Manifest m = createManifest();
0857:                m.getMainAttributes().putValue("OpenIDE-Module", "my.module/3");
0858:                File withoutPkgs = generateJar(
0859:                        new String[] { "DefaultPkg.class", "is/X.class",
0860:                                "is/too/MyClass.class",
0861:                                "not/as/it/is/resource/X.xml" }, m);
0862:
0863:                m = createManifest();
0864:                m.getMainAttributes().putValue("OpenIDE-Module",
0865:                        "my.another.module/3");
0866:                m.getMainAttributes().putValue(
0867:                        "OpenIDE-Module-Public-Packages",
0868:                        "is.there.*, is.recursive.**");
0869:                File withPkgs = generateJar(new String[] { "is/there/A.class",
0870:                        "not/there/B.class", "is/recursive/Root.class",
0871:                        "is/recursive/sub/Under.class", "not/res/X.jpg" }, m);
0872:
0873:                File parent = notAModule.getParentFile();
0874:                assertEquals("All parents are the same 1", parent, withoutPkgs
0875:                        .getParentFile());
0876:                assertEquals("All parents are the same 2", parent, withPkgs
0877:                        .getParentFile());
0878:
0879:                File output = PublicPackagesInProjectizedXMLTest
0880:                        .extractString("");
0881:                output.delete();
0882:                assertFalse("Is gone", output.exists());
0883:                java.io.File f = PublicPackagesInProjectizedXMLTest
0884:                        .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
0885:                                + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
0886:                                + "  <taskdef name=\"deps\" classname=\"org.netbeans.nbbuild.ModuleDependencies\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
0887:                                + "<target name=\"all\" >"
0888:                                + "  <deps>"
0889:                                + "    <input name=\"ahoj\" >"
0890:                                + "      <jars dir=\""
0891:                                + parent
0892:                                + "\" > "
0893:                                + "        <include name=\""
0894:                                + notAModule.getName()
0895:                                + "\" />"
0896:                                + "        <include name=\""
0897:                                + withoutPkgs.getName()
0898:                                + "\" />"
0899:                                + "        <include name=\""
0900:                                + withPkgs.getName()
0901:                                + "\" />"
0902:                                + "      </jars>"
0903:                                + "    </input>"
0904:                                + "    <output type=\"modules\" file=\""
0905:                                + output
0906:                                + "\" />"
0907:                                + "  </deps >"
0908:                                + "</target>"
0909:                                + "</project>");
0910:                PublicPackagesInProjectizedXMLTest.execute(f,
0911:                        new String[] { "-verbose" });
0912:
0913:                assertTrue("Result generated", output.exists());
0914:
0915:                String res = readFile(output);
0916:                StringTokenizer tok = new StringTokenizer(res, "\n\r");
0917:
0918:                assertEquals("We have two modules: " + res, 2, tok
0919:                        .countTokens());
0920:                assertEquals(
0921:                        "First contains another module, as it is sooner in alphabet\n"
0922:                                + res, "MODULE my.another.module/3 (ahoj)", tok
0923:                                .nextToken());
0924:                assertEquals("Second the next one" + res,
0925:                        "MODULE my.module/3 (ahoj)", tok.nextToken());
0926:                assertFalse("No next tokens", tok.hasMoreElements());
0927:            }
0928:
0929:            public void testGenerateListOfForOneCluster() throws Exception {
0930:                File notAModule = generateJar(new String[] { "not/X.class",
0931:                        "not/resource/X.html" }, createManifest());
0932:
0933:                Manifest m = createManifest();
0934:                m.getMainAttributes().putValue("OpenIDE-Module", "my.module/3");
0935:                File withoutPkgs = generateJar(
0936:                        new String[] { "DefaultPkg.class", "is/X.class",
0937:                                "is/too/MyClass.class",
0938:                                "not/as/it/is/resource/X.xml" }, m);
0939:
0940:                m = createManifest();
0941:                m.getMainAttributes().putValue("OpenIDE-Module",
0942:                        "my.another.module/3");
0943:                m.getMainAttributes().putValue(
0944:                        "OpenIDE-Module-Public-Packages",
0945:                        "is.there.*, is.recursive.**");
0946:                File withPkgs = generateJar(new String[] { "is/there/A.class",
0947:                        "not/there/B.class", "is/recursive/Root.class",
0948:                        "is/recursive/sub/Under.class", "not/res/X.jpg" }, m);
0949:
0950:                File parent = notAModule.getParentFile();
0951:                assertEquals("All parents are the same 1", parent, withoutPkgs
0952:                        .getParentFile());
0953:                assertEquals("All parents are the same 2", parent, withPkgs
0954:                        .getParentFile());
0955:
0956:                File output = PublicPackagesInProjectizedXMLTest
0957:                        .extractString("");
0958:                output.delete();
0959:                assertFalse("Is gone", output.exists());
0960:                java.io.File f = PublicPackagesInProjectizedXMLTest
0961:                        .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
0962:                                + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
0963:                                + "  <taskdef name=\"deps\" classname=\"org.netbeans.nbbuild.ModuleDependencies\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
0964:                                + "<target name=\"all\" >"
0965:                                + "  <deps generate='ahoj'>"
0966:                                + "    <input name=\"ignore\" >"
0967:                                + "      <jars dir=\""
0968:                                + parent
0969:                                + "\" > "
0970:                                + "        <include name=\""
0971:                                + withoutPkgs.getName()
0972:                                + "\" />"
0973:                                + "        <include name=\""
0974:                                + withPkgs.getName()
0975:                                + "\" />"
0976:                                + "      </jars>"
0977:                                + "    </input>"
0978:                                + "    <input name=\"ahoj\" >"
0979:                                + "      <jars dir=\""
0980:                                + parent
0981:                                + "\" > "
0982:                                + "        <include name=\""
0983:                                + notAModule.getName()
0984:                                + "\" />"
0985:                                + "      </jars>"
0986:                                + "    </input>"
0987:                                + "    <output type=\"modules\" file=\""
0988:                                + output
0989:                                + "\" />"
0990:                                + "  </deps >"
0991:                                + "</target>"
0992:                                + "</project>");
0993:                PublicPackagesInProjectizedXMLTest.execute(f,
0994:                        new String[] { "-verbose" });
0995:
0996:                assertTrue("Result generated", output.exists());
0997:
0998:                String res = readFile(output);
0999:                StringTokenizer tok = new StringTokenizer(res, "\n\r");
1000:                assertEquals("Should be empty:\n" + res, 0, tok.countTokens());
1001:            }
1002:
1003:            public void testGenerateModuleDependencies() throws Exception {
1004:                Manifest openideManifest = createManifest();
1005:                openideManifest.getMainAttributes().putValue("OpenIDE-Module",
1006:                        "org.openide/1");
1007:                File openide = generateJar(new String[] { "notneeded" },
1008:                        openideManifest);
1009:
1010:                Manifest m = createManifest();
1011:                m.getMainAttributes().putValue("OpenIDE-Module", "my.module/3");
1012:                m.getMainAttributes().putValue(
1013:                        "OpenIDE-Module-Module-Dependencies",
1014:                        "org.openide/1 > 4.17");
1015:                File withoutPkgs = generateJar(new String[] { "notneeded" }, m);
1016:
1017:                m = createManifest();
1018:                m.getMainAttributes().putValue("OpenIDE-Module",
1019:                        "my.another.module/3");
1020:                m.getMainAttributes().putValue(
1021:                        "OpenIDE-Module-Module-Dependencies",
1022:                        "my.module/3, org.openide/1 > 4.17");
1023:                File withPkgs = generateJar(new String[] { "some content" }, m);
1024:
1025:                File parent = openide.getParentFile();
1026:                assertEquals("All parents are the same 1", parent, withoutPkgs
1027:                        .getParentFile());
1028:                assertEquals("All parents are the same 2", parent, withPkgs
1029:                        .getParentFile());
1030:
1031:                File output = PublicPackagesInProjectizedXMLTest
1032:                        .extractString("");
1033:                output.delete();
1034:                assertFalse("Is gone", output.exists());
1035:                java.io.File f = PublicPackagesInProjectizedXMLTest
1036:                        .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
1037:                                + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
1038:                                + "  <taskdef name=\"deps\" classname=\"org.netbeans.nbbuild.ModuleDependencies\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
1039:                                + "<target name=\"all\" >"
1040:                                + "  <deps>"
1041:                                + "    <input name=\"platform\" >"
1042:                                + "      <jars dir=\""
1043:                                + parent
1044:                                + "\" > "
1045:                                + "        <include name=\""
1046:                                + openide.getName()
1047:                                + "\" />"
1048:                                + "      </jars>"
1049:                                + "    </input>"
1050:                                + "    <input name=\"ahoj\" >"
1051:                                + "      <jars dir=\""
1052:                                + parent
1053:                                + "\" > "
1054:                                + "        <include name=\""
1055:                                + withoutPkgs.getName()
1056:                                + "\" />"
1057:                                + "        <include name=\""
1058:                                + withPkgs.getName()
1059:                                + "\" />"
1060:                                + "      </jars>"
1061:                                + "    </input>"
1062:                                + "    <output type=\"dependencies\" file=\""
1063:                                + output
1064:                                + "\" />"
1065:                                + "  </deps >"
1066:                                + "</target>"
1067:                                + "</project>");
1068:                PublicPackagesInProjectizedXMLTest.execute(f,
1069:                        new String[] { "-verbose" });
1070:
1071:                assertTrue("Result generated", output.exists());
1072:
1073:                String res = readFile(output);
1074:                int y = res.indexOf("MODULE", 1);
1075:                if (y <= 0) {
1076:                    fail("There is another module: " + y + " res: " + res);
1077:                }
1078:                assertEquals("No other", -1, res.indexOf("MODULE", y + 1));
1079:
1080:                // f1 is later due to algebraic sorting of modules!!!!
1081:                StringTokenizer f2 = new StringTokenizer(res.substring(0, y),
1082:                        "\r\n");
1083:                StringTokenizer f1 = new StringTokenizer(res.substring(y),
1084:                        "\r\n");
1085:
1086:                assertEquals("One line + one dep for f1\n" + res, 2, f1
1087:                        .countTokens());
1088:                f1.nextToken();
1089:                String dep1 = f1.nextToken();
1090:                assertTrue(dep1, dep1.startsWith("  REQUIRES"));
1091:                assertTrue("on " + dep1, dep1.indexOf("org.openide") >= 0);
1092:
1093:                assertEquals("One line + two dep for f2", 3, f2.countTokens());
1094:                f2.nextToken();
1095:                String dep2 = f2.nextToken();
1096:                assertTrue(dep2, dep2.startsWith("  REQUIRES"));
1097:                assertTrue("on my " + dep2, dep2.indexOf("my.module") >= 0);
1098:                dep2 = f2.nextToken();
1099:                assertTrue(dep2, dep2.startsWith("  REQUIRES"));
1100:                assertTrue("on " + dep2, dep2.indexOf("org.openide") >= 0);
1101:
1102:            }
1103:
1104:            public void testGenerateModuleDependenciesInOneClusterOnly()
1105:                    throws Exception {
1106:                Manifest openideManifest = createManifest();
1107:                openideManifest.getMainAttributes().putValue("OpenIDE-Module",
1108:                        "org.openide/1");
1109:                File openide = generateJar(new String[] { "notneeded" },
1110:                        openideManifest);
1111:
1112:                Manifest m = createManifest();
1113:                m.getMainAttributes().putValue("OpenIDE-Module", "my.module/3");
1114:                m.getMainAttributes().putValue(
1115:                        "OpenIDE-Module-Module-Dependencies",
1116:                        "org.openide/1 > 4.17");
1117:                File withoutPkgs = generateJar(new String[] { "notneeded" }, m);
1118:
1119:                m = createManifest();
1120:                m.getMainAttributes().putValue("OpenIDE-Module",
1121:                        "my.another.module/3");
1122:                m.getMainAttributes().putValue(
1123:                        "OpenIDE-Module-Module-Dependencies",
1124:                        "my.module/3, org.openide/1 > 4.17");
1125:                File withPkgs = generateJar(new String[] { "some content" }, m);
1126:
1127:                File parent = openide.getParentFile();
1128:                assertEquals("All parents are the same 1", parent, withoutPkgs
1129:                        .getParentFile());
1130:                assertEquals("All parents are the same 2", parent, withPkgs
1131:                        .getParentFile());
1132:
1133:                File output = PublicPackagesInProjectizedXMLTest
1134:                        .extractString("");
1135:                output.delete();
1136:                assertFalse("Is gone", output.exists());
1137:                java.io.File f = PublicPackagesInProjectizedXMLTest
1138:                        .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
1139:                                + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
1140:                                + "  <taskdef name=\"deps\" classname=\"org.netbeans.nbbuild.ModuleDependencies\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
1141:                                + "<target name=\"all\" >"
1142:                                + "  <deps generate='ahoj'>"
1143:                                + "    <input name=\"platform\" >"
1144:                                + "      <jars dir=\""
1145:                                + parent
1146:                                + "\" > "
1147:                                + "        <include name=\""
1148:                                + openide.getName()
1149:                                + "\" />"
1150:                                + "        <include name=\""
1151:                                + withoutPkgs.getName()
1152:                                + "\" />"
1153:                                + "      </jars>"
1154:                                + "    </input>"
1155:                                + "    <input name=\"ahoj\" >"
1156:                                + "      <jars dir=\""
1157:                                + parent
1158:                                + "\" > "
1159:                                + "        <include name=\""
1160:                                + withPkgs.getName()
1161:                                + "\" />"
1162:                                + "      </jars>"
1163:                                + "    </input>"
1164:                                + "    <output type=\"dependencies\" file=\""
1165:                                + output
1166:                                + "\" />"
1167:                                + "  </deps >"
1168:                                + "</target>"
1169:                                + "</project>");
1170:                PublicPackagesInProjectizedXMLTest.execute(f,
1171:                        new String[] { "-verbose" });
1172:
1173:                assertTrue("Result generated", output.exists());
1174:
1175:                String res = readFile(output);
1176:                int y = res.indexOf("MODULE");
1177:                if (y < 0) {
1178:                    fail("There is one module: " + y + " res: " + res);
1179:                }
1180:                assertEquals("No other", -1, res.indexOf("MODULE", y + 1));
1181:
1182:                StringTokenizer f2 = new StringTokenizer(res, "\r\n");
1183:
1184:                assertEquals("One line + two dep for f2", 3, f2.countTokens());
1185:                f2.nextToken();
1186:                String dep2 = f2.nextToken();
1187:                assertTrue(dep2, dep2.startsWith("  REQUIRES"));
1188:                assertTrue("on my " + dep2, dep2.indexOf("my.module") >= 0);
1189:                dep2 = f2.nextToken();
1190:                assertTrue(dep2, dep2.startsWith("  REQUIRES"));
1191:                assertTrue("on " + dep2, dep2.indexOf("org.openide") >= 0);
1192:
1193:            }
1194:
1195:            public void testImplementationModuleDependenciesAreRegularDepsAsWell()
1196:                    throws Exception {
1197:                Manifest openideManifest = createManifest();
1198:                openideManifest.getMainAttributes().putValue("OpenIDE-Module",
1199:                        "org.openide/1");
1200:                File openide = generateJar(new String[] { "notneeded" },
1201:                        openideManifest);
1202:
1203:                Manifest m = createManifest();
1204:                m.getMainAttributes().putValue("OpenIDE-Module", "my.module/3");
1205:                m.getMainAttributes().putValue(
1206:                        "OpenIDE-Module-Module-Dependencies",
1207:                        "org.openide/1 > 4.17");
1208:                File withoutPkgs = generateJar(new String[] { "notneeded" }, m);
1209:
1210:                m = createManifest();
1211:                m.getMainAttributes().putValue("OpenIDE-Module",
1212:                        "my.another.module/3");
1213:                m.getMainAttributes().putValue(
1214:                        "OpenIDE-Module-Module-Dependencies",
1215:                        "my.module/3 = Ahoj, org.openide/1 > 4.17");
1216:                File withPkgs = generateJar(new String[] { "some content" }, m);
1217:
1218:                File parent = openide.getParentFile();
1219:                assertEquals("All parents are the same 1", parent, withoutPkgs
1220:                        .getParentFile());
1221:                assertEquals("All parents are the same 2", parent, withPkgs
1222:                        .getParentFile());
1223:
1224:                File output = PublicPackagesInProjectizedXMLTest
1225:                        .extractString("");
1226:                output.delete();
1227:                assertFalse("Is gone", output.exists());
1228:                java.io.File f = PublicPackagesInProjectizedXMLTest
1229:                        .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
1230:                                + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
1231:                                + "  <taskdef name=\"deps\" classname=\"org.netbeans.nbbuild.ModuleDependencies\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
1232:                                + "<target name=\"all\" >"
1233:                                + "  <deps>"
1234:                                + "    <input name=\"platform\" >"
1235:                                + "      <jars dir=\""
1236:                                + parent
1237:                                + "\" > "
1238:                                + "        <include name=\""
1239:                                + openide.getName()
1240:                                + "\" />"
1241:                                + "      </jars>"
1242:                                + "    </input>"
1243:                                + "    <input name=\"ahoj\" >"
1244:                                + "      <jars dir=\""
1245:                                + parent
1246:                                + "\" > "
1247:                                + "        <include name=\""
1248:                                + withoutPkgs.getName()
1249:                                + "\" />"
1250:                                + "        <include name=\""
1251:                                + withPkgs.getName()
1252:                                + "\" />"
1253:                                + "      </jars>"
1254:                                + "    </input>"
1255:                                + "    <output type=\"dependencies\" file=\""
1256:                                + output
1257:                                + "\" />"
1258:                                + "  </deps >"
1259:                                + "</target>"
1260:                                + "</project>");
1261:                PublicPackagesInProjectizedXMLTest.execute(f,
1262:                        new String[] { "-verbose" });
1263:
1264:                assertTrue("Result generated", output.exists());
1265:
1266:                String res = readFile(output);
1267:                int x = res.indexOf("MODULE");
1268:                assertEquals("The file starts with MODULE", 0, x);
1269:                int y = res.indexOf("MODULE", 1);
1270:                if (y <= 0) {
1271:                    fail("There is another module: " + y + " res:\n" + res);
1272:                }
1273:                assertEquals("No other", -1, res.indexOf("MODULE", y + 1));
1274:
1275:                // f1 is later due to algebraic sorting of modules!!!!
1276:                StringTokenizer f2 = new StringTokenizer(res.substring(0, y),
1277:                        "\r\n");
1278:                StringTokenizer f1 = new StringTokenizer(res.substring(y),
1279:                        "\r\n");
1280:
1281:                assertEquals("One line + one dep for f1\n" + res, 2, f1
1282:                        .countTokens());
1283:                f1.nextToken();
1284:                String dep1 = f1.nextToken();
1285:                assertTrue(dep1, dep1.startsWith("  REQUIRES"));
1286:                assertTrue("on " + dep1, dep1.indexOf("org.openide") >= 0);
1287:
1288:                assertEquals("One line + two dep for f2", 3, f2.countTokens());
1289:                f2.nextToken();
1290:                String dep2 = f2.nextToken();
1291:                assertTrue(dep2, dep2.startsWith("  REQUIRES"));
1292:                assertTrue("on my " + dep2, dep2.indexOf("my.module") >= 0);
1293:                dep2 = f2.nextToken();
1294:                assertTrue(dep2, dep2.startsWith("  REQUIRES"));
1295:                assertTrue("on " + dep2, dep2.indexOf("org.openide") >= 0);
1296:
1297:            }
1298:
1299:            public void testGenerateImplementationModuleDependencies()
1300:                    throws Exception {
1301:                Manifest m = createManifest();
1302:                m.getMainAttributes().putValue("OpenIDE-Module", "my.module/3");
1303:                m.getMainAttributes().putValue(
1304:                        "OpenIDE-Module-IDE-Dependencies", "IDE/1 > 4.17");
1305:                File withoutPkgs = generateJar(new String[] { "notneeded" }, m);
1306:
1307:                m = createManifest();
1308:                m.getMainAttributes().putValue("OpenIDE-Module",
1309:                        "my.another.module/3");
1310:                m.getMainAttributes().putValue(
1311:                        "OpenIDE-Module-Module-Dependencies",
1312:                        "my.module/3 = Ahoj, org.openide/1 > 4.17");
1313:                File withPkgs = generateJar(new String[] { "some content" }, m);
1314:
1315:                File parent = withoutPkgs.getParentFile();
1316:                assertEquals("All parents are the same 1", parent, withoutPkgs
1317:                        .getParentFile());
1318:                assertEquals("All parents are the same 2", parent, withPkgs
1319:                        .getParentFile());
1320:
1321:                File output = PublicPackagesInProjectizedXMLTest
1322:                        .extractString("");
1323:                output.delete();
1324:                assertFalse("Is gone", output.exists());
1325:                java.io.File f = PublicPackagesInProjectizedXMLTest
1326:                        .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
1327:                                + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
1328:                                + "  <taskdef name=\"deps\" classname=\"org.netbeans.nbbuild.ModuleDependencies\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
1329:                                + "<target name=\"all\" >"
1330:                                + "  <deps>"
1331:                                + "    <input name=\"ahoj\" >"
1332:                                + "      <jars dir=\""
1333:                                + parent
1334:                                + "\" > "
1335:                                + "        <include name=\""
1336:                                + withoutPkgs.getName()
1337:                                + "\" />"
1338:                                + "        <include name=\""
1339:                                + withPkgs.getName()
1340:                                + "\" />"
1341:                                + "      </jars>"
1342:                                + "    </input>"
1343:                                + "    <output type=\"implementation-dependencies\" file=\""
1344:                                + output
1345:                                + "\" />"
1346:                                + "  </deps >"
1347:                                + "</target>"
1348:                                + "</project>");
1349:                PublicPackagesInProjectizedXMLTest.execute(f,
1350:                        new String[] { "-verbose" });
1351:
1352:                assertTrue("Result generated", output.exists());
1353:
1354:                String res = readFile(output);
1355:                int x = res.indexOf("MODULE");
1356:                assertEquals("The file starts with MODULE", 0, x);
1357:                int y = res.indexOf("MODULE", 1);
1358:                assertEquals("No other:\n" + res, -1, y);
1359:
1360:                StringTokenizer f1 = new StringTokenizer(res, "\r\n");
1361:
1362:                assertEquals("One line + one dep for f1\n" + res, 2, f1
1363:                        .countTokens());
1364:                String modulename = f1.nextToken();
1365:                assertTrue("module is ", modulename
1366:                        .indexOf("my.another.module") >= 0);
1367:                String dep1 = f1.nextToken();
1368:                assertTrue(dep1, dep1.startsWith("  REQUIRES"));
1369:                assertTrue("on " + dep1, dep1.indexOf("my.module") >= 0);
1370:            }
1371:
1372:            public void testCanOutputJustDependenciesBetweenClusters()
1373:                    throws Exception {
1374:                Manifest m = createManifest();
1375:                m.getMainAttributes().putValue("OpenIDE-Module",
1376:                        "org.openide/1");
1377:                File openide = generateJar(new String[] { "notneeded" }, m);
1378:
1379:                m = createManifest();
1380:                m.getMainAttributes().putValue("OpenIDE-Module", "my.module/3");
1381:                m.getMainAttributes().putValue(
1382:                        "OpenIDE-Module-IDE-Dependencies", "IDE/1 > 4.17");
1383:                File withoutPkgs = generateJar(new String[] { "notneeded" }, m);
1384:
1385:                m = createManifest();
1386:                m.getMainAttributes().putValue("OpenIDE-Module",
1387:                        "my.another.module/3");
1388:                m.getMainAttributes().putValue(
1389:                        "OpenIDE-Module-Module-Dependencies",
1390:                        "my.module/3 = Ahoj, org.openide/1 > 4.17");
1391:                File withPkgs = generateJar(new String[] { "some content" }, m);
1392:
1393:                File parent = withoutPkgs.getParentFile();
1394:                assertEquals("All parents are the same 1", parent, withoutPkgs
1395:                        .getParentFile());
1396:                assertEquals("All parents are the same 2", parent, withPkgs
1397:                        .getParentFile());
1398:
1399:                File output = PublicPackagesInProjectizedXMLTest
1400:                        .extractString("");
1401:                output.delete();
1402:                assertFalse("Is gone", output.exists());
1403:                java.io.File f = PublicPackagesInProjectizedXMLTest
1404:                        .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
1405:                                + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
1406:                                + "  <taskdef name=\"deps\" classname=\"org.netbeans.nbbuild.ModuleDependencies\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
1407:                                + "<target name=\"all\" >"
1408:                                + "  <deps>"
1409:                                + "    <input name=\"platform\" >"
1410:                                + "      <jars dir=\""
1411:                                + parent
1412:                                + "\" > "
1413:                                + "        <include name=\""
1414:                                + openide.getName()
1415:                                + "\" />"
1416:                                + "      </jars>"
1417:                                + "    </input>"
1418:                                + "    <input name=\"others\" >"
1419:                                + "      <jars dir=\""
1420:                                + parent
1421:                                + "\" > "
1422:                                + "        <include name=\""
1423:                                + withoutPkgs.getName()
1424:                                + "\" />"
1425:                                + "        <include name=\""
1426:                                + withPkgs.getName()
1427:                                + "\" />"
1428:                                + "      </jars>"
1429:                                + "    </input>"
1430:                                + "    <output type=\"group-dependencies\" file=\""
1431:                                + output
1432:                                + "\" />"
1433:                                + "  </deps >"
1434:                                + "</target>"
1435:                                + "</project>");
1436:                PublicPackagesInProjectizedXMLTest.execute(f,
1437:                        new String[] { "-verbose" });
1438:
1439:                assertTrue("Result generated", output.exists());
1440:
1441:                String res = readFile(output);
1442:                int x = res.indexOf("GROUP");
1443:                assertEquals("The file starts with GROUP", 0, x);
1444:                int y = res.indexOf("GROUP", 1);
1445:                assertEquals("No other:\n" + res, -1, y);
1446:
1447:                StringTokenizer f1 = new StringTokenizer(res, "\r\n");
1448:
1449:                assertEquals("One line + dep on openide\n" + res, 2, f1
1450:                        .countTokens());
1451:                String groupname = f1.nextToken();
1452:                assertTrue("group is " + res, groupname.indexOf("others") >= 0);
1453:                String dep1 = f1.nextToken();
1454:                assertTrue(dep1, dep1.startsWith("  REQUIRES"));
1455:                assertTrue("on openide module" + dep1, dep1
1456:                        .indexOf("org.openide") >= 0);
1457:            }
1458:
1459:            public void testCanOutputJustDependenciesBetweenClustersForOneCluster()
1460:                    throws Exception {
1461:                Manifest m = createManifest();
1462:                m.getMainAttributes().putValue("OpenIDE-Module",
1463:                        "org.openide/1");
1464:                File openide = generateJar(new String[] { "notneeded" }, m);
1465:
1466:                m = createManifest();
1467:                m.getMainAttributes().putValue("OpenIDE-Module", "my.module/3");
1468:                m.getMainAttributes().putValue(
1469:                        "OpenIDE-Module-Module-Dependencies",
1470:                        "org.openide/1 > 4.17");
1471:                File withoutPkgs = generateJar(new String[] { "notneeded" }, m);
1472:
1473:                m = createManifest();
1474:                m.getMainAttributes().putValue("OpenIDE-Module",
1475:                        "my.another.module/3");
1476:                m.getMainAttributes().putValue(
1477:                        "OpenIDE-Module-Module-Dependencies",
1478:                        "my.module/3 = Ahoj, org.openide/1 > 4.17");
1479:                File withPkgs = generateJar(new String[] { "some content" }, m);
1480:
1481:                File parent = withoutPkgs.getParentFile();
1482:                assertEquals("All parents are the same 1", parent, withoutPkgs
1483:                        .getParentFile());
1484:                assertEquals("All parents are the same 2", parent, withPkgs
1485:                        .getParentFile());
1486:
1487:                File output = PublicPackagesInProjectizedXMLTest
1488:                        .extractString("");
1489:                output.delete();
1490:                assertFalse("Is gone", output.exists());
1491:                java.io.File f = PublicPackagesInProjectizedXMLTest
1492:                        .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
1493:                                + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
1494:                                + "  <taskdef name=\"deps\" classname=\"org.netbeans.nbbuild.ModuleDependencies\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
1495:                                + "<target name=\"all\" >"
1496:                                + "  <deps generate='others'>"
1497:                                + "    <input name=\"platform\" >"
1498:                                + "      <jars dir=\""
1499:                                + parent
1500:                                + "\" > "
1501:                                + "        <include name=\""
1502:                                + openide.getName()
1503:                                + "\" />"
1504:                                + "      </jars>"
1505:                                + "    </input>"
1506:                                + "    <input name=\"ide\" >"
1507:                                + "      <jars dir=\""
1508:                                + parent
1509:                                + "\" > "
1510:                                + "        <include name=\""
1511:                                + withoutPkgs.getName()
1512:                                + "\" />"
1513:                                + "      </jars>"
1514:                                + "    </input>"
1515:                                + "    <input name=\"others\" >"
1516:                                + "      <jars dir=\""
1517:                                + parent
1518:                                + "\" > "
1519:                                + "        <include name=\""
1520:                                + withPkgs.getName()
1521:                                + "\" />"
1522:                                + "      </jars>"
1523:                                + "    </input>"
1524:                                + "    <output type=\"group-dependencies\" file=\""
1525:                                + output
1526:                                + "\" />"
1527:                                + "  </deps >"
1528:                                + "</target>"
1529:                                + "</project>");
1530:                PublicPackagesInProjectizedXMLTest.execute(f,
1531:                        new String[] { "-verbose" });
1532:
1533:                assertTrue("Result generated", output.exists());
1534:
1535:                String res = readFile(output);
1536:                int x = res.indexOf("GROUP");
1537:                assertEquals("The file starts with GROUP", 0, x);
1538:                int y = res.indexOf("GROUP", 1);
1539:                assertEquals("No other:\n" + res, -1, y);
1540:
1541:                StringTokenizer f1 = new StringTokenizer(res, "\r\n");
1542:
1543:                assertEquals("One line + dep on openide and the other module\n"
1544:                        + res, 3, f1.countTokens());
1545:                String groupname = f1.nextToken();
1546:                assertTrue("group is " + res, groupname.indexOf("others") >= 0);
1547:                String dep1 = f1.nextToken();
1548:                assertTrue(dep1, dep1.startsWith("  REQUIRES"));
1549:                assertTrue("on my module" + dep1,
1550:                        dep1.indexOf("my.module") >= 0);
1551:                String dep2 = f1.nextToken();
1552:                assertTrue(dep2, dep2.startsWith("  REQUIRES"));
1553:                assertTrue("on openide module" + dep2, dep2
1554:                        .indexOf("org.openide") >= 0);
1555:            }
1556:
1557:            public void testCanOutputJustImplDependenciesBetweenClusters()
1558:                    throws Exception {
1559:                Manifest m = createManifest();
1560:                m.getMainAttributes().putValue("OpenIDE-Module",
1561:                        "org.openide/1");
1562:                File openide = generateJar(new String[] { "notneeded" }, m);
1563:
1564:                m = createManifest();
1565:                m.getMainAttributes().putValue("OpenIDE-Module",
1566:                        "org.netbeans.core/1");
1567:                File core = generateJar(new String[] { "notneeded" }, m);
1568:
1569:                m = createManifest();
1570:                m.getMainAttributes().putValue("OpenIDE-Module", "my.module/3");
1571:                m.getMainAttributes().putValue(
1572:                        "OpenIDE-Module-IDE-Dependencies", "IDE/1 > 4.17");
1573:                File withoutPkgs = generateJar(new String[] { "notneeded" }, m);
1574:
1575:                m = createManifest();
1576:                m.getMainAttributes().putValue("OpenIDE-Module",
1577:                        "my.another.module/3");
1578:                m.getMainAttributes().putValue(
1579:                        "OpenIDE-Module-Module-Dependencies",
1580:                        "my.module/3 = Ahoj, org.openide/1 > 4.17");
1581:                File withPkgs = generateJar(new String[] { "some content" }, m);
1582:
1583:                m = createManifest();
1584:                m.getMainAttributes().putValue("OpenIDE-Module",
1585:                        "my.module.dependingoncore/3");
1586:                m.getMainAttributes().putValue(
1587:                        "OpenIDE-Module-Module-Dependencies",
1588:                        "org.netbeans.core/1 = Ahoj, my.module/3 > 4.17");
1589:                File coredepender = generateJar(new String[] { "notneeded" }, m);
1590:
1591:                File parent = withoutPkgs.getParentFile();
1592:                assertEquals("All parents are the same 1", parent, withoutPkgs
1593:                        .getParentFile());
1594:                assertEquals("All parents are the same 2", parent, withPkgs
1595:                        .getParentFile());
1596:
1597:                File output = PublicPackagesInProjectizedXMLTest
1598:                        .extractString("");
1599:                output.delete();
1600:                assertFalse("Is gone", output.exists());
1601:                java.io.File f = PublicPackagesInProjectizedXMLTest
1602:                        .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
1603:                                + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
1604:                                + "  <taskdef name=\"deps\" classname=\"org.netbeans.nbbuild.ModuleDependencies\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
1605:                                + "<target name=\"all\" >"
1606:                                + "  <deps>"
1607:                                + "    <input name=\"platform\" >"
1608:                                + "      <jars dir=\""
1609:                                + parent
1610:                                + "\" > "
1611:                                + "        <include name=\""
1612:                                + openide.getName()
1613:                                + "\" />"
1614:                                + "        <include name=\""
1615:                                + core.getName()
1616:                                + "\" />"
1617:                                + "      </jars>"
1618:                                + "    </input>"
1619:                                + "    <input name=\"others\" >"
1620:                                + "      <jars dir=\""
1621:                                + parent
1622:                                + "\" > "
1623:                                + "        <include name=\""
1624:                                + withoutPkgs.getName()
1625:                                + "\" />"
1626:                                + "        <include name=\""
1627:                                + withPkgs.getName()
1628:                                + "\" />"
1629:                                + "      </jars>"
1630:                                + "    </input>"
1631:                                + "    <input name=\"rest\" >"
1632:                                + "      <jars dir=\""
1633:                                + parent
1634:                                + "\" > "
1635:                                + "        <include name=\""
1636:                                + coredepender.getName()
1637:                                + "\" />"
1638:                                + "      </jars>"
1639:                                + "    </input>"
1640:                                + "    <output type=\"group-implementation-dependencies\" file=\""
1641:                                + output
1642:                                + "\" />"
1643:                                + "  </deps >"
1644:                                + "</target>"
1645:                                + "</project>");
1646:                PublicPackagesInProjectizedXMLTest.execute(f,
1647:                        new String[] { "-verbose" });
1648:
1649:                assertTrue("Result generated", output.exists());
1650:
1651:                String res = readFile(output);
1652:                int x = res.indexOf("GROUP");
1653:                assertEquals("The file starts with GROUP", 0, x);
1654:                int y = res.indexOf("GROUP", 1);
1655:                assertEquals("No other:\n" + res, -1, y);
1656:
1657:                StringTokenizer f1 = new StringTokenizer(res, "\r\n");
1658:
1659:                assertEquals("One line + dep on openide\n" + res, 2, f1
1660:                        .countTokens());
1661:                String groupname = f1.nextToken();
1662:                assertTrue("group is " + res, groupname.indexOf("rest") >= 0);
1663:                String dep1 = f1.nextToken();
1664:                assertTrue(dep1, dep1.startsWith("  REQUIRES"));
1665:                assertTrue("on openide module" + dep1, dep1
1666:                        .indexOf("org.netbeans.core") >= 0);
1667:            }
1668:
1669:            public void testRangeDependencyNeedsToBeParsed() throws Exception {
1670:                Manifest m = createManifest();
1671:                m.getMainAttributes().putValue("OpenIDE-Module", "my.module/3");
1672:                m.getMainAttributes().putValue(
1673:                        "OpenIDE-Module-IDE-Dependencies", "IDE/1 > 4.17");
1674:                File withoutPkgs = generateJar(new String[] { "notneeded" }, m);
1675:
1676:                m = createManifest();
1677:                m.getMainAttributes().putValue("OpenIDE-Module",
1678:                        "my.another.module/3");
1679:                m.getMainAttributes().putValue(
1680:                        "OpenIDE-Module-Module-Dependencies",
1681:                        "my.module/2-3 = Ahoj, org.openide/1-2 > 4.17");
1682:                File withPkgs = generateJar(new String[] { "some content" }, m);
1683:
1684:                File parent = withoutPkgs.getParentFile();
1685:                assertEquals("All parents are the same 1", parent, withoutPkgs
1686:                        .getParentFile());
1687:                assertEquals("All parents are the same 2", parent, withPkgs
1688:                        .getParentFile());
1689:
1690:                File output = PublicPackagesInProjectizedXMLTest
1691:                        .extractString("");
1692:                output.delete();
1693:                assertFalse("Is gone", output.exists());
1694:                java.io.File f = PublicPackagesInProjectizedXMLTest
1695:                        .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
1696:                                + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
1697:                                + "  <taskdef name=\"deps\" classname=\"org.netbeans.nbbuild.ModuleDependencies\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
1698:                                + "<target name=\"all\" >"
1699:                                + "  <deps>"
1700:                                + "    <input name=\"ahoj\" >"
1701:                                + "      <jars dir=\""
1702:                                + parent
1703:                                + "\" > "
1704:                                + "        <include name=\""
1705:                                + withoutPkgs.getName()
1706:                                + "\" />"
1707:                                + "        <include name=\""
1708:                                + withPkgs.getName()
1709:                                + "\" />"
1710:                                + "      </jars>"
1711:                                + "    </input>"
1712:                                + "    <output type=\"implementation-dependencies\" file=\""
1713:                                + output
1714:                                + "\" />"
1715:                                + "  </deps >"
1716:                                + "</target>"
1717:                                + "</project>");
1718:                PublicPackagesInProjectizedXMLTest.execute(f,
1719:                        new String[] { "-verbose" });
1720:
1721:                assertTrue("Result generated", output.exists());
1722:
1723:                String res = readFile(output);
1724:                int x = res.indexOf("MODULE");
1725:                assertEquals("The file starts with MODULE", 0, x);
1726:                int y = res.indexOf("MODULE", 1);
1727:                assertEquals("No other:\n" + res, -1, y);
1728:
1729:                StringTokenizer f1 = new StringTokenizer(res, "\r\n");
1730:
1731:                assertEquals("One line + one dep for f1\n" + res, 2, f1
1732:                        .countTokens());
1733:                String modulename = f1.nextToken();
1734:                assertTrue("module is ", modulename
1735:                        .indexOf("my.another.module") >= 0);
1736:                String dep1 = f1.nextToken();
1737:                assertTrue(dep1, dep1.startsWith("  REQUIRES"));
1738:                assertTrue("on " + dep1, dep1.indexOf("my.module") >= 0);
1739:            }
1740:
1741:            public void testGenerateProvidesRequiresDependencies()
1742:                    throws Exception {
1743:                Manifest m = createManifest();
1744:                m.getMainAttributes().putValue("OpenIDE-Module", "my.module/3");
1745:                m.getMainAttributes().putValue("OpenIDE-Module-Provides",
1746:                        "my.token");
1747:                File withoutPkgs = generateJar(new String[] { "notneeded" }, m);
1748:
1749:                m = createManifest();
1750:                m.getMainAttributes().putValue("OpenIDE-Module",
1751:                        "my.another.module/7");
1752:                m.getMainAttributes().putValue("OpenIDE-Module-Requires",
1753:                        "my.token");
1754:                File withPkgs = generateJar(new String[] { "some content" }, m);
1755:
1756:                File parent = withoutPkgs.getParentFile();
1757:                assertEquals("All parents are the same 1", parent, withoutPkgs
1758:                        .getParentFile());
1759:                assertEquals("All parents are the same 2", parent, withPkgs
1760:                        .getParentFile());
1761:
1762:                File output = PublicPackagesInProjectizedXMLTest
1763:                        .extractString("");
1764:                output.delete();
1765:                assertFalse("Is gone", output.exists());
1766:                java.io.File f = PublicPackagesInProjectizedXMLTest
1767:                        .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
1768:                                + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
1769:                                + "  <taskdef name=\"deps\" classname=\"org.netbeans.nbbuild.ModuleDependencies\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
1770:                                + "<target name=\"all\" >"
1771:                                + "  <deps>"
1772:                                + "    <input name=\"ahoj\" >"
1773:                                + "      <jars dir=\""
1774:                                + parent
1775:                                + "\" > "
1776:                                + "        <include name=\""
1777:                                + withoutPkgs.getName()
1778:                                + "\" />"
1779:                                + "        <include name=\""
1780:                                + withPkgs.getName()
1781:                                + "\" />"
1782:                                + "      </jars>"
1783:                                + "    </input>"
1784:                                + "    <output type=\"dependencies\" file=\""
1785:                                + output
1786:                                + "\" />"
1787:                                + "  </deps >"
1788:                                + "</target>"
1789:                                + "</project>");
1790:                PublicPackagesInProjectizedXMLTest.execute(f,
1791:                        new String[] { "-verbose" });
1792:
1793:                assertTrue("Result generated", output.exists());
1794:
1795:                String res = readFile(output);
1796:                int x = res.indexOf("MODULE");
1797:                assertEquals("The file starts with MODULE", 0, x);
1798:                int y = res.indexOf("MODULE", 1);
1799:                assertEquals("No other module: " + res, -1, y);
1800:
1801:                StringTokenizer f1 = new StringTokenizer(res, "\r\n");
1802:
1803:                assertEquals("One line + one dep for f1\n" + res, 2, f1
1804:                        .countTokens());
1805:                String modulename = f1.nextToken();
1806:                assertTrue("module name contains another " + modulename,
1807:                        modulename.indexOf("my.another.module") > 0);
1808:                String dep1 = f1.nextToken();
1809:                assertTrue(dep1, dep1.startsWith("  REQUIRES"));
1810:                assertTrue("on " + dep1, dep1.indexOf("my.module") >= 0);
1811:            }
1812:
1813:            public void testSpecialDependenciesArePrintedWithoutSearchingForAppropriateModule()
1814:                    throws Exception {
1815:                Manifest m = createManifest();
1816:                m.getMainAttributes().putValue("OpenIDE-Module",
1817:                        "my.another.module/3");
1818:                m.getMainAttributes().putValue("OpenIDE-Module-Requires",
1819:                        "org.openide.modules.os.MacOSX");
1820:                File withPkgs = generateJar(new String[] { "some content" }, m);
1821:
1822:                File parent = withPkgs.getParentFile();
1823:
1824:                File output = PublicPackagesInProjectizedXMLTest
1825:                        .extractString("");
1826:                File output2 = PublicPackagesInProjectizedXMLTest
1827:                        .extractString("");
1828:                output.delete();
1829:                assertFalse("Is gone", output.exists());
1830:                java.io.File f = PublicPackagesInProjectizedXMLTest
1831:                        .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
1832:                                + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
1833:                                + "  <taskdef name=\"deps\" classname=\"org.netbeans.nbbuild.ModuleDependencies\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
1834:                                + "<target name=\"all\" >"
1835:                                + "  <deps>"
1836:                                + "    <input name=\"ahoj\" >"
1837:                                + "      <jars dir=\""
1838:                                + parent
1839:                                + "\" > "
1840:                                + "        <include name=\""
1841:                                + withPkgs.getName()
1842:                                + "\" />"
1843:                                + "      </jars>"
1844:                                + "    </input>"
1845:                                + "    <output type=\"dependencies\" file=\""
1846:                                + output
1847:                                + "\" />"
1848:                                + "    <output type=\"group-dependencies\" file=\""
1849:                                + output2
1850:                                + "\" />"
1851:                                + "  </deps >"
1852:                                + "</target>" + "</project>");
1853:                PublicPackagesInProjectizedXMLTest.execute(f,
1854:                        new String[] { "-verbose" });
1855:
1856:                assertTrue("Result generated", output.exists());
1857:
1858:                String res = readFile(output);
1859:                int x = res.indexOf("MODULE");
1860:                assertEquals("The file starts with MODULE:" + res, 0, x);
1861:                assertEquals("No other", -1, res.indexOf("MODULE", x + 1));
1862:
1863:                StringTokenizer f1 = new StringTokenizer(res, "\r\n");
1864:
1865:                assertEquals("One line + one dep for f1\n" + res, 2, f1
1866:                        .countTokens());
1867:                String modname = f1.nextToken();
1868:                assertTrue("Name: " + modname, modname
1869:                        .indexOf("my.another.module") > 0);
1870:                String dep1 = f1.nextToken();
1871:                assertTrue(dep1, dep1.startsWith("  REQUIRES"));
1872:                assertTrue("on " + dep1, dep1
1873:                        .indexOf("org.openide.modules.os.MacOSX") >= 0);
1874:
1875:            }
1876:
1877:            public void testPrintNamesOfPackagesSharedBetweenMoreModules()
1878:                    throws Exception {
1879:                File notAModule = generateJar(new String[] {
1880:                        "org/shared/not/X.class", "org/shared/yes/X.html" },
1881:                        createManifest());
1882:
1883:                Manifest m = createManifest();
1884:                m.getMainAttributes().putValue("OpenIDE-Module", "my.module/3");
1885:                File withoutPkgs = generateJar(new String[] {
1886:                        "org/shared/yes/Bla.class",
1887:                        "org/shared/not/sub/MyClass.class", }, m);
1888:
1889:                m = createManifest();
1890:                m.getMainAttributes().putValue("OpenIDE-Module",
1891:                        "my.another.module/3");
1892:                m.getMainAttributes().putValue("Class-Path",
1893:                        notAModule.getName());
1894:                File withPkgs = generateJar(
1895:                        new String[] { "org/shared/not/res/X.jpg" }, m);
1896:
1897:                File parent = notAModule.getParentFile();
1898:                assertEquals("All parents are the same 1", parent, withoutPkgs
1899:                        .getParentFile());
1900:                assertEquals("All parents are the same 2", parent, withPkgs
1901:                        .getParentFile());
1902:
1903:                File output = PublicPackagesInProjectizedXMLTest
1904:                        .extractString("");
1905:                output.delete();
1906:                assertFalse("Is gone", output.exists());
1907:                java.io.File f = PublicPackagesInProjectizedXMLTest
1908:                        .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
1909:                                + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
1910:                                + "  <taskdef name=\"deps\" classname=\"org.netbeans.nbbuild.ModuleDependencies\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
1911:                                + "<target name=\"all\" >"
1912:                                + "  <deps>"
1913:                                + "    <input name=\"ahoj\" >"
1914:                                + "      <jars dir=\""
1915:                                + parent
1916:                                + "\" > "
1917:                                + "        <include name=\""
1918:                                + notAModule.getName()
1919:                                + "\" />"
1920:                                + "        <include name=\""
1921:                                + withoutPkgs.getName()
1922:                                + "\" />"
1923:                                + "        <include name=\""
1924:                                + withPkgs.getName()
1925:                                + "\" />"
1926:                                + "      </jars>"
1927:                                + "    </input>"
1928:                                + "    <output type=\"shared-packages\" file=\""
1929:                                + output
1930:                                + "\" />"
1931:                                + "  </deps >"
1932:                                + "</target>"
1933:                                + "</project>");
1934:                PublicPackagesInProjectizedXMLTest.execute(f,
1935:                        new String[] { "-verbose" });
1936:
1937:                assertTrue("Result generated", output.exists());
1938:
1939:                String res = readFile(output);
1940:
1941:                assertEquals("No not package", -1, res.indexOf("not"));
1942:                assertEquals("No default pkg", -1, res.indexOf("\n\n"));
1943:                assertEquals("No ork pkg", -1, res.indexOf("org\n"));
1944:                assertEquals("No ork pkg", -1, res.indexOf("org/shared\n"));
1945:                assertTrue("Shared is there: " + res, res
1946:                        .indexOf("org.shared.yes\n") >= 0);
1947:                assertEquals("No META-INF pkg", -1, res.indexOf("META"));
1948:            }
1949:
1950:            static String readFile(File f) throws IOException {
1951:                java.io.BufferedReader r = new java.io.BufferedReader(
1952:                        new FileReader(f));
1953:                StringBuffer sb = new StringBuffer();
1954:                String prev = "";
1955:                for (;;) {
1956:                    String line = r.readLine();
1957:                    if (line == null) {
1958:                        // line ending at the end of file
1959:                        sb.append('\n');
1960:                        return sb.toString();
1961:                    }
1962:                    sb.append(prev);
1963:                    sb.append(line);
1964:                    prev = "\n";
1965:                }
1966:            }
1967:
1968:            static Manifest createManifest() {
1969:                Manifest m = new Manifest();
1970:                m.getMainAttributes().putValue(
1971:                        java.util.jar.Attributes.Name.MANIFEST_VERSION
1972:                                .toString(), "1.0");
1973:                return m;
1974:            }
1975:
1976:            private final File createNewJarFile() throws IOException {
1977:                int i = 0;
1978:                for (;;) {
1979:                    File f = new File(this .getWorkDir(), i++ + ".jar");
1980:                    if (!f.exists())
1981:                        return f;
1982:                }
1983:            }
1984:
1985:            protected final File generateJar(String[] content, Manifest manifest)
1986:                    throws IOException {
1987:                File f = createNewJarFile();
1988:
1989:                JarOutputStream os = new JarOutputStream(
1990:                        new FileOutputStream(f), manifest);
1991:
1992:                for (int i = 0; i < content.length; i++) {
1993:                    os.putNextEntry(new JarEntry(content[i]));
1994:                    os.closeEntry();
1995:                }
1996:                os.closeEntry();
1997:                os.close();
1998:
1999:                return f;
2000:            }
2001:
2002:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.