|
Hi,
I just completed the first version of the doclet which
generates the suite file.
In the first version it generates one file only. In the
version 2 I will have it generate
multiple files.
I am just a beginner in xdoclet programming, so please review
the code I have written
and if there is any simpler way of doing the same thing I
would be greatly appreciated!
Thanks!
Michael.
The build.xml file has the following fragment:
============================================================
<target name="junitdoclet"
depends="prepare">
<taskdef
name="junitdoclet"
classname="xdoclet.junit.JunitTask" classpathref="xdoclet.class.path" />
<junitdoclet
sourcepath="${src.dir}" destdir="${generated.src.dir}" mergedir="merge" rootPackage="com.zzz.test"> <classpath refid="class.path"/> <classpath refid="xdoclet.class.path"/> <fileset
dir="${src.dir}">
<include name="**/*.java" /> </fileset>
</junitdoclet>
</target>
========================================================
The template looks like this:
========================================================
package <XDoclet:configParameterValue
paramName="RootPackage"/>;
import junit.framework.*;
public class TestingSuite extends TestCase {
public TestingSuite(String name) { super(name);
}
public void testShouldFail() { fail("The test should
never be invoked directly"); }
public static Test suite() {
TestSuite suite = new TestSuite(); <XDoclet:forAllClasses type="junit.framework.TestCase"> suite.addTest(new TestSuite(<XDoclet:fullClassName/>.class)); </XDoclet:forAllClasses> return suite; } } ========================================================
Two classes were defined:
=========================================================
package xdoclet.junit;
import xdoclet.*;
import org.apache.tools.ant.BuildException; import org.apache.log4j.*; import java.io.File; /**
* @author Michael Larionov * @created October 15, 2001 */ public class JunitTask extends DocletTask { private String
rootPackage;
public void setRootPackage( String newName
)
{ rootPackage = newName; } public String
getRootPackage()
{ return rootPackage; } public void execute() throws
BuildException
{ addTemplate( new JunitSubTask( rootPackage ) ); super.execute(); } }
============================================================
package xdoclet.junit;
import xdoclet.*;
import java.io.*; /**
* @author Michael Larionov * @created October 15, 2001 */ public class JunitSubTask extends
TemplateSubTask
{ private String
rootPackage;
private final static String TEMPLATE_FILE =
"junit.j";
private final static String TESTING_SUITE = "TestingSuite"; public JunitSubTask( String rootPackage
)
{ this.rootPackage = rootPackage; setTemplateFile( new File( TEMPLATE_FILE ) ); setDestinationfile( javaFile( getSuiteClassName() ) ); } public String
getRootPackage()
{ return rootPackage; } private String getSuiteClassName() { return rootPackage + '.' + TESTING_SUITE; } }
========================================================================
|
