Source Code Cross Referenced for MakeJNLPTest.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.FileWriter;
0047:        import java.io.IOException;
0048:        import java.util.Arrays;
0049:        import java.util.Enumeration;
0050:        import java.util.Properties;
0051:        import java.util.Random;
0052:        import java.util.Set;
0053:        import java.util.SortedSet;
0054:        import java.util.TreeSet;
0055:        import java.util.jar.JarEntry;
0056:        import java.util.jar.JarFile;
0057:        import java.util.jar.JarOutputStream;
0058:        import java.util.jar.Manifest;
0059:        import java.util.logging.Level;
0060:        import java.util.logging.Logger;
0061:        import java.util.regex.Matcher;
0062:        import java.util.regex.Pattern;
0063:        import org.netbeans.junit.NbTestCase;
0064:
0065:        /** Is generation of Jnlp files correct?
0066:         *
0067:         * @author Jaroslav Tulach, Jesse Glick
0068:         */
0069:        public class MakeJNLPTest extends NbTestCase {
0070:            public MakeJNLPTest(String name) {
0071:                super (name);
0072:            }
0073:
0074:            protected void setUp() throws Exception {
0075:                clearWorkDir();
0076:            }
0077:
0078:            private static void assertFilenames(File dir, String... contents) {
0079:                assertTrue(dir + " is a directory", dir.isDirectory());
0080:                SortedSet<String> expected = new TreeSet<String>(Arrays
0081:                        .asList(contents));
0082:                SortedSet<String> actual = new TreeSet<String>();
0083:                findFilenames(dir, "", actual);
0084:                assertEquals("correct contents of " + dir,
0085:                        expected/*.toString()*/, actual/*.toString()*/);
0086:            }
0087:
0088:            private static void findFilenames(File dir, String prefix,
0089:                    Set<String> names) {
0090:                for (File f : dir.listFiles()) {
0091:                    if (f.isFile()) {
0092:                        names.add(prefix + f.getName());
0093:                    } else if (f.isDirectory()) {
0094:                        findFilenames(f, prefix + f.getName() + "/", names);
0095:                    }
0096:                }
0097:            }
0098:
0099:            public void testGenerateJNLPAndSignedJarForSimpleModule()
0100:                    throws Exception {
0101:                Manifest m;
0102:
0103:                m = ModuleDependenciesTest.createManifest();
0104:                m.getMainAttributes().putValue("OpenIDE-Module",
0105:                        "org.my.module/3");
0106:                File simpleJar = generateJar(new String[0], m);
0107:
0108:                File parent = simpleJar.getParentFile();
0109:                File output = new File(parent, "output");
0110:                File ks = generateKeystore("jnlp", "netbeans-test");
0111:
0112:                java.io.File f = PublicPackagesInProjectizedXMLTest
0113:                        .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
0114:                                + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
0115:                                + "  <taskdef name=\"jnlp\" classname=\"org.netbeans.nbbuild.MakeJNLP\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
0116:                                + "<target name=\"all\" >"
0117:                                + "  <mkdir dir='"
0118:                                + output
0119:                                + "' />"
0120:                                + "  <jnlp dir='"
0121:                                + output
0122:                                + "' alias='jnlp' storepass='netbeans-test' keystore='"
0123:                                + ks
0124:                                + "' >"
0125:                                + "    <modules dir='"
0126:                                + parent
0127:                                + "' >"
0128:                                + "      <include name='"
0129:                                + simpleJar.getName()
0130:                                + "' />"
0131:                                + "    </modules>"
0132:                                + "  </jnlp>"
0133:                                + "</target>"
0134:                                + "</project>");
0135:                PublicPackagesInProjectizedXMLTest.execute(f,
0136:                        new String[] { "-verbose" });
0137:
0138:                assertFilenames(output, "org-my-module.jnlp",
0139:                        "org-my-module/s0.jar");
0140:
0141:                File jnlp = new File(output, "org-my-module.jnlp");
0142:                String res = ModuleDependenciesTest.readFile(jnlp);
0143:
0144:                assertTrue("Component JNLP type: " + res, res
0145:                        .indexOf("<component-desc/>") >= 0);
0146:                assertTrue("We support all permissions by default: " + res, res
0147:                        .indexOf("<all-permissions/>") >= 0);
0148:
0149:                Matcher match = Pattern.compile(
0150:                        ".*codebase=['\\\"]([^'\\\"]*)['\\\"]").matcher(res);
0151:                assertTrue("codebase is there", match.find());
0152:                assertEquals("one group found", 1, match.groupCount());
0153:                String base = match.group(1);
0154:
0155:                assertEquals("By default the dest directory is $$codebase: ",
0156:                        "$$codebase", base);
0157:
0158:                CHECK_SIGNED: {
0159:                    File jar = new File(output, "org-my-module/s0.jar");
0160:                    JarFile signed = new JarFile(jar);
0161:                    Enumeration it = signed.entries();
0162:                    while (it.hasMoreElements()) {
0163:                        JarEntry entry = (JarEntry) it.nextElement();
0164:                        if (entry.getName().endsWith(".SF")) {
0165:                            break CHECK_SIGNED;
0166:                        }
0167:                    }
0168:                    fail("File does not seem to be signed: " + jar);
0169:                }
0170:            }
0171:
0172:            public void testGenerateJNLPAndUnSignedJarForSimpleModule()
0173:                    throws Exception {
0174:                Manifest m;
0175:
0176:                m = ModuleDependenciesTest.createManifest();
0177:                m.getMainAttributes().putValue("OpenIDE-Module",
0178:                        "org.my.module/3");
0179:                File simpleJar = generateJar(new String[0], m);
0180:
0181:                File parent = simpleJar.getParentFile();
0182:                File output = new File(parent, "output");
0183:                File ks = generateKeystore("jnlp", "netbeans-test");
0184:
0185:                java.io.File f = PublicPackagesInProjectizedXMLTest
0186:                        .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
0187:                                + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
0188:                                + "  <taskdef name=\"jnlp\" classname=\"org.netbeans.nbbuild.MakeJNLP\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
0189:                                + "<target name=\"all\" >"
0190:                                + "  <mkdir dir='"
0191:                                + output
0192:                                + "' />"
0193:                                + "  <jnlp dir='"
0194:                                + output
0195:                                + "' alias='jnlp' storepass='netbeans-test' keystore='"
0196:                                + ks
0197:                                + "' signjars='false' >"
0198:                                + "    <modules dir='"
0199:                                + parent
0200:                                + "' >"
0201:                                + "      <include name='"
0202:                                + simpleJar.getName()
0203:                                + "' />"
0204:                                + "    </modules>"
0205:                                + "  </jnlp>"
0206:                                + "</target>" + "</project>");
0207:                PublicPackagesInProjectizedXMLTest.execute(f,
0208:                        new String[] { "-verbose" });
0209:
0210:                assertFilenames(output, "org-my-module.jnlp",
0211:                        "org-my-module/s0.jar");
0212:
0213:                File jnlp = new File(output, "org-my-module.jnlp");
0214:                String res = ModuleDependenciesTest.readFile(jnlp);
0215:
0216:                assertTrue("Component JNLP type: " + res, res
0217:                        .indexOf("<component-desc/>") >= 0);
0218:                assertTrue("We support all permissions by default: " + res, res
0219:                        .indexOf("<all-permissions/>") >= 0);
0220:
0221:                Matcher match = Pattern.compile(
0222:                        ".*codebase=['\\\"]([^'\\\"]*)['\\\"]").matcher(res);
0223:                assertTrue("codebase is there", match.find());
0224:                assertEquals("one group found", 1, match.groupCount());
0225:                String base = match.group(1);
0226:
0227:                assertEquals("By default the dest directory is $$codebase: ",
0228:                        "$$codebase", base);
0229:
0230:                File jar = new File(output, "org-my-module/s0.jar");
0231:                JarFile signed = new JarFile(jar);
0232:                Enumeration it = signed.entries();
0233:                while (it.hasMoreElements()) {
0234:                    JarEntry entry = (JarEntry) it.nextElement();
0235:                    if (entry.getName().endsWith(".SF")) {
0236:                        fail("File should not be signed: " + jar);
0237:                    }
0238:                }
0239:
0240:            }
0241:
0242:            public void testGenerateOSOnlySimpleModule() throws Exception {
0243:                Manifest m;
0244:
0245:                m = ModuleDependenciesTest.createManifest();
0246:                m.getMainAttributes().putValue("OpenIDE-Module",
0247:                        "org.my.module/3");
0248:                m.getMainAttributes().putValue("OpenIDE-Module-Requires",
0249:                        "org.openide.modules.os.MacOSX, pepa.z.bota");
0250:                File simpleJar = generateJar(new String[0], m);
0251:
0252:                File parent = simpleJar.getParentFile();
0253:                File output = new File(parent, "output");
0254:                File ks = generateKeystore("jnlp", "netbeans-test");
0255:
0256:                java.io.File f = PublicPackagesInProjectizedXMLTest
0257:                        .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
0258:                                + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
0259:                                + "  <taskdef name=\"jnlp\" classname=\"org.netbeans.nbbuild.MakeJNLP\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
0260:                                + "<target name=\"all\" >"
0261:                                + "  <mkdir dir='"
0262:                                + output
0263:                                + "' />"
0264:                                + "  <jnlp dir='"
0265:                                + output
0266:                                + "' alias='jnlp' storepass='netbeans-test' keystore='"
0267:                                + ks
0268:                                + "' signjars='false' >"
0269:                                + "    <modules dir='"
0270:                                + parent
0271:                                + "' >"
0272:                                + "      <include name='"
0273:                                + simpleJar.getName()
0274:                                + "' />"
0275:                                + "    </modules>"
0276:                                + "  </jnlp>"
0277:                                + "</target>" + "</project>");
0278:                PublicPackagesInProjectizedXMLTest.execute(f,
0279:                        new String[] { "-verbose" });
0280:
0281:                assertFilenames(output, "org-my-module.jnlp",
0282:                        "org-my-module/s0.jar");
0283:
0284:                File jnlp = new File(output, "org-my-module.jnlp");
0285:                String res = ModuleDependenciesTest.readFile(jnlp);
0286:
0287:                assertTrue("Component JNLP type: " + res, res
0288:                        .indexOf("<component-desc/>") >= 0);
0289:                assertTrue("Resource is os dependant: " + res, res
0290:                        .indexOf("<resources os='Mac OS X'>") >= 0);
0291:                assertTrue("We support all permissions by default: " + res, res
0292:                        .indexOf("<all-permissions/>") >= 0);
0293:
0294:                Matcher match = Pattern.compile(
0295:                        ".*codebase=['\\\"]([^'\\\"]*)['\\\"]").matcher(res);
0296:                assertTrue("codebase is there", match.find());
0297:                assertEquals("one group found", 1, match.groupCount());
0298:                String base = match.group(1);
0299:
0300:                assertEquals("By default the dest directory is $$codebase: ",
0301:                        "$$codebase", base);
0302:
0303:                File jar = new File(output, "org-my-module/s0.jar");
0304:                JarFile signed = new JarFile(jar);
0305:                Enumeration it = signed.entries();
0306:                while (it.hasMoreElements()) {
0307:                    JarEntry entry = (JarEntry) it.nextElement();
0308:                    if (entry.getName().endsWith(".SF")) {
0309:                        fail("File should not be signed: " + jar);
0310:                    }
0311:                }
0312:
0313:            }
0314:
0315:            public void testTheLocalizedAutoupdateProblem() throws Exception {
0316:                String UTfile = "<?xml version='1.0' encoding='UTF-8'?>"
0317:                        + "<module codename='org.netbeans.modules.autoupdate/1'>"
0318:                        + "    <module_version install_time='1136503038669' last='true' origin='installer' specification_version='2.16.1'>"
0319:                        + "        <file crc='746562502' name='config/Modules/org-netbeans-modules-autoupdate.xml'/>"
0320:                        + "        <file crc='3552349255' name='modules/ext/locale/updater_ja.jar'/>"
0321:                        + "        <file crc='72601456' name='modules/ext/locale/updater_zh_CN.jar'/>"
0322:                        + "        <file crc='3405032071' name='modules/ext/updater.jar'/>"
0323:                        + "        <file crc='2409221434' name='modules/locale/org-netbeans-modules-autoupdate_ja.jar'/>"
0324:                        + "        <file crc='1180043929' name='modules/locale/org-netbeans-modules-autoupdate_zh_CN.jar'/>"
0325:                        + "        <file crc='3477298901' name='modules/org-netbeans-modules-autoupdate.jar'/>"
0326:                        + "    </module_version>" + "</module>";
0327:
0328:                Manifest m = ModuleDependenciesTest.createManifest();
0329:                m.getMainAttributes().putValue("OpenIDE-Module",
0330:                        "org.netbeans.modules.autoupdate/1");
0331:                m.getMainAttributes().putValue("Class-Path", "ext/updater.jar");
0332:                File simpleJar = generateJar("modules/", new String[0], m, null);
0333:                File moduleJar = new File(simpleJar.getParentFile(),
0334:                        "org-netbeans-modules-autoupdate.jar");
0335:                simpleJar.renameTo(moduleJar);
0336:
0337:                File p = simpleJar.getParentFile();
0338:
0339:                simpleJar = generateJar("modules/locale/", new String[0],
0340:                        ModuleDependenciesTest.createManifest(), null);
0341:                simpleJar.renameTo(new File(simpleJar.getParentFile(),
0342:                        "org-netbeans-modules-autoupdate_ja.jar"));
0343:
0344:                simpleJar = generateJar("modules/locale/", new String[0],
0345:                        ModuleDependenciesTest.createManifest(), null);
0346:                simpleJar.renameTo(new File(simpleJar.getParentFile(),
0347:                        "org-netbeans-modules-autoupdate_zh_CN.jar"));
0348:
0349:                simpleJar = generateJar("modules/ext/", new String[0],
0350:                        ModuleDependenciesTest.createManifest(), null);
0351:                simpleJar.renameTo(new File(simpleJar.getParentFile(),
0352:                        "updater.jar"));
0353:
0354:                simpleJar = generateJar("modules/ext/locale/", new String[0],
0355:                        ModuleDependenciesTest.createManifest(), null);
0356:                simpleJar.renameTo(new File(simpleJar.getParentFile(),
0357:                        "updater_ja.jar"));
0358:
0359:                simpleJar = generateJar("modules/ext/locale/", new String[0],
0360:                        ModuleDependenciesTest.createManifest(), null);
0361:                simpleJar.renameTo(new File(simpleJar.getParentFile(),
0362:                        "updater_zh_CN.jar"));
0363:
0364:                File xml = new File(p,
0365:                        "config/Modules/org-netbeans-modules-autoupdate.xml");
0366:                xml.getParentFile().mkdirs();
0367:                xml.createNewFile();
0368:
0369:                File updateTracking = new File(getWorkDir(), "update_tracking");
0370:                updateTracking.mkdirs();
0371:                assertTrue("Created", updateTracking.isDirectory());
0372:
0373:                File trackingFile = new File(updateTracking,
0374:                        "org-netbeans-modules-autoupdate.xml");
0375:                FileWriter w = new FileWriter(trackingFile);
0376:                w.write(UTfile);
0377:                w.close();
0378:
0379:                File output = new File(getWorkDir(), "output");
0380:                File ks = generateKeystore("jnlp", "netbeans-test");
0381:
0382:                java.io.File f = PublicPackagesInProjectizedXMLTest
0383:                        .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
0384:                                + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
0385:                                + "  <taskdef name=\"jnlp\" classname=\"org.netbeans.nbbuild.MakeJNLP\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
0386:                                + "<target name=\"all\" >"
0387:                                + "  <mkdir dir='"
0388:                                + output
0389:                                + "' />"
0390:                                + "  <jnlp dir='"
0391:                                + output
0392:                                + "' alias='jnlp' storepass='netbeans-test' keystore='"
0393:                                + ks
0394:                                + "' verify='true' >"
0395:                                + "    <modules dir='"
0396:                                + p
0397:                                + "' >"
0398:                                + "      <include name='"
0399:                                + moduleJar.getName()
0400:                                + "' />"
0401:                                + "    </modules>"
0402:                                + "  </jnlp>"
0403:                                + "</target>" + "</project>");
0404:                PublicPackagesInProjectizedXMLTest.execute(f,
0405:                        new String[] { "-verbose" });
0406:
0407:                assertFilenames(
0408:                        output,
0409:                        "org-netbeans-modules-autoupdate.jnlp",
0410:                        "org-netbeans-modules-autoupdate/org-netbeans-modules-autoupdate.jar",
0411:                        "org-netbeans-modules-autoupdate/locale-org-netbeans-modules-autoupdate_zh_CN.jar",
0412:                        "org-netbeans-modules-autoupdate/locale-org-netbeans-modules-autoupdate_ja.jar",
0413:                        "org-netbeans-modules-autoupdate/ext-locale-updater_zh_CN.jar",
0414:                        "org-netbeans-modules-autoupdate/ext-locale-updater_ja.jar",
0415:                        "org-netbeans-modules-autoupdate/ext-updater.jar");
0416:
0417:                File jnlp = new File(output,
0418:                        "org-netbeans-modules-autoupdate.jnlp");
0419:                String res = ModuleDependenciesTest.readFile(jnlp);
0420:
0421:                assertTrue("Component JNLP type: " + res, res
0422:                        .indexOf("<component-desc/>") >= 0);
0423:                assertTrue("We support all permissions by default: " + res, res
0424:                        .indexOf("<all-permissions/>") >= 0);
0425:
0426:                Matcher match = Pattern.compile(
0427:                        ".*codebase=['\\\"]([^'\\\"]*)['\\\"]").matcher(res);
0428:                assertTrue("codebase is there", match.find());
0429:                assertEquals("one group found", 1, match.groupCount());
0430:                String base = match.group(1);
0431:
0432:                assertEquals("By default the dest directory is $$codebase: ",
0433:                        "$$codebase", base);
0434:
0435:                assertResource(res, "ja",
0436:                        "org-netbeans-modules-autoupdate/ext-locale-updater_ja.jar");
0437:                assertResource(res, "zh_CN",
0438:                        "org-netbeans-modules-autoupdate/ext-locale-updater_zh_CN.jar");
0439:                assertResource(res, "ja",
0440:                        "org-netbeans-modules-autoupdate/locale-org-netbeans-modules-autoupdate_ja.jar");
0441:                assertResource(
0442:                        res,
0443:                        "zh_CN",
0444:                        "org-netbeans-modules-autoupdate/locale-org-netbeans-modules-autoupdate_zh_CN.jar");
0445:
0446:                CHECK_SIGNED: for (File jar : new File(output,
0447:                        "org-netbeans-modules-autoupdate").listFiles()) {
0448:                    if (!jar.getName().endsWith(".jar")) {
0449:                        continue;
0450:                    }
0451:                    JarFile signed = new JarFile(jar);
0452:                    Enumeration it = signed.entries();
0453:                    while (it.hasMoreElements()) {
0454:                        JarEntry entry = (JarEntry) it.nextElement();
0455:                        if (entry.getName().endsWith(".SF")) {
0456:                            continue CHECK_SIGNED;
0457:                        }
0458:                    }
0459:                    fail("File does not seem to be signed: " + jar);
0460:                }
0461:
0462:            }
0463:
0464:            public void testGenerateJNLPForMissingRegularModule()
0465:                    throws Exception {
0466:                Manifest m;
0467:
0468:                m = ModuleDependenciesTest.createManifest();
0469:                m.getMainAttributes().putValue("OpenIDE-Module",
0470:                        "org.netbeans.core.startup");
0471:                File simpleJar = generateJar("modules/", new String[0], m, null);
0472:                File coreJar = new File(simpleJar.getParentFile(), "core.jar");
0473:                simpleJar.renameTo(coreJar);
0474:                simpleJar = coreJar;
0475:
0476:                File parent = simpleJar.getParentFile();
0477:                File localizedJarCZ = generateJar("modules/locale/",
0478:                        new String[0], ModuleDependenciesTest.createManifest(),
0479:                        null);
0480:                assertTrue("Successful rename", localizedJarCZ
0481:                        .renameTo(new File(localizedJarCZ.getParent(),
0482:                                "core_cs.jar")));
0483:
0484:                File updateTracking = new File(getWorkDir(), "update_tracking");
0485:                updateTracking.mkdirs();
0486:                assertTrue("Created", updateTracking.isDirectory());
0487:
0488:                File trackingFile = new File(updateTracking,
0489:                        "org-netbeans-core-startup.xml");
0490:                FileWriter w = new FileWriter(trackingFile);
0491:                w
0492:                        .write("<?xml version='1.0' encoding='UTF-8'?>\n"
0493:                                + "<module codename='org.my.module/3'>\n"
0494:                                + "<module_version specification_version='3.22' origin='installer' last='true' install_time='1124194231878'>\n"
0495:                                + "<file name='modules/"
0496:                                + simpleJar.getName()
0497:                                + "' crc='3245456472'/>\n"
0498:                                + "<file name='config/Modules/org-netbeans-core-startup.xml' crc='43434' />\n"
0499:                                + "<file name='modules/locale/core_cs.jar' crc='454244' />\n"
0500:                                + "<file name='modules/locale/core_ja.jar' crc='779831' />\n"
0501:                                + "<file name='modules/locale/core_zh_CN.jar' crc='475345' />\n"
0502:                                + "    </module_version>\n" + "</module>\n");
0503:                w.close();
0504:
0505:                File output = new File(parent, "output");
0506:                File ks = generateKeystore("jnlp", "netbeans-test");
0507:
0508:                java.io.File f = PublicPackagesInProjectizedXMLTest
0509:                        .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
0510:                                + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
0511:                                + "  <taskdef name=\"jnlp\" classname=\"org.netbeans.nbbuild.MakeJNLP\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
0512:                                + "<target name=\"all\" >"
0513:                                + "  <mkdir dir='"
0514:                                + output
0515:                                + "' />"
0516:                                + "  <jnlp dir='"
0517:                                + output
0518:                                + "' alias='jnlp' storepass='netbeans-test' keystore='"
0519:                                + ks
0520:                                + "' verify='true' >"
0521:                                + "    <modules dir='"
0522:                                + parent
0523:                                + "' >"
0524:                                + "      <include name='"
0525:                                + simpleJar.getName()
0526:                                + "' />"
0527:                                + "    </modules>"
0528:                                + "  </jnlp>"
0529:                                + "</target>" + "</project>");
0530:                PublicPackagesInProjectizedXMLTest.execute(f,
0531:                        new String[] { "-verbose" });
0532:
0533:                assertFilenames(output, "org-netbeans-core-startup.jnlp",
0534:                        "org-netbeans-core-startup/core.jar",
0535:                        "org-netbeans-core-startup/locale-core_cs.jar");
0536:            }
0537:
0538:            public void testGenerateJNLPAndSignedJarForSimpleLocalizedModule()
0539:                    throws Exception {
0540:                Manifest m;
0541:
0542:                m = ModuleDependenciesTest.createManifest();
0543:                m.getMainAttributes().putValue("OpenIDE-Module",
0544:                        "org.my.module/3");
0545:                File simpleJar = generateJar("modules/", new String[0], m, null);
0546:
0547:                File parent = simpleJar.getParentFile();
0548:                File localizedJarCZ = generateJar("modules/locale/",
0549:                        new String[0], ModuleDependenciesTest.createManifest(),
0550:                        null);
0551:                assertEquals("There need to have the same name", simpleJar
0552:                        .getName(), localizedJarCZ.getName());
0553:                assertTrue("Successful rename", localizedJarCZ
0554:                        .renameTo(new File(localizedJarCZ.getParent(),
0555:                                "0_cs.jar")));
0556:
0557:                File localizedJarZH = generateJar("modules/locale/",
0558:                        new String[0], ModuleDependenciesTest.createManifest(),
0559:                        null);
0560:                assertEquals("There need to have the same name", simpleJar
0561:                        .getName(), localizedJarZH.getName());
0562:                assertTrue("Successful rename", localizedJarZH
0563:                        .renameTo(new File(localizedJarCZ.getParent(),
0564:                                "0_zh_CN.jar")));
0565:
0566:                File localizedJarJA = generateJar("modules/locale/",
0567:                        new String[0], ModuleDependenciesTest.createManifest(),
0568:                        null);
0569:                assertEquals("There need to have the same name", simpleJar
0570:                        .getName(), localizedJarJA.getName());
0571:                assertTrue("Successful rename", localizedJarJA
0572:                        .renameTo(new File(localizedJarCZ.getParent(),
0573:                                "0_ja.jar")));
0574:
0575:                File updateTracking = new File(getWorkDir(), "update_tracking");
0576:                updateTracking.mkdirs();
0577:                assertTrue("Created", updateTracking.isDirectory());
0578:
0579:                File trackingFile = new File(updateTracking,
0580:                        "org-my-module.xml");
0581:                FileWriter w = new FileWriter(trackingFile);
0582:                w
0583:                        .write("<?xml version='1.0' encoding='UTF-8'?>\n"
0584:                                + "<module codename='org.my.module/3'>\n"
0585:                                + "<module_version specification_version='3.22' origin='installer' last='true' install_time='1124194231878'>\n"
0586:                                + "<file name='modules/"
0587:                                + simpleJar.getName()
0588:                                + "' crc='3245456472'/>\n"
0589:                                + "<file name='config/Modules/org-my-module.xml' crc='43434' />\n"
0590:                                + "<file name='modules/locale/0_cs.jar' crc='454244' />\n"
0591:                                + "<file name='modules/locale/0_ja.jar' crc='779831' />\n"
0592:                                + "<file name='modules/locale/0_zh_CN.jar' crc='475345' />\n"
0593:                                + "    </module_version>\n" + "</module>\n");
0594:                w.close();
0595:
0596:                File output = new File(parent, "output");
0597:                File ks = generateKeystore("jnlp", "netbeans-test");
0598:
0599:                java.io.File f = PublicPackagesInProjectizedXMLTest
0600:                        .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
0601:                                + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
0602:                                + "  <taskdef name=\"jnlp\" classname=\"org.netbeans.nbbuild.MakeJNLP\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
0603:                                + "<target name=\"all\" >"
0604:                                + "  <mkdir dir='"
0605:                                + output
0606:                                + "' />"
0607:                                + "  <jnlp dir='"
0608:                                + output
0609:                                + "' alias='jnlp' storepass='netbeans-test' keystore='"
0610:                                + ks
0611:                                + "' verify='true' >"
0612:                                + "    <modules dir='"
0613:                                + parent
0614:                                + "' >"
0615:                                + "      <include name='"
0616:                                + simpleJar.getName()
0617:                                + "' />"
0618:                                + "    </modules>"
0619:                                + "  </jnlp>"
0620:                                + "</target>" + "</project>");
0621:                PublicPackagesInProjectizedXMLTest.execute(f,
0622:                        new String[] { "-verbose" });
0623:
0624:                assertFilenames(output, "org-my-module.jnlp",
0625:                        "org-my-module/0.jar", "org-my-module/locale-0_cs.jar",
0626:                        "org-my-module/locale-0_zh_CN.jar",
0627:                        "org-my-module/locale-0_ja.jar");
0628:
0629:                File jnlp = new File(output, "org-my-module.jnlp");
0630:                String res = ModuleDependenciesTest.readFile(jnlp);
0631:
0632:                assertTrue("Component JNLP type: " + res, res
0633:                        .indexOf("<component-desc/>") >= 0);
0634:                assertTrue("We support all permissions by default: " + res, res
0635:                        .indexOf("<all-permissions/>") >= 0);
0636:
0637:                Matcher match = Pattern.compile(
0638:                        ".*codebase=['\\\"]([^'\\\"]*)['\\\"]").matcher(res);
0639:                assertTrue("codebase is there", match.find());
0640:                assertEquals("one group found", 1, match.groupCount());
0641:                String base = match.group(1);
0642:
0643:                assertEquals("By default the dest directory is $$codebase: ",
0644:                        "$$codebase", base);
0645:
0646:                assertResource(res, "cs", "org-my-module/locale-0_cs.jar");
0647:                assertResource(res, "ja", "org-my-module/locale-0_ja.jar");
0648:                assertResource(res, "zh_CN", "org-my-module/locale-0_zh_CN.jar");
0649:
0650:                CHECK_SIGNED: for (File jar : new File(output, "org-my-module")
0651:                        .listFiles()) {
0652:                    if (!jar.getName().endsWith(".jar")) {
0653:                        continue;
0654:                    }
0655:
0656:                    JarFile signed = new JarFile(jar);
0657:                    Enumeration it = signed.entries();
0658:                    while (it.hasMoreElements()) {
0659:                        JarEntry entry = (JarEntry) it.nextElement();
0660:                        if (entry.getName().endsWith(".SF")) {
0661:                            continue CHECK_SIGNED;
0662:                        }
0663:                    }
0664:                    fail("File does not seem to be signed: " + jar);
0665:                }
0666:            }
0667:
0668:            public void testGenerateJNLPForMissingCoreIssue103301()
0669:                    throws Exception {
0670:                Manifest m;
0671:
0672:                m = ModuleDependenciesTest.createManifest();
0673:                m.getMainAttributes().putValue("OpenIDE-Module",
0674:                        "org.netbeans.core.startup");
0675:                File simpleJar = generateJar("core/", new String[0], m, null);
0676:                File coreJar = new File(simpleJar.getParentFile(), "core.jar");
0677:                simpleJar.renameTo(coreJar);
0678:                simpleJar = coreJar;
0679:
0680:                File parent = simpleJar.getParentFile();
0681:                File localizedJarCZ = generateJar("core/locale/",
0682:                        new String[0], ModuleDependenciesTest.createManifest(),
0683:                        null);
0684:                assertTrue("Successful rename", localizedJarCZ
0685:                        .renameTo(new File(localizedJarCZ.getParent(),
0686:                                "core_cs.jar")));
0687:
0688:                File updateTracking = new File(getWorkDir(), "update_tracking");
0689:                updateTracking.mkdirs();
0690:                assertTrue("Created", updateTracking.isDirectory());
0691:
0692:                File trackingFile = new File(updateTracking,
0693:                        "org-netbeans-core-startup.xml");
0694:                FileWriter w = new FileWriter(trackingFile);
0695:                w
0696:                        .write("<?xml version='1.0' encoding='UTF-8'?>\n"
0697:                                + "<module codename='org.my.module/3'>\n"
0698:                                + "<module_version specification_version='3.22' origin='installer' last='true' install_time='1124194231878'>\n"
0699:                                + "<file name='core/"
0700:                                + simpleJar.getName()
0701:                                + "' crc='3245456472'/>\n"
0702:                                + "<file name='config/Modules/org-netbeans-core-startup.xml' crc='43434' />\n"
0703:                                + "<file name='core/locale/core_cs.jar' crc='454244' />\n"
0704:                                + "<file name='core/locale/core_ja.jar' crc='779831' />\n"
0705:                                + "<file name='core/locale/core_zh_CN.jar' crc='475345' />\n"
0706:                                + "    </module_version>\n" + "</module>\n");
0707:                w.close();
0708:
0709:                File output = new File(parent, "output");
0710:                File ks = generateKeystore("jnlp", "netbeans-test");
0711:
0712:                java.io.File f = PublicPackagesInProjectizedXMLTest
0713:                        .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
0714:                                + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
0715:                                + "  <taskdef name=\"jnlp\" classname=\"org.netbeans.nbbuild.MakeJNLP\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
0716:                                + "<target name=\"all\" >"
0717:                                + "  <mkdir dir='"
0718:                                + output
0719:                                + "' />"
0720:                                + "  <jnlp dir='"
0721:                                + output
0722:                                + "' alias='jnlp' storepass='netbeans-test' keystore='"
0723:                                + ks
0724:                                + "' verify='true' >"
0725:                                + "    <modules dir='"
0726:                                + parent
0727:                                + "' >"
0728:                                + "      <include name='"
0729:                                + simpleJar.getName()
0730:                                + "' />"
0731:                                + "    </modules>"
0732:                                + "  </jnlp>"
0733:                                + "</target>" + "</project>");
0734:                PublicPackagesInProjectizedXMLTest.execute(f,
0735:                        new String[] { "-verbose" });
0736:
0737:                assertFilenames(output, "org-netbeans-core-startup.jnlp",
0738:                        "org-netbeans-core-startup/core.jar",
0739:                        "org-netbeans-core-startup/locale-core_cs.jar");
0740:            }
0741:
0742:            public void testGenerateJNLPAndUnSignedJarForSimpleLocalizedModule()
0743:                    throws Exception {
0744:                Manifest m;
0745:
0746:                m = ModuleDependenciesTest.createManifest();
0747:                m.getMainAttributes().putValue("OpenIDE-Module",
0748:                        "org.my.module/3");
0749:                File simpleJar = generateJar("modules/", new String[0], m, null);
0750:
0751:                File parent = simpleJar.getParentFile();
0752:                File localizedJarCZ = generateJar("modules/locale/",
0753:                        new String[0], ModuleDependenciesTest.createManifest(),
0754:                        null);
0755:                assertEquals("There need to have the same name", simpleJar
0756:                        .getName(), localizedJarCZ.getName());
0757:                assertTrue("Successful rename", localizedJarCZ
0758:                        .renameTo(new File(localizedJarCZ.getParent(),
0759:                                "0_cs.jar")));
0760:
0761:                File localizedJarZH = generateJar("modules/locale/",
0762:                        new String[0], ModuleDependenciesTest.createManifest(),
0763:                        null);
0764:                assertEquals("There need to have the same name", simpleJar
0765:                        .getName(), localizedJarZH.getName());
0766:                assertTrue("Successful rename", localizedJarZH
0767:                        .renameTo(new File(localizedJarCZ.getParent(),
0768:                                "0_zh_CN.jar")));
0769:
0770:                File localizedJarJA = generateJar("modules/locale/",
0771:                        new String[0], ModuleDependenciesTest.createManifest(),
0772:                        null);
0773:                assertEquals("There need to have the same name", simpleJar
0774:                        .getName(), localizedJarJA.getName());
0775:                assertTrue("Successful rename", localizedJarJA
0776:                        .renameTo(new File(localizedJarCZ.getParent(),
0777:                                "0_ja.jar")));
0778:
0779:                File updateTracking = new File(getWorkDir(), "update_tracking");
0780:                updateTracking.mkdirs();
0781:                assertTrue("Created", updateTracking.isDirectory());
0782:
0783:                File trackingFile = new File(updateTracking,
0784:                        "org-my-module.xml");
0785:                FileWriter w = new FileWriter(trackingFile);
0786:                w
0787:                        .write("<?xml version='1.0' encoding='UTF-8'?>\n"
0788:                                + "<module codename='org.my.module/3'>\n"
0789:                                + "<module_version specification_version='3.22' origin='installer' last='true' install_time='1124194231878'>\n"
0790:                                + "<file name='modules/"
0791:                                + simpleJar.getName()
0792:                                + "' crc='3245456472'/>\n"
0793:                                + "<file name='config/Modules/org-my-module.xml' crc='43434' />\n"
0794:                                + "<file name='modules/locale/0_cs.jar' crc='454244' />\n"
0795:                                + "<file name='modules/locale/0_ja.jar' crc='779831' />\n"
0796:                                + "<file name='modules/locale/0_zh_CN.jar' crc='475345' />\n"
0797:                                + "    </module_version>\n" + "</module>\n");
0798:                w.close();
0799:
0800:                File output = new File(parent, "output");
0801:                File ks = generateKeystore("jnlp", "netbeans-test");
0802:
0803:                java.io.File f = PublicPackagesInProjectizedXMLTest
0804:                        .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
0805:                                + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
0806:                                + "  <taskdef name=\"jnlp\" classname=\"org.netbeans.nbbuild.MakeJNLP\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
0807:                                + "<target name=\"all\" >"
0808:                                + "  <mkdir dir='"
0809:                                + output
0810:                                + "' />"
0811:                                + "  <jnlp dir='"
0812:                                + output
0813:                                + "' alias='jnlp' storepass='netbeans-test' keystore='"
0814:                                + ks
0815:                                + "' verify='true' signjars='false' >"
0816:                                + "    <modules dir='"
0817:                                + parent
0818:                                + "' >"
0819:                                + "      <include name='"
0820:                                + simpleJar.getName()
0821:                                + "' />"
0822:                                + "    </modules>"
0823:                                + "  </jnlp>"
0824:                                + "</target>" + "</project>");
0825:                PublicPackagesInProjectizedXMLTest.execute(f,
0826:                        new String[] { "-verbose" });
0827:
0828:                assertFilenames(output, "org-my-module.jnlp",
0829:                        "org-my-module/0.jar", "org-my-module/locale-0_cs.jar",
0830:                        "org-my-module/locale-0_zh_CN.jar",
0831:                        "org-my-module/locale-0_ja.jar");
0832:
0833:                File jnlp = new File(output, "org-my-module.jnlp");
0834:                String res = ModuleDependenciesTest.readFile(jnlp);
0835:
0836:                assertTrue("Component JNLP type: " + res, res
0837:                        .indexOf("<component-desc/>") >= 0);
0838:                assertTrue("We support all permissions by default: " + res, res
0839:                        .indexOf("<all-permissions/>") >= 0);
0840:
0841:                Matcher match = Pattern.compile(
0842:                        ".*codebase=['\\\"]([^'\\\"]*)['\\\"]").matcher(res);
0843:                assertTrue("codebase is there", match.find());
0844:                assertEquals("one group found", 1, match.groupCount());
0845:                String base = match.group(1);
0846:
0847:                assertEquals("By default the dest directory is $$codebase: ",
0848:                        "$$codebase", base);
0849:
0850:                assertResource(res, "cs", "org-my-module/locale-0_cs.jar");
0851:                assertResource(res, "ja", "org-my-module/locale-0_ja.jar");
0852:                assertResource(res, "zh_CN", "org-my-module/locale-0_zh_CN.jar");
0853:
0854:                for (File jar : new File(output, "org-my-module").listFiles()) {
0855:                    if (!jar.getName().endsWith(".jar")) {
0856:                        continue;
0857:                    }
0858:
0859:                    JarFile signed = new JarFile(jar);
0860:                    Enumeration it = signed.entries();
0861:                    while (it.hasMoreElements()) {
0862:                        JarEntry entry = (JarEntry) it.nextElement();
0863:                        if (entry.getName().endsWith(".SF")) {
0864:                            fail("File does not seem to be signed: " + jar);
0865:                        }
0866:                    }
0867:                }
0868:            }
0869:
0870:            private static void assertResource(String where, String locale,
0871:                    String file) {
0872:                where = where.replace('\n', ' ');
0873:                Matcher match = Pattern.compile(
0874:                        "<resources *locale='" + locale + "' *>.*<jar href='"
0875:                                + file + "' */>.*</resources>").matcher(where);
0876:                assertTrue("File really referenced " + file + " in locale "
0877:                        + locale + "\n" + where, match.find());
0878:            }
0879:
0880:            public void testOneCanChangeTheCodeBase() throws Exception {
0881:                Manifest m;
0882:
0883:                m = ModuleDependenciesTest.createManifest();
0884:                m.getMainAttributes().putValue("OpenIDE-Module",
0885:                        "org.my.module/3");
0886:                File simpleJar = generateJar(new String[0], m);
0887:
0888:                File parent = simpleJar.getParentFile();
0889:                File output = new File(parent, "output");
0890:                File ks = generateKeystore("jnlp", "netbeans-test");
0891:
0892:                java.io.File f = PublicPackagesInProjectizedXMLTest
0893:                        .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
0894:                                + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
0895:                                + "  <taskdef name=\"jnlp\" classname=\"org.netbeans.nbbuild.MakeJNLP\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
0896:                                + "<target name=\"all\" >"
0897:                                + "  <mkdir dir='"
0898:                                + output
0899:                                + "' />"
0900:                                + "  <jnlp dir='"
0901:                                + output
0902:                                + "' alias='jnlp' storepass='netbeans-test' keystore='"
0903:                                + ks
0904:                                + "' codebase='http://www.my.org/' >"
0905:                                + "    <modules dir='"
0906:                                + parent
0907:                                + "' >"
0908:                                + "      <include name='"
0909:                                + simpleJar.getName()
0910:                                + "' />"
0911:                                + "    </modules>"
0912:                                + "  </jnlp>"
0913:                                + "</target>" + "</project>");
0914:                PublicPackagesInProjectizedXMLTest.execute(f,
0915:                        new String[] { "-verbose" });
0916:
0917:                assertFilenames(output, "org-my-module.jnlp",
0918:                        "org-my-module/s0.jar");
0919:
0920:                File jnlp = new File(output, "org-my-module.jnlp");
0921:                String res = ModuleDependenciesTest.readFile(jnlp);
0922:
0923:                assertTrue("Component JNLP type: " + res, res
0924:                        .indexOf("<component-desc/>") >= 0);
0925:                assertTrue("We support all permissions by default: " + res, res
0926:                        .indexOf("<all-permissions/>") >= 0);
0927:
0928:                Matcher match = Pattern.compile(
0929:                        ".*codebase=['\\\"]([^'\\\"]*)['\\\"]").matcher(res);
0930:                assertTrue("codebase is there", match.find());
0931:                assertEquals("one group found", 1, match.groupCount());
0932:                String base = match.group(1);
0933:
0934:                assertEquals("By default the codebases can be changed: ",
0935:                        "http://www.my.org/", base);
0936:            }
0937:
0938:            public void testGenerateJNLPAndSignedJarForModuleWithClassPath()
0939:                    throws Exception {
0940:                File output = doClassPathModuleCheck("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
0941:                        + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
0942:                        + "  <taskdef name=\"jnlp\" classname=\"org.netbeans.nbbuild.MakeJNLP\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
0943:                        + "<target name=\"all\" >"
0944:                        + "  <mkdir dir='${test.output}' />"
0945:                        + "  <jnlp dir='${test.output}' alias='jnlp' storepass='netbeans-test' keystore='${test.ks}' >"
0946:                        + "    <modules dir='${test.parent}' >"
0947:                        + "      <include name='${test.name}' />"
0948:                        + "    </modules>"
0949:                        + "  </jnlp>"
0950:                        + "</target>"
0951:                        + "</project>");
0952:
0953:                assertFilenames(output, "aaa-my-module.jnlp",
0954:                        "aaa-my-module/ext-t0.jar", "aaa-my-module/s0.jar");
0955:
0956:                File jnlp = new File(output, "aaa-my-module.jnlp");
0957:                String res = ModuleDependenciesTest.readFile(jnlp);
0958:
0959:                Matcher m = Pattern.compile("<jar href='(.*)' */>")
0960:                        .matcher(res);
0961:                for (int x = 0; x < 2; x++) {
0962:                    assertTrue("Matches at least one" + "(" + x + ")", m.find());
0963:                    assertEquals("Found a group" + "(" + x + ")", m
0964:                            .groupCount(), 1);
0965:                    File f = new File(jnlp.getParentFile(), m.group(1));
0966:                    assertTrue("The file " + f + " exists" + "(" + x + ")", f
0967:                            .exists());
0968:                }
0969:
0970:            }
0971:
0972:            public void testGenerateJNLPAndSignedJarForModuleWithClassPathAndSignedJar()
0973:                    throws Exception {
0974:                File ks = generateKeystore("external", "netbeans-test");
0975:
0976:                File output = doClassPathModuleCheck("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
0977:                        + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
0978:                        + "  <taskdef name=\"jnlp\" classname=\"org.netbeans.nbbuild.MakeJNLP\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
0979:                        + "<target name=\"all\" >"
0980:                        + "  <mkdir dir='${test.output}' />"
0981:                        + "  <signjar jar='${test.ext}' alias='external' storepass='netbeans-test' keystore='${test.ks}' />\n"
0982:                        + "  <jnlp dir='${test.output}' alias='jnlp' storepass='netbeans-test' keystore='${test.ks}' >"
0983:                        + "    <modules dir='${test.parent}' >"
0984:                        + "      <include name='${test.name}' />"
0985:                        + "    </modules>"
0986:                        + "  </jnlp>"
0987:                        + "</target>"
0988:                        + "</project>");
0989:
0990:                assertFilenames(output, "aaa-my-module.jnlp",
0991:                        "aaa-my-module/s0.jar", "aaa-my-module/ext-t0.jar",
0992:                        "aaa-my-module-ext-t0.jnlp");
0993:
0994:                JarFile f = new JarFile(new File(output,
0995:                        "aaa-my-module/ext-t0.jar"));
0996:                Enumeration en = f.entries();
0997:                StringBuffer sb = new StringBuffer();
0998:                int cnt = 0;
0999:                while (en.hasMoreElements()) {
1000:                    JarEntry e = (JarEntry) en.nextElement();
1001:                    if (e.getName().endsWith("SF")) {
1002:                        cnt++;
1003:                        if (!e.getName().equals("META-INF/EXTERNAL.SF")) {
1004:                            fail("Signed with wrong entity: " + e.getName());
1005:                        }
1006:                    }
1007:                    sb.append(e.getName());
1008:                    sb.append('\n');
1009:                }
1010:
1011:                if (cnt == 0) {
1012:                    fail("Signed with wrong file:\n" + sb);
1013:                }
1014:
1015:                File jnlp = new File(output, "aaa-my-module.jnlp");
1016:
1017:                String res = ModuleDependenciesTest.readFile(jnlp);
1018:
1019:                int first = res.indexOf("jar href");
1020:                assertEquals("Just one jar href ", -1, res.indexOf("jar href",
1021:                        first + 1));
1022:
1023:                String extRes = ModuleDependenciesTest.readFile(new File(
1024:                        output, "aaa-my-module-ext-t0.jnlp"));
1025:
1026:                Matcher m = Pattern.compile("<title>(.*)</title>").matcher(
1027:                        extRes);
1028:                assertTrue("title is there: " + extRes, m.find());
1029:                assertEquals("Name of file is used for title", "t0", m.group(1));
1030:            }
1031:
1032:            public void testInformationIsTakenFromLocalizedBundle()
1033:                    throws Exception {
1034:                Manifest m;
1035:
1036:                m = ModuleDependenciesTest.createManifest();
1037:                m.getMainAttributes().putValue("OpenIDE-Module",
1038:                        "org.my.module/3");
1039:
1040:                Properties props = new Properties();
1041:                props.put("OpenIDE-Module-Name", "Module Build Harness");
1042:                props.put("OpenIDE-Module-Display-Category",
1043:                        "Developing NetBeans");
1044:                props
1045:                        .put("OpenIDE-Module-Short-Description",
1046:                                "Lets you build external plug-in modules from sources.");
1047:                props.put("OpenIDE-Module-Long-Description", "XXX");
1048:
1049:                File simpleJar = generateJar(null, new String[0], m, props);
1050:
1051:                File parent = simpleJar.getParentFile();
1052:                File output = new File(parent, "output");
1053:                File ks = generateKeystore("jnlp", "netbeans-test");
1054:
1055:                java.io.File f = PublicPackagesInProjectizedXMLTest
1056:                        .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
1057:                                + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
1058:                                + "  <taskdef name=\"jnlp\" classname=\"org.netbeans.nbbuild.MakeJNLP\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
1059:                                + "<target name=\"all\" >"
1060:                                + "  <mkdir dir='"
1061:                                + output
1062:                                + "' />"
1063:                                + "  <jnlp dir='"
1064:                                + output
1065:                                + "' alias='jnlp' storepass='netbeans-test' keystore='"
1066:                                + ks
1067:                                + "' >"
1068:                                + "    <modules dir='"
1069:                                + parent
1070:                                + "' >"
1071:                                + "      <include name='"
1072:                                + simpleJar.getName()
1073:                                + "' />"
1074:                                + "    </modules>"
1075:                                + "  </jnlp>"
1076:                                + "</target>"
1077:                                + "</project>");
1078:                PublicPackagesInProjectizedXMLTest.execute(f, new String[] {});
1079:
1080:                assertFilenames(output, "org-my-module.jnlp",
1081:                        "org-my-module/s0.jar");
1082:
1083:                File jnlp = new File(output, "org-my-module.jnlp");
1084:                String res = ModuleDependenciesTest.readFile(jnlp);
1085:
1086:                int infoBegin = res.indexOf("<information>");
1087:                int infoEnd = res.indexOf("</information>");
1088:
1089:                if (infoEnd == -1 || infoBegin == -1) {
1090:                    fail("Both information tags must be present: " + res);
1091:                }
1092:
1093:                String info = res.substring(infoBegin, infoEnd);
1094:
1095:                if (info.indexOf("<title>Module Build Harness</title>") == -1) {
1096:                    fail("Title should be there with Module Build Harness inside itself: "
1097:                            + info);
1098:                }
1099:
1100:                if (info
1101:                        .indexOf("<description kind='one-line'>Lets you build external plug-in modules from sources.</description>") == -1) {
1102:                    fail("one-line should be there with 'lets you...' inside itself: "
1103:                            + info);
1104:                }
1105:
1106:                if (info.indexOf("<description kind='short'>XXX</description>") == -1) {
1107:                    fail("short should be there with XXX inside itself: "
1108:                            + info);
1109:                }
1110:            }
1111:
1112:            public void testGenerateJNLPFailsForModulesWithExtraFiles()
1113:                    throws Exception {
1114:                doCompareJNLPFileWithUpdateTracking(true, null, "");
1115:            }
1116:
1117:            public void testGenerateJNLPSucceedsWithExtraFiles()
1118:                    throws Exception {
1119:                doCompareJNLPFileWithUpdateTracking(false, null, "");
1120:            }
1121:
1122:            public void testGenerateJNLPSucceedsWhenExtraFileIsExcluded()
1123:                    throws Exception {
1124:                doCompareJNLPFileWithUpdateTracking(false, "lib/nbexec",
1125:                        " verifyexcludes=' one, lib/nbexec, three ' ");
1126:            }
1127:
1128:            public void testGenerateJNLPSucceedsWhenModuleAutoDepsArePresent()
1129:                    throws Exception {
1130:                doCompareJNLPFileWithUpdateTracking(false,
1131:                        "config/ModuleAutoDeps/aaa-my-module.xml",
1132:                        " verifyexcludes=' none ' ");
1133:            }
1134:
1135:            private void doCompareJNLPFileWithUpdateTracking(
1136:                    boolean useNonModule, String fakeEntry, String extraScript)
1137:                    throws Exception {
1138:                File nonModule = generateJar(new String[0],
1139:                        ModuleDependenciesTest.createManifest());
1140:
1141:                Manifest m = ModuleDependenciesTest.createManifest();
1142:                m.getMainAttributes().putValue("OpenIDE-Module",
1143:                        "aaa.my.module/3");
1144:                File module = generateJar(new String[0], m);
1145:
1146:                File updateTracking = new File(getWorkDir(), "update_tracking");
1147:                updateTracking.mkdirs();
1148:                assertTrue("Created", updateTracking.isDirectory());
1149:
1150:                File enableXML = new File(new File(getWorkDir(), "config"),
1151:                        "Modules");
1152:                enableXML.getParentFile().mkdirs();
1153:                enableXML.createNewFile();
1154:
1155:                File trackingFile = new File(updateTracking,
1156:                        "aaa-my-module.xml");
1157:                FileWriter w = new FileWriter(trackingFile);
1158:                w
1159:                        .write("<?xml version='1.0' encoding='UTF-8'?>\n"
1160:                                + "<module codename='org.apache.tools.ant.module/3'>\n"
1161:                                + "<module_version specification_version='3.22' origin='installer' last='true' install_time='1124194231878'>\n"
1162:                                + (useNonModule ? ("<file name='modules/"
1163:                                        + nonModule.getName() + "' crc='1536373800'/>\n")
1164:                                        : "")
1165:                                + "<file name='modules/"
1166:                                + module.getName()
1167:                                + "' crc='3245456472'/>\n"
1168:                                + "<file name='config/Modules/aaa-my-module.xml' crc='43434' />\n"
1169:                                + (fakeEntry != null ? "<file name='"
1170:                                        + fakeEntry + "' crc='43222' />\n" : "")
1171:                                + "    </module_version>\n" + "</module>\n");
1172:                w.close();
1173:
1174:                String script = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
1175:                        + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
1176:                        + "  <taskdef name=\"jnlp\" classname=\"org.netbeans.nbbuild.MakeJNLP\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
1177:                        + "<target name=\"all\" >"
1178:                        + "  <mkdir dir='${test.output}' />"
1179:                        + "  <jnlp dir='${test.output}' alias='jnlp' storepass='netbeans-test' keystore='${test.ks}' verify='true' "
1180:                        + extraScript + " >"
1181:                        + "    <modules dir='${test.parent}' >"
1182:                        + "      <include name='${test.name}' />"
1183:                        + "    </modules>" + "  </jnlp>" + "</target>"
1184:                        + "</project>";
1185:
1186:                assertEquals("Both modules in the same dir", module
1187:                        .getParentFile(), nonModule.getParentFile());
1188:
1189:                File output = new File(getWorkDir(), "output");
1190:                File ks = generateKeystore("jnlp", "netbeans-test");
1191:
1192:                java.io.File f = PublicPackagesInProjectizedXMLTest
1193:                        .extractString(script);
1194:                try {
1195:                    PublicPackagesInProjectizedXMLTest.execute(f, new String[] {
1196:                            "-Dtest.output=" + output,
1197:                            "-Dtest.parent=" + module.getParent(),
1198:                            "-Dtest.name=" + module.getName(),
1199:                            "-Dtest.ks=" + ks, });
1200:                    if (useNonModule) {
1201:                        fail("The task has to fail");
1202:                    }
1203:
1204:                    assertTrue("Output exists", output.exists());
1205:                    assertTrue("Output directory created", output.isDirectory());
1206:
1207:                    File ext = new File(output, module.getName());
1208:
1209:                    String[] files = ext.getParentFile().list();
1210:                    assertEquals("Two files are there", 2, files.length);
1211:                } catch (PublicPackagesInProjectizedXMLTest.ExecutionError ex) {
1212:                    if (!useNonModule) {
1213:                        throw ex;
1214:                    } else {
1215:                        // ok, this is fine
1216:                        assertTrue("Output exists", output.exists());
1217:                        assertTrue("Output directory created", output
1218:                                .isDirectory());
1219:
1220:                        File ext = new File(output, module.getName());
1221:
1222:                        String[] files = ext.getParentFile().list();
1223:                        assertEquals(
1224:                                "Output dir is empty as nothing has been generated",
1225:                                0, files.length);
1226:                    }
1227:                }
1228:
1229:            }
1230:
1231:            private File doClassPathModuleCheck(String script) throws Exception {
1232:                Manifest m;
1233:
1234:                File extJar = generateJar("modules/ext", new String[0],
1235:                        ModuleDependenciesTest.createManifest(), null);
1236:
1237:                m = ModuleDependenciesTest.createManifest();
1238:                m.getMainAttributes().putValue("OpenIDE-Module",
1239:                        "aaa.my.module/3");
1240:                m.getMainAttributes().putValue("Class-Path",
1241:                        "ext/" + extJar.getName());
1242:                File simpleJar = generateJar("modules", new String[0], m, null);
1243:
1244:                File parent = simpleJar.getParentFile();
1245:
1246:                File output = new File(parent, "output");
1247:                File ks = generateKeystore("jnlp", "netbeans-test");
1248:
1249:                java.io.File f = PublicPackagesInProjectizedXMLTest
1250:                        .extractString(script);
1251:                PublicPackagesInProjectizedXMLTest.execute(f, new String[] {
1252:                        "-Dtest.output=" + output, "-Dtest.parent=" + parent,
1253:                        "-Dtest.name=" + simpleJar.getName(),
1254:                        "-Dtest.ks=" + ks, "-Dtest.ext=" + extJar });
1255:
1256:                return output;
1257:            }
1258:
1259:            private final File createNewJarFile(String prefix)
1260:                    throws IOException {
1261:                if (prefix == null) {
1262:                    prefix = "modules";
1263:                }
1264:                String ss = prefix.substring(prefix.length() - 1, prefix
1265:                        .length());
1266:
1267:                File dir = new File(this .getWorkDir(), prefix);
1268:                dir.mkdirs();
1269:
1270:                int i = 0;
1271:                for (;;) {
1272:                    File f = new File(dir, ss + i++ + ".jar");
1273:                    if (!f.exists())
1274:                        return f;
1275:                }
1276:            }
1277:
1278:            protected final File generateJar(String[] content, Manifest manifest)
1279:                    throws IOException {
1280:                return generateJar(null, content, manifest, null);
1281:            }
1282:
1283:            protected final File generateJar(String prefix, String[] content,
1284:                    Manifest manifest, Properties props) throws IOException {
1285:                File f = createNewJarFile(prefix);
1286:
1287:                if (props != null) {
1288:                    manifest.getMainAttributes().putValue(
1289:                            "OpenIDE-Module-Localizing-Bundle",
1290:                            "some/fake/prop/name/Bundle.properties");
1291:                }
1292:
1293:                JarOutputStream os = new JarOutputStream(
1294:                        new FileOutputStream(f), manifest);
1295:
1296:                if (props != null) {
1297:                    os.putNextEntry(new JarEntry(
1298:                            "some/fake/prop/name/Bundle.properties"));
1299:                    props.store(os, "# properties for the module");
1300:                    os.closeEntry();
1301:                }
1302:
1303:                for (int i = 0; i < content.length; i++) {
1304:                    os.putNextEntry(new JarEntry(content[i]));
1305:                    os.closeEntry();
1306:                }
1307:                os.closeEntry();
1308:                os.close();
1309:
1310:                return f;
1311:            }
1312:
1313:            private final File generateKeystore(String alias, String password)
1314:                    throws Exception {
1315:                Error lastEx = null;
1316:                for (int i = 0; i < 10; i++) {
1317:                    File where = new File(getWorkDir(), "key" + i + ".ks");
1318:
1319:                    String script = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
1320:                            + "<project name=\"Generate Keystore\" basedir=\".\" default=\"all\" >"
1321:                            + "<target name=\"all\" >"
1322:                            + "<genkey \n"
1323:                            + "alias='"
1324:                            + alias
1325:                            + "' \n"
1326:                            + "keystore='"
1327:                            + where
1328:                            + "' \n"
1329:                            + "storepass='"
1330:                            + password
1331:                            + "' \n"
1332:                            + "dname='CN=A NetBeans Friend, OU=NetBeans, O=netbeans.org, C=US' \n"
1333:                            + "/>\n" + "</target></project>\n";
1334:
1335:                    java.io.File f = PublicPackagesInProjectizedXMLTest
1336:                            .extractString(script);
1337:                    try {
1338:                        PublicPackagesInProjectizedXMLTest.execute(f,
1339:                                new String[] {});
1340:                    } catch (PublicPackagesInProjectizedXMLTest.ExecutionError ex) {
1341:                        Logger.getAnonymousLogger().log(Level.WARNING,
1342:                                "Failed for " + i, ex);
1343:                        lastEx = ex;
1344:                        if (ex.getMessage().indexOf("CKR_KEY_SIZE_RANGE") >= 0) {
1345:                            Thread.sleep(new Random().nextInt(1000));
1346:                            continue;
1347:                        }
1348:                        throw ex;
1349:                    }
1350:                    return where;
1351:                }
1352:                throw lastEx;
1353:            }
1354:
1355:            public void testIndirectJars() throws Exception {
1356:                Manifest m = ModuleDependenciesTest.createManifest();
1357:                m.getMainAttributes().putValue("OpenIDE-Module", "me");
1358:                generateJar(new String[0], m);
1359:                generateJar("lib", new String[0], new Manifest(), null);
1360:                assertTrue(new File(getWorkDir(), "lib/b0.jar").isFile());
1361:                File output = new File(getWorkDir(), "output");
1362:                File ks = generateKeystore("jnlp", "netbeans-test");
1363:                File f = PublicPackagesInProjectizedXMLTest
1364:                        .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
1365:                                + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
1366:                                + "  <taskdef name=\"jnlp\" classname=\"org.netbeans.nbbuild.MakeJNLP\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
1367:                                + "<target name=\"all\" >"
1368:                                + "  <mkdir dir='"
1369:                                + output
1370:                                + "' />"
1371:                                + "  <jnlp dir='"
1372:                                + output
1373:                                + "' alias='jnlp' storepass='netbeans-test' keystore='"
1374:                                + ks
1375:                                + "' >"
1376:                                + "    <modules dir='"
1377:                                + getWorkDir()
1378:                                + "'>"
1379:                                + "      <include name='modules/s0.jar'/>"
1380:                                + "    </modules>"
1381:                                + "    <indirectjars dir='"
1382:                                + getWorkDir()
1383:                                + "'>"
1384:                                + "      <include name='lib/b0.jar'/>"
1385:                                + "    </indirectjars>"
1386:                                + "  </jnlp>"
1387:                                + "</target>" + "</project>");
1388:                PublicPackagesInProjectizedXMLTest.execute(f,
1389:                        new String[] { "-verbose" });
1390:                assertFilenames(output, "me.jnlp", "me/s0.jar", "me/lib-b0.jar");
1391:                File jnlp = new File(output, "me.jnlp");
1392:                String res = ModuleDependenciesTest.readFile(jnlp);
1393:                assertTrue(res, res.contains("me/lib-b0.jar"));
1394:                JarFile otherJar = new JarFile(
1395:                        new File(output, "me/lib-b0.jar"));
1396:                assertNotNull(otherJar
1397:                        .getEntry("META-INF/clusterpath/lib/b0.jar"));
1398:            }
1399:
1400:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.