bodewig     2004/04/19 23:24:25

  Modified:    .        WHATSNEW
               src/main/org/apache/tools/ant/types Assertions.java
                        CommandlineJava.java
               src/testcases/org/apache/tools/ant/types
                        CommandlineJavaTest.java
  Log:
  <assertions> inside <java> or <junit> didn't work, PR: 27218
  
  Revision  Changes    Path
  1.589     +2 -2      ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/ant/WHATSNEW,v
  retrieving revision 1.588
  retrieving revision 1.589
  diff -u -r1.588 -r1.589
  --- WHATSNEW  16 Apr 2004 09:35:21 -0000      1.588
  +++ WHATSNEW  20 Apr 2004 06:24:24 -0000      1.589
  @@ -21,8 +21,6 @@
   
   * 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.
   
  @@ -118,6 +116,8 @@
   
   * <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:
   --------------
  
  
  
  1.15      +29 -1     ant/src/main/org/apache/tools/ant/types/Assertions.java
  
  Index: Assertions.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/types/Assertions.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- Assertions.java   14 Apr 2004 15:42:08 -0000      1.14
  +++ Assertions.java   20 Apr 2004 06:24:25 -0000      1.15
  @@ -20,9 +20,10 @@
   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
  @@ -199,6 +200,33 @@
               BaseAssertion assertion = (BaseAssertion) it.next();
               String arg = assertion.toCommand();
               addVmArgument(command, arg);
  +        }
  +    }
  +
  +    /**
  +     * 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);
           }
       }
   
  
  
  
  1.55      +1 -1      
ant/src/main/org/apache/tools/ant/types/CommandlineJava.java
  
  Index: CommandlineJava.java
  ===================================================================
  RCS file: 
/home/cvs/ant/src/main/org/apache/tools/ant/types/CommandlineJava.java,v
  retrieving revision 1.54
  retrieving revision 1.55
  diff -u -r1.54 -r1.55
  --- CommandlineJava.java      14 Apr 2004 15:42:08 -0000      1.54
  +++ CommandlineJava.java      20 Apr 2004 06:24:25 -0000      1.55
  @@ -401,7 +401,7 @@
   
           //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
  
  
  
  1.24      +42 -0     
ant/src/testcases/org/apache/tools/ant/types/CommandlineJavaTest.java
  
  Index: CommandlineJavaTest.java
  ===================================================================
  RCS file: 
/home/cvs/ant/src/testcases/org/apache/tools/ant/types/CommandlineJavaTest.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- CommandlineJavaTest.java  9 Mar 2004 16:49:05 -0000       1.23
  +++ CommandlineJavaTest.java  20 Apr 2004 06:24:25 -0000      1.24
  @@ -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;
  @@ -140,6 +141,47 @@
           }
           assertNull(System.getProperty("key"));
           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]);
  +        }
       }
   
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to