From d6f346f0b3a03100fe4fc63ee36b89f4ffdaf4e7 Mon Sep 17 00:00:00 2001 From: evenisse Date: Wed, 3 Sep 2003 16:27:15 +0000 Subject: [PATCH] First release of jcoverage plugin. git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@113950 13f79535-47bb-0310-9956-ffa450edef68 --- jcoverage/.cvsignore | 3 + jcoverage/announcements/1.0.ann | 20 + jcoverage/plugin.jelly | 198 +++++++ jcoverage/plugin.properties | 5 + jcoverage/project.properties | 7 + jcoverage/project.xml | 115 ++++ .../apache/maven/jcoveragereport/Clazz.java | 170 ++++++ .../jcoveragereport/ClazzComparator.java | 82 +++ .../maven/jcoveragereport/Coverage.java | 179 +++++++ .../maven/jcoveragereport/CoverageReport.java | 506 ++++++++++++++++++ .../CoverageReportGenerator.java | 149 ++++++ .../jcoveragereport/CoverageUnmarshaller.java | 159 ++++++ .../maven/jcoveragereport/JavaToHtml.java | 395 ++++++++++++++ .../apache/maven/jcoveragereport/Line.java | 87 +++ .../apache/maven/jcoveragereport/Main.java | 72 +++ .../apache/maven/jcoveragereport/Package.java | 143 +++++ .../jcoveragereport/PackageComparator.java | 82 +++ jcoverage/src/plugin-resources/style.css | 148 +++++ jcoverage/xdocs/.cvsignore | 1 + jcoverage/xdocs/goals.xml | 40 ++ jcoverage/xdocs/index.xml | 21 + jcoverage/xdocs/navigation.xml | 27 + jcoverage/xdocs/properties.xml | 77 +++ 23 files changed, 2686 insertions(+) create mode 100644 jcoverage/.cvsignore create mode 100644 jcoverage/announcements/1.0.ann create mode 100644 jcoverage/plugin.jelly create mode 100644 jcoverage/plugin.properties create mode 100644 jcoverage/project.properties create mode 100644 jcoverage/project.xml create mode 100644 jcoverage/src/main/org/apache/maven/jcoveragereport/Clazz.java create mode 100644 jcoverage/src/main/org/apache/maven/jcoveragereport/ClazzComparator.java create mode 100644 jcoverage/src/main/org/apache/maven/jcoveragereport/Coverage.java create mode 100644 jcoverage/src/main/org/apache/maven/jcoveragereport/CoverageReport.java create mode 100644 jcoverage/src/main/org/apache/maven/jcoveragereport/CoverageReportGenerator.java create mode 100644 jcoverage/src/main/org/apache/maven/jcoveragereport/CoverageUnmarshaller.java create mode 100644 jcoverage/src/main/org/apache/maven/jcoveragereport/JavaToHtml.java create mode 100644 jcoverage/src/main/org/apache/maven/jcoveragereport/Line.java create mode 100644 jcoverage/src/main/org/apache/maven/jcoveragereport/Main.java create mode 100644 jcoverage/src/main/org/apache/maven/jcoveragereport/Package.java create mode 100644 jcoverage/src/main/org/apache/maven/jcoveragereport/PackageComparator.java create mode 100644 jcoverage/src/plugin-resources/style.css create mode 100644 jcoverage/xdocs/.cvsignore create mode 100644 jcoverage/xdocs/goals.xml create mode 100644 jcoverage/xdocs/index.xml create mode 100644 jcoverage/xdocs/navigation.xml create mode 100644 jcoverage/xdocs/properties.xml diff --git a/jcoverage/.cvsignore b/jcoverage/.cvsignore new file mode 100644 index 00000000..e5e33942 --- /dev/null +++ b/jcoverage/.cvsignore @@ -0,0 +1,3 @@ +target +velocity.log +maven.log diff --git a/jcoverage/announcements/1.0.ann b/jcoverage/announcements/1.0.ann new file mode 100644 index 00000000..b964256e --- /dev/null +++ b/jcoverage/announcements/1.0.ann @@ -0,0 +1,20 @@ +The Maven team is pleased to announce the JCoverage plugin 1.0 release! + +http://maven.apache.org/reference/plugins/jcoverage + +The Maven JCoverage plugin is a plugin for JCoverage +(http://www.jcoverage.com) that generate test coverage reports. + +Features in this version includes: + +o Support for JCoverage 1.0.5 + +o Report generation + +o Merge two or more instrumentation files into one + +You can download the JCoverage Maven plugin here: +http://www.ibiblio.org/maven/maven/plugins/maven-jcoverage-plugin-1.0.jar + +Have fun! +-Vincent \ No newline at end of file diff --git a/jcoverage/plugin.jelly b/jcoverage/plugin.jelly new file mode 100644 index 00000000..2f722697 --- /dev/null +++ b/jcoverage/plugin.jelly @@ -0,0 +1,198 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ${pom.getPluginContext('maven-test-plugin').setVariable('maven.build.dest', instrumented)} + + + ${pom.getPluginContext('maven-test-plugin').setVariable('maven.junit.fork', fork)} + + + + + + instrumenting the class-files... + + + + + + + + + + + + + + + + ${ex} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + jcoverage reports have been generated. + The HTML report is ${maven.build.coverage.dir}/index.html + + + + + + + + + + + + + + ${pom.getPluginContext('maven-test-plugin').setVariable('maven.junit.fork', oldfork)} + + ${pom.getPluginContext('maven-test-plugin').setVariable('maven.build.dest', oldBuildDest)} + + + ${ex} + + + + + + + + + + + + ${maven.jcoverage.merge.instrumentedFiles} + + + + + + + + + + + diff --git a/jcoverage/plugin.properties b/jcoverage/plugin.properties new file mode 100644 index 00000000..007a8301 --- /dev/null +++ b/jcoverage/plugin.properties @@ -0,0 +1,5 @@ +maven.jcoverage.dir=${maven.build.dir}/jcoverage +maven.jcoverage.instrumentation=${maven.jcoverage.dir}/classes +maven.jcoverage.database.dir=${maven.jcoverage.dir}/database +maven.jcoverage.junit.fork=yes +maven.jcoverage.report.template=maven diff --git a/jcoverage/project.properties b/jcoverage/project.properties new file mode 100644 index 00000000..df6f93f4 --- /dev/null +++ b/jcoverage/project.properties @@ -0,0 +1,7 @@ +# ------------------------------------------------------------------- +# P R O J E C T P R O P E R T I E S +# ------------------------------------------------------------------- +maven.xdoc.date=left +maven.xdoc.version=${pom.currentVersion} +maven.license.licenseFile=${basedir}/../../../LICENSE.txt + diff --git a/jcoverage/project.xml b/jcoverage/project.xml new file mode 100644 index 00000000..95015101 --- /dev/null +++ b/jcoverage/project.xml @@ -0,0 +1,115 @@ + + + + ../project.xml + 3 + maven-jcoverage-plugin + Maven JCoverage plugin + 1.0 + org.apache.maven.jcoveragereport + + + This plugin provides coverage analysis of your source-code based on the open-source + jcoverage tool. + + + This plugin provides coverage analysis of your source-code based on the open-source + jcoverage tool. + + + http://maven.apache.org/reference/plugins/jcoverage/ + /www/maven.apache.org/reference/plugins/jcoverage/ + + + scm:cvs:pserver:anoncvs@cvs.apache.org:/home/cvspublic:maven/src/plugins-build/jcoverage/ + http://cvs.apache.org/viewcvs/maven/src/plugins-build/jcoverage/ + + + + + Dominik Dahlem + dahlemd + Dominik.Dahlem@cs.tcd.ie + Trinity College Dublin, Computer Science Department, Distributed Systems Group + + Build Engineer, Java Developer + + + + Emmanuel Venisse + evenisse + evenisse@ifrance.com + + + Java Developer + + +18 + + + + + + jcoverage + jcoverage + 1.0.5 + + root + + http://www.jcoverage.com + + + velocity + velocity + 1.3 + + root.maven + + http://jakarta.apache.org/velocity/ + + + log4j + log4j + 1.2.8 + http://jakarta.apache.org/log4j/ + + + bcel + bcel + 5.1 + http://jakarta.apache.org/bcel/ + + + urbanophile + java-getopt + 1.0.9 + http://www.urbanophile.com/arenn/hacking/download.html + + + junit + junit + 3.8.1 + http://www.junit.org + + + oro + oro + 2.0.7 + http://jakarta.apache.org/oro/ + + + xpp3 + xpp3 + 1.1.2a + http://www.extreme.indiana.edu/xgws/xsoap/xpp/ + + + + + maven-changes-plugin + maven-changelog-plugin + maven-file-activity-plugin + maven-developer-activity-plugin + maven-license-plugin + + + \ No newline at end of file diff --git a/jcoverage/src/main/org/apache/maven/jcoveragereport/Clazz.java b/jcoverage/src/main/org/apache/maven/jcoveragereport/Clazz.java new file mode 100644 index 00000000..58372cc4 --- /dev/null +++ b/jcoverage/src/main/org/apache/maven/jcoveragereport/Clazz.java @@ -0,0 +1,170 @@ +package org.apache.maven.jcoveragereport; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache Maven" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache Maven", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * ==================================================================== + */ + +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +/** + * @author Emmanuel Venisse + * @version $Id: Clazz.java,v 1.1 2003/09/03 16:27:14 evenisse Exp $ + */ +public class Clazz +{ + private String packageName; + private String name; + private String file; + private String lineRate; + private String branchRate; + private Map lines; + + public Clazz() + { + lines = new HashMap(); + } + + public Clazz(String longName) + { + this(); + int pos = longName.lastIndexOf("."); + if (pos > 0) + { + packageName = longName.substring(0, pos); + name = longName.substring(pos + 1); + } + else + { + name = longName; + } + } + + public void setPackageName(String packageName) + { + this.packageName = packageName; + } + + public String getPackageName() + { + return packageName; + } + + public void setName(String name) + { + this.name = name; + } + + public String getName() + { + return name; + } + + public void setFile(String file) + { + this.file = file; + } + + public String getFile() + { + return file; + } + + public void setLineRate(String lineRate) + { + this.lineRate = lineRate; + } + + public String getLineRate() + { + return lineRate; + } + + public void setBranchRate(String branchRate) + { + this.branchRate = branchRate; + } + + public String getBranchRate() + { + return branchRate; + } + + public void setLines(Collection lines) + { + for (Iterator iter = lines.iterator(); iter.hasNext(); ) + { + Line line = (Line) iter.next(); + this.lines.put(new Integer(line.getNumLine()), line); + } + } + + public Collection getLines() + { + return lines.values(); + } + + public void addLine(Line line) + { + lines.put(new Integer(line.getNumLine()), line); + } + + public Map getLinesMap() + { + return lines; + } +} diff --git a/jcoverage/src/main/org/apache/maven/jcoveragereport/ClazzComparator.java b/jcoverage/src/main/org/apache/maven/jcoveragereport/ClazzComparator.java new file mode 100644 index 00000000..7be42eba --- /dev/null +++ b/jcoverage/src/main/org/apache/maven/jcoveragereport/ClazzComparator.java @@ -0,0 +1,82 @@ +package org.apache.maven.jcoveragereport; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache Maven" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache Maven", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * ==================================================================== + */ + +import java.util.Comparator; + +/** + * @author Emmanuel Venisse + * @version $Id: ClazzComparator.java,v 1.1 2003/09/03 16:27:14 evenisse Exp $ + */ +public class ClazzComparator implements Comparator +{ + public int compare(Object class1, Object class2) + { + if (class1 instanceof Clazz && class2 instanceof Clazz) + { + Clazz c1 = (Clazz) class1; + Clazz c2 = (Clazz) class2; + String lower1 = c1.getName().toLowerCase(); + String lower2 = c2.getName().toLowerCase(); + return lower1.compareTo(lower2); + } + else + { + return -1; + } + } +} diff --git a/jcoverage/src/main/org/apache/maven/jcoveragereport/Coverage.java b/jcoverage/src/main/org/apache/maven/jcoveragereport/Coverage.java new file mode 100644 index 00000000..7239f0c6 --- /dev/null +++ b/jcoverage/src/main/org/apache/maven/jcoveragereport/Coverage.java @@ -0,0 +1,179 @@ +package org.apache.maven.jcoveragereport; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache Maven" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache Maven", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * ==================================================================== + */ + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.HashMap; + +/** + * @author Emmanuel Venisse + * @version $Id: Coverage.java,v 1.1 2003/09/03 16:27:14 evenisse Exp $ + */ +public class Coverage +{ + private List classes; + private String srcDirectory; + private Map packageMap; + + public Coverage() + { + classes = new ArrayList(); + packageMap = new HashMap(); + } + + public void setClasses(List classes) + { + this.classes = classes; + } + + public void addClass(Clazz theClass) + { + classes.add(theClass); + Package pkg; + String packageName = theClass.getPackageName(); + if (!packageMap.containsKey(packageName)) + { + pkg = new Package(packageName); + } + else + { + pkg = (Package) packageMap.get(packageName); + } + if (!pkg.contains(theClass)) + { + pkg.setDirectory(theClass.getFile().substring(0, theClass.getFile().lastIndexOf("/"))); + pkg.addClass(theClass); + packageMap.put(packageName, pkg); + } + } + + public List getClasses() + { + return classes; + } + + public List getClassesSortedByName() + { + ClazzComparator comp = new ClazzComparator(); + Collections.sort(classes, comp); + return classes; + } + + public void setSrcDirectory(String srcDirectory) + { + this.srcDirectory = srcDirectory; + } + + public String getSrcDirectory() + { + return srcDirectory; + } + + public List getPackages() + { + return new ArrayList(packageMap.values()); + } + + public List getPackagesSortedByName() + { + PackageComparator comp = new PackageComparator(); + List packages = getPackages(); + Collections.sort(packages, comp); + return packages; + } + + public List getSubPackage(Package thePackage) + { + ArrayList subPkgList = new ArrayList(); + for (Iterator iter = getPackagesSortedByName().iterator(); iter.hasNext(); ) + { + Package pkg = (Package) iter.next(); + if (pkg.getName().startsWith(thePackage.getName()) + && !pkg.getName().equals(thePackage.getName())) + { + subPkgList.add(pkg); + } + } + return subPkgList; + } + + public String getCoveredPercentLine() + { + double total = 0.00d; + for (Iterator iter = getClasses().iterator(); iter.hasNext(); ) + { + Clazz theClass = (Clazz) iter.next(); + total += new Double(theClass.getLineRate()).floatValue(); + } + return String.valueOf(total / getClasses().size()); + } + + public String getCoveredPercentBranch() + { + double total = 0.00d; + for (Iterator iter = getClasses().iterator(); iter.hasNext(); ) + { + Clazz theClass = (Clazz) iter.next(); + total += new Double(theClass.getBranchRate()).floatValue(); + } + return String.valueOf(total / getClasses().size()); + } +} diff --git a/jcoverage/src/main/org/apache/maven/jcoveragereport/CoverageReport.java b/jcoverage/src/main/org/apache/maven/jcoveragereport/CoverageReport.java new file mode 100644 index 00000000..4098ce54 --- /dev/null +++ b/jcoverage/src/main/org/apache/maven/jcoveragereport/CoverageReport.java @@ -0,0 +1,506 @@ +package org.apache.maven.jcoveragereport; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache Maven" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache Maven", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * ==================================================================== + */ + +import java.io.*; +import java.text.NumberFormat; +import java.util.*; + +import org.apache.oro.text.perl.Perl5Util; + +/** + * @author Emmanuel Venisse + * @version $Id: CoverageReport.java,v 1.1 2003/09/03 16:27:14 evenisse Exp $ + */ +public class CoverageReport +{ + private Coverage coverage; + + public CoverageReport(Coverage coverage) + { + this.coverage = coverage; + } + + public void generate(String dir) throws IOException + { + File directory = new File(dir); + directory.mkdirs(); + + generateSourceFiles(directory); + generateFrameset(directory); + generatePackageList(directory); + generateClassList(directory); + generateOverview(directory); + } + + private void generateFrameset(File dir) throws IOException + { + File fsFile = new File(dir, "index.html"); + PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(fsFile))); + pw.println(""); + pw.println(""); + pw.println("unit tests coverage report"); + pw.println(""); + pw.println(""); + pw.println(""); + pw.println(""); + pw.println(""); + pw.println(""); + pw.println(""); + pw.println(""); + pw.println("This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client."); + pw.println("<BR>"); + pw.println("Link to<A HREF=\"overview-summary.html\">Non-frame version.</A>"); + pw.println(""); + pw.println(""); + pw.println(""); + pw.close(); + } + + private void generatePackageList(File dir) throws IOException + { + File fsFile = new File(dir, "overview-frame.html"); + PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(fsFile))); + pw.println(""); + pw.println(""); + pw.println("unit tests coverage report"); + pw.println(""); + pw.println(""); + pw.println(""); + pw.println("Coverage report"); + pw.println(""); + pw.println(""); + pw.println(""); + pw.println(""); + pw.println("
"); + pw.println("Overview
"); + pw.println("All classes"); + pw.println("
"); + pw.println("

"); + pw.println(""); + pw.println(""); + pw.println(""); + pw.println(""); + pw.println(""); + pw.println(""); + pw.println(""); + pw.println("
All packages
"); + + for (Iterator iter = coverage.getPackagesSortedByName().iterator(); iter.hasNext(); ) + { + Package pkg = (Package) iter.next(); + String url = pkg.getDirectory() + "/package-frame.html"; + pw.println("" + pkg.getName() + "
"); + } + + pw.println("
"); + pw.println(""); + pw.println(""); + pw.close(); + + for (Iterator iter = coverage.getPackagesSortedByName().iterator(); iter.hasNext(); ) + { + Package pkg = (Package) iter.next(); + generateClassList(dir, pkg); + generateOverview(dir, pkg); + } + } + + private void generateClassList(File dir) throws IOException + { + generateClassList(dir, null); + } + + private void generateClassList(File dir, Package pkg) throws IOException + { + String filename; + String rootRef; + List classes; + String urlDirectory = ""; + if (pkg == null) + { + rootRef = ""; + filename = "allclasses-frame.html"; + classes = coverage.getClassesSortedByName(); + } + else + { + rootRef = getRelativePath(pkg.getName() + "/"); + filename = pkg.getDirectory() + "/package-frame.html"; + classes = pkg.getClassesSortedByName(); + urlDirectory = "."; + } + File fsFile = new File(dir, filename); + PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(fsFile))); + pw.println(""); + pw.println(""); + pw.println("unit tests coverage report"); + pw.println(""); + pw.println(""); + pw.println(""); + if (pkg != null) + { + pw.println("" + pkg.getName() + "
"); + pw.println("

"); + } + pw.println("All classes"); + pw.println(""); + pw.println(""); + pw.println(""); + pw.println(""); + pw.println("
"); + + for (Iterator iter = classes.iterator(); iter.hasNext(); ) + { + Clazz theClass = (Clazz) iter.next(); + if (pkg == null) + { + urlDirectory = theClass.getFile().substring(0, theClass.getFile().lastIndexOf("/")); + } + String classFilename = theClass.getName() + ".html"; + if (theClass.getFile().endsWith("/" + theClass.getName() + ".java")) + { + pw.println("" + theClass.getName() + " (" + getPercentValue(theClass.getLineRate()) + ")
"); + } + } + + pw.println("
"); + pw.println(""); + pw.println(""); + pw.close(); + } + + private void generateOverview(File dir) throws IOException + { + generateOverview(dir, null); + } + + private void generateOverview(File dir, Package thePackage) throws IOException + { + String filename = "overview-summary.html"; + String rootRef; + if (thePackage != null) + { + filename = thePackage.getDirectory() + "/package-summary.html"; + rootRef = getRelativePath(thePackage.getName() + "/"); + } + else + { + rootRef = ""; + } + File fsFile = new File(dir, filename); + PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(fsFile))); + pw.println(""); + pw.println(""); + pw.println("unit tests coverage report"); + pw.println(""); + pw.println(""); + pw.println(""); + pw.println("Coverage report"); + pw.println("

"); + pw.println(""); + pw.println(""); + pw.println(""); + pw.println(""); + pw.println(""); + pw.println(""); + pw.println(""); + pw.println(""); + if (thePackage != null) + { + pw.println(""); + pw.println(""); + pw.println(""); + pw.println(""); + } + else + { + pw.println(""); + pw.println(""); + pw.println(""); + pw.println(""); + } + pw.println(""); + List pkgList = null; + if (thePackage != null) + { + pkgList = coverage.getSubPackage(thePackage); + if (pkgList.size() > 0) + { + pw.println(""); + pw.println(""); + pw.println(""); + for (Iterator iter = pkgList.iterator(); iter.hasNext(); ) + { + Package pkg = (Package) iter.next(); + pw.println(""); + String subPkgDir = pkg.getDirectory().substring(thePackage.getDirectory().length() + 1); + pw.println(""); + pw.println(""); + pw.println(""); + pw.println(""); + pw.println(""); + } + } + if (thePackage.getClasses().size() > 0) + { + pw.println(""); + pw.println(""); + pw.println(""); + for (Iterator it = thePackage.getClassesSortedByName().iterator(); it.hasNext(); ) + { + Clazz cl = (Clazz) it.next(); + pw.println(""); + pw.println(""); + pw.println(""); + pw.println(""); + pw.println(""); + } + } + } + else + { + pkgList = coverage.getPackages(); + if (pkgList.size() > 0) + { + pw.println(""); + pw.println(""); + pw.println(""); + for (Iterator iter = coverage.getPackagesSortedByName().iterator(); iter.hasNext(); ) + { + Package pkg = (Package) iter.next(); + pw.println(""); + pw.println(""); + pw.println(""); + pw.println(""); + pw.println(""); + pw.println(""); + } + } + if (coverage.getClasses().size() > 0) + { + List classesList = new ArrayList(); + for (Iterator iter = coverage.getClassesSortedByName().iterator(); iter.hasNext(); ) + { + Clazz cl = (Clazz) iter.next(); + if (cl.getPackageName() == null + || cl.getPackageName().equals("")) + { + classesList.add(cl); + } + } + if (classesList.size() > 0) + { + pw.println(""); + pw.println(""); + pw.println(""); + for (Iterator iter = classesList.iterator(); iter.hasNext(); ) + { + Clazz cl = (Clazz) iter.next(); + pw.println(""); + pw.println(""); + pw.println(""); + pw.println(""); + pw.println(""); + } + } + } + } + pw.println("
 Files%line%branch
" + thePackage.getName() + "" + thePackage.getClasses().size() + "" + generatePercentResult(getPercentValue(thePackage.getCoveredPercentLine())) + "" + generatePercentResult(getPercentValue(thePackage.getCoveredPercentBranch())) + "Project" + coverage.getClasses().size() + "" + generatePercentResult(getPercentValue(coverage.getCoveredPercentLine())) + "" + generatePercentResult(getPercentValue(coverage.getCoveredPercentBranch())) + "
Packages
" + pkg.getName() + "" + pkg.getClasses().size() + "" + generatePercentResult(getPercentValue(pkg.getCoveredPercentLine())) + "" + generatePercentResult(getPercentValue(pkg.getCoveredPercentBranch())) + "
Classes
" + cl.getName() + "" + generatePercentResult(getPercentValue(cl.getLineRate())) + "" + generatePercentResult(getPercentValue(cl.getBranchRate())) + "
Packages
" + pkg.getName() + "" + pkg.getClasses().size() + "" + generatePercentResult(getPercentValue(pkg.getCoveredPercentLine())) + "" + generatePercentResult(getPercentValue(pkg.getCoveredPercentBranch())) + "
Classes
" + cl.getName() + "" + generatePercentResult(getPercentValue(cl.getLineRate())) + "" + generatePercentResult(getPercentValue(cl.getBranchRate())) + "
"); + pw.println(generateFooter()); + pw.println(""); + pw.println(""); + pw.close(); + } + + private void generateSourceFiles(File dir) throws IOException + { + for (Iterator iter = coverage.getClasses().iterator(); iter.hasNext(); ) + { + generateSourceFile(dir, (Clazz) iter.next()); + } + } + + private void generateSourceFile(File directory, Clazz theClass) throws IOException + { + String srcOutputFilename = theClass.getFile().substring(0, theClass.getFile().lastIndexOf(".")) + ".html"; + File srcOutputFile = new File(directory, srcOutputFilename); + File dirOutputFile = srcOutputFile.getParentFile(); + if (dirOutputFile != null) + { + dirOutputFile.mkdirs(); + } + + PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(srcOutputFile))); + pw.println(""); + pw.println(""); + pw.println("unit tests coverage"); + String rootRef = getRelativePath(theClass.getPackageName()); + pw.println(""); + pw.println(""); + pw.println(""); + pw.println("Coverage report"); + pw.println("

"); + pw.println(" "); + pw.println(" "); + pw.println(" "); + pw.println(" "); + pw.println(" "); + pw.println(" "); + pw.println(" "); + pw.println(" "); + pw.println(" "); + pw.println(" "); + pw.println(" "); + pw.println("
 %line%branch
" + theClass.getPackageName() + "." + theClass.getName() + "" + generatePercentResult(getPercentValue(theClass.getLineRate())) + "" + generatePercentResult(getPercentValue(theClass.getBranchRate())) + "
"); + pw.println("

"); + pw.println(" "); + + BufferedReader br = new BufferedReader(new FileReader(new File(coverage.getSrcDirectory(), theClass.getFile()))); + String lineStr; + int numLigne = 1; + while ((lineStr = br.readLine()) != null) + { + Line theLine = (Line) theClass.getLinesMap().get(new Integer(numLigne)); + int nbHits = 0; + if (theLine != null) + { + nbHits = theLine.getNbHits(); + } + pw.println(" "); + if (theLine != null) + { + pw.println(" "); + if (nbHits > 0) + { + pw.println(" "); + pw.println(" "); + } + else + { + pw.println(" "); + pw.println(" "); + } + } + else + { + pw.println(" "); + pw.println(" "); + pw.println(" "); + } + pw.println(" "); + numLigne++; + } + pw.println("
 " + numLigne + " " + theLine.getNbHits() + "
 " + JavaToHtml.syntaxHighlight(lineStr) + "
 " + theLine.getNbHits() + "
 "+ JavaToHtml.syntaxHighlight(lineStr) + "
 " + numLigne + " 
 " +  JavaToHtml.syntaxHighlight(lineStr) + "
"); + pw.println(generateFooter()); + pw.println(""); + pw.println(""); + pw.close(); + } + + private String generateFooter() + { + StringBuffer sb = new StringBuffer(); + sb.append("

"); + sb.append(""); + sb.append(" "); + sb.append(" "); + sb.append(" "); + sb.append("
"); + sb.append(" This report is generated by jcoverage, Maven and Maven JCoverage Plugin."); + sb.append("
"); + return sb.toString(); + } + + private String generatePercentResult(String percentValue) + { + if (percentValue.endsWith("%")) + { + percentValue = percentValue.substring(0, percentValue.length() - 1); + } + double rest = 100d - new Double(percentValue).doubleValue(); + StringBuffer sb = new StringBuffer(); + sb.append(""); + sb.append(""); + sb.append(""); + sb.append(""); + sb.append(""); + sb.append("
" + percentValue + "% "); + sb.append(""); + sb.append(""); + sb.append(""); + sb.append(""); + sb.append(""); + sb.append("
"); + sb.append("
"); + return sb.toString(); + } + + private String getRelativePath(String path) + { + return new Perl5Util().substitute("s/[^\\.]*(\\.|$)/\\.\\.\\//g", path); + } + + private String getPercentValue(String value) + { + Double percent = new Double(value); + NumberFormat percentFormatter; + + percentFormatter = NumberFormat.getPercentInstance(); + return percentFormatter.format(percent); + } +} diff --git a/jcoverage/src/main/org/apache/maven/jcoveragereport/CoverageReportGenerator.java b/jcoverage/src/main/org/apache/maven/jcoveragereport/CoverageReportGenerator.java new file mode 100644 index 00000000..5661dada --- /dev/null +++ b/jcoverage/src/main/org/apache/maven/jcoveragereport/CoverageReportGenerator.java @@ -0,0 +1,149 @@ +package org.apache.maven.jcoveragereport; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache Maven" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache Maven", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * ==================================================================== + */ + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.PrintWriter; + +/** + * @author Emmanuel Venisse + * @version $Id: CoverageReportGenerator.java,v 1.1 2003/09/03 16:27:14 evenisse Exp $ + */ +public class CoverageReportGenerator +{ + private String dataFile; + private String outputDir; + + public void setDataFile(String dataFile) + { + this.dataFile = dataFile; + } + + public String getDataFile() + { + return dataFile; + } + + public void setOutputDir(String dir) + { + this.outputDir = dir; + } + + public String getOutputDir() + { + return outputDir; + } + + public void execute() throws Exception + { + System.out.println("Generate report for " + dataFile + " file."); + System.out.println("OutputDir = " + outputDir); + try + { + prepareFile(); + FileReader fr = new FileReader(dataFile); + CoverageUnmarshaller cum = new CoverageUnmarshaller(); + Coverage coverage = cum.parse(fr); + + CoverageReport cr = new CoverageReport(coverage); + cr.generate(outputDir); + } + catch (Exception e) + { + System.out.println("2 bis"); + e.printStackTrace(); + } + } + + /* + * Rewrite all lines of coverage.xml file for obtain a xml well formed + */ + private void prepareFile() throws Exception + { + BufferedReader br = new BufferedReader(new FileReader(dataFile)); + PrintWriter pw = new PrintWriter(new FileOutputStream(dataFile + ".new")); + String line; + while ((line = br.readLine()) != null) + { + line = replace(line, "", "<init>", 0); + line = replace(line, "", "<clinit>", 0); + pw.println(line); + } + pw.close(); + br.close(); + File fSrc = new File(dataFile); + File fNew = new File(dataFile + ".new"); + fSrc.delete(); + fNew.renameTo(fSrc); + } + + private String replace( String line, String oldString, String newString, int startAt ) + { + int i = startAt; + while ((i = line.indexOf(oldString, i)) >= 0) + { + line = (new StringBuffer().append(line.substring(0, i)) + .append(newString) + .append(line.substring(i + oldString.length()))).toString(); + i += newString.length(); + } + return line; + } +} diff --git a/jcoverage/src/main/org/apache/maven/jcoveragereport/CoverageUnmarshaller.java b/jcoverage/src/main/org/apache/maven/jcoveragereport/CoverageUnmarshaller.java new file mode 100644 index 00000000..a9011b62 --- /dev/null +++ b/jcoverage/src/main/org/apache/maven/jcoveragereport/CoverageUnmarshaller.java @@ -0,0 +1,159 @@ +package org.apache.maven.jcoveragereport; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache Maven" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache Maven", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * ==================================================================== + */ + +import java.io.Reader; + +import org.xmlpull.v1.XmlPullParser; +import org.xmlpull.v1.XmlPullParserFactory; + +/** + * @author Emmanuel Venisse + * @version $Id: CoverageUnmarshaller.java,v 1.1 2003/09/03 16:27:14 evenisse Exp $ + */ +public class CoverageUnmarshaller +{ + public Coverage parse(Reader reader) throws Exception + { + Coverage coverage = new Coverage(); + + XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); + XmlPullParser parser = factory.newPullParser(); + parser.setInput(reader); + + int eventType = parser.getEventType(); + + while (eventType != XmlPullParser.END_DOCUMENT) + { + if (eventType == XmlPullParser.START_TAG) + { + if (parser.getName().equals("coverage")) + { + coverage.setSrcDirectory(parser.getAttributeValue("", "src")); + } + if (parser.getName().equals("class")) + { + Clazz theClass = new Clazz(parser.getAttributeValue("", "name")); + while (parser.nextTag() == XmlPullParser.START_TAG) + { + if (parser.getName().equals("file")) + { + String fileName = parser.getAttributeValue("", "name"); + theClass.setFile(fileName); + } + else if (parser.getName().equals("line") + && parser.getAttributeCount() == 1) + { + theClass.setLineRate( + parser.getAttributeValue("", "rate")); + } + else if (parser.getName().equals("line") + && parser.getAttributeCount() == 2) + { + Line line = new Line(); + line.setNumLine( + Integer.valueOf( + parser.getAttributeValue("", "number") + ).intValue()); + line.setNbHits( + Integer.valueOf( + parser.getAttributeValue("", "hits") + ).intValue()); + theClass.addLine(line); + } + else if (parser.getName().equals("branch")) + { + theClass.setBranchRate( + parser.getAttributeValue("", "rate")); + } + if (parser.getName().equals("methods")) + { + while (parser.nextTag() == XmlPullParser.START_TAG) + { + if (parser.getName().equals("method")) + { + while (parser.nextTag() == XmlPullParser.START_TAG) + { + if (parser.getName().equals("line")) + { + //nothing + } + else if (parser.getName().equals("branch")) + { + //nothing + } + parser.next(); + } + } + parser.next(); + } + } + else + { + parser.next(); + } + } + coverage.addClass(theClass); + } + } + + eventType = parser.next(); + } + + return coverage; + } +} diff --git a/jcoverage/src/main/org/apache/maven/jcoveragereport/JavaToHtml.java b/jcoverage/src/main/org/apache/maven/jcoveragereport/JavaToHtml.java new file mode 100644 index 00000000..48c6e861 --- /dev/null +++ b/jcoverage/src/main/org/apache/maven/jcoveragereport/JavaToHtml.java @@ -0,0 +1,395 @@ +package org.apache.maven.jcoveragereport; + +/** + * CodeViewer.java + * + * Bill Lynch & Matt Tucker + * CoolServlets.com, October 1999 + * + * Please visit CoolServlets.com for high quality, open source Java servlets. + * + * Copyright (C) 1999 CoolServlets.com + * + * Any errors or suggested improvements to this class can be reported + * as instructed on Coolservlets.com. We hope you enjoy + * this program... your comments will encourage further development! + * + * This software is distributed under the terms of The BSD License. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither name of CoolServlets.com nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY COOLSERVLETS.COM AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL COOLSERVLETS.COM OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import java.util.HashMap; + +public class JavaToHtml +{ + private static HashMap reservedWords = new HashMap(); + private static boolean inMultiLineComment = false; + private static String commentStart = ""; + private static String commentEnd = ""; + private static String stringStart = ""; + private static String stringEnd = ""; + private static String reservedWordStart = ""; + private static String reservedWordEnd = ""; + + static + { + loadHash(); + } + + /** + * Passes off each line to the first filter. + * @param line The line of Java code to be highlighted. + * @return Highlighted line. + */ + public static String syntaxHighlight( String line ) + { + return htmlFilter(line); + } + + /* + * Filter html tags into more benign text. + */ + private static String htmlFilter(String line) + { + if (line == null || line.equals("")) + { + return ""; + } + + // replace ampersands with HTML escape sequence for ampersand; + line = replace(line, "&", "&"); + + // replace the \\ with HTML escape sequences. fixes a problem when + // backslashes preceed quotes. + line = replace(line, "\\\\", "\\" ); + + // replace \" sequences with HTML escape sequences; + line = replace(line, "" + (char) 92 + (char) 34, "\""); + + // replace less-than signs which might be confused + // by HTML as tag angle-brackets; + line = replace(line, "<", "<"); + // replace greater-than signs which might be confused + // by HTML as tag angle-brackets; + line = replace(line, ">", ">"); + + return multiLineCommentFilter(line); + } + + /* + * Filter out multiLine comments. State is kept with a private boolean + * variable. + */ + private static String multiLineCommentFilter(String line) + { + if (line == null || line.equals("")) + { + return ""; + } + StringBuffer buf = new StringBuffer(); + int index; + //First, check for the end of a multi-line comment. + if (inMultiLineComment && (index = line.indexOf("*/")) > -1 && !isInsideString(line, index)) + { + inMultiLineComment = false; + buf.append(commentStart); + buf.append(line.substring(0, index)); + buf.append("*/").append(commentEnd); + if (line.length() > index + 2) + { + buf.append(inlineCommentFilter(line.substring(index + 2))); + } + return buf.toString(); + } + //If there was no end detected and we're currently in a multi-line + //comment, we don't want to do anymore work, so return line. + else if (inMultiLineComment) + { + buf.append(commentStart); + buf.append(line); + buf.append(commentEnd); + return buf.toString(); + } + //We're not currently in a comment, so check to see if the start + //of a multi-line comment is in this line. + else if ((index = line.indexOf("/*")) > -1 && !isInsideString(line, index)) + { + inMultiLineComment = true; + //Return result of other filters + everything after the start + //of the multiline comment. We need to pass the through the + //to the multiLineComment filter again in case the comment ends + //on the same line. + buf.append(inlineCommentFilter(line.substring(0, index))); + buf.append(commentStart).append("/*"); + buf.append(multiLineCommentFilter(line.substring(index + 2))); + buf.append(commentEnd); + return buf.toString(); + } + //Otherwise, no useful multi-line comment information was found so + //pass the line down to the next filter for processesing. + else + { + return inlineCommentFilter(line); + } + } + + /* + * Filter inline comments from a line and formats them properly. + */ + private static String inlineCommentFilter(String line) + { + if (line == null || line.equals("")) + { + return ""; + } + StringBuffer buf = new StringBuffer(); + int index; + if ((index = line.indexOf("//")) > -1 && !isInsideString(line, index)) + { + buf.append(stringFilter(line.substring(0, index))); + buf.append(commentStart); + buf.append(line.substring(index)); + buf.append(commentEnd); + } + else + { + buf.append(stringFilter(line)); + } + return buf.toString(); + } + + /* + * Filters strings from a line of text and formats them properly. + */ + private static String stringFilter(String line) + { + if (line == null || line.equals("")) + { + return ""; + } + StringBuffer buf = new StringBuffer(); + if (line.indexOf("\"") <= -1) + { + return keywordFilter(line); + } + int start = 0; + int startStringIndex = -1; + int endStringIndex = -1; + int tempIndex; + //Keep moving through String characters until we want to stop... + while ((tempIndex = line.indexOf("\"")) > -1) + { + //We found the beginning of a string + if (startStringIndex == -1) + { + startStringIndex = 0; + buf.append(stringFilter(line.substring(start, tempIndex))); + buf.append(stringStart).append("\""); + line = line.substring(tempIndex + 1); + } + //Must be at the end + else + { + startStringIndex = -1; + endStringIndex = tempIndex; + buf.append(line.substring(0, endStringIndex + 1)); + buf.append(stringEnd); + line = line.substring(endStringIndex + 1); + } + } + + buf.append(keywordFilter(line)); + + return buf.toString(); + } + + /* + * Filters keywords from a line of text and formats them properly. + */ + private static String keywordFilter( String line ) + { + if (line == null || line.equals("")) + { + return ""; + } + StringBuffer buf = new StringBuffer(); + HashMap usedReservedWords = new HashMap(); // >= Java2 only (not thread-safe) + //Hashtable usedReservedWords = new Hashtable(); // < Java2 (thread-safe) + int i = 0, startAt = 0; + char ch; + StringBuffer temp = new StringBuffer(); + while (i < line.length()) + { + temp.setLength(0); + ch = line.charAt(i); + startAt = i; + // 65-90, uppercase letters + // 97-122, lowercase letters + while (i < line.length() && ((ch >= 65 && ch <= 90 ) + || (ch >= 97 && ch <= 122))) + { + temp.append(ch); + i++; + if (i < line.length()) + { + ch = line.charAt(i); + } + } + String tempString = temp.toString(); + if (reservedWords.containsKey(tempString) && !usedReservedWords.containsKey(tempString)) + { + usedReservedWords.put(tempString, tempString); + line = replace(line, tempString, (reservedWordStart + tempString + reservedWordEnd), startAt); + i += (reservedWordStart.length() + reservedWordEnd.length()); + } + else + { + i++; + } + } + buf.append(line); + return buf.toString(); + } + + /* + * All important replace method. Replaces all occurences of oldString in + * line with newString. + */ + private static String replace( String line, String oldString, String newString ) + { + return replace(line, oldString, newString, 0); + } + + /* + * All important replace method. Replaces all occurences of oldString in + * line with newString. + */ + private static String replace( String line, String oldString, String newString, int startAt ) + { + int i = startAt; + while ((i = line.indexOf(oldString, i)) >= 0) + { + line = (new StringBuffer().append(line.substring(0, i)) + .append(newString) + .append(line.substring(i + oldString.length()))).toString(); + i += newString.length(); + } + return line; + } + + /* + * Checks to see if some position in a line is between String start and + * ending characters. Not yet used in code or fully working :) + */ + private static boolean isInsideString(String line, int position) + { + if (line.indexOf("\"") < 0) + { + return false; + } + int index; + String left = line.substring(0, position); + String right = line.substring(position); + int leftCount = 0; + int rightCount = 0; + while ((index = left.indexOf("\"")) > -1) + { + leftCount++; + left = left.substring(index + 1); + } + while ((index = right.indexOf("\"")) > -1) + { + rightCount++; + right = right.substring(index + 1); + } + if (rightCount % 2 != 0 && leftCount % 2 != 0) + { + return true; + } + else + { + return false; + } + } + + /* + * Load Hashtable (or HashMap) with Java reserved words. + */ + private static void loadHash() + { + reservedWords.put( "abstract", "abstract" ); + reservedWords.put( "do", "do" ); + reservedWords.put( "inner", "inner" ); + reservedWords.put( "public", "public" ); + reservedWords.put( "var", "var" ); + reservedWords.put( "boolean", "boolean" ); + reservedWords.put( "continue", "continue" ); + reservedWords.put( "int", "int" ); + reservedWords.put( "return", "return" ); + reservedWords.put( "void", "void" ); + reservedWords.put( "break", "break" ); + reservedWords.put( "else", "else" ); + reservedWords.put( "interface", "interface" ); + reservedWords.put( "short", "short" ); + reservedWords.put( "volatile", "volatile" ); + reservedWords.put( "byvalue", "byvalue" ); + reservedWords.put( "extends", "extends" ); + reservedWords.put( "long", "long" ); + reservedWords.put( "static", "static" ); + reservedWords.put( "while", "while" ); + reservedWords.put( "case", "case" ); + reservedWords.put( "final", "final" ); + reservedWords.put( "native", "native" ); + reservedWords.put( "super", "super" ); + reservedWords.put( "transient", "transient" ); + reservedWords.put( "cast", "cast" ); + reservedWords.put( "float", "float" ); + reservedWords.put( "new", "new" ); + reservedWords.put( "rest", "rest" ); + reservedWords.put( "catch", "catch" ); + reservedWords.put( "for", "for" ); + reservedWords.put( "null", "null" ); + reservedWords.put( "synchronized", "synchronized" ); + reservedWords.put( "char", "char" ); + reservedWords.put( "finally", "finally" ); + reservedWords.put( "operator", "operator" ); + reservedWords.put( "this", "this" ); + reservedWords.put( "class", "class" ); + reservedWords.put( "generic", "generic" ); + reservedWords.put( "outer", "outer" ); + reservedWords.put( "switch", "switch" ); + reservedWords.put( "const", "const" ); + reservedWords.put( "goto", "goto" ); + reservedWords.put( "package", "package" ); + reservedWords.put( "throw", "throw" ); + reservedWords.put( "double", "double" ); + reservedWords.put( "if", "if" ); + reservedWords.put( "private", "private" ); + reservedWords.put( "true", "true" ); + reservedWords.put( "default", "default" ); + reservedWords.put( "import", "import" ); + reservedWords.put( "protected", "protected" ); + reservedWords.put( "try", "try" ); + } +} diff --git a/jcoverage/src/main/org/apache/maven/jcoveragereport/Line.java b/jcoverage/src/main/org/apache/maven/jcoveragereport/Line.java new file mode 100644 index 00000000..46f2668b --- /dev/null +++ b/jcoverage/src/main/org/apache/maven/jcoveragereport/Line.java @@ -0,0 +1,87 @@ +package org.apache.maven.jcoveragereport; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache Maven" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache Maven", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * ==================================================================== + */ + +/** + * @author Emmanuel Venisse + * @version $Id: Line.java,v 1.1 2003/09/03 16:27:14 evenisse Exp $ + */ +public class Line +{ + private int numLine; + private int nbHits; + + public void setNumLine(int num) + { + this.numLine = num; + } + + public int getNumLine() + { + return numLine; + } + + public void setNbHits(int nb) + { + this.nbHits = nb; + } + + public int getNbHits() + { + return nbHits; + } +} diff --git a/jcoverage/src/main/org/apache/maven/jcoveragereport/Main.java b/jcoverage/src/main/org/apache/maven/jcoveragereport/Main.java new file mode 100644 index 00000000..7ad4941f --- /dev/null +++ b/jcoverage/src/main/org/apache/maven/jcoveragereport/Main.java @@ -0,0 +1,72 @@ +package org.apache.maven.jcoveragereport; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache Maven" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache Maven", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * ==================================================================== + */ + +/** + * @author Emmanuel Venisse + * @version $Id: Main.java,v 1.1 2003/09/03 16:27:14 evenisse Exp $ + */ +public class Main +{ + public static void main(String[] args) throws Exception + { + CoverageReportGenerator generator = new CoverageReportGenerator(); + generator.setDataFile(args[0]); + generator.setOutputDir(args[1]); + generator.execute(); + } +} diff --git a/jcoverage/src/main/org/apache/maven/jcoveragereport/Package.java b/jcoverage/src/main/org/apache/maven/jcoveragereport/Package.java new file mode 100644 index 00000000..761a0f57 --- /dev/null +++ b/jcoverage/src/main/org/apache/maven/jcoveragereport/Package.java @@ -0,0 +1,143 @@ +package org.apache.maven.jcoveragereport; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache Maven" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache Maven", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * ==================================================================== + */ + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +/** + * @author Emmanuel Venisse + * @version $Id: Package.java,v 1.1 2003/09/03 16:27:15 evenisse Exp $ + */ +public class Package +{ + private List classes; + private String name; + private String directory; + + public Package(String name) + { + this.name = name; + classes = new ArrayList(); + } + + public void setName(String name) + { + this.name = name; + } + + public String getName() + { + return name; + } + + public void setDirectory(String directory) + { + this.directory = directory; + } + + public String getDirectory() + { + return directory; + } + + public boolean contains(Clazz theClass) + { + return classes.contains(theClass); + } + + public void addClass(Clazz theClass) + { + classes.add(theClass); + } + + public List getClasses() + { + return classes; + } + + public List getClassesSortedByName() + { + ClazzComparator comp = new ClazzComparator(); + Collections.sort(classes, comp); + return classes; + } + + public String getCoveredPercentLine() + { + double total = 0.00d; + for (Iterator iter = getClasses().iterator(); iter.hasNext(); ) + { + Clazz theClass = (Clazz) iter.next(); + total += new Double(theClass.getLineRate()).floatValue(); + } + return String.valueOf(total / getClasses().size()); + } + + public String getCoveredPercentBranch() + { + double total = 0.00d; + for (Iterator iter = getClasses().iterator(); iter.hasNext(); ) + { + Clazz theClass = (Clazz) iter.next(); + total += new Double(theClass.getBranchRate()).floatValue(); + } + return String.valueOf(total / getClasses().size()); + } +} diff --git a/jcoverage/src/main/org/apache/maven/jcoveragereport/PackageComparator.java b/jcoverage/src/main/org/apache/maven/jcoveragereport/PackageComparator.java new file mode 100644 index 00000000..2164d5ae --- /dev/null +++ b/jcoverage/src/main/org/apache/maven/jcoveragereport/PackageComparator.java @@ -0,0 +1,82 @@ +package org.apache.maven.jcoveragereport; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache Maven" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache Maven", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * ==================================================================== + */ + +import java.util.Comparator; + +/** + * @author Emmanuel Venisse + * @version $Id: PackageComparator.java,v 1.1 2003/09/03 16:27:15 evenisse Exp $ + */ +public class PackageComparator implements Comparator +{ + public int compare(Object package1, Object package2) + { + if (package1 instanceof Package && package2 instanceof Package) + { + Package p1 = (Package) package1; + Package p2 = (Package) package2; + String lower1 = p1.getName().toLowerCase(); + String lower2 = p2.getName().toLowerCase(); + return lower1.compareTo(lower2); + } + else + { + return -1; + } + } +} diff --git a/jcoverage/src/plugin-resources/style.css b/jcoverage/src/plugin-resources/style.css new file mode 100644 index 00000000..0a8cc271 --- /dev/null +++ b/jcoverage/src/plugin-resources/style.css @@ -0,0 +1,148 @@ +body { + font-family: verdana, arial, sans-serif + font-size: 12px; +} + +a { + font-size: 12px; +} + +table.src { + font-size: 12px; + border-left: #dcdcdc 1px solid; + border-right: #dcdcdc 1px solid; + border-bottom: #dcdcdc 1px solid; + border-top: #dcdcdc 1px solid; +} + +table.report { + font-size: 12px !important; + border-collapse: collapse; + width: 100%; +} + +tr.report { + border: #dcdcdc 1px solid; +} + +table.percentGraph { + height: 10px; +} + +th.report { + background: #F0F0F0; + font-size: inherit !important; + font-weight: bold; + border: #dcdcdc 1px solid; +} + +td.reportText { + font-size: inherit !important; + border: #dcdcdc 1px solid; +} + +td.reportValue { + font-size: inherit !important; + border: #dcdcdc 1px solid; + text-align: right; +} + +td.spacer { + border-left: #FF0000 0px none; + border-right: #FF0000 0px none; + height: 30px; + padding-top: 15px; +} + +td.percentCovered { + background: #00FF00; + empty-cells: show; +} + +td.percentUnCovered { + background: #FF0000; + empty-cells: show; +} + +td.numLine { + background: #F0F0F0; + border-right: #dcdcdc 1px solid; + padding-right: 3px; + text-align: right; +} + +td.numLineCover { + background: #80ff80; + border-right: #dcdcdc 1px solid; + padding-right: 3px; + text-align: right; +} + +td.nbHits { + background: #F0F0F0; + border-right: #dcdcdc 1px solid; + padding-right: 3px; + text-align: right; +} + +td.nbHitsCovered { + background: #80ff80; + border-right: #dcdcdc 1px solid; + padding-right: 3px; + text-align: right; +} + +td.nbHitsUncovered { + background: #FF8040; + border-right: #dcdcdc 1px solid; + padding-right: 3px; + text-align: right; +} + +td.src { + width: 100%; +} + +pre.src { + background: #ffffff; + margin-top: 0px; + margin-bottom: 0px; +} + +span.srcUncovered { + background: #FF8040; + border-right: #dcdcdc 1px solid; + padding-right: 3px; + text-align: right; +} + +span.keyword { + color: #0000ff; +} + +span.comment { + color: #008080; + font-style: italic; +} + +span.string { + color: #000000; +} + +span.title { + font-weight: bold; + font-size: 16px; +} + +span.title2 { + font-weight: bold; + font-size: 14px; +} +span.text { + font-size: 12px; +} + +span.text_italic { + font-size: 12px; + font-style: italic; +} diff --git a/jcoverage/xdocs/.cvsignore b/jcoverage/xdocs/.cvsignore new file mode 100644 index 00000000..cb6131bb --- /dev/null +++ b/jcoverage/xdocs/.cvsignore @@ -0,0 +1 @@ +stylesheets diff --git a/jcoverage/xdocs/goals.xml b/jcoverage/xdocs/goals.xml new file mode 100644 index 00000000..e20771d8 --- /dev/null +++ b/jcoverage/xdocs/goals.xml @@ -0,0 +1,40 @@ + + + + + Maven JCoverage plugin Goals + Dominik Dahlem + + + + + jcoverage + Generate HTML test coverage reports with JCoverage + + + jcoverage:html-report + Generate HTML test coverage reports with JCoverage + + + jcoverage:merge + Merge two or more instrumentation files into one + + + jcoverage:on + perform the coverage analysis + + + maven-jcoverage-plugin:deregister + Deregister the jcoverage plugin + + + maven-jcoverage-plugin:register + Register the maven-jcoverage-plugin. + + + maven-jcoverage-plugin:report + Run the default report (html). + + + + \ No newline at end of file diff --git a/jcoverage/xdocs/index.xml b/jcoverage/xdocs/index.xml new file mode 100644 index 00000000..788fa89f --- /dev/null +++ b/jcoverage/xdocs/index.xml @@ -0,0 +1,21 @@ + + + + + JCoverage Plugin + Dominik Dahlem + + +

+

+ The JCoverage tool is a free and easy to use source code coverage analyser. + It helps you to discover where your source-code lacks in test coverage. +

+

+ For more information regarding jcoverage check out the + + project homepage. +

+
+ + diff --git a/jcoverage/xdocs/navigation.xml b/jcoverage/xdocs/navigation.xml new file mode 100644 index 00000000..a5e53734 --- /dev/null +++ b/jcoverage/xdocs/navigation.xml @@ -0,0 +1,27 @@ + + + + + Dominik Dahlem + JCoverage Plugin + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jcoverage/xdocs/properties.xml b/jcoverage/xdocs/properties.xml new file mode 100644 index 00000000..10c65dd7 --- /dev/null +++ b/jcoverage/xdocs/properties.xml @@ -0,0 +1,77 @@ + + + + + JCoverage Plugin Properties + Dominik Dahlem + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
PropertyDefaultOptional?Description
maven.jcoverage.dir${maven.build.dir}/jcoverageYes + Specifies the root directory for jcoverage output files. +
maven.jcoverage.instrumentation${maven.jcoverage.dir}/classesYes + Specifies the build directory for the instrumented classes. +
maven.jcoverage.junit.forkyesYes + Specifies the fork attribute for the JUnit test for the coverage analysis. +
maven.jcoverage.merge.instrumentedFilesYes + Specifies the instrumented files list to be merge. Values are separated with commas. +
maven.jcoverage.merge.outputDirYes + Specifies the directory where the resulting jcoverage.ser will be output to. +
+
+ +