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: package org.netbeans.nbbuild;
042:
043: import java.io.FileOutputStream;
044: import java.io.FileWriter;
045: import java.util.jar.JarEntry;
046: import java.util.jar.JarOutputStream;
047: import java.util.jar.Manifest;
048: import junit.framework.*;
049: import java.io.File;
050: import java.io.IOException;
051: import java.util.HashSet;
052: import java.util.Set;
053: import java.util.StringTokenizer;
054: import java.util.jar.JarFile;
055: import org.apache.tools.ant.BuildException;
056: import org.apache.tools.ant.types.Parameter;
057: import org.apache.tools.ant.types.selectors.SelectorUtils;
058:
059: import org.netbeans.junit.NbTestCase;
060:
061: /** Check behaviour of ModuleSelector.
062: *
063: * @author Jaroslav Tulach
064: */
065: public class CreateModuleXMLTest extends NbTestCase {
066:
067: public CreateModuleXMLTest(String testName) {
068: super (testName);
069: }
070:
071: public void testIncludesAllModulesByDefault() throws Exception {
072: Manifest m = ModuleDependenciesTest.createManifest();
073: m.getMainAttributes().putValue("OpenIDE-Module",
074: "org.my.module");
075: File aModule = generateJar(new String[0], m);
076:
077: File output = new File(getWorkDir(), "output");
078:
079: java.io.File f = PublicPackagesInProjectizedXMLTest
080: .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
081: + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
082: + " <taskdef name=\"createmodulexml\" classname=\"org.netbeans.nbbuild.CreateModuleXML\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
083: + "<target name=\"all\" >"
084: + " <mkdir dir='"
085: + output
086: + "' />"
087: + " <createmodulexml xmldir='"
088: + output
089: + "' >"
090: + " <hidden dir='"
091: + aModule.getParent()
092: + "' >"
093: + " <include name='"
094: + aModule.getName()
095: + "' />"
096: + " </hidden>"
097: + " </createmodulexml>"
098: + "</target>"
099: + "</project>");
100: PublicPackagesInProjectizedXMLTest.execute(f,
101: new String[] { "-verbose" });
102:
103: assertTrue("Output exists", output.exists());
104: assertTrue("Output directory created", output.isDirectory());
105:
106: String[] files = output.list();
107: assertEquals("It one file", 1, files.length);
108: assertEquals("Its name reflects the code name of the module",
109: "org-my-module.xml_hidden", files[0]);
110:
111: }
112:
113: private final File createNewJarFile() throws IOException {
114: File dir = new File(this .getWorkDir(), "modules");
115: dir.mkdirs();
116:
117: int i = 0;
118: for (;;) {
119: File f = new File(dir, i++ + ".jar");
120: if (!f.exists())
121: return f;
122: }
123: }
124:
125: protected final File generateJar(String[] content, Manifest manifest)
126: throws IOException {
127: File f = createNewJarFile();
128:
129: JarOutputStream os;
130: if (manifest != null) {
131: os = new JarOutputStream(new FileOutputStream(f), manifest);
132: } else {
133: os = new JarOutputStream(new FileOutputStream(f));
134: }
135:
136: for (int i = 0; i < content.length; i++) {
137: os.putNextEntry(new JarEntry(content[i]));
138: os.closeEntry();
139: }
140: os.closeEntry();
141: os.close();
142:
143: return f;
144: }
145:
146: }
|