git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274372 13f79535-47bb-0310-9956-ffa450edef68master
@@ -0,0 +1,98 @@ | |||||
/* | |||||
* 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="; | |||||
} | |||||
} |
@@ -1,7 +1,7 @@ | |||||
/* | /* | ||||
* The Apache Software License, Version 1.1 | * 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. | * reserved. | ||||
* | * | ||||
* Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | ||||
@@ -63,7 +63,6 @@ import java.util.Vector; | |||||
import org.apache.tools.ant.BuildException; | import org.apache.tools.ant.BuildException; | ||||
import org.apache.tools.ant.DirectoryScanner; | import org.apache.tools.ant.DirectoryScanner; | ||||
import org.apache.tools.ant.Project; | 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.Execute; | ||||
import org.apache.tools.ant.taskdefs.LogStreamHandler; | import org.apache.tools.ant.taskdefs.LogStreamHandler; | ||||
import org.apache.tools.ant.types.Commandline; | import org.apache.tools.ant.types.Commandline; | ||||
@@ -75,10 +74,7 @@ import org.apache.tools.ant.types.FileSet; | |||||
* @author <a href="sbailliez@imediation.com">Stephane Bailliez</a> | * @author <a href="sbailliez@imediation.com">Stephane Bailliez</a> | ||||
* @ant.task name="jpcovmerge" category="metrics" | * @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 */ | /** the name of the output snapshot */ | ||||
private File tofile = null; | private File tofile = null; | ||||
@@ -88,13 +84,6 @@ public class CovMerge extends Task { | |||||
private boolean verbose; | private boolean verbose; | ||||
/** | |||||
* The directory where JProbe is installed. | |||||
*/ | |||||
public void setHome(File value) { | |||||
this.home = value; | |||||
} | |||||
/** | /** | ||||
* Set the output snapshot file. | * Set the output snapshot file. | ||||
*/ | */ | ||||
@@ -129,11 +118,12 @@ public class CovMerge extends Task { | |||||
File paramfile = createParamFile(); | File paramfile = createParamFile(); | ||||
try { | try { | ||||
Commandline cmdl = new Commandline(); | Commandline cmdl = new Commandline(); | ||||
cmdl.setExecutable(new File(home, "jpcovmerge").getAbsolutePath()); | |||||
cmdl.setExecutable(findExecutable("jpcovmerge")); | |||||
if (verbose) { | if (verbose) { | ||||
cmdl.createArgument().setValue("-v"); | 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); | LogStreamHandler handler = new LogStreamHandler(this, Project.MSG_INFO, Project.MSG_WARN); | ||||
Execute exec = new Execute(handler); | Execute exec = new Execute(handler); | ||||
@@ -161,13 +151,12 @@ public class CovMerge extends Task { | |||||
} | } | ||||
// check coverage home | // 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"); | 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()) { | if (!jar.exists()) { | ||||
throw new BuildException("Cannot find Coverage directory: " + home); | |||||
throw new BuildException("Cannot find Coverage directory: " + getHome()); | |||||
} | } | ||||
} | } | ||||
@@ -200,7 +189,7 @@ public class CovMerge extends Task { | |||||
*/ | */ | ||||
protected File createParamFile() throws BuildException { | protected File createParamFile() throws BuildException { | ||||
File[] snapshots = getSnapshots(); | File[] snapshots = getSnapshots(); | ||||
File file = createTmpFile(); | |||||
File file = createTempFile("jpcovm"); | |||||
FileWriter fw = null; | FileWriter fw = null; | ||||
try { | try { | ||||
fw = new FileWriter(file); | fw = new FileWriter(file); | ||||
@@ -224,10 +213,4 @@ public class CovMerge extends Task { | |||||
return file; | 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,7 +1,7 @@ | |||||
/* | /* | ||||
* The Apache Software License, Version 1.1 | * 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. | * reserved. | ||||
* | * | ||||
* Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | ||||
@@ -66,7 +66,6 @@ import javax.xml.transform.dom.DOMSource; | |||||
import javax.xml.transform.stream.StreamResult; | import javax.xml.transform.stream.StreamResult; | ||||
import org.apache.tools.ant.BuildException; | import org.apache.tools.ant.BuildException; | ||||
import org.apache.tools.ant.Project; | 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.Execute; | ||||
import org.apache.tools.ant.taskdefs.LogStreamHandler; | import org.apache.tools.ant.taskdefs.LogStreamHandler; | ||||
import org.apache.tools.ant.types.Commandline; | import org.apache.tools.ant.types.Commandline; | ||||
@@ -81,7 +80,7 @@ import org.w3c.dom.Document; | |||||
* @author <a href="sbailliez@imediation.com">Stephane Bailliez</a> | * @author <a href="sbailliez@imediation.com">Stephane Bailliez</a> | ||||
* @ant.task name="jpcovreport" category="metrics" | * @ant.task name="jpcovreport" category="metrics" | ||||
*/ | */ | ||||
public class CovReport extends Task { | |||||
public class CovReport extends CovBase { | |||||
/* | /* | ||||
jpcoverport [options] -output=file -snapshot=snapshot.jpc | jpcoverport [options] -output=file -snapshot=snapshot.jpc | ||||
jpcovreport [options] [-paramfile=file] -output=<fileName> -snapshot=<fileName> | jpcovreport [options] [-paramfile=file] -output=<fileName> -snapshot=<fileName> | ||||
@@ -130,9 +129,6 @@ public class CovReport extends Task { | |||||
/* | /* | ||||
/** coverage home, mandatory */ | |||||
private File home = null; | |||||
/** format of generated report, optional */ | /** format of generated report, optional */ | ||||
private String format = null; | private String format = null; | ||||
@@ -163,13 +159,6 @@ public class CovReport extends Task { | |||||
private Reference reference = null; | 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 static class ReportFormat extends EnumeratedAttribute { | ||||
public String[] getValues() { | public String[] getValues() { | ||||
return new String[]{"html", "text", "xml"}; | return new String[]{"html", "text", "xml"}; | ||||
@@ -279,13 +268,12 @@ public class CovReport extends Task { | |||||
if (snapshot == null) { | if (snapshot == null) { | ||||
throw new BuildException("'snapshot' attribute must be set."); | 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"); | 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()) { | 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)) { | if (reference != null && !"xml".equals(format)) { | ||||
log("Ignored reference. It cannot be used in non XML report."); | log("Ignored reference. It cannot be used in non XML report."); | ||||
@@ -299,7 +287,7 @@ public class CovReport extends Task { | |||||
try { | try { | ||||
Commandline cmdl = new Commandline(); | Commandline cmdl = new Commandline(); | ||||
// we need to run Coverage from his directory due to dll/jar issues | // 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(); | String[] params = getParameters(); | ||||
for (int i = 0; i < params.length; i++) { | for (int i = 0; i < params.length; i++) { | ||||
cmdl.createArgument().setValue(params[i]); | cmdl.createArgument().setValue(params[i]); | ||||
@@ -398,7 +386,7 @@ public class CovReport extends Task { | |||||
log("Creating enhanced XML report", Project.MSG_VERBOSE); | log("Creating enhanced XML report", Project.MSG_VERBOSE); | ||||
XMLReport report = new XMLReport(CovReport.this, tofile); | XMLReport report = new XMLReport(CovReport.this, tofile); | ||||
report.setReportFilters(filters); | report.setReportFilters(filters); | ||||
report.setJProbehome(new File(home.getParent())); | |||||
report.setJProbehome(new File(getHome().getParent())); | |||||
Document doc = report.createDocument(paths); | Document doc = report.createDocument(paths); | ||||
TransformerFactory tfactory = TransformerFactory.newInstance(); | TransformerFactory tfactory = TransformerFactory.newInstance(); | ||||
Transformer transformer = tfactory.newTransformer(); | Transformer transformer = tfactory.newTransformer(); | ||||
@@ -1,7 +1,7 @@ | |||||
/* | /* | ||||
* The Apache Software License, Version 1.1 | * 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. | * reserved. | ||||
* | * | ||||
* Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | ||||
@@ -72,6 +72,7 @@ import org.apache.tools.ant.types.CommandlineJava; | |||||
import org.apache.tools.ant.types.EnumeratedAttribute; | import org.apache.tools.ant.types.EnumeratedAttribute; | ||||
import org.apache.tools.ant.types.FileSet; | import org.apache.tools.ant.types.FileSet; | ||||
import org.apache.tools.ant.types.Path; | import org.apache.tools.ant.types.Path; | ||||
import org.apache.tools.ant.util.JavaEnvUtils; | |||||
/** | /** | ||||
* Runs Sitraka JProbe Coverage. | * Runs Sitraka JProbe Coverage. | ||||
@@ -86,9 +87,7 @@ import org.apache.tools.ant.types.Path; | |||||
* | * | ||||
* @ant.task name="jpcoverage" category="metrics" | * @ant.task name="jpcoverage" category="metrics" | ||||
*/ | */ | ||||
public class Coverage extends Task { | |||||
protected File home; | |||||
public class Coverage extends CovBase { | |||||
protected Commandline cmdl = new Commandline(); | protected Commandline cmdl = new Commandline(); | ||||
@@ -131,13 +130,6 @@ public class Coverage extends Task { | |||||
//--------- setters used via reflection -- | //--------- 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 */ | /** seed name for snapshot file. Can be null, default to snap */ | ||||
public void setSeedname(String value) { | public void setSeedname(String value) { | ||||
seedName = value; | seedName = value; | ||||
@@ -331,7 +323,7 @@ public class Coverage extends Task { | |||||
} | } | ||||
try { | try { | ||||
// we need to run Coverage from his directory due to dll/jar issues | // 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()); | cmdl.createArgument().setValue("-jp_input=" + paramfile.getAbsolutePath()); | ||||
// use the custom handler for stdin issues | // use the custom handler for stdin issues | ||||
@@ -356,13 +348,12 @@ public class Coverage extends Task { | |||||
/** wheck what is necessary to check, Coverage will do the job for us */ | /** wheck what is necessary to check, Coverage will do the job for us */ | ||||
protected void checkOptions() throws BuildException { | protected void checkOptions() throws BuildException { | ||||
// check coverage home | // 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"); | 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()) { | 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 | // make sure snapshot dir exists and is resolved | ||||
@@ -381,17 +372,11 @@ public class Coverage extends Task { | |||||
// check for info, do your best to select the java executable. | // check for info, do your best to select the java executable. | ||||
// JProbe 3.0 fails if there is no javaexe option. So | // JProbe 3.0 fails if there is no javaexe option. So | ||||
if (javaExe == null && (vm == null || "java2".equals(vm))) { | 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) { | if (vm == null) { | ||||
vm = "java2"; | 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 @@ public class Coverage extends Task { | |||||
*/ | */ | ||||
protected File createParamFile() throws BuildException { | protected File createParamFile() throws BuildException { | ||||
//@todo change this when switching to JDK 1.2 and use File.createTmpFile() | //@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); | log("Creating parameter file: " + file, Project.MSG_VERBOSE); | ||||
// options need to be one per line in the parameter file | // options need to be one per line in the parameter file | ||||
@@ -497,13 +482,6 @@ public class Coverage extends Task { | |||||
return file; | 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; | |||||
} | |||||
/** specific pumper to avoid those nasty stdin issues */ | /** specific pumper to avoid those nasty stdin issues */ | ||||
static class CoverageStreamHandler extends LogStreamHandler { | static class CoverageStreamHandler extends LogStreamHandler { | ||||
CoverageStreamHandler(Task task) { | CoverageStreamHandler(Task task) { | ||||