peterreilly    2003/11/03 07:45:11

  Modified:    docs/manual/OptionalTasks Tag: ANT_16_BRANCH jdepend.html
               src/main/org/apache/tools/ant/taskdefs/optional/jdepend Tag:
                        ANT_16_BRANCH JDependTask.java
  Added:       src/etc/testcases/taskdefs/optional/jdepend Tag:
                        ANT_16_BRANCH jdepend.xml
               src/testcases/org/apache/tools/ant/taskdefs/optional/jdepend
                        Tag: ANT_16_BRANCH JDependTest.java
  Log:
  sync with HEAD
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.10.2.2  +6 -0      ant/docs/manual/OptionalTasks/jdepend.html
  
  Index: jdepend.html
  ===================================================================
  RCS file: /home/cvs/ant/docs/manual/OptionalTasks/jdepend.html,v
  retrieving revision 1.10.2.1
  retrieving revision 1.10.2.2
  diff -u -r1.10.2.1 -r1.10.2.2
  --- jdepend.html      9 Oct 2003 21:01:12 -0000       1.10.2.1
  +++ jdepend.html      3 Nov 2003 15:45:10 -0000       1.10.2.2
  @@ -73,6 +73,12 @@
       <td ALIGN=CENTER VALIGN=TOP>No</td>
     </tr>
     <tr>
  +    <td VALIGN=TOP>includeruntime</td>
  +    <td VALIGN=TOP>Implicitly add the classes required to run jdepend
  +    in forked mode. (Ignored if fork is disabled). Since ant 1.6.</td>
  +    <td ALIGN=CENTER VALIGN=TOP>No, default is "no".</td>
  +  </tr>
  +  <tr>
       <td VALIGN=TOP>classpathref</td>
       <td VALIGN=TOP>the classpath to use, given as reference to a PATH 
defined elsewhere.</td>
       <td ALIGN=CENTER VALIGN=TOP>No</td>
  
  
  
  No                   revision
  No                   revision
  1.1.2.1   +0 -0      
ant/src/etc/testcases/taskdefs/optional/jdepend/jdepend.xml
  
  Index: jdepend.xml
  ===================================================================
  RCS file: 
/home/cvs/ant/src/etc/testcases/taskdefs/optional/jdepend/jdepend.xml,v
  retrieving revision 1.1
  retrieving revision 1.1.2.1
  diff -u -r1.1 -r1.1.2.1
  
  
  
  No                   revision
  No                   revision
  1.22.2.2  +197 -71   
ant/src/main/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTask.java
  
  Index: JDependTask.java
  ===================================================================
  RCS file: 
/home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTask.java,v
  retrieving revision 1.22.2.1
  retrieving revision 1.22.2.2
  diff -u -r1.22.2.1 -r1.22.2.2
  --- JDependTask.java  3 Nov 2003 15:23:57 -0000       1.22.2.1
  +++ JDependTask.java  3 Nov 2003 15:45:11 -0000       1.22.2.2
  @@ -61,6 +61,7 @@
   import java.lang.reflect.Constructor;
   import java.lang.reflect.Method;
   import java.util.Vector;
  +import java.util.Enumeration;
   import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.Project;
   import org.apache.tools.ant.Task;
  @@ -73,6 +74,7 @@
   import org.apache.tools.ant.types.Path;
   import org.apache.tools.ant.types.PatternSet;
   import org.apache.tools.ant.types.Reference;
  +import org.apache.tools.ant.util.LoaderUtils;
   
   /**
    * Runs JDepend tests.
  @@ -90,24 +92,27 @@
       //private CommandlineJava commandline = new CommandlineJava();
   
       // required attributes
  -    private Path _sourcesPath; // Deprecated!
  -    private Path _classesPath; // Use this going forward
  +    private Path sourcesPath; // Deprecated!
  +    private Path classesPath; // Use this going forward
   
       // optional attributes
  -    private File _outputFile;
  -    private File _dir;
  -    private Path _compileClasspath;
  -    private boolean _haltonerror = false;
  -    private boolean _fork = false;
  -    //private Integer _timeout = null;
  +    private File outputFile;
  +    private File dir;
  +    private Path compileClasspath;
  +    private boolean haltonerror = false;
  +    private boolean fork = false;
  +    private Long timeout = null;
   
  -    private String _jvm = null;
  +    private String jvm = null;
       private String format = "text";
       private PatternSet defaultPatterns = new PatternSet();
   
       private static Constructor packageFilterC;
       private static Method setFilter;
   
  +    private boolean includeRuntime = false;
  +    private Path runtimeClasses = null;
  +
       static {
           try {
               Class packageFilter =
  @@ -124,54 +129,83 @@
           }
       }
   
  -    public JDependTask() {
  +    /**
  +     * If true,
  +     *  include jdepend.jar in the forked VM.
  +     *
  +     * @param b include ant run time yes or no
  +     * @since Ant 1.6
  +     */
  +    public void setIncluderuntime(boolean b) {
  +        includeRuntime = b;
  +    }
  +
  +    /**
  +     * Set the timeout value (in milliseconds).
  +     *
  +     * <p>If the operation is running for more than this value, the jdepend
  +     * will be canceled. (works only when in 'fork' mode).</p>
  +     * @param value the maximum time (in milliseconds) allowed before
  +     * declaring the test as 'timed-out'
  +     * @see #setFork(boolean)
  +     */
  +    public void setTimeout(Long value) {
  +        timeout = value;
       }
   
  -    /*
  -      public void setTimeout(Integer value) {
  -      _timeout = value;
  -      }
  -
  -      public Integer getTimeout() {
  -      return _timeout;
  -      }
  -    */
  +    /**
  +     * @return the timeout value
  +     */
  +    public Long getTimeout() {
  +        return timeout;
  +    }
   
       /**
        * The output file name.
        *
  -     * @param outputFile
  +     * @param outputFile the output file name
        */
       public void setOutputFile(File outputFile) {
  -        _outputFile = outputFile;
  +        this.outputFile = outputFile;
       }
   
  +    /**
  +     * @return the output file name
  +     */
       public File getOutputFile() {
  -        return _outputFile;
  +        return outputFile;
       }
   
       /**
        * Whether or not to halt on failure. Default: false.
  +     * @param haltonerror the value to set
        */
  -    public void setHaltonerror(boolean value) {
  -        _haltonerror = value;
  +    public void setHaltonerror(boolean haltonerror) {
  +        this.haltonerror = haltonerror;
       }
   
  +    /**
  +     * @return the value of the haltonerror attribute
  +     */
       public boolean getHaltonerror() {
  -        return _haltonerror;
  +        return haltonerror;
       }
   
       /**
        * If true, forks into a new JVM. Default: false.
        *
  -     * @param   value   <tt>true</tt> if a JVM should be forked, otherwise 
<tt>false<tt>
  +     * @param   value   <tt>true</tt> if a JVM should be forked,
  +     *                  otherwise <tt>false<tt>
        */
       public void setFork(boolean value) {
  -        _fork = value;
  +        fork = value;
       }
   
  +    /**
  +     * @return the value of the fork attribute
  +     */
       public boolean getFork() {
  -        return _fork;
  +        return fork;
       }
   
       /**
  @@ -182,47 +216,49 @@
        * @see #setFork(boolean)
        */
       public void setJvm(String value) {
  -        _jvm = value;
  +        jvm = value;
   
       }
   
       /**
        * Adds a path to source code to analyze.
  +     * @return a source path
        * @deprecated
        */
       public Path createSourcespath() {
  -        if (_sourcesPath == null) {
  -            _sourcesPath = new Path(getProject());
  +        if (sourcesPath == null) {
  +            sourcesPath = new Path(getProject());
           }
  -        return _sourcesPath.createPath();
  +        return sourcesPath.createPath();
       }
   
       /**
        * Gets the sourcepath.
  -     *
  +     * @return the sources path
        * @deprecated
        *
        */
       public Path getSourcespath() {
  -        return _sourcesPath;
  +        return sourcesPath;
       }
   
       /**
        * Adds a path to class code to analyze.
  +     * @return a classes path
        */
       public Path createClassespath() {
  -        if (_classesPath == null) {
  -            _classesPath = new Path(getProject());
  +        if (classesPath == null) {
  +            classesPath = new Path(getProject());
           }
  -        return _classesPath.createPath();
  +        return classesPath.createPath();
       }
   
       /**
        * Gets the classespath.
  -     *
  +     * @return the classes path
        */
       public Path getClassespath() {
  -        return _classesPath;
  +        return classesPath;
       }
   
       /**
  @@ -231,42 +267,52 @@
        * @see #setFork(boolean)
        */
       public void setDir(File dir) {
  -        _dir = dir;
  +        this.dir = dir;
       }
   
  +    /**
  +     * @return the dir attribute
  +     */
       public File getDir() {
  -        return _dir;
  +        return dir;
       }
   
       /**
        * Set the classpath to be used for this compilation.
  +     * @param classpath a class path to be used
        */
       public void setClasspath(Path classpath) {
  -        if (_compileClasspath == null) {
  -            _compileClasspath = classpath;
  +        if (compileClasspath == null) {
  +            compileClasspath = classpath;
           } else {
  -            _compileClasspath.append(classpath);
  +            compileClasspath.append(classpath);
           }
       }
   
  -    /** Gets the classpath to be used for this compilation. */
  +    /**
  +     * Gets the classpath to be used for this compilation.
  +     * @return the class path used for compilation
  +     */
       public Path getClasspath() {
  -        return _compileClasspath;
  +        return compileClasspath;
       }
   
       /**
        * Adds a path to the classpath.
  +     * @return a classpath
        */
       public Path createClasspath() {
  -        if (_compileClasspath == null) {
  -            _compileClasspath = new Path(getProject());
  +        if (compileClasspath == null) {
  +            compileClasspath = new Path(getProject());
           }
  -        return _compileClasspath.createPath();
  +        return compileClasspath.createPath();
       }
   
       /**
        * Create a new JVM argument. Ignored if no JVM is forked.
  -     * @return  create a new JVM argument so that any argument can be passed 
to the JVM.
  +     * @param commandline the commandline to create the argument on
  +     * @return  create a new JVM argument so that any argument can
  +     *          be passed to the JVM.
        * @see #setFork(boolean)
        */
       public Commandline.Argument createJvmarg(CommandlineJava commandline) {
  @@ -275,6 +321,7 @@
   
       /**
        * Adds a reference to a classpath defined elsewhere.
  +     * @param r a classpath reference
        */
       public void setClasspathRef(Reference r) {
           createClasspath().setRefid(r);
  @@ -282,11 +329,15 @@
   
       /**
        * add a name entry on the exclude list
  +     * @return a pattern for the excludes
        */
       public PatternSet.NameEntry createExclude() {
           return defaultPatterns.createExclude();
       }
   
  +    /**
  +     * @return the excludes patterns
  +     */
       public PatternSet getExcludes() {
           return defaultPatterns;
       }
  @@ -294,15 +345,23 @@
       /**
        * The format to write the output in, "xml" or "text".
        *
  -     * @param ea
  +     * @param ea xml or text
        */
       public void setFormat(FormatAttribute ea) {
           format = ea.getValue();
       }
   
  +    /**
  +     * A class for the enumerated attribute format,
  +     * values are xml and text.
  +     * @see EnumeratedAttribute
  +     */
       public static class FormatAttribute extends EnumeratedAttribute {
           private String [] formats = new String[]{"xml", "text"};
   
  +        /**
  +         * @return the enumerated values
  +         */
           public String[] getValues() {
               return formats;
           }
  @@ -317,6 +376,48 @@
        */
       private static final int ERRORS = 1;
   
  +    /**
  +     * 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>
  +     *
  +     * @param resource resource that one wants to lookup
  +     * @since Ant 1.6
  +     */
  +    private void addClasspathEntry(String resource) {
  +        /*
  +         * pre Ant 1.6 this method used to call getClass().getResource
  +         * while Ant 1.6 will call ClassLoader.getResource().
  +         *
  +         * The difference is that Class.getResource expects a leading
  +         * slash for "absolute" resources and will strip it before
  +         * delegating to ClassLoader.getResource - so we now have to
  +         * emulate Class's behavior.
  +         */
  +        if (resource.startsWith("/")) {
  +            resource = resource.substring(1);
  +        } else {
  +            resource = "org/apache/tools/ant/taskdefs/optional/jdepend/"
  +                + resource;
  +        }
  +
  +        File f = LoaderUtils.getResourceSource(getClass().getClassLoader(),
  +                                               resource);
  +        if (f != null) {
  +            log("Found " + f.getAbsolutePath(), Project.MSG_DEBUG);
  +            runtimeClasses.createPath().setLocation(f);
  +        } else {
  +            log("Couldn\'t find " + resource, Project.MSG_DEBUG);
  +        }
  +    }
  +
  +    /**
  +     * execute the task
  +     *
  +     * @exception BuildException if an error occurs
  +     */
       public void execute() throws BuildException {
   
           CommandlineJava commandline = new CommandlineJava();
  @@ -328,8 +429,8 @@
                   commandline.setClassname("jdepend.xmlui.JDepend");
               }
   
  -        if (_jvm != null) {
  -            commandline.setVm(_jvm);
  +        if (jvm != null) {
  +            commandline.setVm(jvm);
           }
           if (getSourcespath() == null && getClassespath() == null) {
               throw new BuildException("Missing classespath required 
argument");
  @@ -342,7 +443,7 @@
   
           // execute the test and get the return code
           int exitValue = JDependTask.ERRORS;
  -        //boolean wasKilled = false;
  +        boolean wasKilled = false;
           if (!getFork()) {
               exitValue = executeInVM(commandline);
           } else {
  @@ -350,21 +451,22 @@
               exitValue = executeAsForked(commandline, watchdog);
               // null watchdog means no timeout, you'd better not check with 
null
               if (watchdog != null) {
  -                //info will be used in later version do nothing for now
  -                //wasKilled = watchdog.killedProcess();
  +                wasKilled = watchdog.killedProcess();
               }
           }
   
           // if there is an error/failure and that it should halt, stop
           // everything otherwise just log a statement
  -        boolean errorOccurred = exitValue == JDependTask.ERRORS;
  +        boolean errorOccurred = exitValue == JDependTask.ERRORS || wasKilled;
   
           if (errorOccurred) {
  +            String errorMessage = "JDepend FAILED"
  +                + (wasKilled ? " - Timed out" : "");
  +
               if  (getHaltonerror()) {
  -                throw new BuildException("JDepend failed",
  -                                         getLocation());
  +                throw new BuildException(errorMessage, getLocation());
               } else {
  -                log("JDepend FAILED", Project.MSG_ERR);
  +                log(errorMessage, Project.MSG_ERR);
               }
           }
       }
  @@ -376,6 +478,10 @@
   
       /**
        * Execute inside VM.
  +     *
  +     * @param commandline the command line
  +     * @return the return value of the mvm
  +     * @exception BuildException if an error occurs
        */
       public int executeInVM(CommandlineJava commandline) throws 
BuildException {
           jdepend.textui.JDepend jdepend;
  @@ -489,13 +595,18 @@
        * Execute the task by forking a new JVM. The command will block until
        * it finishes. To know if the process was destroyed or not, use the
        * <tt>killedProcess()</tt> method of the watchdog class.
  +     * @param commandline the commandline for forked jvm
        * @param  watchdog   the watchdog in charge of cancelling the test if it
  -     * exceeds a certain amount of time. Can be <tt>null</tt>, in this case
  -     * the test could probably hang forever.
  +     * exceeds a certain amount of time. Can be <tt>null</tt>.
  +     * @return the result of running the jdepend
  +     * @throws BuildException in case of error
        */
       // JL: comment extracted from JUnitTask (and slightly modified)
       public int executeAsForked(CommandlineJava commandline,
                                  ExecuteWatchdog watchdog) throws 
BuildException {
  +        runtimeClasses = new Path(getProject());
  +        addClasspathEntry("/jdepend/textui/JDepend.class");
  +
           // if not set, auto-create the ClassPath from the project
           createClasspath();
   
  @@ -506,12 +617,30 @@
               createJvmarg(commandline).setValue(getClasspath().toString());
           }
   
  +        if (includeRuntime) {
  +            Vector v = Execute.getProcEnvironment();
  +            Enumeration e = v.elements();
  +            while (e.hasMoreElements()) {
  +                String s = (String) e.nextElement();
  +                if (s.startsWith("CLASSPATH=")) {
  +                    commandline.createClasspath(getProject()).createPath()
  +                        .append(new Path(getProject(),
  +                                         s.substring("CLASSPATH=".length()
  +                                                     )));
  +                }
  +            }
  +            log("Implicitly adding " + runtimeClasses + " to CLASSPATH",
  +                Project.MSG_VERBOSE);
  +            commandline.createClasspath(getProject()).createPath()
  +                .append(runtimeClasses);
  +        }
  +
           if (getOutputFile() != null) {
               // having a space between the file and its path causes 
commandline
               // to add quotes around the argument thus making JDepend not 
taking
               // it into account. Thus we split it in two
               commandline.createArgument().setValue("-file");
  -            commandline.createArgument().setValue(_outputFile.getPath());
  +            commandline.createArgument().setValue(outputFile.getPath());
               // we have to find a cleaner way to put this output
           }
   
  @@ -573,15 +702,12 @@
       /**
        * @return <tt>null</tt> if there is a timeout value, otherwise the
        * watchdog instance.
  +     * @throws BuildException in case of error
        */
       protected ExecuteWatchdog createWatchdog() throws BuildException {
  -
  -        return null;
  -        /*
  -          if (getTimeout() == null) {
  -          return null;
  -          }
  -          return new ExecuteWatchdog(getTimeout().intValue());
  -        */
  +        if (getTimeout() == null) {
  +            return null;
  +        }
  +        return new ExecuteWatchdog(getTimeout().longValue());
       }
   }
  
  
  
  No                   revision
  No                   revision
  1.1.2.1   +0 -0      
ant/src/testcases/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTest.java
  
  Index: JDependTest.java
  ===================================================================
  RCS file: 
/home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTest.java,v
  retrieving revision 1.1
  retrieving revision 1.1.2.1
  diff -u -r1.1 -r1.1.2.1
  
  
  

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

Reply via email to