KickJava   Java API By Example, From Geeks To Geeks.

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


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

19
20 package org.netbeans.nbbuild;
21
22 import java.io.File JavaDoc;
23 import java.util.Arrays JavaDoc;
24 import java.util.Collections JavaDoc;
25 import java.util.Hashtable JavaDoc;
26 import junit.framework.TestCase;
27 import org.apache.tools.ant.BuildEvent;
28 import org.apache.tools.ant.BuildListener;
29 import org.apache.tools.ant.Project;
30
31 /**
32  * Test {@link ModuleListParser}.
33  * @author Jesse Glick
34  */

35 public class ModuleListParserTest extends TestCase {
36
37     public ModuleListParserTest(String JavaDoc name) {
38         super(name);
39     }
40
41     private File JavaDoc nball;
42
43     private File JavaDoc file(File JavaDoc root, String JavaDoc relpath) {
44         return new File JavaDoc(root, relpath.replace('/', File.separatorChar));
45     }
46     
47     private String JavaDoc filePath(File JavaDoc root, String JavaDoc relpath) {
48         return file(root, relpath).getAbsolutePath();
49     }
50
51     protected void setUp() throws Exception JavaDoc {
52         super.setUp();
53         String JavaDoc prop = System.getProperty("nb_all");
54         assertNotNull("${nb_all} defined", prop);
55         nball = new File JavaDoc(prop);
56     }
57     
58     public void testScanSourcesInNetBeansOrg() throws Exception JavaDoc {
59         Hashtable JavaDoc properties = new Hashtable JavaDoc();
60         properties.put("nb_all", nball.getAbsolutePath());
61         File JavaDoc build = file(nball, "build");
62         properties.put("netbeans.dest.dir", build.getAbsolutePath());
63         properties.put("nb.cluster.foo", "beans,clazz");
64         properties.put("nb.cluster.foo.dir", "foodir");
65         properties.put("nb.cluster.bar", "core/startup");
66         properties.put("nb.cluster.bar.dir", "bardir");
67         long start = System.currentTimeMillis();
68         ModuleListParser p = new ModuleListParser(properties, ParseProjectXml.TYPE_NB_ORG, null);
69         System.err.println("Scanned " + nball + " sources in " + (System.currentTimeMillis() - start) + "msec");
70         ModuleListParser.Entry e = p.findByCodeNameBase("org.netbeans.modules.beans");
71         assertNotNull(e);
72         assertEquals("org.netbeans.modules.beans", e.getCnb());
73         assertEquals(file(build, "foodir/modules/org-netbeans-modules-beans.jar"), e.getJar());
74         assertEquals(Collections.EMPTY_LIST, Arrays.asList(e.getClassPathExtensions()));
75         e = p.findByCodeNameBase("org.netbeans.libs.xerces");
76         assertNotNull("found module in a subdir", e);
77         assertEquals("org.netbeans.libs.xerces", e.getCnb());
78         assertEquals("unknown module put in extra cluster by default", file(build, "extra/modules/org-netbeans-libs-xerces.jar"), e.getJar());
79         assertEquals("correct CP extensions (using <binary-origin> and relative paths)", Arrays.asList(new File JavaDoc[] {
80             file(nball, "libs/external/xerces-2.8.0.jar"),
81             file(nball, "libs/external/xml-commons-dom-ranges-1.0.b2.jar"),
82         }), Arrays.asList(e.getClassPathExtensions()));
83         e = p.findByCodeNameBase("javax.jmi.model");
84         assertNotNull(e);
85         assertEquals("correct CP extensions (using <binary-origin> and property substitutions #1)", Arrays.asList(new File JavaDoc[] {
86             file(nball, "mdr/external/mof.jar"),
87         }), Arrays.asList(e.getClassPathExtensions()));
88         e = p.findByCodeNameBase("org.netbeans.modules.css");
89         assertNotNull(e);
90         assertEquals("correct CP extensions (using <binary-origin> and property substitutions #2)", Arrays.asList(new File JavaDoc[] {
91             file(nball, "xml/external/flute.jar"),
92             file(nball, "xml/external/sac.jar"),
93         }), Arrays.asList(e.getClassPathExtensions()));
94         e = p.findByCodeNameBase("org.netbeans.swing.tabcontrol");
95         assertNotNull("found module in a subsubdir", e);
96         e = p.findByCodeNameBase("org.netbeans.core.startup");
97         assertNotNull(e);
98         assertEquals("org.netbeans.core.startup", e.getCnb());
99         assertEquals("handling special JAR names correctly", file(build, "bardir/core/core.jar"), e.getJar());
100         assertEquals(Collections.EMPTY_LIST, Arrays.asList(e.getClassPathExtensions()));
101         e = p.findByCodeNameBase("org.netbeans.modules.xml.tax");
102         assertNotNull("found xml/tax", e);
103         assertEquals("org.netbeans.modules.xml.tax", e.getCnb());
104         assertEquals(file(build, "extra/modules/org-netbeans-modules-xml-tax.jar"), e.getJar());
105         assertEquals("correct CP extensions (using runtime-relative-path)", Arrays.asList(new File JavaDoc[] {
106             file(build, "extra/modules/ext/org-netbeans-tax.jar"),
107         }), Arrays.asList(e.getClassPathExtensions()));
108     }
109     
110     public void testScanSourcesAndBinariesForExternalSuite() throws Exception JavaDoc {
111         Project fakeproj = new Project();
112         fakeproj.addBuildListener(new BuildListener() {
113             public void messageLogged(BuildEvent buildEvent) {
114                 if (buildEvent.getPriority() <= Project.MSG_VERBOSE) {
115                     System.err.println(buildEvent.getMessage());
116                 }
117             }
118             public void taskStarted(BuildEvent buildEvent) {}
119             public void taskFinished(BuildEvent buildEvent) {}
120             public void targetStarted(BuildEvent buildEvent) {}
121             public void targetFinished(BuildEvent buildEvent) {}
122             public void buildStarted(BuildEvent buildEvent) {}
123             public void buildFinished(BuildEvent buildEvent) {}
124         });
125         Hashtable JavaDoc properties = new Hashtable JavaDoc();
126         properties.put("netbeans.dest.dir", filePath(nball, "nbbuild/netbeans"));
127         properties.put("basedir", filePath(nball, "apisupport/project/test/unit/data/example-external-projects/suite1/action-project"));
128         properties.put("suite.dir", filePath(nball, "apisupport/project/test/unit/data/example-external-projects/suite1"));
129         long start = System.currentTimeMillis();
130         ModuleListParser p = new ModuleListParser(properties, ParseProjectXml.TYPE_SUITE, fakeproj);
131         System.err.println("Scanned " + nball + " binaries in " + (System.currentTimeMillis() - start) + "msec");
132         ModuleListParser.Entry e = p.findByCodeNameBase("org.netbeans.examples.modules.action");
133         assertNotNull("found myself", e);
134         assertEquals("org.netbeans.examples.modules.action", e.getCnb());
135         assertEquals(file(nball, "apisupport/project/test/unit/data/example-external-projects/suite1/build/cluster/modules/org-netbeans-examples-modules-action.jar"), e.getJar());
136         assertEquals(Collections.EMPTY_LIST, Arrays.asList(e.getClassPathExtensions()));
137         e = p.findByCodeNameBase("org.netbeans.examples.modules.lib");
138         assertNotNull("found sister project in suite", e);
139         assertEquals("org.netbeans.examples.modules.lib", e.getCnb());
140         assertEquals(file(nball, "apisupport/project/test/unit/data/example-external-projects/suite1/build/cluster/modules/org-netbeans-examples-modules-lib.jar"), e.getJar());
141         File JavaDoc jar = file(nball, "nbbuild/netbeans/ide8/modules/org-netbeans-libs-xerces.jar");
142         assertTrue("Build all-libs/xerces first!", jar.isFile());
143         e = p.findByCodeNameBase("org.netbeans.libs.xerces");
144         assertNotNull("found netbeans.org module by its binary", e);
145         assertEquals("org.netbeans.libs.xerces", e.getCnb());
146         assertEquals(jar, e.getJar());
147         assertEquals("correct CP extensions (using Class-Path header in manifest)", Arrays.asList(new File JavaDoc[] {
148             file(nball, "nbbuild/netbeans/ide8/modules/ext/xerces-2.8.0.jar"),
149             file(nball, "nbbuild/netbeans/ide8/modules/ext/xml-commons-dom-ranges-1.0.b2.jar"),
150         }), Arrays.asList(e.getClassPathExtensions()));
151         e = p.findByCodeNameBase("org.openide.loaders");
152         assertNotNull(e);
153         assertEquals("org.openide.loaders", e.getCnb());
154         assertEquals(file(nball, "nbbuild/netbeans/platform7/modules/org-openide-loaders.jar"), e.getJar());
155         assertEquals(Collections.EMPTY_LIST, Arrays.asList(e.getClassPathExtensions()));
156         e = p.findByCodeNameBase("org.netbeans.bootstrap");
157         assertNotNull(e);
158         assertEquals("org.netbeans.bootstrap", e.getCnb());
159         assertEquals(file(nball, "nbbuild/netbeans/platform7/lib/boot.jar"), e.getJar());
160         assertEquals(Collections.EMPTY_LIST, Arrays.asList(e.getClassPathExtensions()));
161         jar = file(nball, "nbbuild/netbeans/ide8/modules/org-netbeans-modules-xml-tax.jar");
162         assertTrue("Build all-xml/tax first!", jar.isFile());
163         e = p.findByCodeNameBase("org.netbeans.modules.xml.tax");
164         assertNotNull(e);
165         assertEquals("org.netbeans.modules.xml.tax", e.getCnb());
166         assertEquals(jar, e.getJar());
167         assertEquals(Arrays.asList(new File JavaDoc[] {
168             file(nball, "nbbuild/netbeans/ide8/modules/ext/org-netbeans-tax.jar"),
169         }), Arrays.asList(e.getClassPathExtensions()));
170     }
171     
172     public void testScanSourcesAndBinariesForExternalStandaloneModule() throws Exception JavaDoc {
173         Hashtable JavaDoc properties = new Hashtable JavaDoc();
174         properties.put("netbeans.dest.dir", filePath(nball, "apisupport/project/test/unit/data/example-external-projects/suite3/nbplatform"));
175         properties.put("basedir", filePath(nball, "apisupport/project/test/unit/data/example-external-projects/suite3/dummy-project"));
176         properties.put("project", filePath(nball, "apisupport/project/test/unit/data/example-external-projects/suite3/dummy-project"));
177         ModuleListParser p = new ModuleListParser(properties, ParseProjectXml.TYPE_STANDALONE, null);
178         ModuleListParser.Entry e = p.findByCodeNameBase("org.netbeans.examples.modules.dummy");
179         assertNotNull("found myself", e);
180         assertEquals("org.netbeans.examples.modules.dummy", e.getCnb());
181         assertEquals(file(nball, "apisupport/project/test/unit/data/example-external-projects/suite3/dummy-project/build/cluster/modules/org-netbeans-examples-modules-dummy.jar"), e.getJar());
182         assertEquals(Collections.EMPTY_LIST, Arrays.asList(e.getClassPathExtensions()));
183         e = p.findByCodeNameBase("org.netbeans.modules.classfile");
184         assertNotNull("found (fake) netbeans.org module by its binary", e);
185         assertEquals("org.netbeans.modules.classfile", e.getCnb());
186     }
187     
188 }
189
Popular Tags