You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xmlbeans-cvs@xml.apache.org by da...@apache.org on 2004/06/09 04:29:46 UTC
cvs commit: xml-xmlbeans/v2/test/tools/src/tools/JUnit JUnitXTask.java XmlResultFormatter.java XmlResultFormatterImpl.java
daveremy 2004/06/08 19:29:46
Modified: v2 testbuild.xml
v2/test/src/dom/common NodeTest.java
v2/test/tools/src/tools/JUnit JUnitXTask.java
XmlResultFormatter.java XmlResultFormatterImpl.java
Added: v2/test/tools/lib xerces1.4.4.jar
Log:
Contributed by Yana Kadiyska: JDK1.4 compatibility
Revision Changes Path
1.3 +6 -0 xml-xmlbeans/v2/testbuild.xml
Index: testbuild.xml
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/testbuild.xml,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- testbuild.xml 8 Jun 2004 22:44:18 -0000 1.2
+++ testbuild.xml 9 Jun 2004 02:29:46 -0000 1.3
@@ -149,6 +149,7 @@
<fileset id="tools.ext.lib" dir="${xbeans.test.tools.lib}">
<include name="**/*.jar"/>
+ <exclude name="**/xerces1.4.4.jar"/>
</fileset>
<fileset id="schema.files.copy" dir="${xbeans.test.cases.test.files}">
@@ -194,6 +195,10 @@
<path refid="build.classpath"/>
<fileset refid="test.build.jars"/>
+
+ <!--1.4 JDK compat:JDK Xerces missing DocumentRange-->
+
+ <pathelement path="${xbeans.test.tools.lib}/xerces1.4.4.jar"/>
</path>
<!-- END: Filesets and Paths -->
<!-- =============================================================== -->
@@ -446,6 +451,7 @@
destdir="${build.dir.test.src}"
classpathref="test.run.classpath"
debug="on"
+ source="1.4"
optimize="on"
verbose="false"
failonerror="true">
1.2 +3 -2 xml-xmlbeans/v2/test/src/dom/common/NodeTest.java
Index: NodeTest.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/test/src/dom/common/NodeTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- NodeTest.java 8 Jun 2004 19:38:02 -0000 1.1
+++ NodeTest.java 9 Jun 2004 02:29:46 -0000 1.2
@@ -350,7 +350,8 @@
}
- public static Node getApacheNode(String sXml,boolean namespace,char type)
+
+ public static Node getApacheNode(String sXml,boolean namespace,char type)
throws Exception{
org.apache.xerces.parsers.DOMParser parser = new org.apache.xerces.parsers.DOMParser();
parser.parse(new InputSource(new StringReader(sXml)));
@@ -373,8 +374,8 @@
default: return doc.createTextNode(name);
}
+
}
-
public abstract void moveToNode();
1.1 xml-xmlbeans/v2/test/tools/lib/xerces1.4.4.jar
<<Binary file>>
1.2 +224 -219 xml-xmlbeans/v2/test/tools/src/tools/JUnit/JUnitXTask.java
Index: JUnitXTask.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/test/tools/src/tools/JUnit/JUnitXTask.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JUnitXTask.java 8 Jun 2004 19:38:09 -0000 1.1
+++ JUnitXTask.java 9 Jun 2004 02:29:46 -0000 1.2
@@ -1,219 +1,224 @@
-package tools.JUnit;
-
-import org.apache.tools.ant.DirectoryScanner;
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.types.FileSet;
-
-import java.util.Vector;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.BufferedWriter;
-
-/**
- * <p>This task runs tests from the JUnit testing framework. The latest version
- * of JUnit can be found at <a href="http://www.junit.org">http://www.junit.org</a>.
- *
- * <p><strong>Note:</strong> This task depends on external libraries not included
- * in the Ant distribution. See <a href="http://ant.apache.org/manual/install.html#librarydependencies">
- *
- * Library Dependencies</a> for more information.
- * </p>
- * <p>
- * <strong>Note</strong>:
- * You must have <code>junit.jar</code> and the class files for the
- * <code><junit></code> task in the same classpath.
- * You can do one of:
- * </p><ol>
- * <li>
- * Put both <code>junit.jar</code> and the optional tasks jar file in
- *
- * <code>ANT_HOME/lib</code>.
- * </li>
- * <li>
- * Do not put either in <code>ANT_HOME/lib</code>, and instead
- * include their locations in your <code>CLASSPATH</code> environment variable.
- * </li>
- * <li>
- * Do neither of the above, and instead, specify their locations using
- * a <code><classpath></code> element in the build file.
- *
- * See <a href="http://ant.apache.org/faq.html#delegating-classloader" target="_top">the
- * FAQ</a> for details.</p>
- *
- *
- * <pre>
- * Usage:
- * This task is derived from the Java task and supports all attributes and nested
- * elements of the Java task. Additionally it supports the following attributes
- *
- * formatter = Optional class that implements tools.JUnit.JUnitXResultFormatter
- * to be passed to the JUnit runner for formatting the results
- * reportFile = File for the formatter to write too.
- * (Required if formatter is specified. The formatter may choose
- * to ignore this)
- * showOutput = Tells the formatter to show the output of the tests.
- * The default formatter ignores this flag, since it anyway
- * displays everything to stdout/stderr.
- *
- * The tests to run are specified using nested <code>Fileset</code>s elements
- * The task picks up any .class or .java files from the filesets and tries to run
- * them as JUnit tests.
- * </pre>
- */
-
-public class JUnitXTask extends org.apache.tools.ant.taskdefs.Java
-{
- // Task attributes vars
- private String reportFile;
- private boolean showOutput = false;
- private String formatterClass;
-
- /** the list of filesets containing the testcase filename rules */
- private Vector filesets = new Vector();
-
- /**
- * Add a new fileset instance to this batchtest. Whatever the fileset is,
- * only filename that are <tt>.java</tt> or <tt>.class</tt> will be
- * considered as 'candidates'.
- * @param fs the new fileset containing the rules to get the testcases.
- */
- public void addFileSet(FileSet fs)
- {
- filesets.addElement(fs);
- }
-
- // Additional Attributes
- /**
- * Set the file to write the test run report to
- * @param reportFile
- */
- public void setReportFile(String reportFile)
- {
- this.reportFile = reportFile;
- }
-
- /**
- * Sets the class to be used as the Result formatter for the test results
- * This class should implement tools.JUnit.JUnitXResultFormatter
- * @param fmtClass
- */
- public void setFormatter(String fmtClass)
- {
- this.formatterClass = fmtClass;
- }
-
- /**
- * Controls whether the output from the tests is sent to stdout/stderr.
- * @param show
- */
- public void setShowOutput(boolean show)
- {
- this.showOutput = show;
- }
-
- public void execute() throws BuildException
- {
- validate();
- String[] files = getFilenames();
- File temp;
- try
- {
- temp = File.createTempFile(Long.toString(System.currentTimeMillis()),
- ".tmp");
- temp.deleteOnExit();
- BufferedWriter out = new BufferedWriter(new FileWriter(temp));
- //System.out.println(temp.toString());
- for (int i = 0; i < files.length; i++)
- out.write(javaToClass(files[i]) + "\n");
- out.close();
- } catch (java.io.IOException ioe)
- {
- throw new BuildException("Could not write out temporary file for " +
- "passing arguments to the JUnit runner: " +
- ioe.getMessage());
- }
-
- super.setClassname("tools.JUnit.JUnitXRunner");
- // Args: tempFile reportFormatter outFile <showOutput>
- super.createArg().setFile(temp);
- if (formatterClass != null)
- {
- super.createArg().setValue(this.formatterClass);
- super.createArg().setValue(this.reportFile);
- }
- if (showOutput)
- super.createArg().setValue("showoutput");
- super.execute();
- }
-
- /**
- * Validates the attributes
- */
- private void validate()
- {
- // Check if any filesets have been specified
- if (filesets.size() == 0)
- throw new BuildException("You have to specify atleast one Fileset");
-
- // If Custom ResultFormatter is specified, then an outfile should be
- // specified. The default ResultFormatter write only to Stdout
- if ((formatterClass != null) && (reportFile == null))
- throw new BuildException("Using custom ReportFormatter: " +
- "reportFile attribute should be specified");
-
- }
-
- /**
- * Iterate over all filesets and return the filename of all files
- * that end with <tt>.java</tt> or <tt>.class</tt>. This is to avoid
- * wrapping a <tt>JUnitTest</tt> over an xml file for example. A Testcase
- * is obviously a java file (compiled or not).
- * @return an array of filenames without their extension. As they should
- * normally be taken from their root, filenames should match their fully
- * qualified class name (If it is not the case it will fail when running the test).
- * For the class <tt>org/apache/Whatever.class</tt> it will return <tt>org/apache/Whatever</tt>.
- */
- private String[] getFilenames()
- {
- Vector v = new Vector();
- final int size = this.filesets.size();
- for (int j = 0; j < size; j++)
- {
- FileSet fs = (FileSet) filesets.elementAt(j);
- DirectoryScanner ds = fs.getDirectoryScanner(project);
- ds.scan();
- String[] f = ds.getIncludedFiles();
- for (int k = 0; k < f.length; k++)
- {
- String pathname = f[k];
- if (pathname.endsWith(".java"))
- {
- v.addElement(pathname.substring(0, pathname.length() - ".java".length()));
- } else if (pathname.endsWith(".class"))
- {
- // DOn't try to run inner classes
- if (! pathname.contains("$"))
- v.addElement(pathname.substring(0, pathname.length() - ".class".length()));
- }
- }
- }
-
- String[] files = new String[v.size()];
- v.copyInto(files);
- return files;
- }
-
- /**
- * Convenient method to convert a pathname without extension to a
- * fully qualified classname. For example <tt>org/apache/Whatever</tt> will
- * be converted to <tt>org.apache.Whatever</tt>
- * @param filename the filename to "convert" to a classname.
- * @return the classname matching the filename.
- */
- public static final String javaToClass(String filename)
- {
- return filename.replace(File.separatorChar, '.');
- }
-
-
-}
+package tools.JUnit;
+
+import org.apache.tools.ant.DirectoryScanner;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.types.FileSet;
+
+import java.util.Vector;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.BufferedWriter;
+
+/**
+ * <p>This task runs tests from the JUnit testing framework. The latest version
+ * of JUnit can be found at <a href="http://www.junit.org">http://www.junit.org</a>.
+ *
+ * <p><strong>Note:</strong> This task depends on external libraries not included
+ * in the Ant distribution. See <a href="http://ant.apache.org/manual/install.html#librarydependencies">
+ *
+ * Library Dependencies</a> for more information.
+ * </p>
+ * <p>
+ * <strong>Note</strong>:
+ * You must have <code>junit.jar</code> and the class files for the
+ * <code><junit></code> task in the same classpath.
+ * You can do one of:
+ * </p><ol>
+ * <li>
+ * Put both <code>junit.jar</code> and the optional tasks jar file in
+ *
+ * <code>ANT_HOME/lib</code>.
+ * </li>
+ * <li>
+ * Do not put either in <code>ANT_HOME/lib</code>, and instead
+ * include their locations in your <code>CLASSPATH</code> environment variable.
+ * </li>
+ * <li>
+ * Do neither of the above, and instead, specify their locations using
+ * a <code><classpath></code> element in the build file.
+ *
+ * See <a href="http://ant.apache.org/faq.html#delegating-classloader" target="_top">the
+ * FAQ</a> for details.</p>
+ *
+ *
+ * <pre>
+ * Usage:
+ * This task is derived from the Java task and supports all attributes and nested
+ * elements of the Java task. Additionally it supports the following attributes
+ *
+ * formatter = Optional class that implements tools.JUnit.JUnitXResultFormatter
+ * to be passed to the JUnit runner for formatting the results
+ * reportFile = File for the formatter to write too.
+ * (Required if formatter is specified. The formatter may choose
+ * to ignore this)
+ * showOutput = Tells the formatter to show the output of the tests.
+ * The default formatter ignores this flag, since it anyway
+ * displays everything to stdout/stderr.
+ *
+ * The tests to run are specified using nested <code>Fileset</code>s elements
+ * The task picks up any .class or .java files from the filesets and tries to run
+ * them as JUnit tests.
+ * </pre>
+ */
+
+public class JUnitXTask extends org.apache.tools.ant.taskdefs.Java
+{
+ // Task attributes vars
+ private String reportFile;
+ private boolean showOutput = false;
+ private String formatterClass;
+
+ /** the list of filesets containing the testcase filename rules */
+ private Vector filesets = new Vector();
+
+ /**
+ * Add a new fileset instance to this batchtest. Whatever the fileset is,
+ * only filename that are <tt>.java</tt> or <tt>.class</tt> will be
+ * considered as 'candidates'.
+ * @param fs the new fileset containing the rules to get the testcases.
+ */
+ public void addFileSet(FileSet fs)
+ {
+ filesets.addElement(fs);
+ }
+
+ // Additional Attributes
+ /**
+ * Set the file to write the test run report to
+ * @param reportFile
+ */
+ public void setReportFile(String reportFile)
+ {
+ this.reportFile = reportFile;
+ }
+
+ /**
+ * Sets the class to be used as the Result formatter for the test results
+ * This class should implement tools.JUnit.JUnitXResultFormatter
+ * @param fmtClass
+ */
+ public void setFormatter(String fmtClass)
+ {
+ this.formatterClass = fmtClass;
+ }
+
+ /**
+ * Controls whether the output from the tests is sent to stdout/stderr.
+ * @param show
+ */
+ public void setShowOutput(boolean show)
+ {
+ this.showOutput = show;
+ }
+
+ public void execute() throws BuildException
+ {
+ validate();
+ String[] files = getFilenames();
+ File temp=null;
+ String fName=Long.toString(System.currentTimeMillis());
+
+
+ //issue w/ JDK 1.4 IOException
+ // temp = File.createTempFile(,null);
+ temp=new File(fName);
+
+ try{
+ temp.deleteOnExit();
+ // System.out.println(temp.toString());
+ BufferedWriter out = new BufferedWriter(new FileWriter(temp));
+ System.out.println(temp.toString());
+ for (int i = 0; i < files.length; i++)
+ out.write(javaToClass(files[i]) + "\n");
+ out.close();
+ } catch (java.io.IOException ioe)
+ {
+ throw new BuildException("Could not write out temporary file for " +
+ "passing arguments to the JUnit runner: " +
+ ioe.getMessage());
+ }
+
+ super.setClassname("tools.JUnit.JUnitXRunner");
+ // Args: tempFile reportFormatter outFile <showOutput>
+ super.createArg().setFile(temp);
+ if (formatterClass != null)
+ {
+ super.createArg().setValue(this.formatterClass);
+ super.createArg().setValue(this.reportFile);
+ }
+ if (showOutput)
+ super.createArg().setValue("showoutput");
+ super.execute();
+ }
+
+ /**
+ * Validates the attributes
+ */
+ private void validate()
+ {
+ // Check if any filesets have been specified
+ if (filesets.size() == 0)
+ throw new BuildException("You have to specify atleast one Fileset");
+
+ // If Custom ResultFormatter is specified, then an outfile should be
+ // specified. The default ResultFormatter write only to Stdout
+ if ((formatterClass != null) && (reportFile == null))
+ throw new BuildException("Using custom ReportFormatter: " +
+ "reportFile attribute should be specified");
+
+ }
+
+ /**
+ * Iterate over all filesets and return the filename of all files
+ * that end with <tt>.java</tt> or <tt>.class</tt>. This is to avoid
+ * wrapping a <tt>JUnitTest</tt> over an xml file for example. A Testcase
+ * is obviously a java file (compiled or not).
+ * @return an array of filenames without their extension. As they should
+ * normally be taken from their root, filenames should match their fully
+ * qualified class name (If it is not the case it will fail when running the test).
+ * For the class <tt>org/apache/Whatever.class</tt> it will return <tt>org/apache/Whatever</tt>.
+ */
+ private String[] getFilenames()
+ {
+ Vector v = new Vector();
+ final int size = this.filesets.size();
+ for (int j = 0; j < size; j++)
+ {
+ FileSet fs = (FileSet) filesets.elementAt(j);
+ DirectoryScanner ds = fs.getDirectoryScanner(project);
+ ds.scan();
+ String[] f = ds.getIncludedFiles();
+ for (int k = 0; k < f.length; k++)
+ {
+ String pathname = f[k];
+ if (pathname.endsWith(".java"))
+ {
+ v.addElement(pathname.substring(0, pathname.length() - ".java".length()));
+ } else if (pathname.endsWith(".class"))
+ {
+ // DOn't try to run inner classes
+ if ( pathname.indexOf("$") == -1 )
+ v.addElement(pathname.substring(0, pathname.length() - ".class".length()));
+ }
+ }
+ }
+
+ String[] files = new String[v.size()];
+ v.copyInto(files);
+ return files;
+ }
+
+ /**
+ * Convenient method to convert a pathname without extension to a
+ * fully qualified classname. For example <tt>org/apache/Whatever</tt> will
+ * be converted to <tt>org.apache.Whatever</tt>
+ * @param filename the filename to "convert" to a classname.
+ * @return the classname matching the filename.
+ */
+ public static final String javaToClass(String filename)
+ {
+ return filename.replace(File.separatorChar, '.');
+ }
+
+
+}
1.2 +1 -1 xml-xmlbeans/v2/test/tools/src/tools/JUnit/XmlResultFormatter.java
Index: XmlResultFormatter.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/test/tools/src/tools/JUnit/XmlResultFormatter.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XmlResultFormatter.java 8 Jun 2004 19:38:09 -0000 1.1
+++ XmlResultFormatter.java 9 Jun 2004 02:29:46 -0000 1.2
@@ -222,7 +222,7 @@
testRecord.setStatus(TEST_ERROR);
testRecord.setThrowable(t);
// Special case when test class is missing...
- if (t.toString().contains("ClassNotFoundException"))
+ if (t.toString().indexOf("ClassNotFoundException") > -1)
{
records.add(testRecord);
testRecord = null;
1.2 +1 -1 xml-xmlbeans/v2/test/tools/src/tools/JUnit/XmlResultFormatterImpl.java
Index: XmlResultFormatterImpl.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/test/tools/src/tools/JUnit/XmlResultFormatterImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XmlResultFormatterImpl.java 8 Jun 2004 19:38:09 -0000 1.1
+++ XmlResultFormatterImpl.java 9 Jun 2004 02:29:46 -0000 1.2
@@ -190,7 +190,7 @@
testRecord.setStatus(TEST_ERROR);
testRecord.setThrowable(t);
// Special case when test class is missing...
- if (t.toString().contains("ClassNotFoundException"))
+ if (t.toString().indexOf("ClassNotFoundException") > -1)
{
records.add(testRecord);
testRecord = null;
---------------------------------------------------------------------
To unsubscribe, e-mail: xmlbeans-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-cvs-help@xml.apache.org