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.io.FileNotFoundException;
046: import java.io.FileOutputStream;
047: import java.io.IOException;
048: import java.io.InputStream;
049: import java.io.PrintStream;
050: import java.util.Collections;
051: import java.util.HashSet;
052: import java.util.Iterator;
053: import java.util.Properties;
054: import java.util.Set;
055: import org.apache.tools.ant.BuildException;
056: import org.apache.tools.ant.Project;
057: import org.netbeans.junit.NbTestCase;
058:
059: /**
060: *
061: * @author pzajac
062: */
063: public class FixTestDependenciesTest extends NbTestCase {
064:
065: public FixTestDependenciesTest(String testName) {
066: super (testName);
067: }
068:
069: public void testSimple() throws IOException, Exception {
070: File prjFile = copyFile("FixTestDependenciesProject.xml");
071: File propertiesFile = copyFile("FixTestDependencies.properties");
072: doFixProjectXml(propertiesFile, prjFile);
073: doFixProjectXml(propertiesFile,
074: copyFile("FixTestDependenciesProject2.xml"));
075: }
076:
077: public void testStandalone() throws IOException, Exception {
078: File prjFile = copyFile("FixTestDependenciesProjectStandalone.xml");
079: File propertiesFile = copyFile("FixTestDependencies.properties");
080: FixTestDependencies ftd = newFixTestDependencies();
081: ftd.setPropertiesFile(propertiesFile);
082: ftd.setProjectXml(prjFile);
083: ftd.cachedEntries = getEntries();
084: ftd.execute();
085: assertFile(
086: copyFile("FixTestDependenciesProjectStandalonePass.xml"),
087: prjFile);
088: assertFile(copyFile("FixTestDependenciesPass.properties"),
089: propertiesFile);
090: }
091:
092: public void testWrongBuilClassDep() throws IOException {
093: FixTestDependencies ftd = newFixTestDependencies();
094: Set/*<String>*/cnb = new HashSet();
095: Set/*<String>*/testCnb = new HashSet();
096:
097: Properties props = new Properties();
098: String PNAME = "cp.extra";
099: String PVALUE = "../build/test/unit/classes";
100: props.setProperty(PNAME, PVALUE);
101: ftd.readCodeNameBases(cnb, testCnb, props, "cp.extra",
102: Collections.EMPTY_SET, Collections.EMPTY_SET);
103: assertEquals("No dependency on module.", 0, cnb.size());
104: assertEquals("No test dependency on module.", 0, testCnb.size());
105: assertEquals("property value", PVALUE, props.getProperty(PNAME));
106: }
107:
108: private FixTestDependencies newFixTestDependencies()
109: throws IOException, BuildException {
110: Project project = new Project();
111: project.setBaseDir(getWorkDir());
112: FixTestDependencies ftd = new FixTestDependencies();
113: ftd.setProject(project);
114: return ftd;
115: }
116:
117: private void doFixProjectXml(final File propertiesFile,
118: final File prjFile) throws Exception, IOException {
119: FixTestDependencies ftd = newFixTestDependencies();
120: ftd.setPropertiesFile(propertiesFile);
121: ftd.setProjectXml(prjFile);
122: ftd.cachedEntries = getEntries();
123: ftd.execute();
124: assertFile(copyFile("FixTestDependenciesProjectPass.xml"),
125: prjFile);
126: assertFile(copyFile("FixTestDependenciesPass.properties"),
127: propertiesFile);
128: }
129:
130: private File copyFile(String resourceName) throws IOException {
131: InputStream is = getClass().getResourceAsStream(resourceName);
132: byte buf[] = new byte[10000];
133: File retFile = new File(getWorkDir(), resourceName);
134: FileOutputStream fos = new FileOutputStream(retFile);
135: int size;
136: while ((size = is.read(buf)) > 0) {
137: fos.write(buf, 0, size);
138: }
139: is.close();
140: fos.close();
141: return retFile;
142: }
143:
144: /**
145: * generates body of method the method creates the content of entries
146: */
147: private void logEntries(HashSet cachedCNB, Set entries)
148: throws FileNotFoundException, IOException {
149: FileOutputStream fos = new FileOutputStream("/tmp/test", true);
150: try {
151: PrintStream ps = new PrintStream(fos);
152: ps.println("Set getEntris() {");
153: ps.println(" Set entries = new HashSet();");
154: for (Iterator it = cachedCNB.iterator(); it.hasNext();) {
155: String cnb = (String) it.next();
156: for (Iterator eIt = entries.iterator(); eIt.hasNext();) {
157: ModuleListParser.Entry entry = (ModuleListParser.Entry) eIt
158: .next();
159: if (!cnb.equals(entry.getCnb())) {
160: continue;
161: }
162: ps
163: .println("entries.add(new ModuleListParser.Entry(\""
164: + entry.getCnb()
165: + "\","
166: + getLogFileName(entry.getJar())
167: + ",");
168: File files[] = entry.getClassPathExtensions();
169: if (files.length == 0) {
170: ps.print(" new File[0],");
171: } else {
172: ps.print(" new File[]{");
173: for (int ce = 0; ce < files.length; ce++) {
174: if (ce != 0) {
175: ps.print(",");
176: }
177: ps.print(getLogFileName(files[ce]));
178: }
179: ps.println("},");
180: }
181: ps.println(" null,\""
182: + entry.getNetbeansOrgPath() + "\",");
183:
184: String bp[] = entry.getBuildPrerequisites();
185: if (bp.length == 0) {
186: ps.println(" new String[0],");
187: } else {
188: ps.print(" new String[]{");
189: for (int ce = 0; ce < bp.length; ce++) {
190: if (ce != 0) {
191: ps.print(",");
192: }
193: ps.print("\"" + bp[ce] + "\"");
194: }
195: ps.println("},");
196: }
197: ps.println(" \"" + entry.getClusterName()
198: + "\",");
199: bp = entry.getRuntimeDependencies();
200: if (bp.length == 0) {
201: ps.print(" new String[0]");
202: } else {
203: ps.print(" new String[]{");
204: for (int ce = 0; ce < bp.length; ce++) {
205: if (ce != 0) {
206: ps.print(",");
207: }
208: ps.print("\"" + bp[ce] + "\"");
209: }
210: ps.print("}");
211: }
212: ps.println("));");
213: }
214: }
215: ps.println("}");
216: } finally {
217: fos.close();
218: }
219: }
220:
221: private String getLogFileName(File file) {
222: String path = file.getAbsolutePath();
223: String NB = "/netbeans/";
224: int idx = path.indexOf(NB);
225: String name = (idx == -1) ? "nonsence:" + file.getPath() : path
226: .substring(idx + NB.length());
227: return "new File(\"" + name + "\")";
228:
229: }
230:
231: private Set getEntries() {
232: Set entries = new HashSet();
233: entries.add(new ModuleListParser.Entry("org.openide.io",
234: new File("extra/modules/org-openide-io.jar"),
235: new File[0], null, "openide/io",
236: new String[] { "org.openide.util" }, "extra",
237: new String[] { "org.openide.util" }, null));
238: entries.add(new ModuleListParser.Entry("org.openide.compat",
239: new File("extra/modules/org-openide-compat.jar"),
240: new File[0], null, "openide/compat", new String[] {
241: "org.netbeans.core", "org.openide.actions",
242: "org.openide.awt", "org.openide.dialogs",
243: "org.openide.explorer",
244: "org.openide.filesystems", "org.openide.nodes",
245: "org.openide.options", "org.openide.text",
246: "org.openide.util", "org.openide.windows" },
247: "extra", new String[] { "org.netbeans.core",
248: "org.openide.actions", "org.openide.awt",
249: "org.openide.dialogs", "org.openide.explorer",
250: "org.openide.filesystems", "org.openide.nodes",
251: "org.openide.options", "org.openide.text",
252: "org.openide.util", "org.openide.windows" },
253: null));
254: entries
255: .add(new ModuleListParser.Entry(
256: "org.netbeans.modules.projectapi",
257: new File(
258: "extra/modules/org-netbeans-modules-projectapi.jar"),
259: new File[0], null, "projects/projectapi",
260: new String[] { "org.netbeans.modules.queries",
261: "org.openide.filesystems",
262: "org.openide.util" }, "extra",
263: new String[] { "org.netbeans.modules.queries",
264: "org.openide.filesystems",
265: "org.openide.util" }, null));
266: entries.add(new ModuleListParser.Entry("org.openide.loaders",
267: new File("extra/modules/org-openide-loaders.jar"),
268: new File[0], null, "openide/loaders", new String[] {
269: "org.netbeans.api.progress",
270: "org.openide.actions", "org.openide.awt",
271: "org.openide.dialogs", "org.openide.explorer",
272: "org.openide.filesystems",
273: "org.openide.modules", "org.openide.nodes",
274: "org.openide.text", "org.openide.util",
275: "org.openide.windows" }, "extra", new String[] {
276: "org.netbeans.api.progress",
277: "org.openide.actions", "org.openide.awt",
278: "org.openide.dialogs", "org.openide.explorer",
279: "org.openide.filesystems",
280: "org.openide.modules", "org.openide.nodes",
281: "org.openide.text", "org.openide.util",
282: "org.openide.windows" }, null));
283: entries.add(new ModuleListParser.Entry("org.netbeans.core",
284: new File("extra/modules/org-netbeans-core.jar"),
285: new File[0], null, "core", new String[] {
286: "org.netbeans.bootstrap",
287: "org.netbeans.core.startup",
288: "org.netbeans.swing.plaf",
289: "org.openide.actions", "org.openide.awt",
290: "org.openide.dialogs", "org.openide.explorer",
291: "org.openide.filesystems",
292: "org.openide.loaders", "org.openide.modules",
293: "org.openide.nodes", "org.openide.options",
294: "org.openide.text", "org.openide.util",
295: "org.openide.windows" }, "extra", new String[] {
296: "org.netbeans.bootstrap",
297: "org.netbeans.core.startup",
298: "org.netbeans.swing.plaf",
299: "org.openide.actions", "org.openide.awt",
300: "org.openide.dialogs", "org.openide.explorer",
301: "org.openide.filesystems",
302: "org.openide.loaders", "org.openide.modules",
303: "org.openide.nodes", "org.openide.options",
304: "org.openide.text", "org.openide.util",
305: "org.openide.windows" }, null));
306: entries
307: .add(new ModuleListParser.Entry(
308: "org.netbeans.modules.masterfs",
309: new File(
310: "extra/modules/org-netbeans-modules-masterfs.jar"),
311: new File[0], null, "openide/masterfs",
312: new String[] { "org.openide.filesystems",
313: "org.openide.util",
314: "org.openide.options",
315: "org.netbeans.modules.queries" },
316: "extra", new String[] {
317: "org.openide.filesystems",
318: "org.openide.util",
319: "org.openide.options",
320: "org.netbeans.modules.queries" }, null));
321: entries.add(new ModuleListParser.Entry(
322: "org.netbeans.bootstrap",
323: new File("extra/lib/boot.jar"), new File[0], null,
324: "core/bootstrap", new String[] { "org.openide.modules",
325: "org.openide.util" }, "extra", new String[] {
326: "org.openide.modules", "org.openide.util" },
327: null));
328: entries
329: .add(new ModuleListParser.Entry(
330: "org.netbeans.libs.xerces",
331: new File(
332: "extra/modules/org-netbeans-libs-xerces.jar"),
333: new File[] {
334: new File(
335: "nonsence:/home/pzajac/cvss/freshtrunk/libs/external/xerces-2.8.0.jar"),
336: new File(
337: "nonsence:/home/pzajac/cvss/freshtrunk/libs/external/xml-commons-dom-ranges-1.0.b2.jar") },
338: null, "libs/xerces", new String[0], "extra",
339: new String[0], null));
340: entries.add(new ModuleListParser.Entry(
341: "org.netbeans.api.progress", new File(
342: "extra/modules/org-netbeans-api-progress.jar"),
343: new File[0], null, "core/progress", new String[] {
344: "org.openide.util", "org.openide.awt" },
345: "extra", new String[] { "org.openide.util",
346: "org.openide.awt" }, null));
347: entries.add(new ModuleListParser.Entry("org.openide.options",
348: new File("extra/modules/org-openide-options.jar"),
349: new File[0], null, "openide/options",
350: new String[] { "org.openide.util" }, "extra",
351: new String[] { "org.openide.util" }, null));
352: entries.add(new ModuleListParser.Entry("org.openide.explorer",
353: new File("extra/modules/org-openide-explorer.jar"),
354: new File[0], null, "openide/explorer", new String[] {
355: "org.openide.util", "org.openide.nodes",
356: "org.openide.awt", "org.openide.dialogs",
357: "org.openide.options" }, "extra", new String[] {
358: "org.openide.util", "org.openide.nodes",
359: "org.openide.awt", "org.openide.dialogs",
360: "org.openide.options" }, null));
361: entries.add(new ModuleListParser.Entry("org.openide.dialogs",
362: new File("extra/modules/org-openide-dialogs.jar"),
363: new File[0], null, "openide/dialogs", new String[] {
364: "org.netbeans.api.progress", "org.openide.awt",
365: "org.openide.util" }, "extra", new String[] {
366: "org.netbeans.api.progress", "org.openide.awt",
367: "org.openide.util" }, null));
368: entries.add(new ModuleListParser.Entry("org.openide.nodes",
369: new File("extra/modules/org-openide-nodes.jar"),
370: new File[0], null, "openide/nodes", new String[] {
371: "org.openide.util", "org.openide.awt",
372: "org.openide.dialogs" }, "extra", new String[] {
373: "org.openide.util", "org.openide.awt",
374: "org.openide.dialogs" }, null));
375: entries.add(new ModuleListParser.Entry("org.openide.awt",
376: new File("extra/modules/org-openide-awt.jar"),
377: new File[0], null, "openide/awt",
378: new String[] { "org.openide.util" }, "extra",
379: new String[] { "org.openide.util" }, null));
380: entries.add(new ModuleListParser.Entry("org.openide.text",
381: new File("extra/modules/org-openide-text.jar"),
382: new File[0], null, "openide/text", new String[] {
383: "org.netbeans.modules.editor.mimelookup",
384: "org.openide.awt", "org.openide.dialogs",
385: "org.openide.nodes", "org.openide.options",
386: "org.openide.util", "org.openide.windows" },
387: "extra", new String[] {
388: "org.netbeans.modules.editor.mimelookup",
389: "org.openide.awt", "org.openide.dialogs",
390: "org.openide.nodes", "org.openide.options",
391: "org.openide.util", "org.openide.windows" },
392: null));
393: entries.add(new ModuleListParser.Entry("org.openide.actions",
394: new File("extra/modules/org-openide-actions.jar"),
395: new File[0], null, "openide/actions", new String[] {
396: "org.openide.util", "org.openide.nodes",
397: "org.openide.awt", "org.openide.options",
398: "org.openide.text", "org.openide.explorer",
399: "org.openide.dialogs", "org.openide.windows" },
400: "extra", new String[] { "org.openide.util",
401: "org.openide.nodes", "org.openide.awt",
402: "org.openide.options", "org.openide.text",
403: "org.openide.explorer", "org.openide.dialogs",
404: "org.openide.windows" }, null));
405: entries.add(new ModuleListParser.Entry("org.openide.util",
406: new File("extra/lib/org-openide-util.jar"),
407: new File[0], null, "openide/util", new String[0],
408: "extra", new String[0], null));
409: entries.add(new ModuleListParser.Entry(
410: "org.netbeans.core.startup", new File(
411: "extra/core/core.jar"), new File[0], null,
412: "core/startup", new String[] {
413: "org.netbeans.bootstrap",
414: "org.openide.filesystems",
415: "org.openide.modules", "org.openide.util" },
416: "extra", new String[] { "org.netbeans.bootstrap",
417: "org.openide.filesystems",
418: "org.openide.modules", "org.openide.util" },
419: null));
420: entries.add(new ModuleListParser.Entry("org.openide.modules",
421: new File("extra/lib/org-openide-modules.jar"),
422: new File[0], null, "openide/modules",
423: new String[] { "org.openide.util" }, "extra",
424: new String[] { "org.openide.util" }, null));
425: entries.add(new ModuleListParser.Entry(
426: "org.openide.filesystems", new File(
427: "extra/core/org-openide-filesystems.jar"),
428: new File[0], null, "openide/fs",
429: new String[] { "org.openide.util" }, "extra",
430: new String[] { "org.openide.util" }, null));
431: return entries;
432: }
433: }
|