This is the patch for JUnitTask and CommandlineJava to make them extensible.

The main change in CommandlineJava is that some methods were made protected and in JUnitTask replace the direct usage of commandline for an accessor, this way they can both be extended to provide custom commandline implementations.

The diff was against the 1.6.0 WC, I guess the versions are just the same, If you want me to diff them against the CVS version shout me. :)
MAriano
--- src/main/org/apache/tools/ant/types/CommandlineJava.java    2004-02-11 
15:27:15.000000000 -0300
+++ 
/opt/java/ant/apache-ant-1.6.0/src/main/org/apache/tools/ant/types/CommandlineJava.java
     2004-02-11 15:08:41.000000000 -0300
@@ -383,6 +383,7 @@
         final ListIterator listIterator = commands.listIterator();
         //fill it
         addCommandsToList(listIterator);
+
         //convert to an array
         return (String[]) commands.toArray(new String[0]);
     }
@@ -395,6 +396,7 @@
     private void addCommandsToList(final ListIterator listIterator) {
         //create the command to run Java, including user specified options
         getActualVMCommand().addCommandToList(listIterator);
+
         // properties are part of the vm options...
         sysProperties.addDefinitionsToList(listIterator);
         //boot classpath
@@ -469,7 +471,7 @@
      * Get the VM command parameters, including memory settings
      * @return
      */
-    private Commandline getActualVMCommand() {
+    protected Commandline getActualVMCommand() {
         Commandline actualVMCommand = (Commandline) vmCommand.clone();
         if (maxMemory != null) {
             if (vmVersion.startsWith("1.1")) {
@@ -604,7 +606,7 @@
      *
      * @since Ant 1.6
      */
-    private boolean haveClasspath() {
+    protected boolean haveClasspath() {
         Path fullClasspath = classpath != null
             ? classpath.concatSystemClasspath("ignore") : null;
         return fullClasspath != null
@@ -621,7 +623,7 @@
      *
      * @since Ant 1.6
      */
-    private boolean haveBootclasspath(boolean log) {
+    protected boolean haveBootclasspath(boolean log) {
         if (bootclasspath != null
             && bootclasspath.toString().trim().length() > 0) {

--- src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java        
2004-02-11 15:27:15.000000000 -0300
+++ 
/opt/java/ant/apache-ant-1.6.0/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
 2004-02-11 14:43:03.000000000 -0300
@@ -160,7 +160,7 @@
  */
 public class JUnitTask extends Task {
 
-    private CommandlineJava commandline = new CommandlineJava();
+    private CommandlineJava commandline;
     private Vector tests = new Vector();
     private Vector batchTests = new Vector();
     private Vector formatters = new Vector();
@@ -375,7 +375,7 @@
      * @since Ant 1.2
      */
     public void setMaxmemory(String max) {
-        commandline.setMaxmemory(max);
+        getCommandline().setMaxmemory(max);
     }

     /**
@@ -389,7 +389,7 @@
      * @since Ant 1.2
      */
     public void setJvm(String value) {
-        commandline.setVm(value);
+        getCommandline().setVm(value);
     }

     /**
@@ -402,7 +402,7 @@
      * @since Ant 1.2
      */
     public Commandline.Argument createJvmarg() {
-        return commandline.createVmArgument();
+        return getCommandline().createVmArgument();
     }

     /**
@@ -427,7 +427,7 @@
      */
     public void addSysproperty(Environment.Variable sysp) {

-        commandline.addSysproperty(sysp);
+        getCommandline().addSysproperty(sysp);
     }

     /**
@@ -442,7 +442,7 @@
         // see bugzilla report 21684
         String testString = sysp.getContent();
         getProject().log("sysproperty added : " + testString, 
Project.MSG_DEBUG);
-        commandline.addSysproperty(sysp);
+        getCommandline().addSysproperty(sysp);
     }

     /**
@@ -456,7 +456,7 @@
      * @since Ant 1.6
      */
     public void addSyspropertyset(PropertySet sysp) {
-        commandline.addSyspropertyset(sysp);
+        getCommandline().addSyspropertyset(sysp);
     }

     /**
@@ -466,7 +466,7 @@
      * @since Ant 1.2
      */
     public Path createClasspath() {
-        return commandline.createClasspath(getProject()).createPath();
+        return getCommandline().createClasspath(getProject()).createPath();
     }

     /**
@@ -475,7 +475,7 @@
      * @since Ant 1.6
      */
     public Path createBootclasspath() {
-        return commandline.createBootclasspath(getProject()).createPath();
+        return getCommandline().createBootclasspath(getProject()).createPath();
     }

     /**
@@ -569,10 +569,10 @@
      * @param asserts assertion set
      */
     public void addAssertions(Assertions asserts) {
-        if (commandline.getAssertions() != null) {
+        if (getCommandline().getAssertions() != null) {
             throw new BuildException("Only one assertion declaration is 
allowed");
         }
-        commandline.setAssertions(asserts);
+        getCommandline().setAssertions(asserts);
     }

     /**
@@ -594,7 +594,7 @@
      * @since Ant 1.2
      */
     public JUnitTask() throws Exception {
-        commandline
+        getCommandline()
             
.setClassname("org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner");
     }

@@ -712,7 +712,7 @@
             log("Permissions ignored when running in forked mode!", 
Project.MSG_WARN);
         }

-        CommandlineJava cmd = (CommandlineJava) commandline.clone();
+        CommandlineJava cmd = (CommandlineJava) getCommandline().clone();

         
cmd.setClassname("org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner");
         cmd.createArgument().setValue(test.getName());
@@ -940,13 +940,13 @@
                 + "the same VM.", Project.MSG_WARN);
         }

-        if (commandline.getBootclasspath() != null) {
+        if (getCommandline().getBootclasspath() != null) {
             log("bootclasspath is ignored if running in the same VM.",
                 Project.MSG_WARN);
         }

         CommandlineJava.SysProperties sysProperties =
-            commandline.getSystemProperties();
+                getCommandline().getSystemProperties();
         if (sysProperties != null) {
             sysProperties.setSystem();
         }
@@ -1178,7 +1178,7 @@
      * @since Ant 1.6
      */
     private void createClassLoader() {
-        Path userClasspath = commandline.getClasspath();
+        Path userClasspath = getCommandline().getClasspath();
         if (userClasspath != null) {
             if (reloading || classLoader == null) {
                 Path classpath = (Path) userClasspath.clone();
@@ -1200,4 +1200,12 @@
             }
         }
     }
+
+    protected CommandlineJava getCommandline()
+    {
+        if (commandline == null) {
+            commandline = new CommandlineJava();
+        }
+        return commandline;
+    }
 }

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

Reply via email to