Browse Source

<assertions> inside <java> or <junit> didn't work, PR: 27218

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@276346 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 21 years ago
parent
commit
e8f55deaa7
4 changed files with 74 additions and 4 deletions
  1. +2
    -2
      WHATSNEW
  2. +29
    -1
      src/main/org/apache/tools/ant/types/Assertions.java
  3. +1
    -1
      src/main/org/apache/tools/ant/types/CommandlineJava.java
  4. +42
    -0
      src/testcases/org/apache/tools/ant/types/CommandlineJavaTest.java

+ 2
- 2
WHATSNEW View File

@@ -21,8 +21,6 @@ Fixed bugs:

* AntLikeTasksAtTopLevelTest failed on cygwin.

* <junit> and <assertions> are working together. Bugzilla report 27218

* I/O-intensive processes hung when executed via <exec spawn="true">.
Bugzilla reports 23893/26852.

@@ -119,6 +117,8 @@ Fixed bugs:
* <zip> and friends would delete the original file when trying to update
a read-only archive. Bugzilla Report 28419.

* <junit> and <assertions> are working together. Bugzilla report 27218

Other changes:
--------------



+ 29
- 1
src/main/org/apache/tools/ant/types/Assertions.java View File

@@ -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


+ 1
- 1
src/main/org/apache/tools/ant/types/CommandlineJava.java View File

@@ -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


+ 42
- 0
src/testcases/org/apache/tools/ant/types/CommandlineJavaTest.java View File

@@ -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]);
}
}

}

Loading…
Cancel
Save