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;
043:
044: import java.io.File;
045: import java.util.Collections;
046:
047: /**
048: * Test functionality of ManifestManager.
049: *
050: * @author Martin Krauskopf
051: */
052: public class ManifestManagerTest extends TestBase {
053:
054: // XXX test also implementation version
055:
056: public ManifestManagerTest(String name) {
057: super (name);
058: }
059:
060: private File suite1, suite2;
061:
062: protected void setUp() throws Exception {
063: super .setUp();
064: suite1 = resolveEEPFile("suite1");
065: suite2 = resolveEEPFile("suite2");
066: }
067:
068: public void testDirectManifestFile() throws Exception {
069: File basedir = new File(suite2, "misc-project");
070: ManifestManager mm = ManifestManager.getInstance(new File(
071: basedir, "manifest.mf"), false);
072: assertEquals("right codeNameBase",
073: "org.netbeans.examples.modules.misc", mm
074: .getCodeNameBase());
075: assertEquals("right release version", "1", mm
076: .getReleaseVersion());
077: assertEquals("right specification version", "1.0", mm
078: .getSpecificationVersion());
079: assertEquals("right localizing bundle",
080: "org/netbeans/examples/modules/misc/Bundle.properties",
081: mm.getLocalizingBundle());
082:
083: basedir = new File(suite1, "action-project");
084: mm = ManifestManager.getInstance(new File(basedir,
085: "manifest.mf"), false);
086: assertEquals("right codeNameBase",
087: "org.netbeans.examples.modules.action", mm
088: .getCodeNameBase());
089: assertNull("no release version", mm.getReleaseVersion());
090: }
091:
092: public void testFriends() throws Exception {
093: File manifest = new File(getWorkDir(), "testManifest.mf");
094: String mfContent = "Manifest-Version: 1.0\n"
095: + "Ant-Version: Apache Ant 1.6.5\n"
096: + "Created-By: 1.4.2_10-b03 (Sun Microsystems Inc.)\n"
097: + "OpenIDE-Module-Public-Packages: org.netbeans.modules.editor.hints.spi.*\n"
098: + "OpenIDE-Module-Friends: org.netbeans.modules.java.hints, org.netbeans.\n"
099: + " modules.j2ee.ejbcore, org.netbeans.modules.kjava.editor\n"
100: + "OpenIDE-Module-Module-Dependencies: org.openide.filesystems > 6.2, org\n"
101: + " .openide.util > 6.2, org.openide.modules > 6.2, org.openide.nodes > 6\n"
102: + " .2, org.openide.awt > 6.2, org.openide.text > 6.2, org.openide.loader\n"
103: + " s, org.netbeans.modules.editor.lib/1, org.netbeans.modules.editor.mim\n"
104: + " elookup/1\n"
105: + "OpenIDE-Module-Build-Version: 060123\n"
106: + "OpenIDE-Module-Specification-Version: 1.10.0.1\n"
107: + "OpenIDE-Module: org.netbeans.modules.editor.hints/1\n"
108: + "OpenIDE-Module-Implementation-Version: 1\n"
109: + "OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/editor/hints/re\n"
110: + " sources/Bundle.properties\n"
111: + "OpenIDE-Module-Install: org/netbeans/modules/editor/hints/HintsModule.\n"
112: + " class\n"
113: + "OpenIDE-Module-Requires: org.openide.modules.ModuleFormat1\n";
114: dump(manifest, mfContent);
115: ManifestManager mm = ManifestManager
116: .getInstance(manifest, true);
117: assertEquals("one public package", 1,
118: mm.getPublicPackages().length);
119: }
120:
121: public void testJarWithNoManifest() throws Exception {
122: // See #87064.
123: File jar = new File(getWorkDir(), "test.jar");
124: TestBase.createJar(jar, Collections.singletonMap("foo", "bar"),
125: null);
126: ManifestManager.getInstanceFromJAR(jar);
127: }
128:
129: }
|