KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > nbbuild > CreateModuleXMLTest


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

19 package org.netbeans.nbbuild;
20
21 import java.io.FileOutputStream JavaDoc;
22 import java.io.FileWriter JavaDoc;
23 import java.util.jar.JarEntry JavaDoc;
24 import java.util.jar.JarOutputStream JavaDoc;
25 import java.util.jar.Manifest JavaDoc;
26 import junit.framework.*;
27 import java.io.File JavaDoc;
28 import java.io.IOException JavaDoc;
29 import java.util.HashSet JavaDoc;
30 import java.util.Set JavaDoc;
31 import java.util.StringTokenizer JavaDoc;
32 import java.util.jar.JarFile JavaDoc;
33 import org.apache.tools.ant.BuildException;
34 import org.apache.tools.ant.types.Parameter;
35 import org.apache.tools.ant.types.selectors.SelectorUtils;
36
37 import org.netbeans.junit.NbTestCase;
38
39 /** Check behaviour of ModuleSelector.
40  *
41  * @author Jaroslav Tulach
42  */

43 public class CreateModuleXMLTest extends NbTestCase {
44     
45     public CreateModuleXMLTest(String JavaDoc testName) {
46         super(testName);
47     }
48
49     public void testIncludesAllModulesByDefault() throws Exception JavaDoc {
50         Manifest JavaDoc m = ModuleDependenciesTest.createManifest ();
51         m.getMainAttributes().putValue("OpenIDE-Module", "org.my.module");
52         File JavaDoc aModule = generateJar(new String JavaDoc[0], m);
53         
54         File JavaDoc output = new File JavaDoc(getWorkDir(), "output");
55         
56         java.io.File JavaDoc f = PublicPackagesInProjectizedXMLTest.extractString (
57             "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
58             "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >" +
59             " <taskdef name=\"createmodulexml\" classname=\"org.netbeans.nbbuild.CreateModuleXML\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>" +
60             "<target name=\"all\" >" +
61             " <mkdir dir='" + output + "' />" +
62             " <createmodulexml xmldir='" + output + "' >" +
63             " <hidden dir='" + aModule.getParent() + "' >" +
64             " <include name='" + aModule.getName() + "' />" +
65             " </hidden>" +
66             " </createmodulexml>" +
67             "</target>" +
68             "</project>"
69         );
70         PublicPackagesInProjectizedXMLTest.execute (f, new String JavaDoc[] { "-verbose" });
71         
72         assertTrue ("Output exists", output.exists ());
73         assertTrue ("Output directory created", output.isDirectory());
74         
75         String JavaDoc[] files = output.list();
76         assertEquals("It one file", 1, files.length);
77         assertEquals("Its name reflects the code name of the module", "org-my-module.xml_hidden", files[0]);
78         
79     }
80     
81     
82     private final File JavaDoc createNewJarFile () throws IOException JavaDoc {
83         File JavaDoc dir = new File JavaDoc(this.getWorkDir(), "modules");
84         dir.mkdirs();
85         
86         int i = 0;
87         for (;;) {
88             File JavaDoc f = new File JavaDoc (dir, i++ + ".jar");
89             if (!f.exists ()) return f;
90         }
91     }
92     
93     protected final File JavaDoc generateJar (String JavaDoc[] content, Manifest JavaDoc manifest) throws IOException JavaDoc {
94         File JavaDoc f = createNewJarFile ();
95         
96         JarOutputStream JavaDoc os;
97         if (manifest != null) {
98             os = new JarOutputStream JavaDoc (new FileOutputStream JavaDoc (f), manifest);
99         } else {
100             os = new JarOutputStream JavaDoc (new FileOutputStream JavaDoc (f));
101         }
102         
103         for (int i = 0; i < content.length; i++) {
104             os.putNextEntry(new JarEntry JavaDoc (content[i]));
105             os.closeEntry();
106         }
107         os.closeEntry ();
108         os.close();
109         
110         return f;
111     }
112     
113 }
114
Popular Tags