ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: ant/src/main/org/apache/tools/ant/taskdefs/optional/sitraka CovBase.java CovMerge.java CovReport.java Coverage.java
Date Wed, 02 Apr 2003 12:42:51 GMT
bodewig     2003/04/02 04:42:51

  Modified:    src/main/org/apache/tools/ant/taskdefs/optional/sitraka
                        CovMerge.java CovReport.java Coverage.java
  Added:       src/main/org/apache/tools/ant/taskdefs/optional/sitraka
                        CovBase.java
  Log:
  Initial refactoring to address 14849
  
  Revision  Changes    Path
  1.15      +9 -26     ant/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/CovMerge.java
  
  Index: CovMerge.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/CovMerge.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- CovMerge.java	10 Feb 2003 14:14:23 -0000	1.14
  +++ CovMerge.java	2 Apr 2003 12:42:50 -0000	1.15
  @@ -1,7 +1,7 @@
   /*
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2001-2002 The Apache Software Foundation.  All rights
  + * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -63,7 +63,6 @@
   import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.DirectoryScanner;
   import org.apache.tools.ant.Project;
  -import org.apache.tools.ant.Task;
   import org.apache.tools.ant.taskdefs.Execute;
   import org.apache.tools.ant.taskdefs.LogStreamHandler;
   import org.apache.tools.ant.types.Commandline;
  @@ -75,10 +74,7 @@
    * @author <a href="sbailliez@imediation.com">Stephane Bailliez</a>
    * @ant.task name="jpcovmerge" category="metrics"
    */
  -public class CovMerge extends Task {
  -
  -    /** coverage home, it is mandatory */
  -    private File home = null;
  +public class CovMerge extends CovBase {
   
       /** the name of the output snapshot */
       private File tofile = null;
  @@ -89,13 +85,6 @@
       private boolean verbose;
   
       /**
  -     * The directory where JProbe is installed.
  -     */
  -    public void setHome(File value) {
  -        this.home = value;
  -    }
  -
  -    /**
        * Set the output snapshot file.
        */
       public void setTofile(File value) {
  @@ -129,11 +118,12 @@
           File paramfile = createParamFile();
           try {
               Commandline cmdl = new Commandline();
  -            cmdl.setExecutable(new File(home, "jpcovmerge").getAbsolutePath());
  +            cmdl.setExecutable(findExecutable("jpcovmerge"));
               if (verbose) {
                   cmdl.createArgument().setValue("-v");
               }
  -            cmdl.createArgument().setValue("-jp_paramfile=" + paramfile.getAbsolutePath());
  +            cmdl.createArgument().setValue(getParamFileArgument() 
  +                                           + paramfile.getAbsolutePath());
   
               LogStreamHandler handler = new LogStreamHandler(this, Project.MSG_INFO, Project.MSG_WARN);
               Execute exec = new Execute(handler);
  @@ -161,13 +151,12 @@
           }
   
           // check coverage home
  -        if (home == null || !home.isDirectory()) {
  +        if (getHome() == null || !getHome().isDirectory()) {
               throw new BuildException("Invalid home directory. Must point to JProbe home
directory");
           }
  -        home = new File(home, "coverage");
  -        File jar = new File(home, "coverage.jar");
  +        File jar = findJar("coverage/coverage.jar");
           if (!jar.exists()) {
  -            throw new BuildException("Cannot find Coverage directory: " + home);
  +            throw new BuildException("Cannot find Coverage directory: " + getHome());
           }
       }
   
  @@ -200,7 +189,7 @@
        */
       protected File createParamFile() throws BuildException {
           File[] snapshots = getSnapshots();
  -        File file = createTmpFile();
  +        File file = createTempFile("jpcovm");
           FileWriter fw = null;
           try {
               fw = new FileWriter(file);
  @@ -224,10 +213,4 @@
           return file;
       }
   
  -    /** create a temporary file in the current dir (For JDK1.1 support) */
  -    protected File createTmpFile() {
  -        final long rand = (new Random(System.currentTimeMillis())).nextLong();
  -        File file = new File("jpcovmerge" + rand + ".tmp");
  -        return file;
  -    }
   }
  
  
  
  1.16      +7 -19     ant/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/CovReport.java
  
  Index: CovReport.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/CovReport.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- CovReport.java	10 Feb 2003 14:14:23 -0000	1.15
  +++ CovReport.java	2 Apr 2003 12:42:50 -0000	1.16
  @@ -1,7 +1,7 @@
   /*
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2001-2002 The Apache Software Foundation.  All rights
  + * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -66,7 +66,6 @@
   import javax.xml.transform.stream.StreamResult;
   import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.Project;
  -import org.apache.tools.ant.Task;
   import org.apache.tools.ant.taskdefs.Execute;
   import org.apache.tools.ant.taskdefs.LogStreamHandler;
   import org.apache.tools.ant.types.Commandline;
  @@ -81,7 +80,7 @@
    * @author <a href="sbailliez@imediation.com">Stephane Bailliez</a>
    * @ant.task name="jpcovreport" category="metrics"
    */
  -public class CovReport extends Task {
  +public class CovReport extends CovBase {
       /*
         jpcoverport [options] -output=file -snapshot=snapshot.jpc
         jpcovreport [options] [-paramfile=file] -output=<fileName> -snapshot=<fileName>
  @@ -130,9 +129,6 @@
   
         /*
   
  -      /** coverage home,  mandatory */
  -    private File home = null;
  -
       /** format of generated report, optional */
       private String format = null;
   
  @@ -163,13 +159,6 @@
       private Reference reference = null;
   
   
  -    /**
  -     * The directory where JProbe is installed.
  -     */
  -    public void setHome(File value) {
  -        this.home = value;
  -    }
  -
       public static class ReportFormat extends EnumeratedAttribute {
           public String[] getValues() {
               return new String[]{"html", "text", "xml"};
  @@ -279,13 +268,12 @@
           if (snapshot == null) {
               throw new BuildException("'snapshot' attribute must be set.");
           }
  -        if (home == null) {
  +        if (getHome() == null) {
               throw new BuildException("'home' attribute must be set to JProbe home directory");
           }
  -        home = new File(home, "coverage");
  -        File jar = new File(home, "coverage.jar");
  +        File jar = findJar("coverage/coverage.jar");
           if (!jar.exists()) {
  -            throw new BuildException("Cannot find Coverage directory: " + home);
  +            throw new BuildException("Cannot find Coverage directory: " + getHome());
           }
           if (reference != null && !"xml".equals(format)) {
               log("Ignored reference. It cannot be used in non XML report.");
  @@ -299,7 +287,7 @@
           try {
               Commandline cmdl = new Commandline();
               // we need to run Coverage from his directory due to dll/jar issues
  -            cmdl.setExecutable(new File(home, "jpcovreport").getAbsolutePath());
  +            cmdl.setExecutable(findExecutable("jpcovreport"));
               String[] params = getParameters();
               for (int i = 0; i < params.length; i++) {
                   cmdl.createArgument().setValue(params[i]);
  @@ -398,7 +386,7 @@
                   log("Creating enhanced XML report", Project.MSG_VERBOSE);
                   XMLReport report = new XMLReport(CovReport.this, tofile);
                   report.setReportFilters(filters);
  -                report.setJProbehome(new File(home.getParent()));
  +                report.setJProbehome(new File(getHome().getParent()));
                   Document doc = report.createDocument(paths);
                   TransformerFactory tfactory = TransformerFactory.newInstance();
                   Transformer transformer = tfactory.newTransformer();
  
  
  
  1.15      +10 -32    ant/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/Coverage.java
  
  Index: Coverage.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/Coverage.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- Coverage.java	10 Feb 2003 14:14:23 -0000	1.14
  +++ Coverage.java	2 Apr 2003 12:42:50 -0000	1.15
  @@ -1,7 +1,7 @@
   /*
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2001-2002 The Apache Software Foundation.  All rights
  + * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -72,6 +72,7 @@
   import org.apache.tools.ant.types.EnumeratedAttribute;
   import org.apache.tools.ant.types.FileSet;
   import org.apache.tools.ant.types.Path;
  +import org.apache.tools.ant.util.JavaEnvUtils;
   
   /**
    * Runs Sitraka JProbe Coverage.
  @@ -86,9 +87,7 @@
    *
    * @ant.task name="jpcoverage" category="metrics"
    */
  -public class Coverage extends Task {
  -
  -    protected File home;
  +public class Coverage extends CovBase {
   
       protected Commandline cmdl = new Commandline();
   
  @@ -131,13 +130,6 @@
   
       //--------- setters used via reflection --
   
  -    /**
  -     * The directory where JProbe is installed.
  -     */
  -    public void setHome(File value) {
  -        home = value;
  -    }
  -
       /** seed name for snapshot file. Can be null, default to snap */
       public void setSeedname(String value) {
           seedName = value;
  @@ -331,7 +323,7 @@
           }
           try {
               // we need to run Coverage from his directory due to dll/jar issues
  -            cmdl.setExecutable(new File(home, "jplauncher").getAbsolutePath());
  +            cmdl.setExecutable(findExecutable("jplauncher"));
               cmdl.createArgument().setValue("-jp_input=" + paramfile.getAbsolutePath());
   
               // use the custom handler for stdin issues
  @@ -356,13 +348,12 @@
       /** wheck what is necessary to check, Coverage will do the job for us */
       protected void checkOptions() throws BuildException {
           // check coverage home
  -        if (home == null || !home.isDirectory()) {
  +        if (getHome() == null || !getHome().isDirectory()) {
               throw new BuildException("Invalid home directory. Must point to JProbe home
directory");
           }
  -        home = new File(home, "coverage");
  -        File jar = new File(home, "coverage.jar");
  +        File jar = findJar("coverage/coverage.jar");
           if (!jar.exists()) {
  -            throw new BuildException("Cannot find Coverage directory: " + home);
  +            throw new BuildException("Cannot find Coverage directory: " + getHome());
           }
   
           // make sure snapshot dir exists and is resolved
  @@ -381,17 +372,11 @@
           // check for info, do your best to select the java executable.
           // JProbe 3.0 fails if there is no javaexe option. So
           if (javaExe == null && (vm == null || "java2".equals(vm))) {
  -            String version = System.getProperty("java.version");
  -            // make we are using 1.2+, if it is, then do your best to
  -            // get a javaexe
  -            if (!version.startsWith("1.1")) {
  +            if (!JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_1)) {
                   if (vm == null) {
                       vm = "java2";
                   }
  -                // if we are here obviously it is java2
  -                String home = System.getProperty("java.home");
  -                boolean isUnix = File.separatorChar == '/';
  -                javaExe = isUnix ? new File(home, "bin/java") : new File(home, "/bin/java.exe");
  +                javaExe = new File(JavaEnvUtils.getJreExecutable("java"));
               }
           }
       }
  @@ -464,7 +449,7 @@
        */
       protected File createParamFile() throws BuildException {
           //@todo change this when switching to JDK 1.2 and use File.createTmpFile()
  -        File file = createTmpFile();
  +        File file = createTempFile("jpcov");
           log("Creating parameter file: " + file, Project.MSG_VERBOSE);
   
           // options need to be one per line in the parameter file
  @@ -494,13 +479,6 @@
                   }
               }
           }
  -        return file;
  -    }
  -
  -    /** create a temporary file in the current dir (For JDK1.1 support) */
  -    protected File createTmpFile() {
  -        final long rand = (new Random(System.currentTimeMillis())).nextLong();
  -        File file = new File("jpcoverage" + rand + ".tmp");
           return file;
       }
   
  
  
  
  1.1                  ant/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/CovBase.java
  
  Index: CovBase.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "Ant" and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.tools.ant.taskdefs.optional.sitraka;
  
  import java.io.File;
  import org.apache.tools.ant.Task;
  import org.apache.tools.ant.util.FileUtils;
  
  /**
   * Base class that deals with JProbe version incompatibilities.
   *
   * @since Ant 1.6
   *
   * @author Stefan Bodewig
   */
  public abstract class CovBase extends Task {
      private File home;
      private static FileUtils fu = FileUtils.newFileUtils();
  
      /**
       * The directory where JProbe is installed.
       */
      public void setHome(File value) {
          this.home = value;
      }
  
      protected File getHome() {
          return home;
      }
  
      protected File findJar(String relativePath) {
          return fu.resolveFile(home, relativePath);
      }
  
      protected String findExecutable(String relativePath) {
          return fu.resolveFile(home, relativePath).getAbsolutePath();
      }
  
      protected File createTempFile(String prefix) {
          return fu.createTempFile(prefix, ".tmp", null);
      }
  
      protected String getParamFileArgument() {
          return "-jp_paramfile=";
      }
  }
  
  
  

Mime
View raw message