001: /**************************************************************************/
002: /* N I C E */
003: /* A high-level object-oriented research language */
004: /* (c) Daniel Bonniot 2004 */
005: /* */
006: /* This program is free software; you can redistribute it and/or modify */
007: /* it under the terms of the GNU General Public License as published by */
008: /* the Free Software Foundation; either version 2 of the License, or */
009: /* (at your option) any later version. */
010: /* */
011: /**************************************************************************/package nice.tools.ant;
012:
013: import org.apache.tools.ant.*;
014: import org.apache.tools.ant.types.*;
015: import java.io.File;
016: import java.util.Vector;
017: import bossa.modules.Compilation;
018:
019: /**
020: <h2><a name="java">NiceUnit</a></h2>
021: <h3>Description</h3>
022: <p>Runs unit tests for a Nice package.</p>
023: All arguments to the NiceUnit task have to be placed as attributes in the niceunit xml-element.
024: <h3>Parameters</h3>
025: <table border="1" cellpadding="2" cellspacing="0">
026: <tr>
027: <td valign="top"><b>Attribute</b></td>
028: <td valign="top"><b>Description</b></td>
029: <td align="center" valign="top"><b>Required</b></td>
030: </tr>
031: <tr>
032: <td valign="top">package</td>
033: <td valign="top">The Nice package to test.</td>
034: <td align="center" valign="top">Yes</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>NiceUnit</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: <niceunit package="test" >
050: <classpath>
051: <pathelement location="\test.jar"/>
052: <pathelement path="${java.class.path}"/>
053: </classpath>
054: </niceunit>
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="niceunit" classname="nice.tools.ant.NiceUnit"/>
064: <target name="nice-tests">
065: <niceunit package="test" />
066: </target>
067: </pre>
068:
069:
070: * @author Daniel Bonniot
071: */
072:
073: public class NiceUnit extends Task {
074:
075: /** Search path for compiled packages and libraries.
076: */
077: private String classpath = "";
078:
079: public void setClasspath(String classpath) {
080: this .classpath = classpath;
081: }
082:
083: /** Location of nice.jar
084: */
085: private String runtime = null;
086:
087: public void setRuntime(String runtime) {
088: this .runtime = runtime;
089: }
090:
091: /** The package to test.
092: */
093: private String pack;
094:
095: public void setPackage(String pack) {
096: this .pack = pack;
097: }
098:
099: private Path nestedClasspath = null;
100:
101: /**
102: * Creates a nested classpath element
103: */
104: public Path createClasspath() {
105: nestedClasspath = new Path(project);
106: return nestedClasspath.createPath();
107: }
108:
109: /** Executes niceunit.
110: */
111: public void execute() throws BuildException {
112:
113: String oldUserDir = System.getProperty("user.dir");
114: try {
115: System.setProperty("user.dir", project.getBaseDir()
116: .getAbsolutePath());
117:
118: TestListener listener = new TestListener(this );
119:
120: String classpath = this .classpath
121: + (nestedClasspath != null ? File.pathSeparator
122: + nestedClasspath : "");
123:
124: if (!nice.tools.unit.fun.runTests(pack, listener,
125: classpath, null))
126: throw new BuildException("Package " + pack
127: + " was not found");
128:
129: listener.printSummary();
130: } finally {
131: System.setProperty("user.dir", oldUserDir);
132: }
133: }
134:
135: }
136:
137: // Setting for Emacs
138: // Local variables:
139: // tab-width:2
140: // indent-tabs-mode:t
141: // End:
|