001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.nbbuild;
043:
044: import java.io.File;
045: import java.util.Arrays;
046: import java.util.Collections;
047: import java.util.Hashtable;
048: import junit.framework.TestCase;
049: import org.apache.tools.ant.BuildEvent;
050: import org.apache.tools.ant.BuildListener;
051: import org.apache.tools.ant.Project;
052:
053: /**
054: * Test {@link ModuleListParser}.
055: * @author Jesse Glick
056: */
057: public class ModuleListParserTest extends TestCase {
058:
059: public ModuleListParserTest(String name) {
060: super (name);
061: }
062:
063: private File nball;
064:
065: private File file(File root, String relpath) {
066: return new File(root, relpath.replace('/', File.separatorChar));
067: }
068:
069: private String filePath(File root, String relpath) {
070: return file(root, relpath).getAbsolutePath();
071: }
072:
073: protected @Override
074: void setUp() throws Exception {
075: super .setUp();
076: String prop = System.getProperty("nb_all");
077: assertNotNull("${nb_all} defined", prop);
078: nball = new File(prop);
079: new File(nball, "nbproject/private/scan-cache-full.ser")
080: .delete();
081: new File(nball, "nbproject/private/scan-cache-standard.ser")
082: .delete();
083: }
084:
085: public void testScanSourcesInNetBeansOrg() throws Exception {
086: Hashtable<String, String> properties = new Hashtable<String, String>();
087: properties.put("nb_all", nball.getAbsolutePath());
088: File build = file(nball, "build");
089: properties.put("netbeans.dest.dir", build.getAbsolutePath());
090: properties.put("nb.cluster.foo", "beans,clazz");
091: properties.put("nb.cluster.foo.dir", "foodir");
092: properties.put("nb.cluster.bar", "core/startup");
093: properties.put("nb.cluster.bar.dir", "bardir");
094: long start = System.currentTimeMillis();
095: ModuleListParser p = new ModuleListParser(properties,
096: ParseProjectXml.TYPE_NB_ORG, null);
097: System.err.println("Scanned " + nball + " sources in "
098: + (System.currentTimeMillis() - start) + "msec");
099: ModuleListParser.Entry e = p
100: .findByCodeNameBase("org.netbeans.modules.beans");
101: assertNotNull(e);
102: assertEquals("org.netbeans.modules.beans", e.getCnb());
103: assertEquals(file(build,
104: "foodir/modules/org-netbeans-modules-beans.jar"), e
105: .getJar());
106: assertEquals(Collections.EMPTY_LIST, Arrays.asList(e
107: .getClassPathExtensions()));
108: e = p.findByCodeNameBase("org.netbeans.libs.xerces");
109: assertNotNull("found module in a subdir", e);
110: assertEquals("org.netbeans.libs.xerces", e.getCnb());
111: assertEquals("unknown module put in extra cluster by default",
112: file(build,
113: "extra/modules/org-netbeans-libs-xerces.jar"),
114: e.getJar());
115: assertEquals(
116: "correct CP extensions (using <binary-origin> and relative paths)",
117: Collections.singletonList(file(nball,
118: "libs/external/xerces-2.8.0.jar")), Arrays
119: .asList(e.getClassPathExtensions()));
120: /*
121: e = p.findByCodeNameBase("javax.jmi.model");
122: assertNotNull(e);
123: assertEquals("correct CP extensions (using <binary-origin> and property substitutions #1)", Arrays.asList(new File[] {
124: file(nball, "mdr/external/mof.jar"),
125: }), Arrays.asList(e.getClassPathExtensions()));
126: */
127: e = p.findByCodeNameBase("org.netbeans.modules.css");
128: assertNotNull(e);
129: assertEquals(
130: "correct CP extensions (using <binary-origin> and property substitutions #2)",
131: Arrays.asList(new File[] {
132: file(nball, "xml/external/flute.jar"),
133: file(nball, "xml/external/sac.jar"), }), Arrays
134: .asList(e.getClassPathExtensions()));
135: e = p.findByCodeNameBase("org.netbeans.swing.tabcontrol");
136: assertNotNull("found module in a subsubdir", e);
137: e = p.findByCodeNameBase("org.netbeans.core.startup");
138: assertNotNull(e);
139: assertEquals("org.netbeans.core.startup", e.getCnb());
140: assertEquals("handling special JAR names correctly", file(
141: build, "bardir/core/core.jar"), e.getJar());
142: assertEquals(Collections.EMPTY_LIST, Arrays.asList(e
143: .getClassPathExtensions()));
144: e = p.findByCodeNameBase("org.netbeans.modules.xml.tax");
145: assertNotNull("found xml/tax", e);
146: assertEquals("org.netbeans.modules.xml.tax", e.getCnb());
147: assertEquals(file(build,
148: "extra/modules/org-netbeans-modules-xml-tax.jar"), e
149: .getJar());
150: assertEquals(
151: "correct CP extensions (using runtime-relative-path)",
152: Arrays.asList(new File[] { file(build,
153: "extra/modules/ext/org-netbeans-tax.jar"), }),
154: Arrays.asList(e.getClassPathExtensions()));
155: e = p.findByCodeNameBase("org.netbeans.modules.masterfs");
156: assertNotNull(e);
157: String testDeps[] = e.getTestDependencies();
158: assertNotNull(testDeps);
159: assertEquals("depends on one test entry", 1, testDeps.length);
160: assertEquals("org.openide.filesystems", testDeps[0]);
161: }
162:
163: public void testScanSourcesAndBinariesForExternalSuite()
164: throws Exception {
165: Project fakeproj = new Project();
166: fakeproj.addBuildListener(new BuildListener() {
167: public void messageLogged(BuildEvent buildEvent) {
168: if (buildEvent.getPriority() <= Project.MSG_VERBOSE) {
169: System.err.println(buildEvent.getMessage());
170: }
171: }
172:
173: public void taskStarted(BuildEvent buildEvent) {
174: }
175:
176: public void taskFinished(BuildEvent buildEvent) {
177: }
178:
179: public void targetStarted(BuildEvent buildEvent) {
180: }
181:
182: public void targetFinished(BuildEvent buildEvent) {
183: }
184:
185: public void buildStarted(BuildEvent buildEvent) {
186: }
187:
188: public void buildFinished(BuildEvent buildEvent) {
189: }
190: });
191: Hashtable<String, String> properties = new Hashtable<String, String>();
192: properties.put("netbeans.dest.dir", filePath(nball,
193: "nbbuild/netbeans"));
194: properties
195: .put(
196: "basedir",
197: filePath(
198: nball,
199: "apisupport/project/test/unit/data/example-external-projects/suite1/action-project"));
200: properties
201: .put(
202: "suite.dir",
203: filePath(nball,
204: "apisupport/project/test/unit/data/example-external-projects/suite1"));
205: long start = System.currentTimeMillis();
206: ModuleListParser p = new ModuleListParser(properties,
207: ParseProjectXml.TYPE_SUITE, fakeproj);
208: System.err.println("Scanned " + nball + " binaries in "
209: + (System.currentTimeMillis() - start) + "msec");
210: ModuleListParser.Entry e = p
211: .findByCodeNameBase("org.netbeans.examples.modules.action");
212: assertNotNull("found myself", e);
213: assertEquals("org.netbeans.examples.modules.action", e.getCnb());
214: assertEquals(
215: file(
216: nball,
217: "apisupport/project/test/unit/data/example-external-projects/suite1/build/cluster/modules/org-netbeans-examples-modules-action.jar"),
218: e.getJar());
219: assertEquals(Collections.EMPTY_LIST, Arrays.asList(e
220: .getClassPathExtensions()));
221: e = p.findByCodeNameBase("org.netbeans.examples.modules.lib");
222: assertNotNull("found sister project in suite", e);
223: assertEquals("org.netbeans.examples.modules.lib", e.getCnb());
224: assertEquals(
225: file(
226: nball,
227: "apisupport/project/test/unit/data/example-external-projects/suite1/build/cluster/modules/org-netbeans-examples-modules-lib.jar"),
228: e.getJar());
229: File jar = file(nball,
230: "nbbuild/netbeans/ide9/modules/org-netbeans-libs-xerces.jar");
231: assertTrue("Build all-libs/xerces first!", jar.isFile());
232: e = p.findByCodeNameBase("org.netbeans.libs.xerces");
233: assertNotNull("found netbeans.org module by its binary", e);
234: assertEquals("org.netbeans.libs.xerces", e.getCnb());
235: assertEquals(jar, e.getJar());
236: assertEquals(
237: "correct CP extensions (using Class-Path header in manifest)",
238: Collections
239: .singletonList(file(nball,
240: "nbbuild/netbeans/ide9/modules/ext/xerces-2.8.0.jar")),
241: Arrays.asList(e.getClassPathExtensions()));
242: e = p.findByCodeNameBase("org.openide.loaders");
243: assertNotNull(e);
244: assertEquals("org.openide.loaders", e.getCnb());
245: assertEquals(
246: file(nball,
247: "nbbuild/netbeans/platform8/modules/org-openide-loaders.jar"),
248: e.getJar());
249: assertEquals(Collections.EMPTY_LIST, Arrays.asList(e
250: .getClassPathExtensions()));
251: e = p.findByCodeNameBase("org.netbeans.bootstrap");
252: assertNotNull(e);
253: assertEquals("org.netbeans.bootstrap", e.getCnb());
254: assertEquals(file(nball,
255: "nbbuild/netbeans/platform8/lib/boot.jar"), e.getJar());
256: assertEquals(Collections.EMPTY_LIST, Arrays.asList(e
257: .getClassPathExtensions()));
258: jar = file(nball,
259: "nbbuild/netbeans/ide9/modules/org-netbeans-modules-xml-tax.jar");
260: assertTrue("Build all-xml/tax first!", jar.isFile());
261: e = p.findByCodeNameBase("org.netbeans.modules.xml.tax");
262: assertNotNull(e);
263: assertEquals("org.netbeans.modules.xml.tax", e.getCnb());
264: assertEquals(jar, e.getJar());
265: assertEquals(
266: Arrays
267: .asList(new File[] { file(nball,
268: "nbbuild/netbeans/ide9/modules/ext/org-netbeans-tax.jar"), }),
269: Arrays.asList(e.getClassPathExtensions()));
270: }
271:
272: public void testScanSourcesAndBinariesForExternalStandaloneModule()
273: throws Exception {
274: Hashtable<String, String> properties = new Hashtable<String, String>();
275: properties
276: .put(
277: "netbeans.dest.dir",
278: filePath(nball,
279: "apisupport/project/test/unit/data/example-external-projects/suite3/nbplatform"));
280: properties
281: .put(
282: "basedir",
283: filePath(
284: nball,
285: "apisupport/project/test/unit/data/example-external-projects/suite3/dummy-project"));
286: properties
287: .put(
288: "project",
289: filePath(
290: nball,
291: "apisupport/project/test/unit/data/example-external-projects/suite3/dummy-project"));
292: ModuleListParser p = new ModuleListParser(properties,
293: ParseProjectXml.TYPE_STANDALONE, null);
294: ModuleListParser.Entry e = p
295: .findByCodeNameBase("org.netbeans.examples.modules.dummy");
296: assertNotNull("found myself", e);
297: assertEquals("org.netbeans.examples.modules.dummy", e.getCnb());
298: assertEquals(
299: file(
300: nball,
301: "apisupport/project/test/unit/data/example-external-projects/suite3/dummy-project/build/cluster/modules/org-netbeans-examples-modules-dummy.jar"),
302: e.getJar());
303: assertEquals(Collections.EMPTY_LIST, Arrays.asList(e
304: .getClassPathExtensions()));
305: e = p.findByCodeNameBase("org.netbeans.modules.classfile");
306: assertNotNull("found (fake) netbeans.org module by its binary",
307: e);
308: assertEquals("org.netbeans.modules.classfile", e.getCnb());
309: }
310:
311: }
|