diff --git a/WHATSNEW b/WHATSNEW index 5b2bff393..919ca9b90 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -21,8 +21,6 @@ Fixed bugs: * AntLikeTasksAtTopLevelTest failed on cygwin. -* and are working together. Bugzilla report 27218 - * I/O-intensive processes hung when executed via . Bugzilla reports 23893/26852. @@ -119,6 +117,8 @@ Fixed bugs: * and friends would delete the original file when trying to update a read-only archive. Bugzilla Report 28419. +* and are working together. Bugzilla report 27218 + Other changes: -------------- diff --git a/src/main/org/apache/tools/ant/types/Assertions.java b/src/main/org/apache/tools/ant/types/Assertions.java index ee5824f7d..51c18d9da 100644 --- a/src/main/org/apache/tools/ant/types/Assertions.java +++ b/src/main/org/apache/tools/ant/types/Assertions.java @@ -20,9 +20,10 @@ package org.apache.tools.ant.types; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; -import java.util.List; import java.util.ArrayList; import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; /** * 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 * @param command diff --git a/src/main/org/apache/tools/ant/types/CommandlineJava.java b/src/main/org/apache/tools/ant/types/CommandlineJava.java index 772653082..37b683f8e 100644 --- a/src/main/org/apache/tools/ant/types/CommandlineJava.java +++ b/src/main/org/apache/tools/ant/types/CommandlineJava.java @@ -401,7 +401,7 @@ public class CommandlineJava implements Cloneable { //now any assertions are added if (getAssertions() != null) { - getAssertions().applyAssertions(this); + getAssertions().applyAssertions(listIterator); } // JDK usage command line says that -jar must be the first option, as there is diff --git a/src/testcases/org/apache/tools/ant/types/CommandlineJavaTest.java b/src/testcases/org/apache/tools/ant/types/CommandlineJavaTest.java index 3caf70e66..848c2bac6 100644 --- a/src/testcases/org/apache/tools/ant/types/CommandlineJavaTest.java +++ b/src/testcases/org/apache/tools/ant/types/CommandlineJavaTest.java @@ -18,6 +18,7 @@ package org.apache.tools.ant.types; import org.apache.tools.ant.Project; +import org.apache.tools.ant.util.JavaEnvUtils; import junit.framework.TestCase; import junit.framework.AssertionFailedError; @@ -142,4 +143,45 @@ public class CommandlineJavaTest extends TestCase { 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]); + } + } + }