git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269945 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -54,23 +54,21 @@ | |||||
| package org.apache.tools.ant.taskdefs.optional.sitraka; | package org.apache.tools.ant.taskdefs.optional.sitraka; | ||||
| import java.io.File; | |||||
| import java.io.FileWriter; | |||||
| import java.io.IOException; | |||||
| import java.io.PrintWriter; | |||||
| import java.util.Random; | |||||
| import java.util.Vector; | |||||
| import org.apache.tools.ant.BuildException; | import org.apache.tools.ant.BuildException; | ||||
| import org.apache.tools.ant.DirectoryScanner; | |||||
| import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
| import org.apache.tools.ant.Task; | import org.apache.tools.ant.Task; | ||||
| import org.apache.tools.ant.taskdefs.LogStreamHandler; | |||||
| import org.apache.tools.ant.taskdefs.Execute; | import org.apache.tools.ant.taskdefs.Execute; | ||||
| import org.apache.tools.ant.taskdefs.LogStreamHandler; | |||||
| import org.apache.tools.ant.types.Commandline; | import org.apache.tools.ant.types.Commandline; | ||||
| import org.apache.tools.ant.types.FileSet; | import org.apache.tools.ant.types.FileSet; | ||||
| import org.apache.tools.ant.DirectoryScanner; | |||||
| import java.util.Vector; | |||||
| import java.util.Random; | |||||
| import java.io.File; | |||||
| import java.io.FileWriter; | |||||
| import java.io.PrintWriter; | |||||
| import java.io.IOException; | |||||
| /** | /** | ||||
| * Convenient task to run the snapshot merge utility for JProbe Coverage. | * Convenient task to run the snapshot merge utility for JProbe Coverage. | ||||
| @@ -79,152 +77,152 @@ import java.io.IOException; | |||||
| */ | */ | ||||
| public class CovMerge extends Task { | public class CovMerge extends Task { | ||||
| /** coverage home, it is mandatory */ | |||||
| /** coverage home, it is mandatory */ | |||||
| private File home = null; | private File home = null; | ||||
| /** the name of the output snapshot */ | |||||
| /** the name of the output snapshot */ | |||||
| private File tofile = null; | private File tofile = null; | ||||
| /** the filesets that will get all snapshots to merge */ | |||||
| /** the filesets that will get all snapshots to merge */ | |||||
| private Vector filesets = new Vector(); | private Vector filesets = new Vector(); | ||||
| private boolean verbose; | |||||
| /** | |||||
| * set the coverage home. it must point to JProbe coverage | |||||
| * directories where are stored native librairies and jars | |||||
| */ | |||||
| private boolean verbose; | |||||
| /** | |||||
| * set the coverage home. it must point to JProbe coverage | |||||
| * directories where are stored native librairies and jars | |||||
| */ | |||||
| public void setHome(File value) { | public void setHome(File value) { | ||||
| this.home = value; | this.home = value; | ||||
| } | } | ||||
| /** | |||||
| * Set the output snapshot file | |||||
| */ | |||||
| /** | |||||
| * Set the output snapshot file | |||||
| */ | |||||
| public void setTofile(File value) { | public void setTofile(File value) { | ||||
| this.tofile = value; | this.tofile = value; | ||||
| } | } | ||||
| /** run the merging in verbose mode */ | |||||
| public void setVerbose(boolean flag){ | |||||
| this.verbose = flag; | |||||
| } | |||||
| /** run the merging in verbose mode */ | |||||
| public void setVerbose(boolean flag) { | |||||
| this.verbose = flag; | |||||
| } | |||||
| /** add a fileset containing the snapshots to include/exclude */ | |||||
| public void addFileset(FileSet fs){ | |||||
| filesets.addElement(fs); | |||||
| } | |||||
| /** add a fileset containing the snapshots to include/exclude */ | |||||
| public void addFileset(FileSet fs) { | |||||
| filesets.addElement(fs); | |||||
| } | |||||
| //---------------- the tedious job begins here | |||||
| //---------------- the tedious job begins here | |||||
| public CovMerge() { | |||||
| public CovMerge() { | |||||
| } | } | ||||
| /** execute the jpcovmerge by providing a parameter file */ | |||||
| /** execute the jpcovmerge by providing a parameter file */ | |||||
| public void execute() throws BuildException { | public void execute() throws BuildException { | ||||
| checkOptions(); | |||||
| File paramfile = createParamFile(); | |||||
| try{ | |||||
| Commandline cmdl = new Commandline(); | |||||
| cmdl.setExecutable( new File(home, "jpcovmerge").getAbsolutePath() ); | |||||
| if (verbose) { | |||||
| cmdl.createArgument().setValue("-v"); | |||||
| } | |||||
| cmdl.createArgument().setValue("-jp_paramfile=" + paramfile.getAbsolutePath()); | |||||
| LogStreamHandler handler = new LogStreamHandler(this,Project.MSG_INFO,Project.MSG_WARN); | |||||
| Execute exec = new Execute(handler); | |||||
| log(cmdl.toString(), Project.MSG_VERBOSE); | |||||
| exec.setCommandline(cmdl.getCommandline()); | |||||
| // JProbe process always return 0 so we will not be | |||||
| // able to check for failure ! :-( | |||||
| int exitValue = exec.execute(); | |||||
| if (exitValue!=0) { | |||||
| throw new BuildException("JProbe Coverage Merging failed (" + exitValue + ")"); | |||||
| } | |||||
| checkOptions(); | |||||
| File paramfile = createParamFile(); | |||||
| try { | |||||
| Commandline cmdl = new Commandline(); | |||||
| cmdl.setExecutable(new File(home, "jpcovmerge").getAbsolutePath()); | |||||
| if (verbose) { | |||||
| cmdl.createArgument().setValue("-v"); | |||||
| } | |||||
| cmdl.createArgument().setValue("-jp_paramfile=" + paramfile.getAbsolutePath()); | |||||
| LogStreamHandler handler = new LogStreamHandler(this, Project.MSG_INFO, Project.MSG_WARN); | |||||
| Execute exec = new Execute(handler); | |||||
| log(cmdl.toString(), Project.MSG_VERBOSE); | |||||
| exec.setCommandline(cmdl.getCommandline()); | |||||
| // JProbe process always return 0 so we will not be | |||||
| // able to check for failure ! :-( | |||||
| int exitValue = exec.execute(); | |||||
| if (exitValue != 0) { | |||||
| throw new BuildException("JProbe Coverage Merging failed (" + exitValue + ")"); | |||||
| } | |||||
| } catch (IOException e) { | } catch (IOException e) { | ||||
| throw new BuildException("Failed to run JProbe Coverage Merge: " + e); | throw new BuildException("Failed to run JProbe Coverage Merge: " + e); | ||||
| } finally { | } finally { | ||||
| //@todo should be removed once switched to JDK1.2 | |||||
| paramfile.delete(); | |||||
| } | |||||
| //@todo should be removed once switched to JDK1.2 | |||||
| paramfile.delete(); | |||||
| } | |||||
| } | } | ||||
| /** check for mandatory options */ | |||||
| protected void checkOptions() throws BuildException { | |||||
| if (tofile == null) { | |||||
| throw new BuildException("'tofile' attribute must be set."); | |||||
| } | |||||
| // check coverage home | |||||
| if (home == null || !home.isDirectory() ) { | |||||
| throw new BuildException("Invalid home directory. Must point to JProbe home directory"); | |||||
| } | |||||
| home = new File(home,"Coverage"); | |||||
| File jar = new File(home, "coverage.jar"); | |||||
| if (!jar.exists()) { | |||||
| throw new BuildException("Cannot find Coverage directory: " + home); | |||||
| } | |||||
| } | |||||
| /** get the snapshots from the filesets */ | |||||
| protected File[] getSnapshots() { | |||||
| Vector v = new Vector(); | |||||
| final int size = filesets.size(); | |||||
| for (int i = 0; i < size; i++) { | |||||
| FileSet fs = (FileSet) filesets.elementAt(i); | |||||
| DirectoryScanner ds = fs.getDirectoryScanner(getProject()); | |||||
| ds.scan(); | |||||
| String[] f = ds.getIncludedFiles(); | |||||
| for (int j = 0; j < f.length; j++) { | |||||
| String pathname = f[j]; | |||||
| File file = new File(ds.getBasedir(), pathname); | |||||
| file = project.resolveFile(file.getPath()); | |||||
| v.addElement( file ); | |||||
| } | |||||
| } | |||||
| File[] files = new File[v.size()]; | |||||
| v.copyInto(files); | |||||
| return files; | |||||
| } | |||||
| /** | |||||
| * create the parameters file that contains all file to merge | |||||
| * and the output filename. | |||||
| */ | |||||
| protected File createParamFile() throws BuildException { | |||||
| File[] snapshots = getSnapshots(); | |||||
| File file = createTmpFile(); | |||||
| FileWriter fw = null; | |||||
| try { | |||||
| fw = new FileWriter(file); | |||||
| PrintWriter pw = new PrintWriter(fw); | |||||
| for (int i = 0; i < snapshots.length; i++) { | |||||
| pw.println(snapshots[i].getAbsolutePath()); | |||||
| } | |||||
| // last file is the output snapshot | |||||
| pw.println(project.resolveFile(tofile.getPath())); | |||||
| pw.flush(); | |||||
| return file; | |||||
| } catch (IOException e){ | |||||
| if (fw != null) { | |||||
| try { | |||||
| fw.close(); | |||||
| } catch (IOException ignored){ | |||||
| } | |||||
| } | |||||
| throw new BuildException("I/O error while writing to " + file, e); | |||||
| } | |||||
| } | |||||
| /** create a temporary file in the current dir (For JDK1.1 support) */ | |||||
| protected File createTmpFile(){ | |||||
| final long rand = (new Random(System.currentTimeMillis())).nextLong(); | |||||
| File file = new File("jpcovmerge" + rand + ".tmp"); | |||||
| return file; | |||||
| } | |||||
| /** check for mandatory options */ | |||||
| protected void checkOptions() throws BuildException { | |||||
| if (tofile == null) { | |||||
| throw new BuildException("'tofile' attribute must be set."); | |||||
| } | |||||
| // check coverage home | |||||
| if (home == null || !home.isDirectory()) { | |||||
| throw new BuildException("Invalid home directory. Must point to JProbe home directory"); | |||||
| } | |||||
| home = new File(home, "Coverage"); | |||||
| File jar = new File(home, "coverage.jar"); | |||||
| if (!jar.exists()) { | |||||
| throw new BuildException("Cannot find Coverage directory: " + home); | |||||
| } | |||||
| } | |||||
| /** get the snapshots from the filesets */ | |||||
| protected File[] getSnapshots() { | |||||
| Vector v = new Vector(); | |||||
| final int size = filesets.size(); | |||||
| for (int i = 0; i < size; i++) { | |||||
| FileSet fs = (FileSet) filesets.elementAt(i); | |||||
| DirectoryScanner ds = fs.getDirectoryScanner(getProject()); | |||||
| ds.scan(); | |||||
| String[] f = ds.getIncludedFiles(); | |||||
| for (int j = 0; j < f.length; j++) { | |||||
| String pathname = f[j]; | |||||
| File file = new File(ds.getBasedir(), pathname); | |||||
| file = project.resolveFile(file.getPath()); | |||||
| v.addElement(file); | |||||
| } | |||||
| } | |||||
| File[] files = new File[v.size()]; | |||||
| v.copyInto(files); | |||||
| return files; | |||||
| } | |||||
| /** | |||||
| * create the parameters file that contains all file to merge | |||||
| * and the output filename. | |||||
| */ | |||||
| protected File createParamFile() throws BuildException { | |||||
| File[] snapshots = getSnapshots(); | |||||
| File file = createTmpFile(); | |||||
| FileWriter fw = null; | |||||
| try { | |||||
| fw = new FileWriter(file); | |||||
| PrintWriter pw = new PrintWriter(fw); | |||||
| for (int i = 0; i < snapshots.length; i++) { | |||||
| pw.println(snapshots[i].getAbsolutePath()); | |||||
| } | |||||
| // last file is the output snapshot | |||||
| pw.println(project.resolveFile(tofile.getPath())); | |||||
| pw.flush(); | |||||
| return file; | |||||
| } catch (IOException e) { | |||||
| if (fw != null) { | |||||
| try { | |||||
| fw.close(); | |||||
| } catch (IOException ignored) { | |||||
| } | |||||
| } | |||||
| throw new BuildException("I/O error while writing to " + file, e); | |||||
| } | |||||
| } | |||||
| /** create a temporary file in the current dir (For JDK1.1 support) */ | |||||
| protected File createTmpFile() { | |||||
| final long rand = (new Random(System.currentTimeMillis())).nextLong(); | |||||
| File file = new File("jpcovmerge" + rand + ".tmp"); | |||||
| return file; | |||||
| } | |||||
| } | } | ||||
| @@ -54,35 +54,28 @@ | |||||
| package org.apache.tools.ant.taskdefs.optional.sitraka; | package org.apache.tools.ant.taskdefs.optional.sitraka; | ||||
| import java.io.File; | |||||
| import java.io.IOException; | |||||
| import java.util.Vector; | |||||
| import javax.xml.transform.OutputKeys; | |||||
| import javax.xml.transform.Result; | |||||
| import javax.xml.transform.Source; | |||||
| import javax.xml.transform.Transformer; | |||||
| import javax.xml.transform.TransformerFactory; | |||||
| import javax.xml.transform.dom.DOMSource; | |||||
| import javax.xml.transform.stream.StreamResult; | |||||
| import org.apache.tools.ant.BuildException; | import org.apache.tools.ant.BuildException; | ||||
| import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
| import org.apache.tools.ant.Task; | import org.apache.tools.ant.Task; | ||||
| import org.apache.tools.ant.taskdefs.LogStreamHandler; | |||||
| import org.apache.tools.ant.taskdefs.Execute; | import org.apache.tools.ant.taskdefs.Execute; | ||||
| import org.apache.tools.ant.taskdefs.LogStreamHandler; | |||||
| import org.apache.tools.ant.types.Commandline; | import org.apache.tools.ant.types.Commandline; | ||||
| import org.apache.tools.ant.types.Path; | |||||
| import org.apache.tools.ant.types.EnumeratedAttribute; | import org.apache.tools.ant.types.EnumeratedAttribute; | ||||
| import java.util.Vector; | |||||
| import java.io.File; | |||||
| import java.io.IOException; | |||||
| import javax.xml.transform.TransformerFactory; | |||||
| import javax.xml.transform.Transformer; | |||||
| import javax.xml.transform.OutputKeys; | |||||
| import javax.xml.transform.Source; | |||||
| import javax.xml.transform.Result; | |||||
| import javax.xml.transform.stream.StreamResult; | |||||
| import javax.xml.transform.dom.DOMSource; | |||||
| import org.apache.tools.ant.types.Path; | |||||
| import org.w3c.dom.Document; | import org.w3c.dom.Document; | ||||
| /** | /** | ||||
| * Convenient task to run the snapshot merge utility for JProbe Coverage 3.0. | * Convenient task to run the snapshot merge utility for JProbe Coverage 3.0. | ||||
| * | * | ||||
| @@ -138,7 +131,7 @@ public class CovReport extends Task { | |||||
| /* | /* | ||||
| /** coverage home, mandatory */ | /** coverage home, mandatory */ | ||||
| private File home = null; | |||||
| private File home = null; | |||||
| /** format of generated report, optional */ | /** format of generated report, optional */ | ||||
| private String format = null; | private String format = null; | ||||
| @@ -179,48 +172,50 @@ public class CovReport extends Task { | |||||
| } | } | ||||
| public static class ReportFormat extends EnumeratedAttribute { | public static class ReportFormat extends EnumeratedAttribute { | ||||
| public String[] getValues(){ | |||||
| public String[] getValues() { | |||||
| return new String[]{"html", "text", "xml"}; | return new String[]{"html", "text", "xml"}; | ||||
| } | } | ||||
| } | } | ||||
| /** set the format of the report html|text|xml*/ | /** set the format of the report html|text|xml*/ | ||||
| public void setFormat(ReportFormat value){ | |||||
| public void setFormat(ReportFormat value) { | |||||
| this.format = value.getValue(); | this.format = value.getValue(); | ||||
| } | } | ||||
| public static class ReportType extends EnumeratedAttribute { | public static class ReportType extends EnumeratedAttribute { | ||||
| public String[] getValues(){ | |||||
| public String[] getValues() { | |||||
| return new String[]{"executive", "summary", "detailed", "verydetailed"}; | return new String[]{"executive", "summary", "detailed", "verydetailed"}; | ||||
| } | } | ||||
| } | } | ||||
| /** sets the report type executive|summary|detailed|verydetailed */ | /** sets the report type executive|summary|detailed|verydetailed */ | ||||
| public void setType(ReportType value){ | |||||
| this.type = value.getValue(); | |||||
| public void setType(ReportType value) { | |||||
| this.type = value.getValue(); | |||||
| } | } | ||||
| /** include source code lines. XML report only */ | /** include source code lines. XML report only */ | ||||
| public void setIncludesource(boolean value){ | |||||
| public void setIncludesource(boolean value) { | |||||
| this.includeSource = value; | this.includeSource = value; | ||||
| } | } | ||||
| /** sets the threshold printing method 0-100*/ | /** sets the threshold printing method 0-100*/ | ||||
| public void setPercent(Integer value){ | |||||
| public void setPercent(Integer value) { | |||||
| this.percent = value; | this.percent = value; | ||||
| } | } | ||||
| /** set the filters */ | /** set the filters */ | ||||
| public void setFilters(String values){ | |||||
| public void setFilters(String values) { | |||||
| this.filters = values; | this.filters = values; | ||||
| } | } | ||||
| public Path createSourcepath(){ | |||||
| public Path createSourcepath() { | |||||
| if (sourcePath == null) { | if (sourcePath == null) { | ||||
| sourcePath = new Path(project); | sourcePath = new Path(project); | ||||
| } | } | ||||
| return sourcePath.createPath(); | return sourcePath.createPath(); | ||||
| } | } | ||||
| public void setSnapshot(File value){ | |||||
| public void setSnapshot(File value) { | |||||
| this.snapshot = value; | this.snapshot = value; | ||||
| } | } | ||||
| @@ -232,15 +227,15 @@ public class CovReport extends Task { | |||||
| } | } | ||||
| //@todo to remove | //@todo to remove | ||||
| public Path createCoveragepath(){ | |||||
| public Path createCoveragepath() { | |||||
| if (coveragePath == null) { | if (coveragePath == null) { | ||||
| coveragePath = new Path(project); | coveragePath = new Path(project); | ||||
| } | } | ||||
| return coveragePath.createPath(); | return coveragePath.createPath(); | ||||
| } | } | ||||
| public Reference createReference(){ | |||||
| if (reference == null){ | |||||
| public Reference createReference() { | |||||
| if (reference == null) { | |||||
| reference = new Reference(); | reference = new Reference(); | ||||
| } | } | ||||
| return reference; | return reference; | ||||
| @@ -261,12 +256,12 @@ public class CovReport extends Task { | |||||
| if (home == null) { | if (home == null) { | ||||
| throw new BuildException("'home' attribute must be set to JProbe home directory"); | throw new BuildException("'home' attribute must be set to JProbe home directory"); | ||||
| } | } | ||||
| home = new File(home,"Coverage"); | |||||
| home = new File(home, "Coverage"); | |||||
| File jar = new File(home, "coverage.jar"); | File jar = new File(home, "coverage.jar"); | ||||
| if (!jar.exists()) { | if (!jar.exists()) { | ||||
| throw new BuildException("Cannot find Coverage directory: " + home); | throw new BuildException("Cannot find Coverage directory: " + home); | ||||
| } | } | ||||
| if (reference != null && !"xml".equals(format)){ | |||||
| if (reference != null && !"xml".equals(format)) { | |||||
| log("Ignored reference. It cannot be used in non XML report."); | log("Ignored reference. It cannot be used in non XML report."); | ||||
| reference = null; // nullify it so that there is no ambiguity | reference = null; // nullify it so that there is no ambiguity | ||||
| } | } | ||||
| @@ -278,15 +273,15 @@ public class CovReport extends Task { | |||||
| try { | try { | ||||
| Commandline cmdl = new Commandline(); | Commandline cmdl = new Commandline(); | ||||
| // we need to run Coverage from his directory due to dll/jar issues | // we need to run Coverage from his directory due to dll/jar issues | ||||
| cmdl.setExecutable( new File(home, "jpcovreport").getAbsolutePath() ); | |||||
| cmdl.setExecutable(new File(home, "jpcovreport").getAbsolutePath()); | |||||
| String[] params = getParameters(); | String[] params = getParameters(); | ||||
| for (int i = 0; i < params.length; i++) { | for (int i = 0; i < params.length; i++) { | ||||
| cmdl.createArgument().setValue(params[i]); | cmdl.createArgument().setValue(params[i]); | ||||
| } | } | ||||
| // use the custom handler for stdin issues | // use the custom handler for stdin issues | ||||
| LogStreamHandler handler = new LogStreamHandler(this,Project.MSG_INFO,Project.MSG_WARN); | |||||
| Execute exec = new Execute( handler ); | |||||
| LogStreamHandler handler = new LogStreamHandler(this, Project.MSG_INFO, Project.MSG_WARN); | |||||
| Execute exec = new Execute(handler); | |||||
| log(cmdl.toString(), Project.MSG_VERBOSE); | log(cmdl.toString(), Project.MSG_VERBOSE); | ||||
| exec.setCommandline(cmdl.getCommandline()); | exec.setCommandline(cmdl.getCommandline()); | ||||
| int exitValue = exec.execute(); | int exitValue = exec.execute(); | ||||
| @@ -295,17 +290,17 @@ public class CovReport extends Task { | |||||
| } | } | ||||
| log("coveragePath: " + coveragePath, Project.MSG_VERBOSE); | log("coveragePath: " + coveragePath, Project.MSG_VERBOSE); | ||||
| log("format: " + format, Project.MSG_VERBOSE); | log("format: " + format, Project.MSG_VERBOSE); | ||||
| if (reference != null && "xml".equals(format)){ | |||||
| if (reference != null && "xml".equals(format)) { | |||||
| reference.createEnhancedXMLReport(); | reference.createEnhancedXMLReport(); | ||||
| } | } | ||||
| } catch (IOException e){ | |||||
| } catch (IOException e) { | |||||
| throw new BuildException("Failed to execute JProbe Coverage Report.", e); | throw new BuildException("Failed to execute JProbe Coverage Report.", e); | ||||
| } | } | ||||
| } | } | ||||
| protected String[] getParameters(){ | |||||
| protected String[] getParameters() { | |||||
| Vector v = new Vector(); | Vector v = new Vector(); | ||||
| if (format != null) { | if (format != null) { | ||||
| v.addElement("-format=" + format); | v.addElement("-format=" + format); | ||||
| @@ -341,49 +336,52 @@ public class CovReport extends Task { | |||||
| public class Reference { | public class Reference { | ||||
| protected Path classPath; | protected Path classPath; | ||||
| protected ReportFilters filters; | protected ReportFilters filters; | ||||
| public Path createClasspath(){ | |||||
| public Path createClasspath() { | |||||
| if (classPath == null) { | if (classPath == null) { | ||||
| classPath = new Path(CovReport.this.project); | classPath = new Path(CovReport.this.project); | ||||
| } | } | ||||
| return classPath.createPath(); | return classPath.createPath(); | ||||
| } | } | ||||
| public ReportFilters createFilters(){ | |||||
| if (filters == null){ | |||||
| public ReportFilters createFilters() { | |||||
| if (filters == null) { | |||||
| filters = new ReportFilters(); | filters = new ReportFilters(); | ||||
| } | } | ||||
| return filters; | return filters; | ||||
| } | } | ||||
| 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) { | |||||
| throw new BuildException("Need a 'classpath' element."); | throw new BuildException("Need a 'classpath' element."); | ||||
| } | } | ||||
| // 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) { | |||||
| createFilters(); | createFilters(); | ||||
| log("Adding default include filter to *.*()", Project.MSG_VERBOSE); | log("Adding default include filter to *.*()", Project.MSG_VERBOSE); | ||||
| ReportFilters.Include include = new ReportFilters.Include(); | ReportFilters.Include include = new ReportFilters.Include(); | ||||
| filters.addInclude( include ); | |||||
| filters.addInclude(include); | |||||
| } | } | ||||
| try { | try { | ||||
| log("Creating enhanced XML report", Project.MSG_VERBOSE); | log("Creating enhanced XML report", Project.MSG_VERBOSE); | ||||
| XMLReport report = new XMLReport(CovReport.this, tofile); | XMLReport report = new XMLReport(CovReport.this, tofile); | ||||
| report.setReportFilters(filters); | report.setReportFilters(filters); | ||||
| report.setJProbehome( new File(home.getParent()) ); | |||||
| report.setJProbehome(new File(home.getParent())); | |||||
| Document doc = report.createDocument(paths); | Document doc = report.createDocument(paths); | ||||
| TransformerFactory tfactory = TransformerFactory.newInstance(); | TransformerFactory tfactory = TransformerFactory.newInstance(); | ||||
| Transformer transformer = tfactory.newTransformer(); | Transformer transformer = tfactory.newTransformer(); | ||||
| transformer.setOutputProperty(OutputKeys.INDENT, "yes"); | transformer.setOutputProperty(OutputKeys.INDENT, "yes"); | ||||
| transformer.setOutputProperty(OutputKeys.METHOD, "xml"); | transformer.setOutputProperty(OutputKeys.METHOD, "xml"); | ||||
| Source src = new DOMSource(doc); | Source src = new DOMSource(doc); | ||||
| Result res = new StreamResult( "file:///" + tofile.toString() ); | |||||
| Result res = new StreamResult("file:///" + tofile.toString()); | |||||
| transformer.transform(src, res); | transformer.transform(src, res); | ||||
| } catch (Exception e){ | |||||
| } catch (Exception e) { | |||||
| throw new BuildException("Error while performing enhanced XML report from file " + tofile, e); | throw new BuildException("Error while performing enhanced XML report from file " + tofile, e); | ||||
| } | } | ||||
| } | } | ||||
| @@ -54,25 +54,25 @@ | |||||
| package org.apache.tools.ant.taskdefs.optional.sitraka; | package org.apache.tools.ant.taskdefs.optional.sitraka; | ||||
| import java.io.PrintWriter; | |||||
| import java.io.StringWriter; | |||||
| import java.io.FileWriter; | |||||
| import java.io.File; | import java.io.File; | ||||
| import java.io.OutputStream; | |||||
| import java.io.FileWriter; | |||||
| import java.io.IOException; | import java.io.IOException; | ||||
| import java.util.Vector; | |||||
| import java.io.OutputStream; | |||||
| import java.io.PrintWriter; | |||||
| import java.io.StringWriter; | |||||
| import java.util.Random; | import java.util.Random; | ||||
| import java.util.Vector; | |||||
| import org.apache.tools.ant.BuildException; | |||||
| import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
| import org.apache.tools.ant.Task; | import org.apache.tools.ant.Task; | ||||
| import org.apache.tools.ant.BuildException; | |||||
| import org.apache.tools.ant.types.CommandlineJava; | |||||
| import org.apache.tools.ant.taskdefs.Execute; | |||||
| import org.apache.tools.ant.taskdefs.LogStreamHandler; | |||||
| import org.apache.tools.ant.types.Commandline; | import org.apache.tools.ant.types.Commandline; | ||||
| import org.apache.tools.ant.types.CommandlineJava; | |||||
| import org.apache.tools.ant.types.EnumeratedAttribute; | import org.apache.tools.ant.types.EnumeratedAttribute; | ||||
| import org.apache.tools.ant.types.Path; | |||||
| import org.apache.tools.ant.types.FileSet; | import org.apache.tools.ant.types.FileSet; | ||||
| import org.apache.tools.ant.taskdefs.Execute; | |||||
| import org.apache.tools.ant.taskdefs.LogStreamHandler; | |||||
| import org.apache.tools.ant.types.Path; | |||||
| /** | /** | ||||
| * Convenient task to run Sitraka JProbe Coverage from Ant. | * Convenient task to run Sitraka JProbe Coverage from Ant. | ||||
| @@ -86,376 +86,380 @@ import org.apache.tools.ant.taskdefs.LogStreamHandler; | |||||
| */ | */ | ||||
| public class Coverage extends Task { | public class Coverage extends Task { | ||||
| protected File home; | |||||
| protected File home; | |||||
| protected Commandline cmdl = new Commandline(); | |||||
| protected CommandlineJava cmdlJava = new CommandlineJava(); | |||||
| protected String function = "coverage"; | |||||
| protected String seedName; | |||||
| protected File inputFile; | |||||
| protected Commandline cmdl = new Commandline(); | |||||
| protected File javaExe; | |||||
| protected CommandlineJava cmdlJava = new CommandlineJava(); | |||||
| protected String vm; | |||||
| protected String function = "coverage"; | |||||
| protected boolean applet = false; | |||||
| protected String seedName; | |||||
| /** this is a somewhat annoying thing, set it to never */ | |||||
| protected String exitPrompt = "never"; | |||||
| protected File inputFile; | |||||
| protected Filters filters = new Filters(); | |||||
| protected File javaExe; | |||||
| protected Triggers triggers; | |||||
| protected String vm; | |||||
| protected String finalSnapshot = "coverage"; | |||||
| protected boolean applet = false; | |||||
| protected String recordFromStart = "coverage"; | |||||
| /** this is a somewhat annoying thing, set it to never */ | |||||
| protected String exitPrompt = "never"; | |||||
| protected File snapshotDir; | |||||
| protected Filters filters = new Filters(); | |||||
| protected File workingDir; | |||||
| protected Triggers triggers; | |||||
| protected boolean trackNatives = false; | |||||
| protected String finalSnapshot = "coverage"; | |||||
| protected Socket socket; | |||||
| protected String recordFromStart = "coverage"; | |||||
| protected int warnLevel = 0; | |||||
| protected File snapshotDir; | |||||
| protected Vector filesets = new Vector(); | |||||
| protected File workingDir; | |||||
| //--------- setters used via reflection -- | |||||
| protected boolean trackNatives = false; | |||||
| /** set the coverage home directory where are libraries, jars and jplauncher */ | |||||
| public void setHome(File value) { | |||||
| home = value; | |||||
| } | |||||
| /** seed name for snapshot file. can be null, default to snap */ | |||||
| public void setSeedname(String value) { | |||||
| seedName = value; | |||||
| } | |||||
| public void setInputfile(File value) { | |||||
| inputFile = value; | |||||
| } | |||||
| protected Socket socket; | |||||
| public void setJavaexe(File value) { | |||||
| javaExe = value; | |||||
| } | |||||
| protected int warnLevel = 0; | |||||
| public static class Javavm extends EnumeratedAttribute { | |||||
| public String[] getValues() { | |||||
| return new String[]{"java2", "jdk118", "jdk117"}; | |||||
| } | |||||
| } | |||||
| protected Vector filesets = new Vector(); | |||||
| /** jdk117, jdk118 or java2, can be null, default to java2 */ | |||||
| public void setVm(Javavm value) { | |||||
| vm = value.getValue(); | |||||
| } | |||||
| //--------- setters used via reflection -- | |||||
| /** default to false unless file is htm or html */ | |||||
| public void setApplet(boolean value) { | |||||
| applet = value; | |||||
| } | |||||
| /** set the coverage home directory where are libraries, jars and jplauncher */ | |||||
| public void setHome(File value){ | |||||
| home = value; | |||||
| } | |||||
| /** always, error, never */ | |||||
| public void setExitprompt(String value) { | |||||
| exitPrompt = value; | |||||
| } | |||||
| /** seed name for snapshot file. can be null, default to snap */ | |||||
| public void setSeedname(String value){ | |||||
| seedName = value; | |||||
| } | |||||
| public Filters createFilters() { | |||||
| return filters; | |||||
| } | |||||
| public void setInputfile(File value){ | |||||
| inputFile = value; | |||||
| } | |||||
| public Triggers createTriggers() { | |||||
| if (triggers == null) { | |||||
| triggers = new Triggers(); | |||||
| } | |||||
| return triggers; | |||||
| } | |||||
| public void setJavaexe(File value){ | |||||
| javaExe = value; | |||||
| } | |||||
| public Socket createSocket() { | |||||
| if (socket == null) { | |||||
| socket = new Socket(); | |||||
| } | |||||
| return socket; | |||||
| } | |||||
| public static class Javavm extends EnumeratedAttribute { | |||||
| public String[] getValues(){ | |||||
| return new String[]{"java2", "jdk118", "jdk117"}; | |||||
| } | |||||
| } | |||||
| /** jdk117, jdk118 or java2, can be null, default to java2 */ | |||||
| public void setVm(Javavm value) { | |||||
| vm = value.getValue(); | |||||
| } | |||||
| public static class Finalsnapshot extends EnumeratedAttribute { | |||||
| public String[] getValues() { | |||||
| return new String[]{"coverage", "none", "all"}; | |||||
| } | |||||
| } | |||||
| /** default to false unless file is htm or html */ | |||||
| public void setApplet(boolean value){ | |||||
| applet = value; | |||||
| } | |||||
| /** none, coverage, all. can be null, default to none */ | |||||
| public void setFinalsnapshot(String value) { | |||||
| finalSnapshot = value; | |||||
| } | |||||
| /** always, error, never */ | |||||
| public void setExitprompt(String value){ | |||||
| exitPrompt = value; | |||||
| } | |||||
| public static class Recordfromstart extends EnumeratedAttribute { | |||||
| public String[] getValues() { | |||||
| return new String[]{"coverage", "none", "all"}; | |||||
| } | |||||
| } | |||||
| public Filters createFilters(){ | |||||
| return filters; | |||||
| } | |||||
| /** all, coverage, none */ | |||||
| public void setRecordfromstart(Recordfromstart value) { | |||||
| recordFromStart = value.getValue(); | |||||
| } | |||||
| public Triggers createTriggers(){ | |||||
| if (triggers == null) { | |||||
| triggers = new Triggers(); | |||||
| } | |||||
| return triggers; | |||||
| } | |||||
| public void setWarnlevel(Integer value) { | |||||
| warnLevel = value.intValue(); | |||||
| } | |||||
| public Socket createSocket(){ | |||||
| if (socket == null ) { | |||||
| socket = new Socket(); | |||||
| } | |||||
| return socket; | |||||
| } | |||||
| public void setSnapshotdir(File value) { | |||||
| snapshotDir = value; | |||||
| } | |||||
| public static class Finalsnapshot extends EnumeratedAttribute { | |||||
| public String[] getValues(){ | |||||
| return new String[]{"coverage", "none", "all"}; | |||||
| } | |||||
| } | |||||
| public void setWorkingdir(File value) { | |||||
| workingDir = value; | |||||
| } | |||||
| /** none, coverage, all. can be null, default to none */ | |||||
| public void setFinalsnapshot(String value){ | |||||
| finalSnapshot = value; | |||||
| } | |||||
| public void setTracknatives(boolean value) { | |||||
| trackNatives = value; | |||||
| } | |||||
| public static class Recordfromstart extends EnumeratedAttribute { | |||||
| public String[] getValues(){ | |||||
| return new String[]{"coverage", "none", "all"}; | |||||
| } | |||||
| } | |||||
| /** all, coverage, none */ | |||||
| public void setRecordfromstart(Recordfromstart value) { | |||||
| recordFromStart = value.getValue(); | |||||
| } | |||||
| // | |||||
| public void setWarnlevel(Integer value){ | |||||
| warnLevel = value.intValue(); | |||||
| } | |||||
| public void setSnapshotdir(File value){ | |||||
| snapshotDir = value; | |||||
| } | |||||
| public void setWorkingdir(File value){ | |||||
| workingDir = value; | |||||
| } | |||||
| public void setTracknatives(boolean value){ | |||||
| trackNatives = value; | |||||
| } | |||||
| // | |||||
| /** the jvm arguments */ | |||||
| /** the jvm arguments */ | |||||
| public Commandline.Argument createJvmarg() { | public Commandline.Argument createJvmarg() { | ||||
| return cmdlJava.createVmArgument(); | return cmdlJava.createVmArgument(); | ||||
| } | } | ||||
| /** the command arguments */ | |||||
| /** the command arguments */ | |||||
| public Commandline.Argument createArg() { | public Commandline.Argument createArg() { | ||||
| return cmdlJava.createArgument(); | return cmdlJava.createArgument(); | ||||
| } | } | ||||
| /** classpath to run the files */ | |||||
| /** classpath to run the files */ | |||||
| public Path createClasspath() { | public Path createClasspath() { | ||||
| return cmdlJava.createClasspath(project).createPath(); | return cmdlJava.createClasspath(project).createPath(); | ||||
| } | } | ||||
| /** classname to run as standalone or runner for filesets */ | |||||
| public void setClassname(String value){ | |||||
| cmdlJava.setClassname(value); | |||||
| } | |||||
| /** the classnames to execute */ | |||||
| public void addFileset(FileSet fs){ | |||||
| filesets.addElement(fs); | |||||
| } | |||||
| //---------------- the tedious job begins here | |||||
| public Coverage(){ | |||||
| } | |||||
| /** execute the jplauncher by providing a parameter file */ | |||||
| public void execute() throws BuildException { | |||||
| File paramfile = null; | |||||
| // if an input file is used, all other options are ignored... | |||||
| if (inputFile == null){ | |||||
| checkOptions(); | |||||
| paramfile = createParamFile(); | |||||
| } else { | |||||
| paramfile = inputFile; | |||||
| } | |||||
| try { | |||||
| // we need to run Coverage from his directory due to dll/jar issues | |||||
| cmdl.setExecutable( new File(home, "jplauncher").getAbsolutePath() ); | |||||
| cmdl.createArgument().setValue("-jp_input=" + paramfile.getAbsolutePath()); | |||||
| // use the custom handler for stdin issues | |||||
| LogStreamHandler handler = new CoverageStreamHandler(this); | |||||
| Execute exec = new Execute( handler ); | |||||
| log(cmdl.toString(), Project.MSG_VERBOSE); | |||||
| exec.setCommandline(cmdl.getCommandline()); | |||||
| int exitValue = exec.execute(); | |||||
| if (exitValue != 0) { | |||||
| throw new BuildException("JProbe Coverage failed (" + exitValue + ")"); | |||||
| } | |||||
| } catch (IOException e){ | |||||
| throw new BuildException("Failed to execute JProbe Coverage.", e); | |||||
| } finally { | |||||
| //@todo should be removed once switched to JDK1.2 | |||||
| if (inputFile == null && paramfile != null){ | |||||
| paramfile.delete(); | |||||
| } | |||||
| } | |||||
| } | |||||
| /** wheck what is necessary to check, Coverage will do the job for us */ | |||||
| protected void checkOptions() throws BuildException { | |||||
| // check coverage home | |||||
| if (home == null || !home.isDirectory() ) { | |||||
| throw new BuildException("Invalid home directory. Must point to JProbe home directory"); | |||||
| } | |||||
| home = new File(home,"Coverage"); | |||||
| File jar = new File(home, "coverage.jar"); | |||||
| if (!jar.exists()) { | |||||
| throw new BuildException("Cannot find Coverage directory: " + home); | |||||
| } | |||||
| // make sure snapshot dir exists and is resolved | |||||
| if (snapshotDir == null) { | |||||
| snapshotDir = new File("."); | |||||
| } | |||||
| snapshotDir = project.resolveFile(snapshotDir.getPath()); | |||||
| if (!snapshotDir.isDirectory() || !snapshotDir.exists()) { | |||||
| throw new BuildException("Snapshot directory does not exists :" + snapshotDir); | |||||
| } | |||||
| if (workingDir == null) { | |||||
| workingDir = new File("."); | |||||
| } | |||||
| workingDir = project.resolveFile(workingDir.getPath()); | |||||
| // check for info, do your best to select the java executable. | |||||
| // JProbe 3.0 fails if there is no javaexe option. So | |||||
| if (javaExe == null && ( vm == null || "java2".equals(vm) ) ) { | |||||
| String version = System.getProperty("java.version"); | |||||
| // make we are using 1.2+, if it is, then do your best to | |||||
| // get a javaexe | |||||
| if ( !version.startsWith("1.1") ){ | |||||
| if (vm == null){ | |||||
| vm = "java2"; | |||||
| } | |||||
| // if we are here obviously it is java2 | |||||
| String home = System.getProperty("java.home"); | |||||
| boolean isUnix = File.separatorChar == '/'; | |||||
| javaExe = isUnix ? new File(home, "bin/java") : new File(home,"/bin/java.exe"); | |||||
| } | |||||
| } | |||||
| } | |||||
| /** | |||||
| * 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>) | |||||
| * if they are too numerous. | |||||
| */ | |||||
| protected String[] getParameters(){ | |||||
| Vector params = new Vector(); | |||||
| params.addElement("-jp_function=" + function); | |||||
| if (vm != null) { | |||||
| params.addElement("-jp_vm=" + vm); | |||||
| } | |||||
| if (javaExe != null) { | |||||
| params.addElement("-jp_java_exe=" + project.resolveFile(javaExe.getPath())); | |||||
| } | |||||
| params.addElement("-jp_working_dir=" + workingDir.getPath() ); | |||||
| params.addElement("-jp_snapshot_dir=" + snapshotDir.getPath() ); | |||||
| params.addElement("-jp_record_from_start=" + recordFromStart); | |||||
| params.addElement("-jp_warn=" + warnLevel); | |||||
| if (seedName != null) { | |||||
| params.addElement("-jp_output_file=" + seedName); | |||||
| } | |||||
| params.addElement("-jp_filter=" + filters.toString() ); | |||||
| if (triggers != null) { | |||||
| params.addElement("-jp_trigger=" + triggers.toString() ); | |||||
| } | |||||
| if (finalSnapshot != null) { | |||||
| params.addElement("-jp_final_snapshot=" + finalSnapshot); | |||||
| } | |||||
| /** classname to run as standalone or runner for filesets */ | |||||
| public void setClassname(String value) { | |||||
| cmdlJava.setClassname(value); | |||||
| } | |||||
| /** the classnames to execute */ | |||||
| public void addFileset(FileSet fs) { | |||||
| filesets.addElement(fs); | |||||
| } | |||||
| //---------------- the tedious job begins here | |||||
| public Coverage() { | |||||
| } | |||||
| /** execute the jplauncher by providing a parameter file */ | |||||
| public void execute() throws BuildException { | |||||
| File paramfile = null; | |||||
| // if an input file is used, all other options are ignored... | |||||
| if (inputFile == null) { | |||||
| checkOptions(); | |||||
| paramfile = createParamFile(); | |||||
| } else { | |||||
| paramfile = inputFile; | |||||
| } | |||||
| try { | |||||
| // we need to run Coverage from his directory due to dll/jar issues | |||||
| cmdl.setExecutable(new File(home, "jplauncher").getAbsolutePath()); | |||||
| cmdl.createArgument().setValue("-jp_input=" + paramfile.getAbsolutePath()); | |||||
| // use the custom handler for stdin issues | |||||
| LogStreamHandler handler = new CoverageStreamHandler(this); | |||||
| Execute exec = new Execute(handler); | |||||
| log(cmdl.toString(), Project.MSG_VERBOSE); | |||||
| exec.setCommandline(cmdl.getCommandline()); | |||||
| int exitValue = exec.execute(); | |||||
| if (exitValue != 0) { | |||||
| throw new BuildException("JProbe Coverage failed (" + exitValue + ")"); | |||||
| } | |||||
| } catch (IOException e) { | |||||
| throw new BuildException("Failed to execute JProbe Coverage.", e); | |||||
| } finally { | |||||
| //@todo should be removed once switched to JDK1.2 | |||||
| if (inputFile == null && paramfile != null) { | |||||
| paramfile.delete(); | |||||
| } | |||||
| } | |||||
| } | |||||
| /** wheck what is necessary to check, Coverage will do the job for us */ | |||||
| protected void checkOptions() throws BuildException { | |||||
| // check coverage home | |||||
| if (home == null || !home.isDirectory()) { | |||||
| throw new BuildException("Invalid home directory. Must point to JProbe home directory"); | |||||
| } | |||||
| home = new File(home, "Coverage"); | |||||
| File jar = new File(home, "coverage.jar"); | |||||
| if (!jar.exists()) { | |||||
| throw new BuildException("Cannot find Coverage directory: " + home); | |||||
| } | |||||
| // make sure snapshot dir exists and is resolved | |||||
| if (snapshotDir == null) { | |||||
| snapshotDir = new File("."); | |||||
| } | |||||
| snapshotDir = project.resolveFile(snapshotDir.getPath()); | |||||
| if (!snapshotDir.isDirectory() || !snapshotDir.exists()) { | |||||
| throw new BuildException("Snapshot directory does not exists :" + snapshotDir); | |||||
| } | |||||
| if (workingDir == null) { | |||||
| workingDir = new File("."); | |||||
| } | |||||
| workingDir = project.resolveFile(workingDir.getPath()); | |||||
| // check for info, do your best to select the java executable. | |||||
| // JProbe 3.0 fails if there is no javaexe option. So | |||||
| if (javaExe == null && (vm == null || "java2".equals(vm))) { | |||||
| String version = System.getProperty("java.version"); | |||||
| // make we are using 1.2+, if it is, then do your best to | |||||
| // get a javaexe | |||||
| if (!version.startsWith("1.1")) { | |||||
| if (vm == null) { | |||||
| vm = "java2"; | |||||
| } | |||||
| // if we are here obviously it is java2 | |||||
| String home = System.getProperty("java.home"); | |||||
| boolean isUnix = File.separatorChar == '/'; | |||||
| javaExe = isUnix ? new File(home, "bin/java") : new File(home, "/bin/java.exe"); | |||||
| } | |||||
| } | |||||
| } | |||||
| /** | |||||
| * 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>) | |||||
| * if they are too numerous. | |||||
| */ | |||||
| protected String[] getParameters() { | |||||
| Vector params = new Vector(); | |||||
| params.addElement("-jp_function=" + function); | |||||
| if (vm != null) { | |||||
| params.addElement("-jp_vm=" + vm); | |||||
| } | |||||
| if (javaExe != null) { | |||||
| params.addElement("-jp_java_exe=" + project.resolveFile(javaExe.getPath())); | |||||
| } | |||||
| params.addElement("-jp_working_dir=" + workingDir.getPath()); | |||||
| params.addElement("-jp_snapshot_dir=" + snapshotDir.getPath()); | |||||
| params.addElement("-jp_record_from_start=" + recordFromStart); | |||||
| params.addElement("-jp_warn=" + warnLevel); | |||||
| if (seedName != null) { | |||||
| params.addElement("-jp_output_file=" + seedName); | |||||
| } | |||||
| params.addElement("-jp_filter=" + filters.toString()); | |||||
| if (triggers != null) { | |||||
| params.addElement("-jp_trigger=" + triggers.toString()); | |||||
| } | |||||
| if (finalSnapshot != null) { | |||||
| params.addElement("-jp_final_snapshot=" + finalSnapshot); | |||||
| } | |||||
| params.addElement("-jp_exit_prompt=" + exitPrompt); | params.addElement("-jp_exit_prompt=" + exitPrompt); | ||||
| //params.addElement("-jp_append=" + append); | |||||
| params.addElement("-jp_track_natives=" + trackNatives); | |||||
| //.... now the jvm | |||||
| // arguments | |||||
| String[] vmargs = cmdlJava.getVmCommand().getArguments(); | |||||
| for (int i = 0; i < vmargs.length; i++) { | |||||
| params.addElement(vmargs[i]); | |||||
| } | |||||
| // classpath | |||||
| Path classpath = cmdlJava.getClasspath(); | |||||
| if (classpath != null && classpath.size() > 0) { | |||||
| params.addElement("-classpath " + classpath.toString()); | |||||
| } | |||||
| // classname (runner or standalone) | |||||
| if (cmdlJava.getClassname() != null) { | |||||
| params.addElement(cmdlJava.getClassname()); | |||||
| } | |||||
| // arguments for classname | |||||
| String[] args = cmdlJava.getJavaCommand().getArguments(); | |||||
| for (int i = 0; i < args.length; i++) { | |||||
| params.addElement(args[i]); | |||||
| } | |||||
| String[] array = new String[params.size()]; | |||||
| params.copyInto(array); | |||||
| return array; | |||||
| } | |||||
| /** | |||||
| * create the parameter file from the given options. The file is | |||||
| * created with a random name in the current directory. | |||||
| * @return the file object where are written the configuration to run | |||||
| * JProbe Coverage | |||||
| * @throws BuildException thrown if something bad happens while writing | |||||
| * the arguments to the file. | |||||
| */ | |||||
| protected File createParamFile() throws BuildException { | |||||
| //@todo change this when switching to JDK 1.2 and use File.createTmpFile() | |||||
| File file = createTmpFile(); | |||||
| log("Creating parameter file: " + file, Project.MSG_VERBOSE); | |||||
| // options need to be one per line in the parameter file | |||||
| // so write them all in a single string | |||||
| StringWriter sw = new StringWriter(); | |||||
| PrintWriter pw = new PrintWriter(sw); | |||||
| String[] params = getParameters(); | |||||
| for (int i = 0; i < params.length; i++){ | |||||
| pw.println(params[i]); | |||||
| } | |||||
| pw.flush(); | |||||
| log("JProbe Coverage parameters:\n" + sw.toString(), Project.MSG_VERBOSE); | |||||
| // now write them to the file | |||||
| FileWriter fw = null; | |||||
| try { | |||||
| fw = new FileWriter(file); | |||||
| fw.write(sw.toString()); | |||||
| fw.flush(); | |||||
| } catch (IOException e){ | |||||
| throw new BuildException("Could not write parameter file " + file, e); | |||||
| } finally { | |||||
| if (fw != null) { | |||||
| try { | |||||
| fw.close(); | |||||
| } catch (IOException ignored){} | |||||
| } | |||||
| } | |||||
| return file; | |||||
| } | |||||
| /** create a temporary file in the current dir (For JDK1.1 support) */ | |||||
| protected File createTmpFile(){ | |||||
| final long rand = (new Random(System.currentTimeMillis())).nextLong(); | |||||
| File file = new File("jpcoverage" + rand + ".tmp"); | |||||
| return file; | |||||
| } | |||||
| /** specific pumper to avoid those nasty stdin issues */ | |||||
| static class CoverageStreamHandler extends LogStreamHandler { | |||||
| CoverageStreamHandler(Task task){ | |||||
| super(task, Project.MSG_INFO, Project.MSG_WARN); | |||||
| } | |||||
| /** | |||||
| * there are some issues concerning all JProbe executable | |||||
| * In our case a 'Press ENTER to close this window..." will | |||||
| * be displayed in the current window waiting for enter. | |||||
| * So I'm closing the stream right away to avoid problems. | |||||
| */ | |||||
| public void setProcessInputStream(OutputStream os) { | |||||
| try { | |||||
| os.close(); | |||||
| } catch (IOException ignored){ | |||||
| } | |||||
| } | |||||
| } | |||||
| //params.addElement("-jp_append=" + append); | |||||
| params.addElement("-jp_track_natives=" + trackNatives); | |||||
| //.... now the jvm | |||||
| // arguments | |||||
| String[] vmargs = cmdlJava.getVmCommand().getArguments(); | |||||
| for (int i = 0; i < vmargs.length; i++) { | |||||
| params.addElement(vmargs[i]); | |||||
| } | |||||
| // classpath | |||||
| Path classpath = cmdlJava.getClasspath(); | |||||
| if (classpath != null && classpath.size() > 0) { | |||||
| params.addElement("-classpath " + classpath.toString()); | |||||
| } | |||||
| // classname (runner or standalone) | |||||
| if (cmdlJava.getClassname() != null) { | |||||
| params.addElement(cmdlJava.getClassname()); | |||||
| } | |||||
| // arguments for classname | |||||
| String[] args = cmdlJava.getJavaCommand().getArguments(); | |||||
| for (int i = 0; i < args.length; i++) { | |||||
| params.addElement(args[i]); | |||||
| } | |||||
| String[] array = new String[params.size()]; | |||||
| params.copyInto(array); | |||||
| return array; | |||||
| } | |||||
| /** | |||||
| * create the parameter file from the given options. The file is | |||||
| * created with a random name in the current directory. | |||||
| * @return the file object where are written the configuration to run | |||||
| * JProbe Coverage | |||||
| * @throws BuildException thrown if something bad happens while writing | |||||
| * the arguments to the file. | |||||
| */ | |||||
| protected File createParamFile() throws BuildException { | |||||
| //@todo change this when switching to JDK 1.2 and use File.createTmpFile() | |||||
| File file = createTmpFile(); | |||||
| log("Creating parameter file: " + file, Project.MSG_VERBOSE); | |||||
| // options need to be one per line in the parameter file | |||||
| // so write them all in a single string | |||||
| StringWriter sw = new StringWriter(); | |||||
| PrintWriter pw = new PrintWriter(sw); | |||||
| String[] params = getParameters(); | |||||
| for (int i = 0; i < params.length; i++) { | |||||
| pw.println(params[i]); | |||||
| } | |||||
| pw.flush(); | |||||
| log("JProbe Coverage parameters:\n" + sw.toString(), Project.MSG_VERBOSE); | |||||
| // now write them to the file | |||||
| FileWriter fw = null; | |||||
| try { | |||||
| fw = new FileWriter(file); | |||||
| fw.write(sw.toString()); | |||||
| fw.flush(); | |||||
| } catch (IOException e) { | |||||
| throw new BuildException("Could not write parameter file " + file, e); | |||||
| } finally { | |||||
| if (fw != null) { | |||||
| try { | |||||
| fw.close(); | |||||
| } catch (IOException ignored) { | |||||
| } | |||||
| } | |||||
| } | |||||
| return file; | |||||
| } | |||||
| /** create a temporary file in the current dir (For JDK1.1 support) */ | |||||
| protected File createTmpFile() { | |||||
| final long rand = (new Random(System.currentTimeMillis())).nextLong(); | |||||
| File file = new File("jpcoverage" + rand + ".tmp"); | |||||
| return file; | |||||
| } | |||||
| /** specific pumper to avoid those nasty stdin issues */ | |||||
| static class CoverageStreamHandler extends LogStreamHandler { | |||||
| CoverageStreamHandler(Task task) { | |||||
| super(task, Project.MSG_INFO, Project.MSG_WARN); | |||||
| } | |||||
| /** | |||||
| * there are some issues concerning all JProbe executable | |||||
| * In our case a 'Press ENTER to close this window..." will | |||||
| * be displayed in the current window waiting for enter. | |||||
| * So I'm closing the stream right away to avoid problems. | |||||
| */ | |||||
| public void setProcessInputStream(OutputStream os) { | |||||
| try { | |||||
| os.close(); | |||||
| } catch (IOException ignored) { | |||||
| } | |||||
| } | |||||
| } | |||||
| } | } | ||||
| @@ -72,22 +72,22 @@ public class Filters { | |||||
| /** user defined filters */ | /** user defined filters */ | ||||
| protected Vector filters = new Vector(); | protected Vector filters = new Vector(); | ||||
| public Filters(){ | |||||
| public Filters() { | |||||
| } | } | ||||
| public void setDefaultExclude(boolean value){ | |||||
| public void setDefaultExclude(boolean value) { | |||||
| defaultExclude = value; | defaultExclude = value; | ||||
| } | } | ||||
| public void addInclude(Include incl){ | |||||
| public void addInclude(Include incl) { | |||||
| filters.addElement(incl); | filters.addElement(incl); | ||||
| } | } | ||||
| public void addExclude(Exclude excl){ | |||||
| public void addExclude(Exclude excl) { | |||||
| filters.addElement(excl); | filters.addElement(excl); | ||||
| } | } | ||||
| public String toString(){ | |||||
| public String toString() { | |||||
| StringBuffer buf = new StringBuffer(); | StringBuffer buf = new StringBuffer(); | ||||
| final int size = filters.size(); | final int size = filters.size(); | ||||
| if (defaultExclude) { | if (defaultExclude) { | ||||
| @@ -98,7 +98,7 @@ public class Filters { | |||||
| } | } | ||||
| for (int i = 0; i < size; i++) { | for (int i = 0; i < size; i++) { | ||||
| buf.append(filters.elementAt(i).toString()); | buf.append(filters.elementAt(i).toString()); | ||||
| if ( i < size - 1) { | |||||
| if (i < size - 1) { | |||||
| buf.append(','); | buf.append(','); | ||||
| } | } | ||||
| } | } | ||||
| @@ -109,25 +109,30 @@ public class Filters { | |||||
| protected String clazz; | protected String clazz; | ||||
| protected String method = "*"; // default is all methods | protected String method = "*"; // default is all methods | ||||
| protected boolean enabled = true; // default is enable | protected boolean enabled = true; // default is enable | ||||
| public void setName(String value){ // this one is deprecated. | |||||
| public void setName(String value) { // this one is deprecated. | |||||
| clazz = value; | clazz = value; | ||||
| } | } | ||||
| public void setClass(String value){ | |||||
| clazz = value; | |||||
| public void setClass(String value) { | |||||
| clazz = value; | |||||
| } | } | ||||
| public void setMethod(String value){ | |||||
| public void setMethod(String value) { | |||||
| method = value; | method = value; | ||||
| } | } | ||||
| public void setEnabled(boolean value){ | |||||
| public void setEnabled(boolean value) { | |||||
| enabled = value; | enabled = value; | ||||
| } | } | ||||
| public String toString(){ | |||||
| public String toString() { | |||||
| return clazz + "." + method + "()"; | return clazz + "." + method + "()"; | ||||
| } | } | ||||
| } | } | ||||
| public static class Include extends FilterElement { | public static class Include extends FilterElement { | ||||
| public String toString(){ | |||||
| public String toString() { | |||||
| return super.toString() + ":I" + (enabled ? "" : "#"); | return super.toString() + ":I" + (enabled ? "" : "#"); | ||||
| } | } | ||||
| } | } | ||||
| @@ -66,101 +66,104 @@ import org.apache.tools.ant.util.regexp.RegexpMatcherFactory; | |||||
| */ | */ | ||||
| public class ReportFilters { | public class ReportFilters { | ||||
| /** user defined filters */ | |||||
| protected Vector filters = new Vector(); | |||||
| /** cached matcher for each filter */ | |||||
| protected Vector matchers = null; | |||||
| public ReportFilters(){ | |||||
| } | |||||
| public void addInclude(Include incl){ | |||||
| filters.addElement(incl); | |||||
| } | |||||
| public void addExclude(Exclude excl){ | |||||
| filters.addElement(excl); | |||||
| } | |||||
| public int size(){ | |||||
| return filters.size(); | |||||
| } | |||||
| /** | |||||
| * Check whether a given <classname><method>() is accepted by the list | |||||
| * of filters or not. | |||||
| * @param methodname the full method name in the format <classname><method>() | |||||
| */ | |||||
| public boolean accept(String methodname){ | |||||
| // I'm deferring matcher instantiations at runtime to avoid computing | |||||
| // the filters at parsing time | |||||
| if (matchers == null){ | |||||
| createMatchers(); | |||||
| } | |||||
| boolean result = false; | |||||
| // assert filters.size() == matchers.size() | |||||
| final int size = filters.size(); | |||||
| for (int i = 0; i < size; i++){ | |||||
| FilterElement filter = (FilterElement)filters.elementAt(i); | |||||
| RegexpMatcher matcher = (RegexpMatcher)matchers.elementAt(i); | |||||
| if (filter instanceof Include){ | |||||
| result = result || matcher.matches(methodname); | |||||
| } else if (filter instanceof Exclude){ | |||||
| result = result && !matcher.matches(methodname); | |||||
| } else{ | |||||
| //not possible | |||||
| throw new IllegalArgumentException("Invalid filter element: " + filter.getClass().getName()); | |||||
| } | |||||
| } | |||||
| return result; | |||||
| } | |||||
| /** should be called only once to cache matchers */ | |||||
| protected void createMatchers(){ | |||||
| RegexpMatcherFactory factory = new RegexpMatcherFactory(); | |||||
| final int size = filters.size(); | |||||
| matchers = new Vector(); | |||||
| for (int i = 0; i < size; i++){ | |||||
| FilterElement filter = (FilterElement)filters.elementAt(i); | |||||
| RegexpMatcher matcher = factory.newRegexpMatcher(); | |||||
| String pattern = filter.getAsPattern(); | |||||
| matcher.setPattern(pattern); | |||||
| matchers.addElement(matcher); | |||||
| } | |||||
| } | |||||
| /** default abstract filter element class */ | |||||
| abstract public static class FilterElement { | |||||
| protected String clazz = "*"; // default is all classes | |||||
| protected String method = "*"; // default is all methods | |||||
| public void setClass(String value){ | |||||
| clazz = value; | |||||
| } | |||||
| public void setMethod(String value){ | |||||
| method = value; | |||||
| } | |||||
| public String getAsPattern(){ | |||||
| StringBuffer buf = new StringBuffer(toString()); | |||||
| StringUtil.replace(buf, ".", "\\."); | |||||
| StringUtil.replace(buf, "*", ".*"); | |||||
| StringUtil.replace(buf, "(", "\\("); | |||||
| StringUtil.replace(buf, ")", "\\)"); | |||||
| return buf.toString(); | |||||
| } | |||||
| public String toString(){ | |||||
| return clazz + "." + method + "()"; | |||||
| } | |||||
| } | |||||
| /** concrete include class */ | |||||
| public static class Include extends FilterElement {} | |||||
| /** concrete exclude class */ | |||||
| public static class Exclude extends FilterElement {} | |||||
| /** user defined filters */ | |||||
| protected Vector filters = new Vector(); | |||||
| /** cached matcher for each filter */ | |||||
| protected Vector matchers = null; | |||||
| public ReportFilters() { | |||||
| } | |||||
| public void addInclude(Include incl) { | |||||
| filters.addElement(incl); | |||||
| } | |||||
| public void addExclude(Exclude excl) { | |||||
| filters.addElement(excl); | |||||
| } | |||||
| public int size() { | |||||
| return filters.size(); | |||||
| } | |||||
| /** | |||||
| * Check whether a given <classname><method>() is accepted by the list | |||||
| * of filters or not. | |||||
| * @param methodname the full method name in the format <classname><method>() | |||||
| */ | |||||
| public boolean accept(String methodname) { | |||||
| // I'm deferring matcher instantiations at runtime to avoid computing | |||||
| // the filters at parsing time | |||||
| if (matchers == null) { | |||||
| createMatchers(); | |||||
| } | |||||
| boolean result = false; | |||||
| // assert filters.size() == matchers.size() | |||||
| final int size = filters.size(); | |||||
| for (int i = 0; i < size; i++) { | |||||
| FilterElement filter = (FilterElement) filters.elementAt(i); | |||||
| RegexpMatcher matcher = (RegexpMatcher) matchers.elementAt(i); | |||||
| if (filter instanceof Include) { | |||||
| result = result || matcher.matches(methodname); | |||||
| } else if (filter instanceof Exclude) { | |||||
| result = result && !matcher.matches(methodname); | |||||
| } else { | |||||
| //not possible | |||||
| throw new IllegalArgumentException("Invalid filter element: " + filter.getClass().getName()); | |||||
| } | |||||
| } | |||||
| return result; | |||||
| } | |||||
| /** should be called only once to cache matchers */ | |||||
| protected void createMatchers() { | |||||
| RegexpMatcherFactory factory = new RegexpMatcherFactory(); | |||||
| final int size = filters.size(); | |||||
| matchers = new Vector(); | |||||
| for (int i = 0; i < size; i++) { | |||||
| FilterElement filter = (FilterElement) filters.elementAt(i); | |||||
| RegexpMatcher matcher = factory.newRegexpMatcher(); | |||||
| String pattern = filter.getAsPattern(); | |||||
| matcher.setPattern(pattern); | |||||
| matchers.addElement(matcher); | |||||
| } | |||||
| } | |||||
| /** default abstract filter element class */ | |||||
| abstract public static class FilterElement { | |||||
| protected String clazz = "*"; // default is all classes | |||||
| protected String method = "*"; // default is all methods | |||||
| public void setClass(String value) { | |||||
| clazz = value; | |||||
| } | |||||
| public void setMethod(String value) { | |||||
| method = value; | |||||
| } | |||||
| public String getAsPattern() { | |||||
| StringBuffer buf = new StringBuffer(toString()); | |||||
| StringUtil.replace(buf, ".", "\\."); | |||||
| StringUtil.replace(buf, "*", ".*"); | |||||
| StringUtil.replace(buf, "(", "\\("); | |||||
| StringUtil.replace(buf, ")", "\\)"); | |||||
| return buf.toString(); | |||||
| } | |||||
| public String toString() { | |||||
| return clazz + "." + method + "()"; | |||||
| } | |||||
| } | |||||
| /** concrete include class */ | |||||
| public static class Include extends FilterElement { | |||||
| } | |||||
| /** concrete exclude class */ | |||||
| public static class Exclude extends FilterElement { | |||||
| } | |||||
| } | } | ||||
| @@ -64,22 +64,22 @@ package org.apache.tools.ant.taskdefs.optional.sitraka; | |||||
| */ | */ | ||||
| public class Socket { | public class Socket { | ||||
| /** default to localhost */ | |||||
| private String host = "127.0.0.1"; | |||||
| /** default to localhost */ | |||||
| private String host = "127.0.0.1"; | |||||
| /** default to 4444 */ | |||||
| private int port = 4444; | |||||
| /** default to 4444 */ | |||||
| private int port = 4444; | |||||
| public void setHost(String value){ | |||||
| host = value; | |||||
| } | |||||
| public void setHost(String value) { | |||||
| host = value; | |||||
| } | |||||
| public void setPort(Integer value){ | |||||
| port = value.intValue(); | |||||
| } | |||||
| public void setPort(Integer value) { | |||||
| port = value.intValue(); | |||||
| } | |||||
| /** if no host is set, returning ':<port>', will take localhost */ | |||||
| public String toString(){ | |||||
| return host + ":" + port; | |||||
| } | |||||
| /** if no host is set, returning ':<port>', will take localhost */ | |||||
| public String toString() { | |||||
| return host + ":" + port; | |||||
| } | |||||
| } | } | ||||
| @@ -58,27 +58,27 @@ package org.apache.tools.ant.taskdefs.optional.sitraka; | |||||
| * @author <a href="mailto:sbailliez@imediation.com">Stephane Bailliez</a> | * @author <a href="mailto:sbailliez@imediation.com">Stephane Bailliez</a> | ||||
| */ | */ | ||||
| public final class StringUtil { | public final class StringUtil { | ||||
| /** private constructor, it's a utility class */ | |||||
| private StringUtil() { | |||||
| } | |||||
| /** private constructor, it's a utility class */ | |||||
| private StringUtil() { | |||||
| } | |||||
| /** | |||||
| * Replaces all occurences of <tt>find</tt> with <tt>replacement</tt> in the | |||||
| * source StringBuffer. | |||||
| * @param src the original string buffer to modify. | |||||
| * @param find the string to be replaced. | |||||
| * @param replacement the replacement string for <tt>find</tt> matches. | |||||
| */ | |||||
| public static void replace(StringBuffer src, String find, String replacement){ | |||||
| int index = 0; | |||||
| while (index < src.length() ){ | |||||
| index = src.toString().indexOf(find, index); | |||||
| if (index == -1){ | |||||
| break; | |||||
| } | |||||
| src.delete(index, index + find.length()); | |||||
| src.insert(index, replacement); | |||||
| index += replacement.length() + 1; | |||||
| } | |||||
| } | |||||
| /** | |||||
| * Replaces all occurences of <tt>find</tt> with <tt>replacement</tt> in the | |||||
| * source StringBuffer. | |||||
| * @param src the original string buffer to modify. | |||||
| * @param find the string to be replaced. | |||||
| * @param replacement the replacement string for <tt>find</tt> matches. | |||||
| */ | |||||
| public static void replace(StringBuffer src, String find, String replacement) { | |||||
| int index = 0; | |||||
| while (index < src.length()) { | |||||
| index = src.toString().indexOf(find, index); | |||||
| if (index == -1) { | |||||
| break; | |||||
| } | |||||
| src.delete(index, index + find.length()); | |||||
| src.insert(index, replacement); | |||||
| index += replacement.length() + 1; | |||||
| } | |||||
| } | |||||
| } | } | ||||
| @@ -54,8 +54,9 @@ | |||||
| package org.apache.tools.ant.taskdefs.optional.sitraka; | package org.apache.tools.ant.taskdefs.optional.sitraka; | ||||
| import java.util.Vector; | |||||
| import java.util.Hashtable; | import java.util.Hashtable; | ||||
| import java.util.Vector; | |||||
| import org.apache.tools.ant.BuildException; | import org.apache.tools.ant.BuildException; | ||||
| /** | /** | ||||
| @@ -66,82 +67,86 @@ import org.apache.tools.ant.BuildException; | |||||
| */ | */ | ||||
| public class Triggers { | public class Triggers { | ||||
| protected Vector triggers = new Vector(); | |||||
| public Triggers(){ | |||||
| } | |||||
| public void addMethod(Method method){ | |||||
| triggers.addElement(method); | |||||
| } | |||||
| // -jp_trigger=ClassName.*():E:S,ClassName.MethodName():X:X | |||||
| public String toString(){ | |||||
| StringBuffer buf = new StringBuffer(); | |||||
| final int size = triggers.size(); | |||||
| for(int i = 0; i < size; i++) { | |||||
| buf.append( triggers.elementAt(i).toString() ); | |||||
| if (i < size - 1) { | |||||
| buf.append(','); | |||||
| } | |||||
| } | |||||
| return buf.toString(); | |||||
| } | |||||
| public static class Method { | |||||
| protected String name; | |||||
| protected String event; | |||||
| protected String action; | |||||
| protected String param; | |||||
| public void setName(String value){ | |||||
| name = value; | |||||
| } | |||||
| public void setEvent(String value){ | |||||
| if (eventMap.get(value) == null) { | |||||
| throw new BuildException("Invalid event, must be one of " + eventMap); | |||||
| } | |||||
| event = value; | |||||
| } | |||||
| public void setAction(String value) throws BuildException { | |||||
| if (actionMap.get(value) == null) { | |||||
| throw new BuildException("Invalid action, must be one of " + actionMap); | |||||
| } | |||||
| action = value; | |||||
| } | |||||
| public void setParam(String value){ | |||||
| param = value; | |||||
| } | |||||
| // return <name>:<event>:<action>[:param] | |||||
| public String toString(){ | |||||
| StringBuffer buf = new StringBuffer(); | |||||
| buf.append(name).append(":"); //@todo name must not be null, check for it | |||||
| buf.append(eventMap.get(event)).append(":"); | |||||
| buf.append(actionMap.get(action)); | |||||
| if (param != null) { | |||||
| buf.append(":").append(param); | |||||
| } | |||||
| return buf.toString(); | |||||
| } | |||||
| } | |||||
| /** mapping of actions to cryptic command line mnemonics */ | |||||
| private final static Hashtable actionMap = new Hashtable(3); | |||||
| /** mapping of events to cryptic command line mnemonics */ | |||||
| private final static Hashtable eventMap = new Hashtable(3); | |||||
| static { | |||||
| actionMap.put("enter", "E"); | |||||
| actionMap.put("exit", "X"); | |||||
| // 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"); | |||||
| } | |||||
| protected Vector triggers = new Vector(); | |||||
| public Triggers() { | |||||
| } | |||||
| public void addMethod(Method method) { | |||||
| triggers.addElement(method); | |||||
| } | |||||
| // -jp_trigger=ClassName.*():E:S,ClassName.MethodName():X:X | |||||
| public String toString() { | |||||
| StringBuffer buf = new StringBuffer(); | |||||
| final int size = triggers.size(); | |||||
| for (int i = 0; i < size; i++) { | |||||
| buf.append(triggers.elementAt(i).toString()); | |||||
| if (i < size - 1) { | |||||
| buf.append(','); | |||||
| } | |||||
| } | |||||
| return buf.toString(); | |||||
| } | |||||
| public static class Method { | |||||
| protected String name; | |||||
| protected String event; | |||||
| protected String action; | |||||
| protected String param; | |||||
| public void setName(String value) { | |||||
| name = value; | |||||
| } | |||||
| public void setEvent(String value) { | |||||
| if (eventMap.get(value) == null) { | |||||
| throw new BuildException("Invalid event, must be one of " + eventMap); | |||||
| } | |||||
| event = value; | |||||
| } | |||||
| public void setAction(String value) throws BuildException { | |||||
| if (actionMap.get(value) == null) { | |||||
| throw new BuildException("Invalid action, must be one of " + actionMap); | |||||
| } | |||||
| action = value; | |||||
| } | |||||
| public void setParam(String value) { | |||||
| param = value; | |||||
| } | |||||
| // return <name>:<event>:<action>[:param] | |||||
| public String toString() { | |||||
| StringBuffer buf = new StringBuffer(); | |||||
| buf.append(name).append(":"); //@todo name must not be null, check for it | |||||
| buf.append(eventMap.get(event)).append(":"); | |||||
| buf.append(actionMap.get(action)); | |||||
| if (param != null) { | |||||
| buf.append(":").append(param); | |||||
| } | |||||
| return buf.toString(); | |||||
| } | |||||
| } | |||||
| /** mapping of actions to cryptic command line mnemonics */ | |||||
| private final static Hashtable actionMap = new Hashtable(3); | |||||
| /** mapping of events to cryptic command line mnemonics */ | |||||
| private final static Hashtable eventMap = new Hashtable(3); | |||||
| static { | |||||
| actionMap.put("enter", "E"); | |||||
| actionMap.put("exit", "X"); | |||||
| // 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"); | |||||
| } | |||||
| } | } | ||||
| @@ -53,6 +53,15 @@ | |||||
| */ | */ | ||||
| package org.apache.tools.ant.taskdefs.optional.sitraka; | package org.apache.tools.ant.taskdefs.optional.sitraka; | ||||
| import java.io.File; | |||||
| import java.io.FileInputStream; | |||||
| import java.util.Enumeration; | |||||
| import java.util.Hashtable; | |||||
| import java.util.NoSuchElementException; | |||||
| import java.util.Vector; | |||||
| import javax.xml.parsers.DocumentBuilder; | |||||
| import javax.xml.parsers.DocumentBuilderFactory; | |||||
| import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
| import org.apache.tools.ant.Task; | import org.apache.tools.ant.Task; | ||||
| import org.apache.tools.ant.taskdefs.optional.sitraka.bytecode.ClassFile; | import org.apache.tools.ant.taskdefs.optional.sitraka.bytecode.ClassFile; | ||||
| @@ -65,21 +74,6 @@ import org.w3c.dom.Node; | |||||
| import org.w3c.dom.NodeList; | import org.w3c.dom.NodeList; | ||||
| import org.xml.sax.InputSource; | import org.xml.sax.InputSource; | ||||
| import javax.xml.parsers.DocumentBuilder; | |||||
| import javax.xml.parsers.DocumentBuilderFactory; | |||||
| import javax.xml.transform.OutputKeys; | |||||
| import javax.xml.transform.Transformer; | |||||
| import javax.xml.transform.TransformerFactory; | |||||
| import javax.xml.transform.dom.DOMSource; | |||||
| import javax.xml.transform.stream.StreamResult; | |||||
| import java.io.File; | |||||
| import java.io.FileInputStream; | |||||
| import java.io.FileOutputStream; | |||||
| import java.util.Enumeration; | |||||
| import java.util.Hashtable; | |||||
| import java.util.NoSuchElementException; | |||||
| import java.util.Vector; | |||||
| /** | /** | ||||
| * Little hack to process XML report from JProbe. It will fix | * Little hack to process XML report from JProbe. It will fix | ||||
| * some reporting errors from JProbe 3.0 and makes use of a reference | * some reporting errors from JProbe 3.0 and makes use of a reference | ||||