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.modules.apisupport.project.universe;
043:
044: import java.io.File;
045: import java.io.IOException;
046: import java.util.Arrays;
047: import java.util.HashSet;
048: import org.netbeans.api.project.ProjectManager;
049: import org.netbeans.modules.apisupport.project.EditableManifest;
050: import org.netbeans.modules.apisupport.project.ManifestManager;
051: import org.netbeans.modules.apisupport.project.NbModuleProject;
052: import org.netbeans.modules.apisupport.project.ProjectXMLManager;
053: import org.netbeans.modules.apisupport.project.TestBase;
054: import org.netbeans.modules.apisupport.project.Util;
055: import org.netbeans.modules.apisupport.project.suite.SuiteProject;
056: import org.netbeans.modules.apisupport.project.ui.customizer.SingleModuleProperties;
057: import org.netbeans.spi.project.support.ant.AntProjectHelper;
058: import org.netbeans.spi.project.support.ant.EditableProperties;
059: import org.netbeans.spi.project.support.ant.PropertyEvaluator;
060: import org.netbeans.spi.project.support.ant.PropertyUtils;
061: import org.openide.util.Mutex;
062:
063: /**
064: * Test functionality of ModuleList.
065: * @author Jesse Glick
066: */
067: public class ModuleListTest extends TestBase {
068:
069: public ModuleListTest(String name) {
070: super (name);
071: }
072:
073: private File suite1, suite2, standaloneSuite3;
074:
075: protected void setUp() throws Exception {
076: super .setUp();
077: suite1 = resolveEEPFile("suite1");
078: suite2 = resolveEEPFile("suite2");
079: standaloneSuite3 = resolveEEPFile("suite3");
080: }
081:
082: public void testParseProperties() throws Exception {
083: File basedir = file("ant.browsetask");
084: PropertyEvaluator eval = ModuleList.parseProperties(basedir,
085: nbRootFile(), false, false,
086: "org.netbeans.modules.ant.browsetask");
087: String nbdestdir = eval.getProperty("netbeans.dest.dir");
088: assertNotNull(nbdestdir);
089: assertEquals(file("nbbuild/netbeans"), PropertyUtils
090: .resolveFile(basedir, nbdestdir));
091: assertEquals("modules/org-netbeans-modules-ant-browsetask.jar",
092: eval.getProperty("module.jar"));
093: assertEquals(file("nbbuild/netbeans/" + TestBase.CLUSTER_JAVA),
094: PropertyUtils.resolveFile(basedir, eval
095: .getProperty("cluster")));
096: assertNull(eval.getProperty("suite.dir"));
097: basedir = file("openide.loaders");
098: eval = ModuleList.parseProperties(basedir, nbRootFile(), false,
099: false, "org.openide.loaders");
100: assertEquals("modules/org-openide-loaders.jar", eval
101: .getProperty("module.jar"));
102: basedir = new File(suite1, "action-project");
103: eval = ModuleList.parseProperties(basedir, suite1, true, false,
104: "org.netbeans.examples.modules.action");
105: nbdestdir = eval.getProperty("netbeans.dest.dir");
106: assertNotNull(nbdestdir);
107: assertEquals(file("nbbuild/netbeans"), PropertyUtils
108: .resolveFile(basedir, nbdestdir));
109: assertEquals(suite1, PropertyUtils.resolveFile(basedir, eval
110: .getProperty("suite.dir")));
111: basedir = new File(suite2, "misc-project");
112: eval = ModuleList.parseProperties(basedir, suite2, true, false,
113: "org.netbeans.examples.modules.misc");
114: nbdestdir = eval.getProperty("netbeans.dest.dir");
115: assertNotNull(nbdestdir);
116: assertEquals(file("nbbuild/netbeans"), PropertyUtils
117: .resolveFile(basedir, nbdestdir));
118: assertEquals(file(suite2, "build/cluster"), PropertyUtils
119: .resolveFile(basedir, eval.getProperty("cluster")));
120: assertEquals(suite2, PropertyUtils.resolveFile(basedir, eval
121: .getProperty("suite.dir")));
122: basedir = new File(standaloneSuite3, "dummy-project");
123: eval = ModuleList.parseProperties(basedir, standaloneSuite3,
124: false, true, "org.netbeans.examples.modules.dummy");
125: nbdestdir = eval.getProperty("netbeans.dest.dir");
126: assertNotNull(nbdestdir);
127: assertEquals(file(standaloneSuite3, "nbplatform"),
128: PropertyUtils.resolveFile(basedir, nbdestdir));
129: assertEquals(file(standaloneSuite3,
130: "dummy-project/build/cluster"), PropertyUtils
131: .resolveFile(basedir, eval.getProperty("cluster")));
132: assertNull(eval.getProperty("suite.dir"));
133: }
134:
135: public void testFindModulesInSuite() throws Exception {
136: assertEquals("correct modules in suite1", new HashSet<File>(
137: Arrays.asList(file(suite1, "action-project"), file(
138: suite1, "support/lib-project"))),
139: new HashSet<File>(Arrays.asList(ModuleList
140: .findModulesInSuite(suite1))));
141: assertEquals("correct modules in suite2", new HashSet<File>(
142: Arrays.asList(file(suite2, "misc-project"))),
143: new HashSet<File>(Arrays.asList(ModuleList
144: .findModulesInSuite(suite2))));
145: }
146:
147: public void testNetBeansOrgEntries() throws Exception {
148: long start = System.currentTimeMillis();
149: ModuleList ml = ModuleList
150: .getModuleList(file("ant.browsetask")); // should be arbitrary
151: System.err.println("Time to scan netbeans.org sources: "
152: + (System.currentTimeMillis() - start) + "msec");
153: System.err.println("Directories traversed: "
154: + ModuleList.directoriesChecked);
155: System.err.println("XML files parsed: "
156: + ModuleList.xmlFilesParsed + " in "
157: + ModuleList.timeSpentInXmlParsing + "msec");
158: ModuleEntry e = ml
159: .getEntry("org.netbeans.modules.java.project");
160: assertNotNull("have org.netbeans.modules.java.project", e);
161: assertEquals("right jarLocation", file("nbbuild/netbeans/"
162: + TestBase.CLUSTER_JAVA
163: + "/modules/org-netbeans-modules-java-project.jar"), e
164: .getJarLocation());
165: assertTrue("in all entries", ml.getAllEntries().contains(e));
166: assertEquals("right path", "java.project", e
167: .getNetBeansOrgPath());
168: assertEquals("right source location", file("java.project"), e
169: .getSourceLocation());
170: assertTrue("same by JAR", ModuleList.getKnownEntries(
171: e.getJarLocation()).contains(e));
172: /* will fail if nbbuild/netbeans/nbproject/private/scan-cache-full.ser exists:
173: assertTrue("same by other random file", ModuleList.getKnownEntries(file("nbbuild/netbeans/" + TestBase.CLUSTER_JAVA + "/config/Modules/org-netbeans-modules-java-project.xml")).contains(e));
174: */
175: assertEquals("right codeNameBase",
176: "org.netbeans.modules.java.project", e
177: .getCodeNameBase());
178: assertEquals(file("nbbuild/netbeans"), e.getDestDir());
179: assertEquals("", e.getClassPathExtensions());
180: assertNotNull("localized name", e.getLocalizedName());
181: assertNotNull("display category", e.getCategory());
182: assertNotNull("short description", e.getShortDescription());
183: assertNotNull("long description", e.getLongDescription());
184: assertNotNull("release version", e.getReleaseVersion());
185: assertNotNull("specification version", e
186: .getSpecificationVersion());
187: assertEquals("number of public packages for " + e, new Integer(
188: 7), new Integer(e.getPublicPackages().length));
189: assertFalse("not deprecated", e.isDeprecated());
190: // Test something in a different cluster and dir:
191: e = ml.getEntry("org.openide.filesystems");
192: assertNotNull("have org.openide.filesystems", e);
193: assertEquals("right jarLocation", file("nbbuild/netbeans/"
194: + TestBase.CLUSTER_PLATFORM
195: + "/core/org-openide-filesystems.jar"), e
196: .getJarLocation());
197: assertEquals("right source location",
198: file("openide.filesystems"), e.getSourceLocation());
199: assertTrue("same by JAR", ModuleList.getKnownEntries(
200: e.getJarLocation()).contains(e));
201: assertEquals("right path", "openide.filesystems", e
202: .getNetBeansOrgPath());
203: // Test class-path extensions:
204: e = ml.getEntry("org.netbeans.libs.xerces");
205: assertNotNull(e);
206: assertEquals(
207: "correct CP extensions (using <binary-origin> and relative paths)",
208: ":" + file("libs.xerces/external/xerces-2.8.0.jar"), e
209: .getClassPathExtensions());
210: /* XXX unmaintained:
211: e = ml.getEntry("javax.jmi.model");
212: assertNotNull(e);
213: assertEquals("correct CP extensions (using <binary-origin> and property substitutions #1)",
214: ":" + file("mdr/external/mof.jar"),
215: e.getClassPathExtensions());
216: */
217: /* XXX org.netbeans.modules.css moved to "org.netbeans.modules.languages.css?
218: e = ml.getEntry("org.netbeans.modules.css");
219: assertNotNull(e);
220: assertEquals("correct CP extensions (using <binary-origin> and property substitutions #2)",
221: ":" + file("xml/external/flute.jar") + ":" + file("xml/external/sac.jar"),
222: e.getClassPathExtensions());
223: */
224: e = ml.getEntry("org.netbeans.modules.xml.tax");
225: assertNotNull(e);
226: assertEquals(
227: "correct CP extensions (using runtime-relative-path)",
228: ":"
229: + file("nbbuild/netbeans/"
230: + TestBase.CLUSTER_IDE
231: + "/modules/ext/org-netbeans-tax.jar"),
232: e.getClassPathExtensions());
233: e = ml.getEntry("org.openide.util.enumerations");
234: assertNotNull(e);
235: assertTrue("this one is deprecated", e.isDeprecated());
236: e = ml.getEntry("org.netbeans.modules.projectui");
237: assertNotNull(e);
238: assertNotNull(e.getProvidedTokens());
239: assertTrue("There are some provided tokens", e
240: .getProvidedTokens().length > 0);
241: // XXX test that getAllEntries() also includes nonstandard modules, and so does getKnownEntries() if necessary
242: // Test a nonstandard module:
243: e = ml.getEntry("org.netbeans.modules.looks");
244: assertNotNull(e);
245: assertEquals("right path", "contrib/looks", e
246: .getNetBeansOrgPath());
247: }
248:
249: public void testExternalEntries() throws Exception {
250: // Start with suite1 - should find also nb_all.
251: long start = System.currentTimeMillis();
252: ModuleList ml = ModuleList.getModuleList(file(suite1,
253: "support/lib-project"));
254: System.err.println("Time to scan suite + NB binaries: "
255: + (System.currentTimeMillis() - start) + "msec");
256: ModuleEntry e = ml
257: .getEntry("org.netbeans.examples.modules.action");
258: assertNotNull("action-project found", e);
259: File jar = resolveEEPFile("/suite1/build/cluster/modules/org-netbeans-examples-modules-action.jar");
260: assertEquals("right JAR location", jar, e.getJarLocation());
261: assertTrue("in all entries", ml.getAllEntries().contains(e));
262: assertNull("no nb.org path", e.getNetBeansOrgPath());
263: assertEquals("right source location", file(suite1,
264: "action-project"), e.getSourceLocation());
265: assertTrue("same by JAR", ModuleList.getKnownEntries(
266: e.getJarLocation()).contains(e));
267: assertEquals("right codeNameBase",
268: "org.netbeans.examples.modules.action", e
269: .getCodeNameBase());
270: e = ml.getEntry("org.netbeans.modules.classfile");
271: assertNotNull(
272: "can find nb.org sources too (classfile module must be built)",
273: e);
274: assertEquals("correct nb.org source location",
275: file("classfile"), e.getSourceLocation());
276: assertNotNull("localized name", e.getLocalizedName());
277: assertNotNull("display category", e.getCategory());
278: assertNotNull("short description", e.getShortDescription());
279: assertNotNull("long description", e.getLongDescription());
280: assertNotNull("release version", e.getReleaseVersion());
281: assertNotNull("specification version", e
282: .getSpecificationVersion());
283: assertNotNull(e.getProvidedTokens());
284: assertEquals("there are no provided tokens", 0, e
285: .getProvidedTokens().length);
286: /*
287: e = ml.getEntry("org.netbeans.examples.modules.misc");
288: assertNotNull("can find sources from another suite (misc must have been built first)", e);
289: assertEquals("correct source location", file(suite2, "misc-project"), e.getSourceLocation());
290: assertEquals("number of public packages for " + e, new Integer(1), new Integer(e.getPublicPackages().length));
291: */
292: e = ml.getEntry("org.netbeans.libs.xerces");
293: assertEquals(
294: "correct CP exts for a nb.org module (using Class-Path only)",
295: ":"
296: + file("nbbuild/netbeans/"
297: + TestBase.CLUSTER_IDE
298: + "/modules/ext/xerces-2.8.0.jar"), e
299: .getClassPathExtensions());
300: // From suite2, can only find itself, and netbeans.org modules only available in binary form.
301: ml = ModuleList.getModuleList(file(suite2, "misc-project"));
302: e = ml.getEntry("org.netbeans.examples.modules.misc");
303: assertNotNull("can find module from my own suite", e);
304: assertEquals(
305: "correct JAR location",
306: resolveEEPFile("/suite2/build/cluster/modules/org-netbeans-examples-modules-misc.jar"),
307: e.getJarLocation());
308: assertNotNull("localized name", e.getLocalizedName());
309: assertNotNull("display category", e.getCategory());
310: assertNotNull("short description", e.getShortDescription());
311: assertNotNull("long description", e.getLongDescription());
312: assertEquals("right codeNameBase",
313: "org.netbeans.examples.modules.misc", e
314: .getCodeNameBase());
315: assertNotNull("release version", e.getReleaseVersion());
316: assertNotNull("specification version", e
317: .getSpecificationVersion());
318: assertNotNull(e.getProvidedTokens());
319: assertEquals("there are no provided tokens", 0, e
320: .getProvidedTokens().length);
321: assertEquals("number of public packages for " + e, new Integer(
322: 1), new Integer(e.getPublicPackages().length));
323: e = ml.getEntry("org.netbeans.libs.xerces");
324: assertNotNull("can find nb.org binary module too", e);
325: assertEquals("have sources for that", file("libs.xerces"), e
326: .getSourceLocation());
327: assertEquals("and correct JAR location",
328: file("nbbuild/netbeans/" + TestBase.CLUSTER_IDE
329: + "/modules/org-netbeans-libs-xerces.jar"), e
330: .getJarLocation());
331: assertEquals("and correct CP exts (using Class-Path only)", ":"
332: + file("nbbuild/netbeans/" + TestBase.CLUSTER_IDE
333: + "/modules/ext/xerces-2.8.0.jar"), e
334: .getClassPathExtensions());
335: e = ml.getEntry("org.openide.util");
336: assertNotNull(e);
337: assertFalse("binary API not deprecated", e.isDeprecated());
338: e = ml.getEntry("org.openide.util.enumerations");
339: assertNotNull(e);
340: assertTrue("this one is deprecated", e.isDeprecated());
341: // From suite3, can find itself and netbeans.org modules in binary form.
342: ml = ModuleList.getModuleList(file(standaloneSuite3,
343: "dummy-project"));
344: e = ml.getEntry("org.netbeans.examples.modules.dummy");
345: assertNotNull("can find myself", e);
346: e = ml.getEntry("org.netbeans.modules.classfile");
347: assertNotNull("found (fake) nb.org module", e);
348: assertNull("...without sources", e.getSourceLocation());
349: assertEquals("and with a special JAR location", file(
350: standaloneSuite3,
351: "nbplatform/random/modules/random.jar"), e
352: .getJarLocation());
353: assertEquals(
354: "correct CP extensions (using Class-Path only, and ignoring sources completely)",
355: ":"
356: + file(standaloneSuite3,
357: "nbplatform/random/modules/ext/stuff.jar"),
358: e.getClassPathExtensions());
359: }
360:
361: public void testNewlyAddedModule() throws Exception {
362: // XXX make new module, call refresh, check that things work
363: // (partially tested already by NbModuleProjectGeneratorTest.testCreateSuiteComponentModule)
364: }
365:
366: public void testFindNetBeansOrg() throws Exception {
367: assertEquals(nbRootFile(), ModuleList
368: .findNetBeansOrg(file("xml.tax")));
369: assertEquals(null, ModuleList
370: .findNetBeansOrg(file("xml.tax/lib")));
371: assertEquals(null, ModuleList
372: .findNetBeansOrg(File.listRoots()[0]));
373: }
374:
375: public void testRefreshSuiteModuleList() throws Exception {
376: SuiteProject suite = generateSuite("suite1");
377: final NbModuleProject p = TestBase.generateSuiteComponent(
378: suite, "module1a");
379: ModuleList ml = ModuleList.getModuleList(p
380: .getProjectDirectoryFile(), NbPlatform
381: .getDefaultPlatform().getDestDir());
382: assertNotNull("module1a is in the suite1's module list", ml
383: .getEntry("org.example.module1a"));
384: assertEquals(
385: "no public packages in the ModuleEntry",
386: 0,
387: ml.getEntry("org.example.module1a").getPublicPackages().length);
388:
389: // added package must be reflected in the refreshed list (63561)
390: Boolean result = ProjectManager.mutex().writeAccess(
391: new Mutex.ExceptionAction<Boolean>() {
392: public Boolean run() throws IOException {
393: ProjectXMLManager pxm = new ProjectXMLManager(p);
394: String[] newPP = new String[] { "org.example.module1a" };
395: pxm.replacePublicPackages(newPP);
396: return true;
397: }
398: });
399: assertTrue("replace public packages", result);
400: ProjectManager.getDefault().saveProject(p);
401:
402: ModuleList.refreshSuiteModuleList(suite
403: .getProjectDirectoryFile());
404: ml = ModuleList.getModuleList(p.getProjectDirectoryFile(),
405: NbPlatform.getDefaultPlatform().getDestDir());
406: assertEquals(
407: "one public packages in the refreshed ModuleEntry",
408: 1,
409: ml.getEntry("org.example.module1a").getPublicPackages().length);
410: }
411:
412: public void testSpecVersionBaseSourceEntries() throws Exception { // #72463
413: SuiteProject suite = generateSuite("suite");
414: NbModuleProject p = TestBase.generateSuiteComponent(suite,
415: "module");
416: ModuleList ml = ModuleList.getModuleList(p
417: .getProjectDirectoryFile());
418: ModuleEntry e = ml.getEntry("org.example.module");
419: assertNotNull("have entry", e);
420: assertEquals("right initial spec vers from manifest", "1.0", e
421: .getSpecificationVersion());
422: EditableProperties ep = p.getHelper().getProperties(
423: AntProjectHelper.PROJECT_PROPERTIES_PATH);
424: ep.setProperty(SingleModuleProperties.SPEC_VERSION_BASE,
425: "1.1.0");
426: p.getHelper().putProperties(
427: AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
428: EditableManifest em = Util.loadManifest(p.getManifestFile());
429: em.removeAttribute(
430: ManifestManager.OPENIDE_MODULE_SPECIFICATION_VERSION,
431: null);
432: Util.storeManifest(p.getManifestFile(), em);
433: ProjectManager.getDefault().saveProject(p);
434: assertEquals("right spec.version.base", "1.1", e
435: .getSpecificationVersion());
436: ep.setProperty(SingleModuleProperties.SPEC_VERSION_BASE,
437: "1.2.0");
438: p.getHelper().putProperties(
439: AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
440: ProjectManager.getDefault().saveProject(p);
441: assertEquals("right modified spec.version.base", "1.2", e
442: .getSpecificationVersion());
443: }
444:
445: }
|