KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > nbbuild > GenerateJavadoc


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.nbbuild;
21
22 import java.io.File JavaDoc;
23 import java.util.*;
24 import java.util.ArrayList JavaDoc;
25 import java.util.ArrayList JavaDoc;
26
27 import org.apache.tools.ant.BuildException;
28 import org.apache.tools.ant.Task;
29 import org.apache.tools.ant.taskdefs.*;
30 import org.apache.tools.ant.types.*;
31
32 /**
33  * This class generating javadoc
34  * @author Michal Zlamal
35  */

36 public class GenerateJavadoc extends Task
37 {
38     private File JavaDoc dest;
39     private List JavaDoc<String JavaDoc> modules = new ArrayList JavaDoc<String JavaDoc>();
40     private String JavaDoc packageNames = null;
41     private List JavaDoc<File JavaDoc> topdirs = new ArrayList JavaDoc<File JavaDoc>();
42
43     /** Target directory to unpack to (top of IDE installation). */
44     public void setDestdir(File JavaDoc f) {
45         dest = f;
46     }
47
48     /** Comma-separated list of modules to include. */
49     public void setModules (String JavaDoc s) {
50         StringTokenizer tok = new StringTokenizer (s, ",");
51         modules = new ArrayList JavaDoc<String JavaDoc>();
52         while (tok.hasMoreTokens ())
53             modules.add(tok.nextToken ());
54     }
55
56     /** Comma-separated list of modules to include. */
57     public void setPackageNames (String JavaDoc s) {
58         packageNames = s;
59     }
60
61     /** Set the top directory.
62      * There should be subdirectories under this for each named module.
63      */

64     public void setTopdir (File JavaDoc t) {
65         topdirs.add (t);
66     }
67
68     /** Nested topdir addition. */
69     public class Topdir {
70         /** Path to an extra topdir. */
71         public void setPath (File JavaDoc t) {
72             topdirs.add (t);
73         }
74     }
75
76     /** Add a nested topdir.
77      * If there is more than one topdir total, build products
78      * may be taken from any of them, including from multiple places
79      * for the same module. (Later topdirs may override build
80      * products in earlier topdirs.)
81      */

82     public Topdir createTopdir () {
83         return new Topdir ();
84     }
85
86     public void execute () throws BuildException {
87
88         if (topdirs.isEmpty ()) {
89             throw new BuildException("You must set at least one topdir attribute", getLocation());
90         }
91
92 /* Delete delete = (Delete) project.createTask ("delete");
93
94         delete.setDir (dest);
95         delete.init ();
96         delete.setLocation (location);
97         delete.execute ();*/

98         Path path = new Path(getProject());
99         for (File JavaDoc topdir : topdirs) {
100             for (String JavaDoc module : modules) {
101                 File JavaDoc sources = new File JavaDoc (new File JavaDoc (topdir, module), "javadoc-temp/");
102                 if (! sources.exists ()) { //testing existination of 'javadoc-temp' dir if existing - skiping dafult source dirs...
103
sources = new File JavaDoc (new File JavaDoc (topdir, module), "src/");
104                     if (sources.exists ())
105                         path.append(new Path(getProject(), sources.getPath()));
106                     sources = new File JavaDoc (new File JavaDoc (topdir, module), "libsrc/");
107                     if (sources.exists ())
108                         path.append(new Path(getProject(), sources.getPath()));
109                 }
110                 else {
111                     path.append(new Path(getProject(), sources.getPath()));
112                 }
113             }
114         }
115         Javadoc javaDoc = (Javadoc) getProject().createTask("javadoc");
116         javaDoc.setSourcepath( path );
117         
118         javaDoc.setDestdir( dest );
119         if (packageNames != null)
120             javaDoc.setPackagenames(packageNames);
121         else javaDoc.setPackagenames("org.netbeans.*,com.sun.*");
122         javaDoc.setUse(true);
123         javaDoc.setMaxmemory("256M");
124         javaDoc.execute();
125
126     }
127 }
128
Popular Tags