git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@278358 13f79535-47bb-0310-9956-ffa450edef68master
@@ -1,5 +1,5 @@ | |||||
/* | /* | ||||
* Copyright 2001-2004 The Apache Software Foundation | |||||
* Copyright 2001-2005 The Apache Software Foundation | |||||
* | * | ||||
* Licensed under the Apache License, Version 2.0 (the "License"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
@@ -38,6 +38,9 @@ public abstract class DefaultJspCompilerAdapter | |||||
/** | /** | ||||
* Logs the compilation parameters, adds the files to compile and logs the | * Logs the compilation parameters, adds the files to compile and logs the | ||||
* "niceSourceList" | * "niceSourceList" | ||||
* @param jspc the compiler task for logging | |||||
* @param compileList the list of files to compile | |||||
* @param cmd the command line used | |||||
*/ | */ | ||||
protected void logAndAddFilesToCompile(JspC jspc, | protected void logAndAddFilesToCompile(JspC jspc, | ||||
Vector compileList, | Vector compileList, | ||||
@@ -70,6 +73,7 @@ public abstract class DefaultJspCompilerAdapter | |||||
/** | /** | ||||
* set the owner | * set the owner | ||||
* @param owner the owner JspC compiler | |||||
*/ | */ | ||||
public void setJspc(JspC owner) { | public void setJspc(JspC owner) { | ||||
this.owner = owner; | this.owner = owner; | ||||
@@ -85,7 +89,7 @@ public abstract class DefaultJspCompilerAdapter | |||||
/** | /** | ||||
* add an argument oneple to the argument list, if the value aint null | * add an argument oneple to the argument list, if the value aint null | ||||
* | |||||
* @param cmd the command line | |||||
* @param argument The argument | * @param argument The argument | ||||
*/ | */ | ||||
protected void addArg(CommandlineJava cmd, String argument) { | protected void addArg(CommandlineJava cmd, String argument) { | ||||
@@ -97,7 +101,7 @@ public abstract class DefaultJspCompilerAdapter | |||||
/** | /** | ||||
* add an argument tuple to the argument list, if the value aint null | * add an argument tuple to the argument list, if the value aint null | ||||
* | |||||
* @param cmd the command line | |||||
* @param argument The argument | * @param argument The argument | ||||
* @param value the parameter | * @param value the parameter | ||||
*/ | */ | ||||
@@ -110,7 +114,7 @@ public abstract class DefaultJspCompilerAdapter | |||||
/** | /** | ||||
* add an argument tuple to the arg list, if the file parameter aint null | * add an argument tuple to the arg list, if the file parameter aint null | ||||
* | |||||
* @param cmd the command line | |||||
* @param argument The argument | * @param argument The argument | ||||
* @param file the parameter | * @param file the parameter | ||||
*/ | */ | ||||
@@ -41,12 +41,18 @@ public class JasperC extends DefaultJspCompilerAdapter { | |||||
*/ | */ | ||||
JspMangler mangler; | JspMangler mangler; | ||||
/** | |||||
* Constructor for JasperC. | |||||
* @param mangler a filename converter | |||||
*/ | |||||
public JasperC(JspMangler mangler) { | public JasperC(JspMangler mangler) { | ||||
this.mangler = mangler; | this.mangler = mangler; | ||||
} | } | ||||
/** | /** | ||||
* our execute method | |||||
* Our execute method. | |||||
* @return true if successful | |||||
* @throws BuildException on error | |||||
*/ | */ | ||||
public boolean execute() | public boolean execute() | ||||
throws BuildException { | throws BuildException { | ||||
@@ -69,7 +75,7 @@ public class JasperC extends DefaultJspCompilerAdapter { | |||||
java.setDir(getProject().getBaseDir()); | java.setDir(getProject().getBaseDir()); | ||||
java.setClassname("org.apache.jasper.JspC"); | java.setClassname("org.apache.jasper.JspC"); | ||||
//this is really irritating; we need a way to set stuff | //this is really irritating; we need a way to set stuff | ||||
String args[] = cmd.getJavaCommand().getArguments(); | |||||
String []args = cmd.getJavaCommand().getArguments(); | |||||
for (int i = 0; i < args.length; i++) { | for (int i = 0; i < args.length; i++) { | ||||
java.createArg().setValue(args[i]); | java.createArg().setValue(args[i]); | ||||
} | } | ||||
@@ -1,5 +1,5 @@ | |||||
/* | /* | ||||
* Copyright 2001-2004 The Apache Software Foundation | |||||
* Copyright 2001-2005 The Apache Software Foundation | |||||
* | * | ||||
* Licensed under the Apache License, Version 2.0 (the "License"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
@@ -36,6 +36,7 @@ public interface JspCompilerAdapter { | |||||
/** | /** | ||||
* Sets the compiler attributes, which are stored in the Jspc task. | * Sets the compiler attributes, which are stored in the Jspc task. | ||||
* @param attributes the jsp compiler attributes | |||||
*/ | */ | ||||
void setJspc(JspC attributes); | void setJspc(JspC attributes); | ||||
@@ -43,6 +44,7 @@ public interface JspCompilerAdapter { | |||||
* Executes the task. | * Executes the task. | ||||
* | * | ||||
* @return has the compilation been successful | * @return has the compilation been successful | ||||
* @throws BuildException on error | |||||
*/ | */ | ||||
boolean execute() throws BuildException; | boolean execute() throws BuildException; | ||||
@@ -1,5 +1,5 @@ | |||||
/* | /* | ||||
* Copyright 2001-2004 The Apache Software Foundation | |||||
* Copyright 2001-2005 The Apache Software Foundation | |||||
* | * | ||||
* Licensed under the Apache License, Version 2.0 (the "License"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
@@ -27,7 +27,7 @@ import org.apache.tools.ant.taskdefs.optional.jsp.Jasper41Mangler; | |||||
* Creates the necessary compiler adapter, given basic criteria. | * Creates the necessary compiler adapter, given basic criteria. | ||||
* | * | ||||
*/ | */ | ||||
public class JspCompilerAdapterFactory { | |||||
public final class JspCompilerAdapterFactory { | |||||
/** This is a singleton -- can't create instances!! */ | /** This is a singleton -- can't create instances!! */ | ||||
private JspCompilerAdapterFactory() { | private JspCompilerAdapterFactory() { | ||||
@@ -46,6 +46,7 @@ public class JspCompilerAdapterFactory { | |||||
* @param compilerType either the name of the desired compiler, or the | * @param compilerType either the name of the desired compiler, or the | ||||
* full classname of the compiler's adapter. | * full classname of the compiler's adapter. | ||||
* @param task a task to log through. | * @param task a task to log through. | ||||
* @return the compiler | |||||
* @throws BuildException if the compiler type could not be resolved into | * @throws BuildException if the compiler type could not be resolved into | ||||
* a compiler adapter. | * a compiler adapter. | ||||
*/ | */ | ||||
@@ -69,6 +70,7 @@ public class JspCompilerAdapterFactory { | |||||
* full classname of the compiler's adapter. | * full classname of the compiler's adapter. | ||||
* @param task a task to log through. | * @param task a task to log through. | ||||
* @param loader AntClassLoader with which the compiler should be loaded | * @param loader AntClassLoader with which the compiler should be loaded | ||||
* @return the compiler | |||||
* @throws BuildException if the compiler type could not be resolved into | * @throws BuildException if the compiler type could not be resolved into | ||||
* a compiler adapter. | * a compiler adapter. | ||||
*/ | */ | ||||
@@ -36,15 +36,24 @@ public abstract class CovBase extends Task { | |||||
/** | /** | ||||
* The directory where JProbe is installed. | * The directory where JProbe is installed. | ||||
* @param value the JProbe directory | |||||
*/ | */ | ||||
public void setHome(File value) { | public void setHome(File value) { | ||||
this.home = value; | this.home = value; | ||||
} | } | ||||
/** | |||||
* Get the JProbe directory. | |||||
* @return the JProbe directory | |||||
*/ | |||||
protected File getHome() { | protected File getHome() { | ||||
return home; | return home; | ||||
} | } | ||||
/** | |||||
* Get the location of the JProbe coverage jar file. | |||||
* @return the location of the JProbe coverage jar file | |||||
*/ | |||||
protected File findCoverageJar() { | protected File findCoverageJar() { | ||||
File loc = null; | File loc = null; | ||||
if (isJProbe4) { | if (isJProbe4) { | ||||
@@ -63,6 +72,11 @@ public abstract class CovBase extends Task { | |||||
return loc; | return loc; | ||||
} | } | ||||
/** | |||||
* Find the JProbe executable. | |||||
* @param relativePath the name of the executuable without the trailing .exe on dos | |||||
* @return the absolute path to the executable | |||||
*/ | |||||
protected String findExecutable(String relativePath) { | protected String findExecutable(String relativePath) { | ||||
if (isDos) { | if (isDos) { | ||||
relativePath += ".exe"; | relativePath += ".exe"; | ||||
@@ -84,16 +98,28 @@ public abstract class CovBase extends Task { | |||||
return loc.getAbsolutePath(); | return loc.getAbsolutePath(); | ||||
} | } | ||||
/** | |||||
* Create a temporary file. | |||||
* @param prefix a prefix to use in the filename | |||||
* @return a File reference to the temporary file | |||||
*/ | |||||
protected File createTempFile(String prefix) { | protected File createTempFile(String prefix) { | ||||
return FILE_UTILS.createTempFile(prefix, ".tmp", null); | return FILE_UTILS.createTempFile(prefix, ".tmp", null); | ||||
} | } | ||||
/** | |||||
* Get the param file arguement. | |||||
* This checks the version of jprobe to return the correct name of | |||||
* the parameter. | |||||
* @return the name of the argument | |||||
*/ | |||||
protected String getParamFileArgument() { | protected String getParamFileArgument() { | ||||
return "-" + (!isJProbe4 ? "jp_" : "") + "paramfile="; | return "-" + (!isJProbe4 ? "jp_" : "") + "paramfile="; | ||||
} | } | ||||
/** | /** | ||||
* Are we running on a version of JProbe 4.x or higher? | * Are we running on a version of JProbe 4.x or higher? | ||||
* @return true if we are running JProbe 4 or higher | |||||
*/ | */ | ||||
protected boolean isJProbe4Plus() { | protected boolean isJProbe4Plus() { | ||||
return isJProbe4; | return isJProbe4; | ||||
@@ -1,5 +1,5 @@ | |||||
/* | /* | ||||
* Copyright 2001-2004 The Apache Software Foundation | |||||
* Copyright 2001-2005 The Apache Software Foundation | |||||
* | * | ||||
* Licensed under the Apache License, Version 2.0 (the "License"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
@@ -47,6 +47,7 @@ public class CovMerge extends CovBase { | |||||
/** | /** | ||||
* Set the output snapshot file. | * Set the output snapshot file. | ||||
* @param value the snapshot file | |||||
*/ | */ | ||||
public void setTofile(File value) { | public void setTofile(File value) { | ||||
this.tofile = value; | this.tofile = value; | ||||
@@ -55,6 +56,7 @@ public class CovMerge extends CovBase { | |||||
/** | /** | ||||
* If true, perform the merge in verbose mode giving details | * If true, perform the merge in verbose mode giving details | ||||
* about the snapshot processing. | * about the snapshot processing. | ||||
* @param flag if true perform the merge in verbose mode | |||||
*/ | */ | ||||
public void setVerbose(boolean flag) { | public void setVerbose(boolean flag) { | ||||
this.verbose = flag; | this.verbose = flag; | ||||
@@ -62,6 +64,7 @@ public class CovMerge extends CovBase { | |||||
/** | /** | ||||
* add a fileset containing the snapshots to include. | * add a fileset containing the snapshots to include. | ||||
* @param fs nested fileset element | |||||
*/ | */ | ||||
public void addFileset(FileSet fs) { | public void addFileset(FileSet fs) { | ||||
filesets.addElement(fs); | filesets.addElement(fs); | ||||
@@ -69,10 +72,14 @@ public class CovMerge extends CovBase { | |||||
//---------------- the tedious job begins here | //---------------- the tedious job begins here | ||||
/** Constructor for CovMerge. */ | |||||
public CovMerge() { | public CovMerge() { | ||||
} | } | ||||
/** execute the jpcovmerge by providing a parameter file */ | |||||
/** | |||||
* Execute the jpcovmerge by providing a parameter file. | |||||
* @throws BuildException on error | |||||
*/ | |||||
public void execute() throws BuildException { | public void execute() throws BuildException { | ||||
checkOptions(); | checkOptions(); | ||||
@@ -112,7 +119,10 @@ public class CovMerge extends CovBase { | |||||
} | } | ||||
} | } | ||||
/** check for mandatory options */ | |||||
/** | |||||
* Check for mandatory options. | |||||
* @throws BuildException on error | |||||
*/ | |||||
protected void checkOptions() throws BuildException { | protected void checkOptions() throws BuildException { | ||||
if (tofile == null) { | if (tofile == null) { | ||||
throw new BuildException("'tofile' attribute must be set."); | throw new BuildException("'tofile' attribute must be set."); | ||||
@@ -128,7 +138,10 @@ public class CovMerge extends CovBase { | |||||
} | } | ||||
} | } | ||||
/** get the snapshots from the filesets */ | |||||
/** | |||||
* Get the snapshots from the filesets. | |||||
* @return an array of snapshot files | |||||
*/ | |||||
protected File[] getSnapshots() { | protected File[] getSnapshots() { | ||||
Vector v = new Vector(); | Vector v = new Vector(); | ||||
final int size = filesets.size(); | final int size = filesets.size(); | ||||
@@ -152,8 +165,10 @@ public class CovMerge extends CovBase { | |||||
/** | /** | ||||
* create the parameters file that contains all file to merge | |||||
* Create the parameters file that contains all file to merge | |||||
* and the output filename. | * and the output filename. | ||||
* @return the parameters file | |||||
* @throws BuildException on error | |||||
*/ | */ | ||||
protected File createParamFile() throws BuildException { | protected File createParamFile() throws BuildException { | ||||
File[] snapshots = getSnapshots(); | File[] snapshots = getSnapshots(); | ||||
@@ -179,6 +194,7 @@ public class CovMerge extends CovBase { | |||||
try { | try { | ||||
fw.close(); | fw.close(); | ||||
} catch (IOException ignored) { | } catch (IOException ignored) { | ||||
// Ignore Exception | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -1,5 +1,5 @@ | |||||
/* | /* | ||||
* Copyright 2001-2004 The Apache Software Foundation | |||||
* Copyright 2001-2005 The Apache Software Foundation | |||||
* | * | ||||
* Licensed under the Apache License, Version 2.0 (the "License"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
@@ -121,7 +121,9 @@ public class CovReport extends CovBase { | |||||
private Reference reference = null; | private Reference reference = null; | ||||
/** Enumerated type for format attribute. */ | |||||
public static class ReportFormat extends EnumeratedAttribute { | public static class ReportFormat extends EnumeratedAttribute { | ||||
/** @see EnumeratedAttribute@getValues() */ | |||||
public String[] getValues() { | public String[] getValues() { | ||||
return new String[]{"html", "text", "xml"}; | return new String[]{"html", "text", "xml"}; | ||||
} | } | ||||
@@ -129,12 +131,15 @@ public class CovReport extends CovBase { | |||||
/** | /** | ||||
* set the format of the report: "html", "text", or "xml" | * set the format of the report: "html", "text", or "xml" | ||||
* @param value an enumerated <code>ReportFormat</code> value | |||||
*/ | */ | ||||
public void setFormat(ReportFormat value) { | public void setFormat(ReportFormat value) { | ||||
this.format = value.getValue(); | this.format = value.getValue(); | ||||
} | } | ||||
/** Enumerated type for type attribute. */ | |||||
public static class ReportType extends EnumeratedAttribute { | public static class ReportType extends EnumeratedAttribute { | ||||
/** @see EnumeratedAttribute@getValues() */ | |||||
public String[] getValues() { | public String[] getValues() { | ||||
return new String[]{"executive", "summary", "detailed", "verydetailed"}; | return new String[]{"executive", "summary", "detailed", "verydetailed"}; | ||||
} | } | ||||
@@ -143,6 +148,7 @@ public class CovReport extends CovBase { | |||||
/** | /** | ||||
* The type of report to be generated: "executive", "summary", | * The type of report to be generated: "executive", "summary", | ||||
* "detailed" or "verydetailed". | * "detailed" or "verydetailed". | ||||
* @param value an enumerated <code>ReportType</code> value | |||||
*/ | */ | ||||
public void setType(ReportType value) { | public void setType(ReportType value) { | ||||
this.type = value.getValue(); | this.type = value.getValue(); | ||||
@@ -151,6 +157,7 @@ public class CovReport extends CovBase { | |||||
/** | /** | ||||
* If true, include text of the source code lines. | * If true, include text of the source code lines. | ||||
* Only applies to format="xml" and type="verydetailed" | * Only applies to format="xml" and type="verydetailed" | ||||
* @param value a <code>boolean</code> value | |||||
*/ | */ | ||||
public void setIncludesource(boolean value) { | public void setIncludesource(boolean value) { | ||||
this.includeSource = value; | this.includeSource = value; | ||||
@@ -159,6 +166,7 @@ public class CovReport extends CovBase { | |||||
/** | /** | ||||
* A numeric value for the threshold for printing methods. | * A numeric value for the threshold for printing methods. | ||||
* Must be between 0 and 100. | * Must be between 0 and 100. | ||||
* @param value an <code>Integer</code> value | |||||
*/ | */ | ||||
public void setPercent(Integer value) { | public void setPercent(Integer value) { | ||||
this.percent = value; | this.percent = value; | ||||
@@ -166,6 +174,7 @@ public class CovReport extends CovBase { | |||||
/** | /** | ||||
* set the filters | * set the filters | ||||
* @param values a <code>String</code> value | |||||
* @ant.attribute ignore="true" | * @ant.attribute ignore="true" | ||||
*/ | */ | ||||
public void setFilters(String values) { | public void setFilters(String values) { | ||||
@@ -174,6 +183,7 @@ public class CovReport extends CovBase { | |||||
/** | /** | ||||
* Adds a path to source files. | * Adds a path to source files. | ||||
* @return a path to be configured | |||||
*/ | */ | ||||
public Path createSourcepath() { | public Path createSourcepath() { | ||||
if (sourcePath == null) { | if (sourcePath == null) { | ||||
@@ -184,6 +194,7 @@ public class CovReport extends CovBase { | |||||
/** | /** | ||||
* The name of the snapshot file that is the source to the report. | * The name of the snapshot file that is the source to the report. | ||||
* @param value the snapshot file | |||||
*/ | */ | ||||
public void setSnapshot(File value) { | public void setSnapshot(File value) { | ||||
this.snapshot = value; | this.snapshot = value; | ||||
@@ -191,12 +202,14 @@ public class CovReport extends CovBase { | |||||
/** | /** | ||||
* The name of the generated output file. | * The name of the generated output file. | ||||
* @param value the output file | |||||
*/ | */ | ||||
public void setTofile(File value) { | public void setTofile(File value) { | ||||
this.tofile = value; | this.tofile = value; | ||||
} | } | ||||
/** | /** | ||||
* @return a path to be configured | |||||
* @todo needs to be removed | * @todo needs to be removed | ||||
* @ant.element ignore="true" | * @ant.element ignore="true" | ||||
*/ | */ | ||||
@@ -210,6 +223,7 @@ public class CovReport extends CovBase { | |||||
/** | /** | ||||
* Adds a set of classes whose coverage information will be | * Adds a set of classes whose coverage information will be | ||||
* checked against. | * checked against. | ||||
* @return a <code>CovReport.Reference</code> object to be configured | |||||
*/ | */ | ||||
public Reference createReference() { | public Reference createReference() { | ||||
if (reference == null) { | if (reference == null) { | ||||
@@ -219,10 +233,14 @@ public class CovReport extends CovBase { | |||||
} | } | ||||
/** Constructor for CovReport. */ | |||||
public CovReport() { | public CovReport() { | ||||
} | } | ||||
/** check for mandatory options */ | |||||
/** | |||||
* Check for mandatory options. | |||||
* @throws BuildException on error | |||||
*/ | |||||
protected void checkOptions() throws BuildException { | protected void checkOptions() throws BuildException { | ||||
if (tofile == null) { | if (tofile == null) { | ||||
throw new BuildException("'tofile' attribute must be set."); | throw new BuildException("'tofile' attribute must be set."); | ||||
@@ -244,6 +262,10 @@ public class CovReport extends CovBase { | |||||
} | } | ||||
/** | |||||
* Execute the task. | |||||
* @throws BuildException on error | |||||
*/ | |||||
public void execute() throws BuildException { | public void execute() throws BuildException { | ||||
checkOptions(); | checkOptions(); | ||||
try { | try { | ||||
@@ -278,6 +300,10 @@ public class CovReport extends CovBase { | |||||
} | } | ||||
/** | |||||
* Get the parameters for the executable. | |||||
* @return an array of parameters | |||||
*/ | |||||
protected String[] getParameters() { | protected String[] getParameters() { | ||||
Vector v = new Vector(); | Vector v = new Vector(); | ||||
if (format != null) { | if (format != null) { | ||||
@@ -311,10 +337,17 @@ public class CovReport extends CovBase { | |||||
} | } | ||||
/** | |||||
* An inner class for the reference element. | |||||
*/ | |||||
public class Reference { | public class Reference { | ||||
protected Path classPath; | protected Path classPath; | ||||
protected ReportFilters filters; | protected ReportFilters filters; | ||||
/** | |||||
* Create a path for the reference. | |||||
* @return a path to be configured | |||||
*/ | |||||
public Path createClasspath() { | public Path createClasspath() { | ||||
if (classPath == null) { | if (classPath == null) { | ||||
classPath = new Path(CovReport.this.getProject()); | classPath = new Path(CovReport.this.getProject()); | ||||
@@ -322,6 +355,10 @@ public class CovReport extends CovBase { | |||||
return classPath.createPath(); | return classPath.createPath(); | ||||
} | } | ||||
/** | |||||
* An nested element to include/exclude classes/methods. | |||||
* @return ReportFilters to be configured | |||||
*/ | |||||
public ReportFilters createFilters() { | public ReportFilters createFilters() { | ||||
if (filters == null) { | if (filters == null) { | ||||
filters = new ReportFilters(); | filters = new ReportFilters(); | ||||
@@ -329,6 +366,10 @@ public class CovReport extends CovBase { | |||||
return filters; | return filters; | ||||
} | } | ||||
/** | |||||
* Create the xml report. | |||||
* @throws BuildException on error | |||||
*/ | |||||
protected void createEnhancedXMLReport() throws BuildException { | protected void createEnhancedXMLReport() throws BuildException { | ||||
// we need a classpath element | // we need a classpath element | ||||
if (classPath == null) { | if (classPath == null) { | ||||
@@ -337,7 +378,8 @@ public class CovReport extends CovBase { | |||||
// and a valid one... | // and a valid one... | ||||
String[] paths = classPath.list(); | String[] paths = classPath.list(); | ||||
if (paths.length == 0) { | if (paths.length == 0) { | ||||
throw new BuildException("Coverage path is invalid. It does not contain any existing path."); | |||||
throw new BuildException( | |||||
"Coverage path is invalid. It does not contain any existing path."); | |||||
} | } | ||||
// and we need at least one filter include/exclude. | // and we need at least one filter include/exclude. | ||||
if (filters == null || filters.size() == 0) { | if (filters == null || filters.size() == 0) { | ||||
@@ -90,12 +90,17 @@ public class Coverage extends CovBase { | |||||
//--------- setters used via reflection -- | //--------- setters used via reflection -- | ||||
/** seed name for snapshot file. Can be null, default to snap */ | |||||
/** | |||||
* Set the seed name for snapshot file. Can be null, default to snap. | |||||
* @param value a <code>String</code> value | |||||
*/ | |||||
public void setSeedname(String value) { | public void setSeedname(String value) { | ||||
seedName = value; | seedName = value; | ||||
} | } | ||||
/** | /** | ||||
* Set the input file. | |||||
* @param value a <code>File</code> value | |||||
* @ant.attribute ignore="true" | * @ant.attribute ignore="true" | ||||
*/ | */ | ||||
public void setInputfile(File value) { | public void setInputfile(File value) { | ||||
@@ -104,12 +109,20 @@ public class Coverage extends CovBase { | |||||
/** | /** | ||||
* Path to the java executable. | * Path to the java executable. | ||||
* @param value the path to the java executable | |||||
*/ | */ | ||||
public void setJavaexe(File value) { | public void setJavaexe(File value) { | ||||
javaExe = value; | javaExe = value; | ||||
} | } | ||||
/** | |||||
* Enumerated type corresponding to the javavms known by the task. | |||||
*/ | |||||
public static class Javavm extends EnumeratedAttribute { | public static class Javavm extends EnumeratedAttribute { | ||||
/** | |||||
* Get the valid javavms names. | |||||
* @return an array of strings = "java2", "jdk118", and "jdk117" | |||||
*/ | |||||
public String[] getValues() { | public String[] getValues() { | ||||
return new String[]{"java2", "jdk118", "jdk117"}; | return new String[]{"java2", "jdk118", "jdk117"}; | ||||
} | } | ||||
@@ -117,13 +130,16 @@ public class Coverage extends CovBase { | |||||
/** | /** | ||||
* Indicates which virtual machine to run: "jdk117", "jdk118" or "java2". | * Indicates which virtual machine to run: "jdk117", "jdk118" or "java2". | ||||
* Can be null, default to "java2". */ | |||||
* Can be null, default to "java2". | |||||
* @param value an enumerated value | |||||
*/ | |||||
public void setVm(Javavm value) { | public void setVm(Javavm value) { | ||||
vm = value.getValue(); | vm = value.getValue(); | ||||
} | } | ||||
/** | /** | ||||
* If true, run an applet. | * If true, run an applet. | ||||
* @param value a <code>boolean</code> value | |||||
*/ | */ | ||||
public void setApplet(boolean value) { | public void setApplet(boolean value) { | ||||
applet = value; | applet = value; | ||||
@@ -131,6 +147,7 @@ public class Coverage extends CovBase { | |||||
/** | /** | ||||
* Toggles display of the console prompt: always, error, never | * Toggles display of the console prompt: always, error, never | ||||
* @param value when to display the prompt - "always", "error" or "never" | |||||
*/ | */ | ||||
public void setExitprompt(String value) { | public void setExitprompt(String value) { | ||||
exitPrompt = value; | exitPrompt = value; | ||||
@@ -139,6 +156,7 @@ public class Coverage extends CovBase { | |||||
/** | /** | ||||
* Defines class/method filters based on pattern matching. | * Defines class/method filters based on pattern matching. | ||||
* The syntax is filters is similar to a fileset. | * The syntax is filters is similar to a fileset. | ||||
* @return the filters to be configured | |||||
*/ | */ | ||||
public Filters createFilters() { | public Filters createFilters() { | ||||
return filters; | return filters; | ||||
@@ -151,6 +169,7 @@ public class Coverage extends CovBase { | |||||
* For example you may run a whole application but only decide | * For example you may run a whole application but only decide | ||||
* to collect data once it reaches a certain method and once it | * to collect data once it reaches a certain method and once it | ||||
* exits another one. | * exits another one. | ||||
* @return the triggers to be configured | |||||
*/ | */ | ||||
public Triggers createTriggers() { | public Triggers createTriggers() { | ||||
if (triggers == null) { | if (triggers == null) { | ||||
@@ -162,6 +181,7 @@ public class Coverage extends CovBase { | |||||
/** | /** | ||||
* Define a host and port to connect to if you want to do | * Define a host and port to connect to if you want to do | ||||
* remote viewing. | * remote viewing. | ||||
* @return the socket to be configured | |||||
*/ | */ | ||||
public Socket createSocket() { | public Socket createSocket() { | ||||
if (socket == null) { | if (socket == null) { | ||||
@@ -170,7 +190,14 @@ public class Coverage extends CovBase { | |||||
return socket; | return socket; | ||||
} | } | ||||
/** | |||||
* Enumerated type for finalsnapshot attribute. | |||||
*/ | |||||
public static class Finalsnapshot extends EnumeratedAttribute { | public static class Finalsnapshot extends EnumeratedAttribute { | ||||
/** | |||||
* Get the valid strings for the attribute. | |||||
* @return an array of strings - "coverage", "none" and "all" | |||||
*/ | |||||
public String[] getValues() { | public String[] getValues() { | ||||
return new String[]{"coverage", "none", "all"}; | return new String[]{"coverage", "none", "all"}; | ||||
} | } | ||||
@@ -179,19 +206,29 @@ public class Coverage extends CovBase { | |||||
/** | /** | ||||
* Type of snapshot to send at program termination: none, coverage, all. | * Type of snapshot to send at program termination: none, coverage, all. | ||||
* Can be null, default to none | * Can be null, default to none | ||||
* @param value a <code>String</code> value | |||||
*/ | */ | ||||
public void setFinalsnapshot(String value) { | public void setFinalsnapshot(String value) { | ||||
finalSnapshot = value; | finalSnapshot = value; | ||||
} | } | ||||
/** | |||||
* Enumerated type for recordfromstart attribute. | |||||
*/ | |||||
public static class Recordfromstart extends EnumeratedAttribute { | public static class Recordfromstart extends EnumeratedAttribute { | ||||
/** | |||||
* Get the valid strings for the attribute. | |||||
* @return an array of strings - "coverage", "none" and "all" | |||||
*/ | |||||
public String[] getValues() { | public String[] getValues() { | ||||
return new String[]{"coverage", "none", "all"}; | return new String[]{"coverage", "none", "all"}; | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Set the recordfromstart attribute, valid values are | |||||
* "all", "coverage", or "none". | * "all", "coverage", or "none". | ||||
* @param value an enumerated type having the correct values. | |||||
*/ | */ | ||||
public void setRecordfromstart(Recordfromstart value) { | public void setRecordfromstart(Recordfromstart value) { | ||||
recordFromStart = value.getValue(); | recordFromStart = value.getValue(); | ||||
@@ -199,6 +236,7 @@ public class Coverage extends CovBase { | |||||
/** | /** | ||||
* Set warning level (0-3, where 0 is the least amount of warnings). | * Set warning level (0-3, where 0 is the least amount of warnings). | ||||
* @param value an <code>Integer</code> value | |||||
*/ | */ | ||||
public void setWarnlevel(Integer value) { | public void setWarnlevel(Integer value) { | ||||
warnLevel = value.intValue(); | warnLevel = value.intValue(); | ||||
@@ -209,6 +247,7 @@ public class Coverage extends CovBase { | |||||
* Choose a directory that is reachable by both the remote | * Choose a directory that is reachable by both the remote | ||||
* and local computers, and enter the same path on the command-line | * and local computers, and enter the same path on the command-line | ||||
* and in the viewer. | * and in the viewer. | ||||
* @param value the snapshot directory | |||||
*/ | */ | ||||
public void setSnapshotdir(File value) { | public void setSnapshotdir(File value) { | ||||
snapshotDir = value; | snapshotDir = value; | ||||
@@ -216,6 +255,7 @@ public class Coverage extends CovBase { | |||||
/** | /** | ||||
* The physical path to the working directory for the VM. | * The physical path to the working directory for the VM. | ||||
* @param value the working directory | |||||
*/ | */ | ||||
public void setWorkingdir(File value) { | public void setWorkingdir(File value) { | ||||
workingDir = value; | workingDir = value; | ||||
@@ -223,6 +263,7 @@ public class Coverage extends CovBase { | |||||
/** | /** | ||||
* If true, track native methods. | * If true, track native methods. | ||||
* @param value a <code>boolean</code> value | |||||
*/ | */ | ||||
public void setTracknatives(boolean value) { | public void setTracknatives(boolean value) { | ||||
trackNatives = value; | trackNatives = value; | ||||
@@ -232,6 +273,7 @@ public class Coverage extends CovBase { | |||||
/** | /** | ||||
* Adds a JVM argument. | * Adds a JVM argument. | ||||
* @return a command line argument to configure | |||||
*/ | */ | ||||
public Commandline.Argument createJvmarg() { | public Commandline.Argument createJvmarg() { | ||||
return cmdlJava.createVmArgument(); | return cmdlJava.createVmArgument(); | ||||
@@ -239,6 +281,7 @@ public class Coverage extends CovBase { | |||||
/** | /** | ||||
* Adds a command argument. | * Adds a command argument. | ||||
* @return a command line argument to configure | |||||
*/ | */ | ||||
public Commandline.Argument createArg() { | public Commandline.Argument createArg() { | ||||
return cmdlJava.createArgument(); | return cmdlJava.createArgument(); | ||||
@@ -246,6 +289,7 @@ public class Coverage extends CovBase { | |||||
/** | /** | ||||
* classpath to run the files. | * classpath to run the files. | ||||
* @return a Path to configure | |||||
*/ | */ | ||||
public Path createClasspath() { | public Path createClasspath() { | ||||
return cmdlJava.createClasspath(getProject()).createPath(); | return cmdlJava.createClasspath(getProject()).createPath(); | ||||
@@ -253,6 +297,7 @@ public class Coverage extends CovBase { | |||||
/** | /** | ||||
* classname to run as standalone or runner for filesets. | * classname to run as standalone or runner for filesets. | ||||
* @param value a <code>String</code> value for the classname | |||||
*/ | */ | ||||
public void setClassname(String value) { | public void setClassname(String value) { | ||||
cmdlJava.setClassname(value); | cmdlJava.setClassname(value); | ||||
@@ -260,6 +305,7 @@ public class Coverage extends CovBase { | |||||
/** | /** | ||||
* the classnames to execute. | * the classnames to execute. | ||||
* @param fs a nested fileset element | |||||
*/ | */ | ||||
public void addFileset(FileSet fs) { | public void addFileset(FileSet fs) { | ||||
filesets.addElement(fs); | filesets.addElement(fs); | ||||
@@ -268,10 +314,16 @@ public class Coverage extends CovBase { | |||||
//---------------- the tedious job begins here | //---------------- the tedious job begins here | ||||
/** | |||||
* Constructor for Coverage. | |||||
*/ | |||||
public Coverage() { | public Coverage() { | ||||
} | } | ||||
/** execute the jplauncher by providing a parameter file */ | |||||
/** | |||||
* Execute the jplauncher by providing a parameter file. | |||||
* @throws BuildException on error | |||||
*/ | |||||
public void execute() throws BuildException { | public void execute() throws BuildException { | ||||
File paramfile = null; | File paramfile = null; | ||||
// if an input file is used, all other options are ignored... | // if an input file is used, all other options are ignored... | ||||
@@ -305,7 +357,10 @@ public class Coverage extends CovBase { | |||||
} | } | ||||
} | } | ||||
/** wheck what is necessary to check, Coverage will do the job for us */ | |||||
/** | |||||
* Check what is necessary to check, Coverage will do the job for us. | |||||
* @throws BuildException on error | |||||
*/ | |||||
protected void checkOptions() throws BuildException { | protected void checkOptions() throws BuildException { | ||||
// check coverage home | // check coverage home | ||||
if (getHome() == null || !getHome().isDirectory()) { | if (getHome() == null || !getHome().isDirectory()) { | ||||
@@ -343,6 +398,7 @@ public class Coverage extends CovBase { | |||||
* return the command line parameters. Parameters can either be passed | * return the command line parameters. Parameters can either be passed | ||||
* to the command line and stored to a file (then use the -jp_input=<filename>) | * to the command line and stored to a file (then use the -jp_input=<filename>) | ||||
* if they are too numerous. | * if they are too numerous. | ||||
* @return the command line parameters | |||||
*/ | */ | ||||
protected String[] getParameters() { | protected String[] getParameters() { | ||||
Vector params = new Vector(); | Vector params = new Vector(); | ||||
@@ -435,6 +491,7 @@ public class Coverage extends CovBase { | |||||
try { | try { | ||||
fw.close(); | fw.close(); | ||||
} catch (IOException ignored) { | } catch (IOException ignored) { | ||||
// Ignore Exception | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -457,6 +514,7 @@ public class Coverage extends CovBase { | |||||
try { | try { | ||||
os.close(); | os.close(); | ||||
} catch (IOException ignored) { | } catch (IOException ignored) { | ||||
// Ignore exception | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -1,5 +1,5 @@ | |||||
/* | /* | ||||
* Copyright 2001-2002,2004 The Apache Software Foundation | |||||
* Copyright 2001-2002,2004-2005 The Apache Software Foundation | |||||
* | * | ||||
* Licensed under the Apache License, Version 2.0 (the "License"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
@@ -34,12 +34,14 @@ public class Filters { | |||||
/** user defined filters */ | /** user defined filters */ | ||||
protected Vector filters = new Vector(); | protected Vector filters = new Vector(); | ||||
/** Constructor for Filters. */ | |||||
public Filters() { | public Filters() { | ||||
} | } | ||||
/** | /** | ||||
* Automatically exclude all classes and methods | * Automatically exclude all classes and methods | ||||
* unless included in nested elements; optional, default true. | * unless included in nested elements; optional, default true. | ||||
* @param value a <code>boolean</code> value | |||||
*/ | */ | ||||
public void setDefaultExclude(boolean value) { | public void setDefaultExclude(boolean value) { | ||||
defaultExclude = value; | defaultExclude = value; | ||||
@@ -47,6 +49,7 @@ public class Filters { | |||||
/** | /** | ||||
* include classes and methods in the analysis | * include classes and methods in the analysis | ||||
* @param incl an nested Include object | |||||
*/ | */ | ||||
public void addInclude(Include incl) { | public void addInclude(Include incl) { | ||||
filters.addElement(incl); | filters.addElement(incl); | ||||
@@ -54,11 +57,16 @@ public class Filters { | |||||
/** | /** | ||||
* exclude classes and methods from the analysis | * exclude classes and methods from the analysis | ||||
* @param excl an nested Exclude object | |||||
*/ | */ | ||||
public void addExclude(Exclude excl) { | public void addExclude(Exclude excl) { | ||||
filters.addElement(excl); | filters.addElement(excl); | ||||
} | } | ||||
/** | |||||
* Get a comma separated list of filters. | |||||
* @return a comma separated list of filters | |||||
*/ | |||||
public String toString() { | public String toString() { | ||||
StringBuffer buf = new StringBuffer(); | StringBuffer buf = new StringBuffer(); | ||||
final int size = filters.size(); | final int size = filters.size(); | ||||
@@ -87,6 +95,7 @@ public class Filters { | |||||
/** | /** | ||||
* this one is deprecated. | * this one is deprecated. | ||||
* @param value a <code>String</code> value | |||||
* @ant.task ignore="true" | * @ant.task ignore="true" | ||||
*/ | */ | ||||
@@ -97,6 +106,7 @@ public class Filters { | |||||
/** | /** | ||||
* The classname mask as a simple regular expression; | * The classname mask as a simple regular expression; | ||||
* optional, defaults to "*" | * optional, defaults to "*" | ||||
* @param value a <code>String</code> value | |||||
*/ | */ | ||||
public void setClass(String value) { | public void setClass(String value) { | ||||
clazz = value; | clazz = value; | ||||
@@ -105,6 +115,7 @@ public class Filters { | |||||
/** | /** | ||||
* The method mask as a simple regular expression; | * The method mask as a simple regular expression; | ||||
* optional, defaults to "*" | * optional, defaults to "*" | ||||
* @param value a <code>String</code> value | |||||
*/ | */ | ||||
public void setMethod(String value) { | public void setMethod(String value) { | ||||
method = value; | method = value; | ||||
@@ -112,24 +123,45 @@ public class Filters { | |||||
/** | /** | ||||
* enable or disable the filter; optional, default true | * enable or disable the filter; optional, default true | ||||
* @param value a <code>boolean</code> value | |||||
*/ | */ | ||||
public void setEnabled(boolean value) { | public void setEnabled(boolean value) { | ||||
enabled = value; | enabled = value; | ||||
} | } | ||||
/** | |||||
* The classname and the method. | |||||
* @return the classname and the method - "class.method()" | |||||
*/ | |||||
public String toString() { | public String toString() { | ||||
return clazz + "." + method + "()"; | return clazz + "." + method + "()"; | ||||
} | } | ||||
} | } | ||||
/** | |||||
* A class for the nested include element. | |||||
*/ | |||||
public static class Include extends FilterElement { | public static class Include extends FilterElement { | ||||
/** | |||||
* The classname and method postfixed with ":I" and (#) if not | |||||
* enabled. | |||||
* @return a string version of this filter that can be used on the commandline | |||||
*/ | |||||
public String toString() { | public String toString() { | ||||
return super.toString() + ":I" + (enabled ? "" : "#"); | return super.toString() + ":I" + (enabled ? "" : "#"); | ||||
} | } | ||||
} | } | ||||
/** | |||||
* A class for the nested exclude element. | |||||
*/ | |||||
public static class Exclude extends FilterElement { | public static class Exclude extends FilterElement { | ||||
/** | |||||
* The classname and method postfixed with ":E" and (#) if not | |||||
* enabled. | |||||
* @return a string version of this filter that can be used on the commandline | |||||
*/ | |||||
public String toString() { | public String toString() { | ||||
return super.toString() + ":E" + (enabled ? "" : "#"); | return super.toString() + ":E" + (enabled ? "" : "#"); | ||||
} | } | ||||
@@ -1,5 +1,5 @@ | |||||
/* | /* | ||||
* Copyright 2001-2002,2004 The Apache Software Foundation | |||||
* Copyright 2001-2002,2004-2005 The Apache Software Foundation | |||||
* | * | ||||
* Licensed under the Apache License, Version 2.0 (the "License"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
@@ -33,17 +33,30 @@ public class ReportFilters { | |||||
/** cached matcher for each filter */ | /** cached matcher for each filter */ | ||||
protected Vector matchers = null; | protected Vector matchers = null; | ||||
/** Constructor for ReportFilters. */ | |||||
public ReportFilters() { | public ReportFilters() { | ||||
} | } | ||||
/** | |||||
* Add an include nested element. | |||||
* @param incl an include filter element | |||||
*/ | |||||
public void addInclude(Include incl) { | public void addInclude(Include incl) { | ||||
filters.addElement(incl); | filters.addElement(incl); | ||||
} | } | ||||
/** | |||||
* Add an exclude nested element. | |||||
* @param excl an exclude filter element | |||||
*/ | |||||
public void addExclude(Exclude excl) { | public void addExclude(Exclude excl) { | ||||
filters.addElement(excl); | filters.addElement(excl); | ||||
} | } | ||||
/** | |||||
* Get the number of nested filters. | |||||
* @return the number | |||||
*/ | |||||
public int size() { | public int size() { | ||||
return filters.size(); | return filters.size(); | ||||
} | } | ||||
@@ -52,6 +65,7 @@ public class ReportFilters { | |||||
* Check whether a given <classname><method>() is accepted by the list | * Check whether a given <classname><method>() is accepted by the list | ||||
* of filters or not. | * of filters or not. | ||||
* @param methodname the full method name in the format <classname><method>() | * @param methodname the full method name in the format <classname><method>() | ||||
* @return true if the methodname passes the list of filters | |||||
*/ | */ | ||||
public boolean accept(String methodname) { | public boolean accept(String methodname) { | ||||
// I'm deferring matcher instantiations at runtime to avoid computing | // I'm deferring matcher instantiations at runtime to avoid computing | ||||
@@ -98,14 +112,28 @@ public class ReportFilters { | |||||
protected String clazz = "*"; // default is all classes | protected String clazz = "*"; // default is all classes | ||||
protected String method = "*"; // default is all methods | protected String method = "*"; // default is all methods | ||||
/** | |||||
* Set the class name to match | |||||
* Default is match all classes | |||||
* @param value the classname to match | |||||
*/ | |||||
public void setClass(String value) { | public void setClass(String value) { | ||||
clazz = value; | clazz = value; | ||||
} | } | ||||
/** | |||||
* Set the method name to match. | |||||
* Default is "*", match all methods | |||||
* @param value the method name to match | |||||
*/ | |||||
public void setMethod(String value) { | public void setMethod(String value) { | ||||
method = value; | method = value; | ||||
} | } | ||||
/** | |||||
* Get a regular expression matching this filter. | |||||
* @return a regular expression pattern matching this filer. | |||||
*/ | |||||
public String getAsPattern() { | public String getAsPattern() { | ||||
StringBuffer buf = new StringBuffer(toString()); | StringBuffer buf = new StringBuffer(toString()); | ||||
StringUtil.replace(buf, ".", "\\."); | StringUtil.replace(buf, ".", "\\."); | ||||
@@ -115,6 +143,11 @@ public class ReportFilters { | |||||
return buf.toString(); | return buf.toString(); | ||||
} | } | ||||
/** | |||||
* Get this object as a string. | |||||
* The form is ClassName.method(). | |||||
* @return this filter as a string. | |||||
*/ | |||||
public String toString() { | public String toString() { | ||||
return clazz + "." + method + "()"; | return clazz + "." + method + "()"; | ||||
} | } | ||||
@@ -1,5 +1,5 @@ | |||||
/* | /* | ||||
* Copyright 2001-2002,2004 The Apache Software Foundation | |||||
* Copyright 2001-2002,2004-2005 The Apache Software Foundation | |||||
* | * | ||||
* Licensed under the Apache License, Version 2.0 (the "License"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
@@ -36,6 +36,7 @@ public class Socket { | |||||
/** | /** | ||||
* the host name/ip of the machine on which the Viewer is running; | * the host name/ip of the machine on which the Viewer is running; | ||||
* defaults to localhost. | * defaults to localhost. | ||||
* @param value the home name/ip | |||||
*/ | */ | ||||
public void setHost(String value) { | public void setHost(String value) { | ||||
host = value; | host = value; | ||||
@@ -43,12 +44,16 @@ public class Socket { | |||||
/** | /** | ||||
* Optional port number for the viewer; default is 4444 | * Optional port number for the viewer; default is 4444 | ||||
* @param value the port number | |||||
*/ | */ | ||||
public void setPort(Integer value) { | public void setPort(Integer value) { | ||||
port = value.intValue(); | port = value.intValue(); | ||||
} | } | ||||
/** if no host is set, returning ':<port>', will take localhost */ | |||||
/** | |||||
* if no host is set, returning ':<port>', will take localhost | |||||
* @return "host:port" | |||||
*/ | |||||
public String toString() { | public String toString() { | ||||
return host + ":" + port; | return host + ":" + port; | ||||
} | } | ||||
@@ -1,5 +1,5 @@ | |||||
/* | /* | ||||
* Copyright 2001-2002,2004 The Apache Software Foundation | |||||
* Copyright 2001-2002,2004-2005 The Apache Software Foundation | |||||
* | * | ||||
* Licensed under the Apache License, Version 2.0 (the "License"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
@@ -30,18 +30,24 @@ public class Triggers { | |||||
protected Vector triggers = new Vector(); | protected Vector triggers = new Vector(); | ||||
/** Constructor of Triggers. */ | |||||
public Triggers() { | public Triggers() { | ||||
} | } | ||||
/** | /** | ||||
* add a method trigger | * add a method trigger | ||||
* @param method a method to trigger on | |||||
*/ | */ | ||||
public void addMethod(Method method) { | public void addMethod(Method method) { | ||||
triggers.addElement(method); | triggers.addElement(method); | ||||
} | } | ||||
// -jp_trigger=ClassName.*():E:S,ClassName.MethodName():X:X | |||||
/** | |||||
* Get the command line option of the form | |||||
* -jp_trigger=ClassName.*():E:S,ClassName.MethodName():X:X | |||||
* @return a trigger option | |||||
*/ | |||||
public String toString() { | public String toString() { | ||||
StringBuffer buf = new StringBuffer(); | StringBuffer buf = new StringBuffer(); | ||||
final int size = triggers.size(); | final int size = triggers.size(); | ||||
@@ -68,6 +74,7 @@ public class Triggers { | |||||
* The name of the method(s) as a regular expression. The name | * The name of the method(s) as a regular expression. The name | ||||
* is the fully qualified name on the form <tt>package.classname.method</tt> | * is the fully qualified name on the form <tt>package.classname.method</tt> | ||||
* required. | * required. | ||||
* @param value the fully qualified name | |||||
*/ | */ | ||||
public void setName(String value) { | public void setName(String value) { | ||||
name = value; | name = value; | ||||
@@ -77,10 +84,11 @@ public class Triggers { | |||||
* the event on the method that will trigger the action. Must be | * the event on the method that will trigger the action. Must be | ||||
* "enter" or "exit" | * "enter" or "exit" | ||||
* required. | * required. | ||||
* @param value the event - either "enter" or "exit" | |||||
*/ | */ | ||||
public void setEvent(String value) { | public void setEvent(String value) { | ||||
if (eventMap.get(value) == null) { | |||||
throw new BuildException("Invalid event, must be one of " + eventMap); | |||||
if (EVENT_MAP.get(value) == null) { | |||||
throw new BuildException("Invalid event, must be one of " + EVENT_MAP); | |||||
} | } | ||||
event = value; | event = value; | ||||
} | } | ||||
@@ -90,27 +98,33 @@ public class Triggers { | |||||
* "pause", "resume", "snapshot", "suspend", | * "pause", "resume", "snapshot", "suspend", | ||||
* or "exit". They respectively clear recording, pause recording, | * or "exit". They respectively clear recording, pause recording, | ||||
* resume recording, take a snapshot, suspend the recording and exit the program. | * resume recording, take a snapshot, suspend the recording and exit the program. | ||||
* @param value the action - "clear", "pause", "resume", "snapshot", "suspend" | |||||
* or "exit" | |||||
* @throws BuildException on error | |||||
*/ | */ | ||||
public void setAction(String value) throws BuildException { | public void setAction(String value) throws BuildException { | ||||
if (actionMap.get(value) == null) { | |||||
throw new BuildException("Invalid action, must be one of " + actionMap); | |||||
if (ACTION_MAP.get(value) == null) { | |||||
throw new BuildException("Invalid action, must be one of " + ACTION_MAP); | |||||
} | } | ||||
action = value; | action = value; | ||||
} | } | ||||
/** | /** | ||||
* A alphanumeric custom name for the snapshot; optional. | * A alphanumeric custom name for the snapshot; optional. | ||||
* @param value the custom name for the snapshot | |||||
*/ | */ | ||||
public void setParam(String value) { | public void setParam(String value) { | ||||
param = value; | param = value; | ||||
} | } | ||||
// return <name>:<event>:<action>[:param] | |||||
/** | |||||
* @return <name>:<event>:<action>[:param] | |||||
*/ | |||||
public String toString() { | public String toString() { | ||||
StringBuffer buf = new StringBuffer(); | StringBuffer buf = new StringBuffer(); | ||||
buf.append(name).append(":"); //@todo name must not be null, check for it | buf.append(name).append(":"); //@todo name must not be null, check for it | ||||
buf.append(eventMap.get(event)).append(":"); | |||||
buf.append(actionMap.get(action)); | |||||
buf.append(EVENT_MAP.get(event)).append(":"); | |||||
buf.append(ACTION_MAP.get(action)); | |||||
if (param != null) { | if (param != null) { | ||||
buf.append(":").append(param); | buf.append(":").append(param); | ||||
} | } | ||||
@@ -119,21 +133,21 @@ public class Triggers { | |||||
} | } | ||||
/** mapping of actions to cryptic command line mnemonics */ | /** mapping of actions to cryptic command line mnemonics */ | ||||
private static final Hashtable actionMap = new Hashtable(3); | |||||
private static final Hashtable ACTION_MAP = new Hashtable(3); | |||||
/** mapping of events to cryptic command line mnemonics */ | /** mapping of events to cryptic command line mnemonics */ | ||||
private static final Hashtable eventMap = new Hashtable(3); | |||||
private static final Hashtable EVENT_MAP = new Hashtable(3); | |||||
static { | static { | ||||
actionMap.put("enter", "E"); | |||||
actionMap.put("exit", "X"); | |||||
ACTION_MAP.put("enter", "E"); | |||||
ACTION_MAP.put("exit", "X"); | |||||
// clear|pause|resume|snapshot|suspend|exit | // clear|pause|resume|snapshot|suspend|exit | ||||
eventMap.put("clear", "C"); | |||||
eventMap.put("pause", "P"); | |||||
eventMap.put("resume", "R"); | |||||
eventMap.put("snapshot", "S"); | |||||
eventMap.put("suspend", "A"); | |||||
eventMap.put("exit", "X"); | |||||
EVENT_MAP.put("clear", "C"); | |||||
EVENT_MAP.put("pause", "P"); | |||||
EVENT_MAP.put("resume", "R"); | |||||
EVENT_MAP.put("snapshot", "S"); | |||||
EVENT_MAP.put("suspend", "A"); | |||||
EVENT_MAP.put("exit", "X"); | |||||
} | } | ||||
} | } |
@@ -1,5 +1,5 @@ | |||||
/* | /* | ||||
* Copyright 2001-2004 The Apache Software Foundation | |||||
* Copyright 2001-2005 The Apache Software Foundation | |||||
* | * | ||||
* Licensed under the Apache License, Version 2.0 (the "License"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
@@ -71,23 +71,36 @@ public class XMLReport { | |||||
/** method filters */ | /** method filters */ | ||||
private ReportFilters filters; | private ReportFilters filters; | ||||
/** create a new XML report, logging will be on stdout */ | |||||
/** | |||||
* Create a new XML report, logging will be on stdout. | |||||
* @param file the file to place the report in | |||||
*/ | |||||
public XMLReport(File file) { | public XMLReport(File file) { | ||||
this(null, file); | this(null, file); | ||||
} | } | ||||
/** create a new XML report, logging done on the task */ | |||||
/** | |||||
* Create a new XML report, logging done on the task. | |||||
* @param task the task to use for logging | |||||
* @param file the file to place the report in | |||||
*/ | |||||
public XMLReport(Task task, File file) { | public XMLReport(Task task, File file) { | ||||
this.file = file; | this.file = file; | ||||
this.task = task; | this.task = task; | ||||
} | } | ||||
/** set the JProbe home path. Used to get the DTD */ | |||||
/** | |||||
* Set the JProbe home path. Used to get the DTD. | |||||
* @param home the JProbe directory | |||||
*/ | |||||
public void setJProbehome(File home) { | public void setJProbehome(File home) { | ||||
jprobeHome = home; | jprobeHome = home; | ||||
} | } | ||||
/** set the */ | |||||
/** | |||||
* set the filters attribute. | |||||
* @param filters a filtersreport value | |||||
*/ | |||||
public void setReportFilters(ReportFilters filters) { | public void setReportFilters(ReportFilters filters) { | ||||
this.filters = filters; | this.filters = filters; | ||||
} | } | ||||
@@ -154,7 +167,12 @@ public class XMLReport { | |||||
log("Indexed " + classMap.size() + " classes in " + pkgMap.size() + " packages"); | log("Indexed " + classMap.size() + " classes in " + pkgMap.size() + " packages"); | ||||
} | } | ||||
/** create the whole new document */ | |||||
/** | |||||
* Create the whole new document. | |||||
* @param classPath the classpath | |||||
* @return a dom document | |||||
* @throws Exception on error | |||||
*/ | |||||
public Document createDocument(String[] classPath) throws Exception { | public Document createDocument(String[] classPath) throws Exception { | ||||
// Iterate over the classpath to identify reference classes | // Iterate over the classpath to identify reference classes | ||||
@@ -199,6 +217,9 @@ public class XMLReport { | |||||
* JProbe does not put the java.lang prefix for classes | * JProbe does not put the java.lang prefix for classes | ||||
* in this package, so used this nice method so that | * in this package, so used this nice method so that | ||||
* I have the same signature for methods | * I have the same signature for methods | ||||
* @param method info on a method | |||||
* @return a method signature with the "java.lang" prefixes removed from | |||||
* the method arguments | |||||
*/ | */ | ||||
protected String getMethodSignature(MethodInfo method) { | protected String getMethodSignature(MethodInfo method) { | ||||
StringBuffer buf = new StringBuffer(method.getName()); | StringBuffer buf = new StringBuffer(method.getName()); | ||||
@@ -224,6 +245,9 @@ public class XMLReport { | |||||
/** | /** | ||||
* Convert to a CovReport-like signature - <classname>.<method>(). | * Convert to a CovReport-like signature - <classname>.<method>(). | ||||
* @param clazz the class to use | |||||
* @param method the method to use | |||||
* @return the CovReport-like signature | |||||
*/ | */ | ||||
protected String getMethodSignature(ClassFile clazz, MethodInfo method) { | protected String getMethodSignature(ClassFile clazz, MethodInfo method) { | ||||
StringBuffer buf = new StringBuffer(clazz.getFullName()); | StringBuffer buf = new StringBuffer(clazz.getFullName()); | ||||
@@ -236,6 +260,8 @@ public class XMLReport { | |||||
/** | /** | ||||
* Do additional work on an element to remove abstract methods that | * Do additional work on an element to remove abstract methods that | ||||
* are reported by JProbe 3.0 | * are reported by JProbe 3.0 | ||||
* @param classFile the class to use | |||||
* @param classNode information on the class | |||||
*/ | */ | ||||
protected void removeAbstractMethods(ClassFile classFile, Element classNode) { | protected void removeAbstractMethods(ClassFile classFile, Element classNode) { | ||||
MethodInfo[] methods = classFile.getMethods(); | MethodInfo[] methods = classFile.getMethods(); | ||||
@@ -254,7 +280,11 @@ public class XMLReport { | |||||
} | } | ||||
} | } | ||||
/** create an empty method element with its cov.data values */ | |||||
/** | |||||
* Create an empty method element with its cov.data values. | |||||
* @param method jprobe info on a method | |||||
* @return the method element | |||||
*/ | |||||
protected Element createMethodElement(MethodInfo method) { | protected Element createMethodElement(MethodInfo method) { | ||||
String methodsig = getMethodSignature(method); | String methodsig = getMethodSignature(method); | ||||
Element methodElem = report.createElement("method"); | Element methodElem = report.createElement("method"); | ||||
@@ -268,7 +298,11 @@ public class XMLReport { | |||||
return methodElem; | return methodElem; | ||||
} | } | ||||
/** create an empty package element with its default cov.data (0) */ | |||||
/** | |||||
* Create an empty package element with its default cov.data (0). | |||||
* @param pkgname the packet name | |||||
* @return the package element | |||||
*/ | |||||
protected Element createPackageElement(String pkgname) { | protected Element createPackageElement(String pkgname) { | ||||
Element pkgElem = report.createElement("package"); | Element pkgElem = report.createElement("package"); | ||||
pkgElem.setAttribute("name", pkgname); | pkgElem.setAttribute("name", pkgname); | ||||
@@ -284,7 +318,11 @@ public class XMLReport { | |||||
return pkgElem; | return pkgElem; | ||||
} | } | ||||
/** create an empty class element with its default cov.data (0) */ | |||||
/** | |||||
* Create an empty class element with its default cov.data (0). | |||||
* @param classFile jprobe class info | |||||
* @return an class element | |||||
*/ | |||||
protected Element createClassElement(ClassFile classFile) { | protected Element createClassElement(ClassFile classFile) { | ||||
// create the class element | // create the class element | ||||
Element classElem = report.createElement("class"); | Element classElem = report.createElement("class"); | ||||
@@ -305,7 +343,10 @@ public class XMLReport { | |||||
return classElem; | return classElem; | ||||
} | } | ||||
/** serialize a classfile into XML */ | |||||
/** | |||||
* serialize a classfile into XML. | |||||
* @param classFile the class file to serialize | |||||
*/ | |||||
protected void serializeClass(ClassFile classFile) { | protected void serializeClass(ClassFile classFile) { | ||||
// the class already is reported so ignore it | // the class already is reported so ignore it | ||||
String fullclassname = classFile.getFullName(); | String fullclassname = classFile.getFullName(); | ||||
@@ -368,6 +409,11 @@ public class XMLReport { | |||||
classMap.put(fullclassname, classElem); | classMap.put(fullclassname, classElem); | ||||
} | } | ||||
/** | |||||
* Get the methods from a classFile that pass the filters. | |||||
* @param classFile the class file to get the methods from | |||||
* @return the list of methods | |||||
*/ | |||||
protected Vector getFilteredMethods(ClassFile classFile) { | protected Vector getFilteredMethods(ClassFile classFile) { | ||||
MethodInfo[] methodlist = classFile.getMethods(); | MethodInfo[] methodlist = classFile.getMethods(); | ||||
Vector methods = new Vector(methodlist.length); | Vector methods = new Vector(methodlist.length); | ||||
@@ -449,6 +495,13 @@ public class XMLReport { | |||||
covdata.setAttribute("total_lines", String.valueOf(total_lines)); | covdata.setAttribute("total_lines", String.valueOf(total_lines)); | ||||
} | } | ||||
/** | |||||
* Search for an element with the tag "cov.data" in the children | |||||
* of the parent element and return it. | |||||
* @param parent the parent element to search in | |||||
* @return the "cov.data" element | |||||
* @throws NoSuchElementException if unable to find a cov.data element | |||||
*/ | |||||
protected Element getCovDataChild(Element parent) { | protected Element getCovDataChild(Element parent) { | ||||
NodeList children = parent.getChildNodes(); | NodeList children = parent.getChildNodes(); | ||||
int len = children.getLength(); | int len = children.getLength(); | ||||
@@ -465,6 +518,11 @@ public class XMLReport { | |||||
+ "element in parent '" + parent.getNodeName() + "'"); | + "element in parent '" + parent.getNodeName() + "'"); | ||||
} | } | ||||
/** | |||||
* Get the method elements of an class element. | |||||
* @param clazz the element to search it | |||||
* @return a name to element map of methods | |||||
*/ | |||||
protected Hashtable getMethods(Element clazz) { | protected Hashtable getMethods(Element clazz) { | ||||
Hashtable map = new Hashtable(); | Hashtable map = new Hashtable(); | ||||
NodeList children = clazz.getChildNodes(); | NodeList children = clazz.getChildNodes(); | ||||
@@ -482,6 +540,11 @@ public class XMLReport { | |||||
return map; | return map; | ||||
} | } | ||||
/** | |||||
* Get the class elements of an package element. | |||||
* @param pkg the element to search it | |||||
* @return an array of class elements | |||||
*/ | |||||
protected Element[] getClasses(Element pkg) { | protected Element[] getClasses(Element pkg) { | ||||
Vector v = new Vector(); | Vector v = new Vector(); | ||||
NodeList children = pkg.getChildNodes(); | NodeList children = pkg.getChildNodes(); | ||||
@@ -501,6 +564,11 @@ public class XMLReport { | |||||
} | } | ||||
/** | |||||
* Get the package elements of an snapshot element. | |||||
* @param snapshot the element to search it | |||||
* @return an array of package elements | |||||
*/ | |||||
protected Element[] getPackages(Element snapshot) { | protected Element[] getPackages(Element snapshot) { | ||||
Vector v = new Vector(); | Vector v = new Vector(); | ||||
NodeList children = snapshot.getChildNodes(); | NodeList children = snapshot.getChildNodes(); | ||||
@@ -530,6 +598,10 @@ public class XMLReport { | |||||
} | } | ||||
} | } | ||||
/** | |||||
* Log a message to the associated task. | |||||
* @param message a <code>String</code> attribute | |||||
*/ | |||||
public void log(String message) { | public void log(String message) { | ||||
if (task == null) { | if (task == null) { | ||||
//System.out.println(message); | //System.out.println(message); | ||||
@@ -1,5 +1,5 @@ | |||||
/* | /* | ||||
* Copyright 2001-2002,2004 The Apache Software Foundation | |||||
* Copyright 2001-2002,2004-2005 The Apache Software Foundation | |||||
* | * | ||||
* Licensed under the Apache License, Version 2.0 (the "License"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
@@ -44,6 +44,11 @@ public final class ClassFile { | |||||
private int access_flags; | private int access_flags; | ||||
/** | |||||
* Constructor for ClassFile. | |||||
* @param is the input stream containing the class. | |||||
* @throws IOException on error | |||||
*/ | |||||
public ClassFile(InputStream is) throws IOException { | public ClassFile(InputStream is) throws IOException { | ||||
DataInputStream dis = new DataInputStream(is); | DataInputStream dis = new DataInputStream(is); | ||||
ConstantPool constantPool = new ConstantPool(); | ConstantPool constantPool = new ConstantPool(); | ||||
@@ -57,8 +62,9 @@ public final class ClassFile { | |||||
// class information | // class information | ||||
access_flags = dis.readShort(); | access_flags = dis.readShort(); | ||||
int this_class = dis.readShort(); | |||||
fullname = ((ClassCPInfo) constantPool.getEntry(this_class)).getClassName().replace('/', '.'); | |||||
int thisClass = dis.readShort(); | |||||
fullname = ((ClassCPInfo) constantPool.getEntry( | |||||
thisClass)).getClassName().replace('/', '.'); | |||||
/* int super_class = */ dis.readShort(); | /* int super_class = */ dis.readShort(); | ||||
// skip interfaces... | // skip interfaces... | ||||
@@ -71,8 +77,8 @@ public final class ClassFile { | |||||
// 3 short: access flags, name index, descriptor index | // 3 short: access flags, name index, descriptor index | ||||
dis.skip(2 * 3); | dis.skip(2 * 3); | ||||
// attribute list... | // attribute list... | ||||
int attributes_count = dis.readUnsignedShort(); | |||||
for (int j = 0; j < attributes_count; j++) { | |||||
int attributesCount = dis.readUnsignedShort(); | |||||
for (int j = 0; j < attributesCount; j++) { | |||||
dis.skipBytes(2); // skip attr_id (short) | dis.skipBytes(2); // skip attr_id (short) | ||||
int len = dis.readInt(); | int len = dis.readInt(); | ||||
dis.skipBytes(len); | dis.skipBytes(len); | ||||
@@ -80,44 +86,64 @@ public final class ClassFile { | |||||
} | } | ||||
// read methods | // read methods | ||||
int method_count = dis.readShort(); | |||||
methods = new MethodInfo[method_count]; | |||||
for (int i = 0; i < method_count; i++) { | |||||
int methodCount = dis.readShort(); | |||||
methods = new MethodInfo[methodCount]; | |||||
for (int i = 0; i < methodCount; i++) { | |||||
methods[i] = new MethodInfo(); | methods[i] = new MethodInfo(); | ||||
methods[i].read(constantPool, dis); | methods[i].read(constantPool, dis); | ||||
} | } | ||||
// get interesting attributes. | // get interesting attributes. | ||||
int attributes_count = dis.readUnsignedShort(); | |||||
for (int j = 0; j < attributes_count; j++) { | |||||
int attr_id = dis.readShort(); | |||||
int attributesCount = dis.readUnsignedShort(); | |||||
for (int j = 0; j < attributesCount; j++) { | |||||
int attrId = dis.readShort(); | |||||
int len = dis.readInt(); | int len = dis.readInt(); | ||||
String attr_name = Utils.getUTF8Value(constantPool, attr_id); | |||||
if (AttributeInfo.SOURCE_FILE.equals(attr_name)) { | |||||
int name_index = dis.readShort(); | |||||
sourceFile = ((Utf8CPInfo) constantPool.getEntry(name_index)).getValue(); | |||||
String attrName = Utils.getUTF8Value(constantPool, attrId); | |||||
if (AttributeInfo.SOURCE_FILE.equals(attrName)) { | |||||
int nameIndex = dis.readShort(); | |||||
sourceFile = ((Utf8CPInfo) constantPool.getEntry(nameIndex)).getValue(); | |||||
} else { | } else { | ||||
dis.skipBytes(len); | dis.skipBytes(len); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
/** | |||||
* Get the access flags of the class. | |||||
* @return the flags | |||||
*/ | |||||
public int getAccess() { | public int getAccess() { | ||||
return access_flags; | return access_flags; | ||||
} | } | ||||
/** | |||||
* Get the source filename | |||||
* @return the source filename | |||||
*/ | |||||
public String getSourceFile() { | public String getSourceFile() { | ||||
return sourceFile; | return sourceFile; | ||||
} | } | ||||
/** | |||||
* Get the methods of the class. | |||||
* @return the methods | |||||
*/ | |||||
public MethodInfo[] getMethods() { | public MethodInfo[] getMethods() { | ||||
return methods; | return methods; | ||||
} | } | ||||
/** | |||||
* Get the full name of the class. | |||||
* @return the full name | |||||
*/ | |||||
public String getFullName() { | public String getFullName() { | ||||
return fullname; | return fullname; | ||||
} | } | ||||
/** | |||||
* Get the name of the class (minus package name) | |||||
* @return the name | |||||
*/ | |||||
public String getName() { | public String getName() { | ||||
String name = getFullName(); | String name = getFullName(); | ||||
int pos = name.lastIndexOf('.'); | int pos = name.lastIndexOf('.'); | ||||
@@ -127,6 +153,10 @@ public final class ClassFile { | |||||
return name.substring(pos + 1); | return name.substring(pos + 1); | ||||
} | } | ||||
/** | |||||
* Get the package name of the class. | |||||
* @return the package name | |||||
*/ | |||||
public String getPackage() { | public String getPackage() { | ||||
String name = getFullName(); | String name = getFullName(); | ||||
int pos = name.lastIndexOf('.'); | int pos = name.lastIndexOf('.'); | ||||
@@ -137,8 +167,3 @@ public final class ClassFile { | |||||
} | } | ||||
} | } | ||||
@@ -1,5 +1,5 @@ | |||||
/* | /* | ||||
* Copyright 2001-2004 The Apache Software Foundation | |||||
* Copyright 2001-2005 The Apache Software Foundation | |||||
* | * | ||||
* Licensed under the Apache License, Version 2.0 (the "License"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
@@ -38,6 +38,7 @@ import java.util.zip.ZipFile; | |||||
*/ | */ | ||||
public class ClassPathLoader { | public class ClassPathLoader { | ||||
/** A null loader */ | |||||
public static final FileLoader NULL_LOADER = new NullLoader(); | public static final FileLoader NULL_LOADER = new NullLoader(); | ||||
/** the list of files to look for */ | /** the list of files to look for */ | ||||
@@ -80,10 +81,17 @@ public class ClassPathLoader { | |||||
/** the interface to implement to look up for specific resources */ | /** the interface to implement to look up for specific resources */ | ||||
public interface FileLoader { | public interface FileLoader { | ||||
/** the file url that is looked for .class files */ | |||||
/** | |||||
* the file url that is looked for .class files. | |||||
* @return the file | |||||
*/ | |||||
File getFile(); | File getFile(); | ||||
/** return the set of classes found in the file */ | |||||
/** | |||||
* Return the set of classes found in the file. | |||||
* @return the list of classes | |||||
* @throws IOException on error | |||||
*/ | |||||
ClassFile[] getClasses() throws IOException; | ClassFile[] getClasses() throws IOException; | ||||
} | } | ||||
@@ -104,6 +112,7 @@ public class ClassPathLoader { | |||||
* @return the hashtable containing ALL classes that are found in the given | * @return the hashtable containing ALL classes that are found in the given | ||||
* classpath. Note that the first entry of a given classname will shadow | * classpath. Note that the first entry of a given classname will shadow | ||||
* classes with the same name (as a classloader does) | * classes with the same name (as a classloader does) | ||||
* @throws IOException on error | |||||
*/ | */ | ||||
public Hashtable getClasses() throws IOException { | public Hashtable getClasses() throws IOException { | ||||
Hashtable map = new Hashtable(); | Hashtable map = new Hashtable(); | ||||
@@ -159,6 +168,9 @@ public class ClassPathLoader { | |||||
* useful methods to read the whole input stream in memory so that | * useful methods to read the whole input stream in memory so that | ||||
* it can be accessed faster. Processing rt.jar and tools.jar from JDK 1.3.1 | * it can be accessed faster. Processing rt.jar and tools.jar from JDK 1.3.1 | ||||
* brings time from 50s to 7s. | * brings time from 50s to 7s. | ||||
* @param is the inout stream to cache | |||||
* @return the cached input stream | |||||
* @throws IOException on error | |||||
*/ | */ | ||||
public static InputStream getCachedStream(InputStream is) throws IOException { | public static InputStream getCachedStream(InputStream is) throws IOException { | ||||
final InputStream bis = new BufferedInputStream(is); | final InputStream bis = new BufferedInputStream(is); | ||||
@@ -266,6 +278,7 @@ final class DirectoryLoader implements ClassPathLoader.FileLoader { | |||||
try { | try { | ||||
is.close(); | is.close(); | ||||
} catch (IOException ignored) { | } catch (IOException ignored) { | ||||
// Ignore Exception | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -1,5 +1,5 @@ | |||||
/* | /* | ||||
* Copyright 2001-2002,2004 The Apache Software Foundation | |||||
* Copyright 2001-2002,2004-2005 The Apache Software Foundation | |||||
* | * | ||||
* Licensed under the Apache License, Version 2.0 (the "License"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
@@ -27,16 +27,23 @@ import org.apache.tools.ant.taskdefs.optional.sitraka.bytecode.attributes.Attrib | |||||
* | * | ||||
*/ | */ | ||||
public final class MethodInfo { | public final class MethodInfo { | ||||
private int access_flags; | |||||
private int accessFlags; | |||||
private int loc = -1; | private int loc = -1; | ||||
private String name; | private String name; | ||||
private String descriptor; | private String descriptor; | ||||
/** Constructor for MethodInfo. */ | |||||
public MethodInfo() { | public MethodInfo() { | ||||
} | } | ||||
/** | |||||
* Read the method info from a data input stream. | |||||
* @param constantPool a constant pool | |||||
* @param dis the data input stream | |||||
* @throws IOException on error | |||||
*/ | |||||
public void read(ConstantPool constantPool, DataInputStream dis) throws IOException { | public void read(ConstantPool constantPool, DataInputStream dis) throws IOException { | ||||
access_flags = dis.readShort(); | |||||
accessFlags = dis.readShort(); | |||||
int name_index = dis.readShort(); | int name_index = dis.readShort(); | ||||
name = Utils.getUTF8Value(constantPool, name_index); | name = Utils.getUTF8Value(constantPool, name_index); | ||||
@@ -58,6 +65,12 @@ public final class MethodInfo { | |||||
} | } | ||||
/** | |||||
* Read a code from a data input stream. | |||||
* @param constantPool a constant pool | |||||
* @param dis the data input stream | |||||
* @throws IOException on error | |||||
*/ | |||||
protected void readCode(ConstantPool constantPool, DataInputStream dis) throws IOException { | protected void readCode(ConstantPool constantPool, DataInputStream dis) throws IOException { | ||||
// skip max_stack (short), max_local (short) | // skip max_stack (short), max_local (short) | ||||
dis.skipBytes(2 * 2); | dis.skipBytes(2 * 2); | ||||
@@ -87,22 +100,44 @@ public final class MethodInfo { | |||||
} | } | ||||
} | } | ||||
/** | |||||
* Get the access flags. | |||||
* @return the access flags | |||||
*/ | |||||
public int getAccessFlags() { | public int getAccessFlags() { | ||||
return access_flags; | |||||
return accessFlags; | |||||
} | } | ||||
/** | |||||
* Get the name. | |||||
* @return the name | |||||
*/ | |||||
public String getName() { | public String getName() { | ||||
return name; | return name; | ||||
} | } | ||||
/** | |||||
* Get the descriptor. | |||||
* @return the descriptor | |||||
*/ | |||||
public String getDescriptor() { | public String getDescriptor() { | ||||
return descriptor; | return descriptor; | ||||
} | } | ||||
/** | |||||
* Get the full signature of the method. | |||||
* This is the return type, the name and the parameters. | |||||
* @return the full signature | |||||
*/ | |||||
public String getFullSignature() { | public String getFullSignature() { | ||||
return getReturnType() + " " + getShortSignature(); | return getReturnType() + " " + getShortSignature(); | ||||
} | } | ||||
/** | |||||
* Get the short signature of the method. | |||||
* This is just the name and the parameters. | |||||
* @return the short signature | |||||
*/ | |||||
public String getShortSignature() { | public String getShortSignature() { | ||||
StringBuffer buf = new StringBuffer(getName()); | StringBuffer buf = new StringBuffer(getName()); | ||||
buf.append("("); | buf.append("("); | ||||
@@ -117,22 +152,42 @@ public final class MethodInfo { | |||||
return buf.toString(); | return buf.toString(); | ||||
} | } | ||||
/** | |||||
* Get the return type. | |||||
* @return the return type | |||||
*/ | |||||
public String getReturnType() { | public String getReturnType() { | ||||
return Utils.getMethodReturnType(getDescriptor()); | return Utils.getMethodReturnType(getDescriptor()); | ||||
} | } | ||||
/** | |||||
* Get the paramaters types. | |||||
* @return an array of types | |||||
*/ | |||||
public String[] getParametersType() { | public String[] getParametersType() { | ||||
return Utils.getMethodParams(getDescriptor()); | return Utils.getMethodParams(getDescriptor()); | ||||
} | } | ||||
/** | |||||
* Get the number of lines in the method. | |||||
* @return the number of lines | |||||
*/ | |||||
public int getNumberOfLines() { | public int getNumberOfLines() { | ||||
return loc; | return loc; | ||||
} | } | ||||
/** | |||||
* Get the access flags as a string. | |||||
* @return the access flags. | |||||
*/ | |||||
public String getAccess() { | public String getAccess() { | ||||
return Utils.getMethodAccess(access_flags); | |||||
return Utils.getMethodAccess(accessFlags); | |||||
} | } | ||||
/** | |||||
* Return a string represention of this object. | |||||
* @return the access, and the full signature | |||||
*/ | |||||
public String toString() { | public String toString() { | ||||
StringBuffer sb = new StringBuffer(); | StringBuffer sb = new StringBuffer(); | ||||
sb.append("Method: ").append(getAccess()).append(" "); | sb.append("Method: ").append(getAccess()).append(" "); | ||||
@@ -140,5 +195,3 @@ public final class MethodInfo { | |||||
return sb.toString(); | return sb.toString(); | ||||
} | } | ||||
} | } | ||||
@@ -1,5 +1,5 @@ | |||||
/* | /* | ||||
* Copyright 2001-2004 The Apache Software Foundation | |||||
* Copyright 2001-2005 The Apache Software Foundation | |||||
* | * | ||||
* Licensed under the Apache License, Version 2.0 (the "License"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
@@ -25,7 +25,7 @@ import org.apache.tools.ant.taskdefs.optional.depend.constantpool.Utf8CPInfo; | |||||
* Utilities mostly to manipulate methods and access flags. | * Utilities mostly to manipulate methods and access flags. | ||||
* | * | ||||
*/ | */ | ||||
public class Utils { | |||||
public final class Utils { | |||||
/** public access flag */ | /** public access flag */ | ||||
public static final short ACC_PUBLIC = 1; | public static final short ACC_PUBLIC = 1; | ||||
/** private access flag */ | /** private access flag */ | ||||
@@ -98,7 +98,7 @@ public class Utils { | |||||
/** | /** | ||||
* return the object type of a return type. | * return the object type of a return type. | ||||
* @param descriptor | |||||
* @param descriptor the description symbol | |||||
* @return get the return type objet of a given descriptor | * @return get the return type objet of a given descriptor | ||||
*/ | */ | ||||
public static String getMethodReturnType(String descriptor) { | public static String getMethodReturnType(String descriptor) { | ||||
@@ -172,143 +172,157 @@ public class Utils { | |||||
/** | /** | ||||
* check for abstract access | * check for abstract access | ||||
* @param access_flags access flags | |||||
* @param accessFlags access flags | |||||
* @return true if there is abstact access | |||||
*/ | */ | ||||
public static boolean isAbstract(int access_flags) { | |||||
return (access_flags & ACC_ABSTRACT) != 0; | |||||
public static boolean isAbstract(int accessFlags) { | |||||
return (accessFlags & ACC_ABSTRACT) != 0; | |||||
} | } | ||||
/** | /** | ||||
* check for public access | * check for public access | ||||
* @param access_flags access flags | |||||
* @param accessFlags access flags | |||||
* @return true if there is public access | |||||
*/ | */ | ||||
public static boolean isPublic(int access_flags) { | |||||
return (access_flags & ACC_PUBLIC) != 0; | |||||
public static boolean isPublic(int accessFlags) { | |||||
return (accessFlags & ACC_PUBLIC) != 0; | |||||
} | } | ||||
/** | /** | ||||
* check for a static access | * check for a static access | ||||
* @param access_flags access flags | |||||
* @param accessFlags access flags | |||||
* @return true if there is static access | |||||
*/ | */ | ||||
public static boolean isStatic(int access_flags) { | |||||
return (access_flags & ACC_STATIC) != 0; | |||||
public static boolean isStatic(int accessFlags) { | |||||
return (accessFlags & ACC_STATIC) != 0; | |||||
} | } | ||||
/** | /** | ||||
* check for native access | |||||
* @param access_flags access flags | |||||
* check for native access | |||||
* @param accessFlags access flags | |||||
* @return true if there is native access | |||||
*/ | */ | ||||
public static boolean isNative(int access_flags) { | |||||
return (access_flags & ACC_NATIVE) != 0; | |||||
public static boolean isNative(int accessFlags) { | |||||
return (accessFlags & ACC_NATIVE) != 0; | |||||
} | } | ||||
/** | /** | ||||
* check for class access | * check for class access | ||||
* @param access_flags access flags | |||||
* @param accessFlags access flags | |||||
* @return true if there is class access | |||||
*/ | */ | ||||
public static boolean isClass(int access_flags) { | |||||
return !isInterface(access_flags); | |||||
public static boolean isClass(int accessFlags) { | |||||
return !isInterface(accessFlags); | |||||
} | } | ||||
/** | /** | ||||
* check for strict access | * check for strict access | ||||
* @param access_flags access flags | |||||
* @param accessFlags access flags | |||||
* @return true if there is strict access | |||||
*/ | */ | ||||
public static boolean isStrict(int access_flags) { | |||||
return (access_flags & ACC_STRICT) != 0; | |||||
public static boolean isStrict(int accessFlags) { | |||||
return (accessFlags & ACC_STRICT) != 0; | |||||
} | } | ||||
/** | /** | ||||
* check for interface access | * check for interface access | ||||
* @param access_flags access flags | |||||
* @param accessFlags access flags | |||||
* @return true if there is interface access | |||||
*/ | */ | ||||
public static boolean isInterface(int access_flags) { | |||||
return (access_flags & ACC_INTERFACE) != 0; | |||||
public static boolean isInterface(int accessFlags) { | |||||
return (accessFlags & ACC_INTERFACE) != 0; | |||||
} | } | ||||
/** | /** | ||||
* check for private access | * check for private access | ||||
* @param access_flags access flags | |||||
* @param accessFlags access flags | |||||
* @return true if there is private access | |||||
*/ | */ | ||||
public static boolean isPrivate(int access_flags) { | |||||
return (access_flags & ACC_PRIVATE) != 0; | |||||
public static boolean isPrivate(int accessFlags) { | |||||
return (accessFlags & ACC_PRIVATE) != 0; | |||||
} | } | ||||
/** | /** | ||||
* check for transient flag | * check for transient flag | ||||
* @param access_flags access flags | |||||
* @param accessFlags access flags | |||||
* @return true if there is transient access | |||||
*/ | */ | ||||
public static boolean isTransient(int access_flags) { | |||||
return (access_flags & ACC_TRANSIENT) != 0; | |||||
public static boolean isTransient(int accessFlags) { | |||||
return (accessFlags & ACC_TRANSIENT) != 0; | |||||
} | } | ||||
/** | /** | ||||
* check for volatile flag | * check for volatile flag | ||||
* @param access_flags access flags | |||||
* @param accessFlags access flags | |||||
* @return true if there is volatile access | |||||
*/ | */ | ||||
public static boolean isVolatile(int access_flags) { | |||||
return (access_flags & ACC_VOLATILE) != 0; | |||||
public static boolean isVolatile(int accessFlags) { | |||||
return (accessFlags & ACC_VOLATILE) != 0; | |||||
} | } | ||||
/** | /** | ||||
* check for super flag | * check for super flag | ||||
* @param access_flags access flag | |||||
* @param accessFlags access flag | |||||
* @return true if there the super flag is set | |||||
*/ | */ | ||||
public static boolean isSuper(int access_flags) { | |||||
return (access_flags & ACC_SUPER) != 0; | |||||
public static boolean isSuper(int accessFlags) { | |||||
return (accessFlags & ACC_SUPER) != 0; | |||||
} | } | ||||
/** | /** | ||||
* check for protected flag | * check for protected flag | ||||
* @param access_flags access flags | |||||
* @param accessFlags access flags | |||||
* @return true if there is protected access | |||||
*/ | */ | ||||
public static boolean isProtected(int access_flags) { | |||||
return (access_flags & ACC_PROTECTED) != 0; | |||||
public static boolean isProtected(int accessFlags) { | |||||
return (accessFlags & ACC_PROTECTED) != 0; | |||||
} | } | ||||
/** | /** | ||||
* chck for final flag | * chck for final flag | ||||
* @param access_flags access flags | |||||
* @param accessFlags access flags | |||||
* @return true if there the final flag is set | |||||
*/ | */ | ||||
public static boolean isFinal(int access_flags) { | |||||
return (access_flags & ACC_FINAL) != 0; | |||||
public static boolean isFinal(int accessFlags) { | |||||
return (accessFlags & ACC_FINAL) != 0; | |||||
} | } | ||||
/** | /** | ||||
* check for synchronized flag | * check for synchronized flag | ||||
* @param access_flags access flags | |||||
* @param accessFlags access flags | |||||
* @return true if there the synchronized flag is set | |||||
*/ | */ | ||||
public static boolean isSynchronized(int access_flags) { | |||||
return (access_flags & ACC_SYNCHRONIZED) != 0; | |||||
public static boolean isSynchronized(int accessFlags) { | |||||
return (accessFlags & ACC_SYNCHRONIZED) != 0; | |||||
} | } | ||||
/** | /** | ||||
* return the method access flag as java modifiers | * return the method access flag as java modifiers | ||||
* @param access_flags access flags | |||||
* @param accessFlags access flags | |||||
* @return the access flags as modifier strings | * @return the access flags as modifier strings | ||||
*/ | */ | ||||
public static String getMethodAccess(int access_flags) { | |||||
public static String getMethodAccess(int accessFlags) { | |||||
StringBuffer sb = new StringBuffer(); | StringBuffer sb = new StringBuffer(); | ||||
if (isPublic(access_flags)) { | |||||
if (isPublic(accessFlags)) { | |||||
sb.append("public "); | sb.append("public "); | ||||
} else if (isPrivate(access_flags)) { | |||||
} else if (isPrivate(accessFlags)) { | |||||
sb.append("private "); | sb.append("private "); | ||||
} else if (isProtected(access_flags)) { | |||||
} else if (isProtected(accessFlags)) { | |||||
sb.append("protected "); | sb.append("protected "); | ||||
} | } | ||||
if (isFinal(access_flags)) { | |||||
if (isFinal(accessFlags)) { | |||||
sb.append("final "); | sb.append("final "); | ||||
} | } | ||||
if (isStatic(access_flags)) { | |||||
if (isStatic(accessFlags)) { | |||||
sb.append("static "); | sb.append("static "); | ||||
} | } | ||||
if (isSynchronized(access_flags)) { | |||||
if (isSynchronized(accessFlags)) { | |||||
sb.append("synchronized "); | sb.append("synchronized "); | ||||
} | } | ||||
if (isNative(access_flags)) { | |||||
if (isNative(accessFlags)) { | |||||
sb.append("native "); | sb.append("native "); | ||||
} | } | ||||
if (isAbstract(access_flags)) { | |||||
if (isAbstract(accessFlags)) { | |||||
sb.append("abstract "); | sb.append("abstract "); | ||||
} | } | ||||
return sb.toString().trim(); | return sb.toString().trim(); | ||||
@@ -316,28 +330,28 @@ public class Utils { | |||||
/** | /** | ||||
* return the field access flag as java modifiers | * return the field access flag as java modifiers | ||||
* @param access_flags access flags | |||||
* @param accessFlags access flags | |||||
* @return the access flags as modifier strings | * @return the access flags as modifier strings | ||||
*/ | */ | ||||
public static String getFieldAccess(int access_flags) { | |||||
public static String getFieldAccess(int accessFlags) { | |||||
StringBuffer sb = new StringBuffer(); | StringBuffer sb = new StringBuffer(); | ||||
if (isPublic(access_flags)) { | |||||
if (isPublic(accessFlags)) { | |||||
sb.append("public "); | sb.append("public "); | ||||
} else if (isPrivate(access_flags)) { | |||||
} else if (isPrivate(accessFlags)) { | |||||
sb.append("private "); | sb.append("private "); | ||||
} else if (isProtected(access_flags)) { | |||||
} else if (isProtected(accessFlags)) { | |||||
sb.append("protected "); | sb.append("protected "); | ||||
} | } | ||||
if (isFinal(access_flags)) { | |||||
if (isFinal(accessFlags)) { | |||||
sb.append("final "); | sb.append("final "); | ||||
} | } | ||||
if (isStatic(access_flags)) { | |||||
if (isStatic(accessFlags)) { | |||||
sb.append("static "); | sb.append("static "); | ||||
} | } | ||||
if (isVolatile(access_flags)) { | |||||
if (isVolatile(accessFlags)) { | |||||
sb.append("volatile "); | sb.append("volatile "); | ||||
} | } | ||||
if (isTransient(access_flags)) { | |||||
if (isTransient(accessFlags)) { | |||||
sb.append("transient "); | sb.append("transient "); | ||||
} | } | ||||
return sb.toString().trim(); | return sb.toString().trim(); | ||||
@@ -345,31 +359,31 @@ public class Utils { | |||||
/** | /** | ||||
* return the class access flag as java modifiers | * return the class access flag as java modifiers | ||||
* @param access_flags access flags | |||||
* @param accessFlags access flags | |||||
* @return the access flags as modifier strings | * @return the access flags as modifier strings | ||||
*/ | */ | ||||
public static String getClassAccess(int access_flags) { | |||||
public static String getClassAccess(int accessFlags) { | |||||
StringBuffer sb = new StringBuffer(); | StringBuffer sb = new StringBuffer(); | ||||
if (isPublic(access_flags)) { | |||||
if (isPublic(accessFlags)) { | |||||
sb.append("public "); | sb.append("public "); | ||||
} else if (isProtected(access_flags)) { | |||||
} else if (isProtected(accessFlags)) { | |||||
sb.append("protected "); | sb.append("protected "); | ||||
} else if (isPrivate(access_flags)) { | |||||
} else if (isPrivate(accessFlags)) { | |||||
sb.append("private "); | sb.append("private "); | ||||
} | } | ||||
if (isFinal(access_flags)) { | |||||
if (isFinal(accessFlags)) { | |||||
sb.append("final "); | sb.append("final "); | ||||
} | } | ||||
if (isSuper(access_flags)) { | |||||
if (isSuper(accessFlags)) { | |||||
sb.append("/*super*/ "); | sb.append("/*super*/ "); | ||||
} | } | ||||
if (isInterface(access_flags)) { | |||||
if (isInterface(accessFlags)) { | |||||
sb.append("interface "); | sb.append("interface "); | ||||
} | } | ||||
if (isAbstract(access_flags)) { | |||||
if (isAbstract(accessFlags)) { | |||||
sb.append("abstract "); | sb.append("abstract "); | ||||
} | } | ||||
if (isClass(access_flags)) { | |||||
if (isClass(accessFlags)) { | |||||
sb.append("class "); | sb.append("class "); | ||||
} | } | ||||
return sb.toString().trim(); | return sb.toString().trim(); | ||||
@@ -1,5 +1,5 @@ | |||||
/* | /* | ||||
* Copyright 2001-2002,2004 The Apache Software Foundation | |||||
* Copyright 2001-2002,2004-2005 The Apache Software Foundation | |||||
* | * | ||||
* Licensed under the Apache License, Version 2.0 (the "License"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
@@ -22,26 +22,36 @@ package org.apache.tools.ant.taskdefs.optional.sitraka.bytecode.attributes; | |||||
*/ | */ | ||||
public interface AttributeInfo { | public interface AttributeInfo { | ||||
/** The source file attribute */ | |||||
String SOURCE_FILE = "SourceFile"; | String SOURCE_FILE = "SourceFile"; | ||||
/** The constant value attribute */ | |||||
String CONSTANT_VALUE = "ConstantValue"; | String CONSTANT_VALUE = "ConstantValue"; | ||||
/** The code attribute */ | |||||
String CODE = "Code"; | String CODE = "Code"; | ||||
/** The exceptions attribute */ | |||||
String EXCEPTIONS = "Exceptions"; | String EXCEPTIONS = "Exceptions"; | ||||
/** The line number table attribute */ | |||||
String LINE_NUMBER_TABLE = "LineNumberTable"; | String LINE_NUMBER_TABLE = "LineNumberTable"; | ||||
/** The local variable table attribute */ | |||||
String LOCAL_VARIABLE_TABLE = "LocalVariableTable"; | String LOCAL_VARIABLE_TABLE = "LocalVariableTable"; | ||||
/** The inner classes attribute */ | |||||
String INNER_CLASSES = "InnerClasses"; | String INNER_CLASSES = "InnerClasses"; | ||||
/** The source dir attribute */ | |||||
String SOURCE_DIR = "SourceDir"; | String SOURCE_DIR = "SourceDir"; | ||||
/** The synthetic attribute */ | |||||
String SYNTHETIC = "Synthetic"; | String SYNTHETIC = "Synthetic"; | ||||
/** The deprecated attribute */ | |||||
String DEPRECATED = "Deprecated"; | String DEPRECATED = "Deprecated"; | ||||
/** The unknown attribute */ | |||||
String UNKNOWN = "Unknown"; | String UNKNOWN = "Unknown"; | ||||
} | } |