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.queries;
043:
044: import java.io.File;
045: import java.net.URL;
046: import java.util.SortedSet;
047: import java.util.TreeSet;
048: import org.netbeans.api.java.classpath.ClassPath;
049: import org.netbeans.api.java.queries.JavadocForBinaryQuery;
050: import org.netbeans.modules.apisupport.project.TestBase;
051: import org.netbeans.modules.apisupport.project.Util;
052:
053: /**
054: * Test {@link JavadocForBinaryImpl}.
055: *
056: * @author Jesse Glick
057: */
058: public class JavadocForBinaryImplTest extends TestBase {
059:
060: static {
061: JavadocForBinaryImpl.ignoreNonexistentRoots = false;
062: }
063:
064: private File suite2, suite3;
065:
066: public JavadocForBinaryImplTest(String name) {
067: super (name);
068: }
069:
070: protected void setUp() throws Exception {
071: super .setUp();
072: suite2 = resolveEEPFile("suite2");
073: suite3 = resolveEEPFile("suite3");
074: }
075:
076: public void testJavadocForNetBeansOrgModules() throws Exception {
077: // Have to load at least one module to get the scan going.
078: ClassPath.getClassPath(nbRoot().getFileObject(
079: "o.apache.tools.ant.module/src"), ClassPath.COMPILE);
080: File classfileJar = file("nbbuild/netbeans/"
081: + TestBase.CLUSTER_IDE
082: + "/modules/org-netbeans-modules-classfile.jar");
083: URL[] roots = JavadocForBinaryQuery.findJavadoc(
084: Util.urlForJar(classfileJar)).getRoots();
085: URL[] expectedRoots = {
086: Util
087: .urlForDir(file("nbbuild/build/javadoc/org-netbeans-modules-classfile")),
088: urlForJar(apisZip, "org-netbeans-modules-classfile/"), };
089: assertEquals("correct Javadoc roots for classfile",
090: urlSet(expectedRoots), urlSet(roots));
091: }
092:
093: public void testJavadocForExternalModules() throws Exception {
094: ClassPath.getClassPath(resolveEEP("/suite2/misc-project/src"),
095: ClassPath.COMPILE);
096: File miscJar = resolveEEPFile("/suite2/build/cluster/modules/org-netbeans-examples-modules-misc.jar");
097: URL[] roots = JavadocForBinaryQuery.findJavadoc(
098: Util.urlForJar(miscJar)).getRoots();
099: URL[] expectedRoots = new URL[] {
100: Util
101: .urlForDir(file(suite2,
102: "misc-project/build/javadoc/org-netbeans-examples-modules-misc")),
103: // It is inside ${netbeans.home}/.. so read this.
104: urlForJar(apisZip,
105: "org-netbeans-examples-modules-misc/"), };
106: assertEquals("correct Javadoc roots for misc",
107: urlSet(expectedRoots), urlSet(roots));
108: ClassPath.getClassPath(resolveEEP("/suite3/dummy-project/src"),
109: ClassPath.COMPILE);
110: File dummyJar = file(suite3,
111: "dummy-project/build/cluster/modules/org-netbeans-examples-modules-dummy.jar");
112: roots = JavadocForBinaryQuery.findJavadoc(
113: Util.urlForJar(dummyJar)).getRoots();
114: expectedRoots = new URL[] { Util
115: .urlForDir(file(suite3,
116: "dummy-project/build/javadoc/org-netbeans-examples-modules-dummy")), };
117: assertEquals("correct Javadoc roots for dummy",
118: urlSet(expectedRoots), urlSet(roots));
119: }
120:
121: private static URL urlForJar(File jar, String path)
122: throws Exception {
123: return new URL(Util.urlForJar(jar), path);
124: }
125:
126: private static SortedSet<String> urlSet(URL[] urls) {
127: SortedSet<String> set = new TreeSet<String>();
128: for (URL url : urls) {
129: set.add(url.toExternalForm());
130: }
131: return set;
132: }
133:
134: }
|