You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by pe...@apache.org on 2006/12/29 17:51:56 UTC
svn commit: r491045 -
/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
Author: peterreilly
Date: Fri Dec 29 08:51:56 2006
New Revision: 491045
URL: http://svn.apache.org/viewvc?view=rev&rev=491045
Log:
Check if classpath used with forked junit contains multi versions of ant
Modified:
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java?view=diff&rev=491045&r1=491044&r2=491045
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java Fri Dec 29 08:51:56 2006
@@ -28,6 +28,7 @@
import java.io.OutputStream;
import java.io.PrintWriter;
import java.lang.reflect.Constructor;
+import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
@@ -126,6 +127,8 @@
*/
public class JUnitTask extends Task {
+ private static final String LINE_SEP
+ = System.getProperty("line.separator");
private static final String CLASSPATH = "CLASSPATH=";
private CommandlineJava commandline;
private Vector tests = new Vector();
@@ -159,6 +162,9 @@
private boolean splitJunit = false;
private JUnitTaskMirror delegate;
+ /** A boolean on whether to get the forked path for ant classes */
+ private boolean forkedPathChecked = false;
+
// Attributes for basetest
private boolean haltOnError = false;
private boolean haltOnFail = false;
@@ -1016,6 +1022,9 @@
execute.setEnvironment(environment);
log(cmd.describeCommand(), Project.MSG_VERBOSE);
+
+ checkForkedPath(cmd);
+
TestResultHolder result = new TestResultHolder();
try {
result.exitCode = execute.execute();
@@ -1058,6 +1067,42 @@
}
return result;
+ }
+
+ /**
+ * Check the path for multiple different versions of
+ * ant.
+ */
+ private void checkForkedPath(CommandlineJava cmd) {
+ if (forkedPathChecked) {
+ return;
+ }
+ forkedPathChecked = true;
+ if (!cmd.haveClasspath()) {
+ return;
+ }
+ AntClassLoader loader = new AntClassLoader(
+ getProject(), cmd.createClasspath(getProject()));
+ String projectResourceName = LoaderUtils.classNameToResource(
+ Project.class.getName());
+ URL previous = null;
+ try {
+ for (Enumeration e = loader.getResources(projectResourceName);
+ e.hasMoreElements();) {
+ URL current = (URL) e.nextElement();
+ if (previous != null && !current.equals(previous)) {
+ log("WARNING: multiple versions of ant detected "
+ + "in path for junit "
+ + LINE_SEP + " " + previous
+ + LINE_SEP + " and " + current,
+ Project.MSG_WARN);
+ return;
+ }
+ previous = current;
+ }
+ } catch (Exception ex) {
+ // Ignore exception
+ }
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org
Re: svn commit: r491045 - /ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
Posted by Peter Reilly <pe...@gmail.com>.
On 12/30/06, Jesse Glick <je...@sun.com> wrote:
> peterreilly@apache.org wrote:
> > URL: http://svn.apache.org/viewvc?view=rev&rev=491045
> > Check if classpath used with forked junit contains multi versions of ant
>
> I just spent about two hours today trying to figure out why my unit
> tests were failing with a FNFE on junitvmwatcher*.properties from
> JUnitTask.executeAsForked. Turned out I was somehow mixing Ant 1.6.5 and
> 1.7.0. (The unit test was running a nested copy of Ant which in turn ran
> forked unit tests...don't ask.) Is that what this commit checks for?
Exactly.
I think that mixing of ant.1.6.5 jars with ant.1.7 will happen quite a lot.
This patch checks if multiple versions of ant.jar is in the junit classpath.
Another way to fix this is to change the order of jars in the junit
command line.
Currently the ant jars are placed after the jars in the nested <classpath>
so the <classpath> jars take priority. I did not what to do this as
it would change the behaviour of the <junit> task.
Peter
>
> -J.
>
> --
> jesse.glick@sun.com x22801 netbeans.org ant.apache.org
> http://google.com/search?q=e%5E%28pi*i%29%2B1
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org
Re: svn commit: r491045 - /ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
Posted by Jesse Glick <je...@sun.com>.
peterreilly@apache.org wrote:
> URL: http://svn.apache.org/viewvc?view=rev&rev=491045
> Check if classpath used with forked junit contains multi versions of ant
I just spent about two hours today trying to figure out why my unit
tests were failing with a FNFE on junitvmwatcher*.properties from
JUnitTask.executeAsForked. Turned out I was somehow mixing Ant 1.6.5 and
1.7.0. (The unit test was running a nested copy of Ant which in turn ran
forked unit tests...don't ask.) Is that what this commit checks for?
-J.
--
jesse.glick@sun.com x22801 netbeans.org ant.apache.org
http://google.com/search?q=e%5E%28pi*i%29%2B1
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org