001: package nice.tools.ant;
002:
003: import org.apache.tools.ant.*;
004: import org.apache.tools.ant.types.*;
005: import java.io.File;
006: import java.util.Vector;
007: import bossa.modules.Compilation;
008:
009: /**
010: <h2><a name="java">NiceDoc</a></h2>
011: <h3>Description</h3>
012: <p>Runs the Nice documentation generator.</p>
013: All arguments to the NiceDoc task have to be placed as attributes in the nicedoc xml-element.
014: <h3>Parameters</h3>
015: <table border="1" cellpadding="2" cellspacing="0">
016: <tr>
017: <td valign="top"><b>Attribute</b></td>
018: <td valign="top"><b>Description</b></td>
019: <td align="center" valign="top"><b>Required</b></td>
020: </tr>
021: <tr>
022: <td valign="top">package</td>
023: <td valign="top">The Nice package to compile.</td>
024: <td align="center" valign="top">Yes</td>
025: </tr>
026: <tr>
027: <td valign="top">sourcepath</td>
028: <td valign="top">Search path for source packages. Is a list of directories and .jar archives.</td>
029: <td align="center" valign="top">No</td>
030: </tr>
031: <tr>
032: <td valign="top">destination</td>
033: <td valign="top">Destination directory for compiled packages.</td>
034: <td align="center" valign="top">No</td>
035: </tr>
036: <tr>
037: <td valign="top">classpath</td>
038: <td valign="top">Search path for compiled packages and libraries.</td>
039: <td align="center" valign="top">No</td>
040: </tr>
041: </table>
042:
043: <h4>classpath</h4>
044: <p><code>Nicec</code>'s <i>classpath</i> attribute is a PATH like structure and can also be set via a nested
045: <i>classpath</i> element. This is very reasonable if you want to make your build script's pathes platform
046: independent. </p>
047: <h5>Example</h5>
048: <pre>
049: <nicedoc package="test" >
050: <classpath>
051: <pathelement location="\test.jar"/>
052: <pathelement path="${java.class.path}"/>
053: </classpath>
054: </nicedoc>
055: </pre>
056: <p>It is possible to use the <i>classpath</i> attribute together with the
057: <i>classpath<i> nested tag. In this case the result is a concatenated path.</p>
058: <p>It is highly recommended to use the nested version!<p>
059:
060:
061: <h3>Examples</h3>
062: <pre>
063: <taskdef name="nicedoc" classname="nice.tools.ant.NiceDoc"/>
064: <target name="nice-documentation">
065: <nicedoc package="test" />
066: </target>
067: </pre>
068:
069:
070: * @author Daniel Bonniot
071: */
072:
073: public class NiceDoc extends Task {
074:
075: private static final String ERROR_MSG = "Generation failed with errors.";
076: private static final String BUG_MSG = "Generation failed because of a bug.";
077: private static final String WARNING_MSG = "Generation successful despite warnings.";
078: private static final String OK_MSG = "Generation successful.";
079:
080: /** Search path for source packages
081: PATH is a list of directories and .jar archives
082: */
083: private String sourcepath;
084:
085: public void setSourcepath(String sourcepath) {
086: this .sourcepath = sourcepath;
087: }
088:
089: /** Destination directory for compiled packages
090: */
091: private File destination;
092:
093: public void setDestination(File destdir) {
094: this .destination = destdir;
095: }
096:
097: /** Search path for compiled packages and libraries
098: */
099: private String classpath = "";
100:
101: public void setClasspath(String classpath) {
102: this .classpath = classpath;
103: }
104:
105: /** Location of nice.jar
106: */
107: private String runtime = null;
108:
109: public void setRuntime(String runtime) {
110: this .runtime = runtime;
111: }
112:
113: /** The root package to document.
114: */
115: private String pack;
116:
117: public void setPackage(String pack) {
118: this .pack = pack;
119: }
120:
121: private Path nestedClasspath = null;
122:
123: /**
124: * Creates a nested classpath element
125: */
126: public Path createClasspath() {
127: nestedClasspath = new Path(project);
128: return nestedClasspath.createPath();
129: }
130:
131: /** Executes nicedoc.
132: */
133: public void execute() throws BuildException {
134:
135: String oldUserDir = System.getProperty("user.dir");
136: try {
137: System.setProperty("user.dir", project.getBaseDir()
138: .getAbsolutePath());
139:
140: NicecListener listener = new NicecListener(this );
141: Compilation compilation = bossa.modules.fun
142: .createCompilation(listener,
143: new bossa.parser.JavaccParser(true));
144: if (sourcepath != null)
145: compilation.sourcePath = sourcepath;
146: compilation.packagePath = classpath
147: + (nestedClasspath != null ? File.pathSeparator
148: + nestedClasspath : "");
149:
150: nice.tools.doc.fun.generate(compilation, pack, destination);
151:
152: int retval = listener.statusCode;
153:
154: switch (retval) {
155: case nice.tools.compiler.fun.ERROR:
156: throw new BuildException(ERROR_MSG, location);
157: case nice.tools.compiler.fun.BUG:
158: throw new BuildException(BUG_MSG, location);
159: case nice.tools.compiler.fun.WARNING:
160: log(WARNING_MSG, Project.MSG_WARN);
161: break;
162: case nice.tools.compiler.fun.OK:
163: log(OK_MSG, Project.MSG_INFO);
164: break;
165: }
166: } finally {
167: System.setProperty("user.dir", oldUserDir);
168: }
169: }
170:
171: }
172:
173: // Setting for Emacs
174: // Local variables:
175: // tab-width:2
176: // indent-tabs-mode:t
177: // End:
|