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.util.*;
046: import java.util.ArrayList;
047: import java.util.ArrayList;
048:
049: import org.apache.tools.ant.BuildException;
050: import org.apache.tools.ant.Task;
051: import org.apache.tools.ant.taskdefs.*;
052: import org.apache.tools.ant.types.*;
053:
054: /**
055: * This class generating javadoc
056: * @author Michal Zlamal
057: */
058: public class GenerateJavadoc extends Task {
059: private File dest;
060: private List<String> modules = new ArrayList<String>();
061: private String packageNames = null;
062: private List<File> topdirs = new ArrayList<File>();
063:
064: /** Target directory to unpack to (top of IDE installation). */
065: public void setDestdir(File f) {
066: dest = f;
067: }
068:
069: /** Comma-separated list of modules to include. */
070: public void setModules(String s) {
071: StringTokenizer tok = new StringTokenizer(s, ",");
072: modules = new ArrayList<String>();
073: while (tok.hasMoreTokens())
074: modules.add(tok.nextToken());
075: }
076:
077: /** Comma-separated list of modules to include. */
078: public void setPackageNames(String s) {
079: packageNames = s;
080: }
081:
082: /** Set the top directory.
083: * There should be subdirectories under this for each named module.
084: */
085: public void setTopdir(File t) {
086: topdirs.add(t);
087: }
088:
089: /** Nested topdir addition. */
090: public class Topdir {
091: /** Path to an extra topdir. */
092: public void setPath(File t) {
093: topdirs.add(t);
094: }
095: }
096:
097: /** Add a nested topdir.
098: * If there is more than one topdir total, build products
099: * may be taken from any of them, including from multiple places
100: * for the same module. (Later topdirs may override build
101: * products in earlier topdirs.)
102: */
103: public Topdir createTopdir() {
104: return new Topdir();
105: }
106:
107: public void execute() throws BuildException {
108:
109: if (topdirs.isEmpty()) {
110: throw new BuildException(
111: "You must set at least one topdir attribute",
112: getLocation());
113: }
114:
115: /* Delete delete = (Delete) project.createTask ("delete");
116:
117: delete.setDir (dest);
118: delete.init ();
119: delete.setLocation (location);
120: delete.execute ();*/
121: Path path = new Path(getProject());
122: for (File topdir : topdirs) {
123: for (String module : modules) {
124: File sources = new File(new File(topdir, module),
125: "javadoc-temp/");
126: if (!sources.exists()) { //testing existination of 'javadoc-temp' dir if existing - skiping dafult source dirs...
127: sources = new File(new File(topdir, module), "src/");
128: if (sources.exists())
129: path.append(new Path(getProject(), sources
130: .getPath()));
131: sources = new File(new File(topdir, module),
132: "libsrc/");
133: if (sources.exists())
134: path.append(new Path(getProject(), sources
135: .getPath()));
136: } else {
137: path.append(new Path(getProject(), sources
138: .getPath()));
139: }
140: }
141: }
142: Javadoc javaDoc = (Javadoc) getProject().createTask("javadoc");
143: javaDoc.setSourcepath(path);
144:
145: javaDoc.setDestdir(dest);
146: if (packageNames != null)
147: javaDoc.setPackagenames(packageNames);
148: else
149: javaDoc.setPackagenames("org.netbeans.*,com.sun.*");
150: javaDoc.setUse(true);
151: javaDoc.setMaxmemory("256M");
152: javaDoc.execute();
153:
154: }
155: }
|