git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@276346 13f79535-47bb-0310-9956-ffa450edef68master
@@ -21,8 +21,6 @@ Fixed bugs: | |||||
* AntLikeTasksAtTopLevelTest failed on cygwin. | * AntLikeTasksAtTopLevelTest failed on cygwin. | ||||
* <junit> and <assertions> are working together. Bugzilla report 27218 | |||||
* I/O-intensive processes hung when executed via <exec spawn="true">. | * I/O-intensive processes hung when executed via <exec spawn="true">. | ||||
Bugzilla reports 23893/26852. | Bugzilla reports 23893/26852. | ||||
@@ -119,6 +117,8 @@ Fixed bugs: | |||||
* <zip> and friends would delete the original file when trying to update | * <zip> and friends would delete the original file when trying to update | ||||
a read-only archive. Bugzilla Report 28419. | a read-only archive. Bugzilla Report 28419. | ||||
* <junit> and <assertions> are working together. Bugzilla report 27218 | |||||
Other changes: | Other changes: | ||||
-------------- | -------------- | ||||
@@ -20,9 +20,10 @@ package org.apache.tools.ant.types; | |||||
import org.apache.tools.ant.BuildException; | import org.apache.tools.ant.BuildException; | ||||
import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
import java.util.List; | |||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.Iterator; | import java.util.Iterator; | ||||
import java.util.List; | |||||
import java.util.ListIterator; | |||||
/** | /** | ||||
* The assertion datatype. This type describes | * The assertion datatype. This type describes | ||||
@@ -202,6 +203,33 @@ public class Assertions extends DataType implements Cloneable { | |||||
} | } | ||||
} | } | ||||
/** | |||||
* add the assertions to a list in a format suitable | |||||
* for adding to a command line | |||||
* @param commandList | |||||
*/ | |||||
public void applyAssertions(final ListIterator commandIterator) { | |||||
getProject().log("Applying assertions", Project.MSG_DEBUG); | |||||
Assertions clause = getFinalReference(); | |||||
//do the system assertions | |||||
if (Boolean.TRUE.equals(clause.enableSystemAssertions)) { | |||||
getProject().log("Enabling system assertions", Project.MSG_DEBUG); | |||||
commandIterator.add("-enablesystemassertions"); | |||||
} else if (Boolean.FALSE.equals(clause.enableSystemAssertions)) { | |||||
getProject().log("disabling system assertions", Project.MSG_DEBUG); | |||||
commandIterator.add("-disablesystemassertions"); | |||||
} | |||||
//now any inner assertions | |||||
Iterator it = clause.assertionList.iterator(); | |||||
while (it.hasNext()) { | |||||
BaseAssertion assertion = (BaseAssertion) it.next(); | |||||
String arg = assertion.toCommand(); | |||||
getProject().log("adding assertion "+arg, Project.MSG_DEBUG); | |||||
commandIterator.add(arg); | |||||
} | |||||
} | |||||
/** | /** | ||||
* helper method to add a string JVM argument to a command | * helper method to add a string JVM argument to a command | ||||
* @param command | * @param command | ||||
@@ -401,7 +401,7 @@ public class CommandlineJava implements Cloneable { | |||||
//now any assertions are added | //now any assertions are added | ||||
if (getAssertions() != null) { | if (getAssertions() != null) { | ||||
getAssertions().applyAssertions(this); | |||||
getAssertions().applyAssertions(listIterator); | |||||
} | } | ||||
// JDK usage command line says that -jar must be the first option, as there is | // JDK usage command line says that -jar must be the first option, as there is | ||||
@@ -18,6 +18,7 @@ | |||||
package org.apache.tools.ant.types; | package org.apache.tools.ant.types; | ||||
import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
import org.apache.tools.ant.util.JavaEnvUtils; | |||||
import junit.framework.TestCase; | import junit.framework.TestCase; | ||||
import junit.framework.AssertionFailedError; | import junit.framework.AssertionFailedError; | ||||
@@ -142,4 +143,45 @@ public class CommandlineJavaTest extends TestCase { | |||||
assertNull(System.getProperty("key2")); | assertNull(System.getProperty("key2")); | ||||
} | } | ||||
public void testAssertions() { | |||||
if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_2) | |||||
|| JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_3)) { | |||||
return; | |||||
} | |||||
CommandlineJava c = new CommandlineJava(); | |||||
c.createArgument().setValue("org.apache.tools.ant.CommandlineJavaTest"); | |||||
c.setClassname("junit.textui.TestRunner"); | |||||
c.createVmArgument().setValue("-Djava.compiler=NONE"); | |||||
Assertions a = new Assertions(); | |||||
a.setProject(project); | |||||
Assertions.EnabledAssertion ea = new Assertions.EnabledAssertion(); | |||||
ea.setClass("junit.textui.TestRunner"); | |||||
a.addEnable(ea); | |||||
c.setAssertions(a); | |||||
String[] expected = new String[] { | |||||
null, | |||||
"-Djava.compiler=NONE", | |||||
"-ea:junit.textui.TestRunner", | |||||
"junit.textui.TestRunner", | |||||
"org.apache.tools.ant.CommandlineJavaTest", | |||||
}; | |||||
// only the second iteration would pass because of PR 27218 | |||||
for (int i = 0; i < 3; i++) { | |||||
String[] s = c.getCommandline(); | |||||
assertEquals(expected.length, s.length); | |||||
for (int j = 1; j < expected.length; j++) { | |||||
assertEquals(expected[j], s[j]); | |||||
} | |||||
} | |||||
CommandlineJava c2 = (CommandlineJava) c.clone(); | |||||
String[] s = c2.getCommandline(); | |||||
assertEquals(expected.length, s.length); | |||||
for (int j = 1; j < expected.length; j++) { | |||||
assertEquals(expected[j], s[j]); | |||||
} | |||||
} | |||||
} | } |