ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/junit JUnitTask.java
Date Thu, 12 Jul 2001 07:09:29 GMT
bodewig     01/07/12 00:09:26

  Modified:    .        WHATSNEW build.xml
               src/main/org/apache/tools/ant/taskdefs/optional/junit
                        JUnitTask.java
  Log:
  <junit> will now try to include the task-definition itself as well as
  the needed support classes (Ant and JUnit itself) in the classpath if
  running in forked mode - this means that you shouldn't have to use
  different classpath elements for "in VM" and "fork" mode any longer.
  
  Doesn't work for JDK 1.1 as the URL returned by Class.getResource
  doesn't contain the name of the JAR file there.
  
  PR: 1239
  
  Revision  Changes    Path
  1.125     +3 -0      jakarta-ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/WHATSNEW,v
  retrieving revision 1.124
  retrieving revision 1.125
  diff -u -r1.124 -r1.125
  --- WHATSNEW	2001/07/11 16:11:21	1.124
  +++ WHATSNEW	2001/07/12 07:09:05	1.125
  @@ -166,6 +166,9 @@
   
   * <ftp> closes remote connection when it's done.
   
  +* <junit> tries to include all necessary classes for the task itself
  +  to the classpath when running in fork mode - doesn't work for JDK 1.1
  +
   Changes from Ant 1.2 to Ant 1.3
   ===========================================
   
  
  
  
  1.160     +0 -9      jakarta-ant/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/build.xml,v
  retrieving revision 1.159
  retrieving revision 1.160
  diff -u -r1.159 -r1.160
  --- build.xml	2001/07/11 16:11:22	1.159
  +++ build.xml	2001/07/12 07:09:08	1.160
  @@ -711,13 +711,4 @@
       <antcall target="dist-lite"/>
     </target>
     
  -  <!--
  -       =================================================================== 
  -         Creates the Ant website
  -       =================================================================== 
  -  -->
  -  <target name="website"
  -          description="--> creates the Ant website">
  -    <ant dir="webpage" target="docs" />
  -  </target>
   </project>
  
  
  
  1.21      +45 -0     jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
  
  Index: JUnitTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- JUnitTask.java	2001/07/11 09:29:50	1.20
  +++ JUnitTask.java	2001/07/12 07:09:19	1.21
  @@ -79,6 +79,8 @@
   import java.util.Random;
   import java.util.Vector;
   
  +import java.net.URL;
  +
   /**
    * Ant task to run JUnit tests.
    *
  @@ -281,6 +283,17 @@
       }
   
       /**
  +     * Adds the jars or directories containing Ant, this task and
  +     * JUnit to the classpath - this should make the forked JVM work
  +     * without having to specify the directly.
  +     */
  +    public void init() {
  +        addClasspathEntry("/junit/framework/TestCase.class");
  +        addClasspathEntry("/org/apache/tools/ant/Task.class");
  +        addClasspathEntry("/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.class");
  +    }
  +
  +    /**
        * Runs the testcase.
        */
       public void execute() throws BuildException {
  @@ -521,6 +534,38 @@
               return project.resolveFile(absFilename);
           }
           return null;
  +    }
  +
  +    /**
  +     * Search for the given resource and add the directory or archive
  +     * that contains it to the classpath.
  +     *
  +     * <p>Doesn't work for archives in JDK 1.1 as the URL returned by
  +     * getResource doesn't contain the name of the archive.</p>
  +     */
  +    protected void addClasspathEntry(String resource) {
  +        URL url = getClass().getResource(resource);
  +        if (url != null) {
  +            String u = url.toString();
  +            if (u.startsWith("jar:file:")) {
  +                int pling = u.indexOf("!");
  +                String jarName = u.substring(9, pling);
  +                log("Implicitly adding "+jarName+" to classpath", 
  +                    Project.MSG_DEBUG);
  +                createClasspath().setLocation(new File((new File(jarName)).getAbsolutePath()));
  +            } else if (u.startsWith("file:")) {
  +                int tail = u.indexOf(resource);
  +                String dirName = u.substring(5, tail);
  +                log("Implicitly adding "+dirName+" to classpath", 
  +                    Project.MSG_DEBUG);
  +                createClasspath().setLocation(new File((new File(dirName)).getAbsolutePath()));
  +            } else {
  +                log("Don\'t know how to handle resource URL "+u, 
  +                    Project.MSG_DEBUG);
  +            }
  +        } else {
  +            log("Couldn\'t find "+resource, Project.MSG_DEBUG);
  +        }
       }
   
   }
  
  
  

Mime
View raw message