Index: src/main/java/org/codehaus/castor/AbstractTestSuiteMojo.java =================================================================== --- src/main/java/org/codehaus/castor/AbstractTestSuiteMojo.java (revision 0) +++ src/main/java/org/codehaus/castor/AbstractTestSuiteMojo.java (revision 0) @@ -0,0 +1,122 @@ +package org.codehaus.castor; + +import java.io.File; +import java.util.Iterator; + +import junit.framework.Test; + +import org.apache.maven.artifact.DependencyResolutionRequiredException; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.project.MavenProject; +import org.castor.xmlctf.TestCaseAggregator; + +/** + * Abstract Mojo that initialises the junit test cases from xml + * Subclasses implement the runJUnit method to provide the Runner (eg. text, swing, ..) + * + * @requiresProject true + * @requiresDependencyResolution runtime + */ +public abstract class AbstractTestSuiteMojo extends AbstractMojo{ + + private static final String TEST_ROOT_PROPERTY = "castor.xmlctf.testRoot"; + + /** + * The root of of the xml representations of the tests + * @parameter + * @required + */ + protected String testRoot; + + /** + * The target dir used for the testclasses. + * @parameter expression="./target/xmlctf" + */ + protected String outputRoot; + + /** + * The project whose project files to create. + * @parameter expression="${project}" + * @required + */ + private MavenProject project; + + /** + * Turn on verbose output + * @parameter expression=false + */ + protected boolean verbose; + + /** + * Turn on stacktraces + * @parameter expression=false + */ + protected boolean printStack; + + public void execute() throws MojoExecutionException, MojoFailureException { + getLog().info("Starting Castor Mastertestsuite"); + + // override testRoot by system property? + if (System.getProperty(TEST_ROOT_PROPERTY) != null) { + testRoot = System.getProperty(TEST_ROOT_PROPERTY); + } + if (testRoot == null) { + throw new MojoExecutionException("No testRoot found, please specify property -Dcastor.xmlctf.testRoot or the " + + "testRoot property in the pom"); + } + if (testRoot.equals(".") || testRoot.equals("..")) { + //-- convert relative directories "." and ".." to a Canonical path + File tmp = new File(testRoot); + try { + testRoot = tmp.getCanonicalPath(); + } catch (java.io.IOException iox) { + + } + } else if (testRoot.startsWith("./") || testRoot.startsWith(".\\")) { + //-- Remove leading ./ or .\ -- URLClassLoader can't handle such file URLs + testRoot = testRoot.substring(2); + } + File testRootFile = new File(testRoot); + if (!testRootFile.exists()) { + throw new MojoExecutionException("Root not found: " + testRoot); + } + getLog().info("using testRoot: " + testRoot); + + + // set possible properties + if (verbose) { + getLog().info("Verbose on"); + System.setProperty(TestCaseAggregator.VERBOSE_PROPERTY, "true"); + } else { + getLog().info("Verbose off"); + } + + if (printStack) { + getLog().info("Printing stack traces on error on."); + System.setProperty(TestCaseAggregator.PRINT_STACK_TRACE, "true"); + } else { + getLog().info("Printing stack traces on error off."); + } + + + // set classpath for testcompiler + String classpath = System.getProperty("java.home") + "/lib/tools.jar:"; + try { + for (Iterator iter = project.getTestClasspathElements().iterator(); iter.hasNext();) { + classpath += iter.next() + ":"; + } + } catch (DependencyResolutionRequiredException e) { + throw new MojoExecutionException("Error setting classpath:" + classpath); + } + System.setProperty("xmlctf.classpath.override",classpath); + getLog().info("classpath for sourcegenerator tests is: " + classpath); + + // run testCase + runJUnit(new TestCaseAggregator(testRootFile, outputRoot).suite()); + } + + public abstract void runJUnit(Test testSuite )throws MojoExecutionException; + +} Index: src/main/java/org/codehaus/castor/TextTestSuiteMojo.java =================================================================== --- src/main/java/org/codehaus/castor/TextTestSuiteMojo.java (revision 0) +++ src/main/java/org/codehaus/castor/TextTestSuiteMojo.java (revision 0) @@ -0,0 +1,29 @@ +package org.codehaus.castor; + +import org.apache.maven.plugin.MojoExecutionException; + +import junit.framework.Test; +import junit.framework.TestResult; +import junit.textui.TestRunner; + +/** + * Uses a simple TextRunner to run the xmlctf tests + * + * @goal xmlctf-run-text + */ + +public class TextTestSuiteMojo extends AbstractTestSuiteMojo{ + + @Override + public void runJUnit(Test testSuite) throws MojoExecutionException{ + TestResult result = TestRunner.run(testSuite); + if (result.errorCount() > 0 || result.failureCount() > 0) { + throw new MojoExecutionException("Errors or Failures occured testing " + testRoot); + } + } + + + +} + + Index: pom.xml =================================================================== --- pom.xml (revision 0) +++ pom.xml (revision 0) @@ -0,0 +1,67 @@ + + 4.0.0 + org.codehaus.castor + maven-plugins + + maven-plugin + 1.0-SNAPSHOT + castor-xmlctf-plugin Maven Mojo + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.5 + 1.5 + + + + + + + org.apache.maven + maven-plugin-api + 2.0 + + + org.apache.maven + maven-project + 2.0.1 + + + org.codehaus.castor + castor-testsuite-xml + 1.1.1-SNAPSHOT + + + junit + junit + 3.8.1 + + + + + + codehaus.org + Castor Central Distribution Repository + dav:https://dav.codehaus.org/repository/castor/ + + + codehaus.org + Castor Central Development Repository + dav:https://dav.codehaus.org/snapshots.repository/castor/ + + + codehaus.org + dav:https://dav.codehaus.org/castor/ + + +