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
This commit is contained in:
evenisse 2003-09-03 16:27:15 +00:00
parent eb2f2555ab
commit d6f346f0b3
23 changed files with 2686 additions and 0 deletions

3
jcoverage/.cvsignore Normal file
View File

@ -0,0 +1,3 @@
target
velocity.log
maven.log

View File

@ -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

198
jcoverage/plugin.jelly Normal file
View File

@ -0,0 +1,198 @@
<?xml version="1.0"?>
<project
xmlns:j="jelly:core"
xmlns:ant="jelly:ant"
xmlns:log="jelly:log"
xmlns:maven="jelly:maven"
xmlns:define="jelly:define"
xmlns:jcoverage="jcoverage"
xmlns:u="jelly:util"
xmlns:doc="doc">
<define:taglib uri="jcoverage">
<define:jellybean
name="report"
className="org.apache.maven.jcoveragereport.CoverageReportGenerator"
method="execute"
/>
</define:taglib>
<!-- global definitions -->
<ant:path id="jcoverage.classpath">
<ant:pathelement path="${plugin.getDependencyPath('bcel')}"/>
<ant:pathelement path="${plugin.getDependencyPath('urbanophile:java-getopt')}"/>
<ant:pathelement path="${plugin.getDependencyPath('log4j')}"/>
<ant:pathelement path="${plugin.getDependencyPath('jcoverage')}"/>
<ant:pathelement path="${plugin.getDependencyPath('oro')}"/>
<ant:pathelement path="${plugin.getDependencyPath('junit')}"/>
</ant:path>
<ant:taskdef classpath="${plugin.getDependencyPath('jcoverage')}" resource="tasks.properties" />
<j:set var="maven.coverage.dir"
value="${pom.getPluginContext('maven-xdoc-plugin').getVariable('maven.docs.dest')}/jcoverage" />
<!-- ================================================================== -->
<!-- J C O V E R A G E R E P O R T D E -/R E G I S T R A T I O N -->
<!-- ================================================================== -->
<goal name="maven-jcoverage-plugin:register"
description="Register the maven-jcoverage-plugin.">
<doc:registerReport
name="JCoverage"
pluginName="maven-jcoverage-plugin"
link="jcoverage/index"
description="JCoverage test coverage report." />
</goal>
<goal name="maven-jcoverage-plugin:deregister"
description="Deregister the jcoverage plugin">
<doc:deregisterReport name="JCoverage" />
</goal>
<!-- ================================================================== -->
<!-- D E F A U L T R E P O R T -->
<!-- ================================================================== -->
<goal name="maven-jcoverage-plugin:report"
description="Run the default report (html).">
<attainGoal name="jcoverage:html-report" />
</goal>
<!-- ================================================================== -->
<!-- I N S T R U M E N T A T I O N -->
<!-- ================================================================== -->
<goal name="jcoverage:on" description="perform the coverage analysis"
prereqs="java:compile">
<j:catch var="ex">
<j:set var="instrumented" value="${maven.jcoverage.instrumentation}"/>
<j:set var="oldBuildDest" value="${maven.build.dest}"/>
<j:set var="fork" value="${maven.jcoverage.junit.fork}"/>
<j:set var="oldfork" value="${pom.getPluginContext('maven-test-plugin').getVariable('maven.junit.fork')}"/>
<!-- reset the maven.build.dest for the test plugin to find the instrumented classes -->
${pom.getPluginContext('maven-test-plugin').setVariable('maven.build.dest', instrumented)}
<!--
set the maven.junit.fork property
-->
${pom.getPluginContext('maven-test-plugin').setVariable('maven.junit.fork', fork)}
<ant:mkdir dir="${maven.coverage.dir}" />
<ant:mkdir dir="${maven.jcoverage.database.dir}" />
<ant:mkdir dir="${maven.jcoverage.instrumentation}" />
<log:info>instrumenting the class-files...</log:info>
<maven:addPath id="maven.dependency.classpath" refid="jcoverage.classpath"/>
<maven:addPath id="maven.dependency.classpath" refid="${pom.getDependencyClasspath()}"/>
<instrument todir="${maven.jcoverage.instrumentation}">
<ant:fileset dir="${maven.build.dest}">
<ant:include name="**/*.class" />
</ant:fileset>
<ant:classpath>
<ant:path refid="jcoverage.classpath"/>
</ant:classpath>
</instrument>
</j:catch>
<j:if test="${ex != null}">
<log:error>${ex}</log:error>
<ant:fail message="${ex}" />
</j:if>
<j:if test="${!pom.build.resources.isEmpty()}">
<maven:copy-resources
resources="${pom.build.resources}"
todir="${maven.jcoverage.instrumentation}"/>
</j:if>
</goal>
<!-- ================================================================== -->
<!-- D E F A U L T G O A L -->
<!-- ================================================================== -->
<goal name="jcoverage"
description="Generate HTML test coverage reports with JCoverage"
prereqs="jcoverage:html-report"
/>
<!-- ================================================================== -->
<!-- R E P O R T G O A L -->
<!-- ================================================================== -->
<goal name="jcoverage:html-report"
description="Generate HTML test coverage reports with JCoverage"
prereqs="jcoverage:on,test:test">
<j:catch var="ex">
<j:set var="template" value="${maven.jcoverage.report.template}"/>
<j:choose>
<j:when test="${template == 'jcoverage'}">
<report srcdir="${pom.build.sourceDirectory}" destdir="${maven.coverage.dir}">
<ant:classpath>
<ant:path refid="jcoverage.classpath"/>
</ant:classpath>
</report>
<log:info>jcoverage reports have been generated.</log:info>
<log:info>The HTML report is ${maven.build.coverage.dir}/index.html</log:info>
</j:when>
<j:otherwise>
<report srcdir="${pom.build.sourceDirectory}" destdir="${maven.jcoverage.dir}"
format="xml">
<ant:classpath>
<ant:path refid="jcoverage.classpath"/>
</ant:classpath>
</report>
<ant:copy file="${plugin.resources}/style.css" todir="${maven.coverage.dir}"/>
<jcoverage:report
dataFile="${maven.jcoverage.dir}/coverage.xml"
outputDir="${maven.coverage.dir}"/>
</j:otherwise>
</j:choose>
<!--
restore the maven.junit.fork property
-->
${pom.getPluginContext('maven-test-plugin').setVariable('maven.junit.fork', oldfork)}
<!--
restore the maven.build.dest property
-->
${pom.getPluginContext('maven-test-plugin').setVariable('maven.build.dest', oldBuildDest)}
</j:catch>
<j:if test="${ex != null}">
<log:error>${ex}</log:error>
<ant:fail message="${ex}" />
</j:if>
</goal>
<!-- ================================================================== -->
<!-- M E R G E G O A L -->
<!-- ================================================================== -->
<goal name="jcoverage:merge"
description="Merge two or more instrumentation files into one">
<java classname="com.jcoverage.tool.merge.Main">
<u:tokenize var="listOfinput" delim=",">${maven.jcoverage.merge.instrumentedFiles}</u:tokenize>
<j:forEach var="instrumentedFile" items="${listOfinput}">
<arg line="-i ${instrumentedFile}"/>
</j:forEach>
<arg line="-o ${maven.jcoverage.merge.outputDir}"/>
<classpath>
<path refid="jcoverage.classpath"/>
</classpath>
</java>
</goal>
</project>

View File

@ -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

View File

@ -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

115
jcoverage/project.xml Normal file
View File

@ -0,0 +1,115 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<project>
<extend>../project.xml</extend>
<pomVersion>3</pomVersion>
<id>maven-jcoverage-plugin</id>
<name>Maven JCoverage plugin</name>
<currentVersion>1.0</currentVersion>
<package>org.apache.maven.jcoveragereport</package>
<description>
This plugin provides coverage analysis of your source-code based on the open-source
jcoverage tool.
</description>
<shortDescription>
This plugin provides coverage analysis of your source-code based on the open-source
jcoverage tool.
</shortDescription>
<url>http://maven.apache.org/reference/plugins/jcoverage/</url>
<siteDirectory>/www/maven.apache.org/reference/plugins/jcoverage/</siteDirectory>
<repository>
<connection>scm:cvs:pserver:anoncvs@cvs.apache.org:/home/cvspublic:maven/src/plugins-build/jcoverage/</connection>
<url>http://cvs.apache.org/viewcvs/maven/src/plugins-build/jcoverage/</url>
</repository>
<developers>
<developer>
<name>Dominik Dahlem</name>
<id>dahlemd</id>
<email>Dominik.Dahlem@cs.tcd.ie</email>
<organization>Trinity College Dublin, Computer Science Department, Distributed Systems Group</organization>
<roles>
<role>Build Engineer, Java Developer</role>
</roles>
</developer>
<developer>
<name>Emmanuel Venisse</name>
<id>evenisse</id>
<email>evenisse@ifrance.com</email>
<organization></organization>
<roles>
<role>Java Developer</role>
</roles>
<timezone>+18</timezone>
</developer>
</developers>
<dependencies>
<dependency>
<groupId>jcoverage</groupId>
<artifactId>jcoverage</artifactId>
<version>1.0.5</version>
<properties>
<classloader>root</classloader>
</properties>
<url>http://www.jcoverage.com</url>
</dependency>
<dependency>
<groupId>velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.3</version>
<properties>
<classloader>root.maven</classloader>
</properties>
<url>http://jakarta.apache.org/velocity/</url>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.8</version>
<url>http://jakarta.apache.org/log4j/</url>
</dependency>
<dependency>
<groupId>bcel</groupId>
<artifactId>bcel</artifactId>
<version>5.1</version>
<url>http://jakarta.apache.org/bcel/</url>
</dependency>
<dependency>
<groupId>urbanophile</groupId>
<artifactId>java-getopt</artifactId>
<version>1.0.9</version>
<url>http://www.urbanophile.com/arenn/hacking/download.html</url>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<url>http://www.junit.org</url>
</dependency>
<dependency>
<groupId>oro</groupId>
<artifactId>oro</artifactId>
<version>2.0.7</version>
<url>http://jakarta.apache.org/oro/</url>
</dependency>
<dependency>
<groupId>xpp3</groupId>
<artifactId>xpp3</artifactId>
<version>1.1.2a</version>
<url>http://www.extreme.indiana.edu/xgws/xsoap/xpp/</url>
</dependency>
</dependencies>
<reports>
<report>maven-changes-plugin</report>
<report>maven-changelog-plugin</report>
<report>maven-file-activity-plugin</report>
<report>maven-developer-activity-plugin</report>
<report>maven-license-plugin</report>
</reports>
</project>

View File

@ -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
* <http://www.apache.org/>.
*
* ====================================================================
*/
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;
}
}

View File

@ -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
* <http://www.apache.org/>.
*
* ====================================================================
*/
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;
}
}
}

View File

@ -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
* <http://www.apache.org/>.
*
* ====================================================================
*/
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());
}
}

View File

@ -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
* <http://www.apache.org/>.
*
* ====================================================================
*/
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("<html>");
pw.println("<head>");
pw.println("<title>unit tests coverage report</title>");
pw.println("</head>");
pw.println("<FRAMESET cols=\"20%,80%\">");
pw.println("<FRAMESET rows=\"30%,70%\">");
pw.println("<FRAME src=\"overview-frame.html\" name=\"packageListFrame\" title=\"All Packages\">");
pw.println("<FRAME src=\"allclasses-frame.html\" name=\"packageFrame\" title=\"All classes and interfaces (except non-static nested types)\">");
pw.println("</FRAMESET>");
pw.println("<FRAME src=\"overview-summary.html\" name=\"classFrame\" title=\"Package, class and interface descriptions\" scrolling=\"yes\">");
pw.println("<NOFRAMES>");
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("</NOFRAMES>");
pw.println("</FRAMESET>");
pw.println("</html>");
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("<html>");
pw.println("<head>");
pw.println("<title>unit tests coverage report</title>");
pw.println("<link rel =\"stylesheet\" type=\"text/css\" href=\"style.css\" title=\"Style\">");
pw.println("</head>");
pw.println("<body>");
pw.println("<span class=\"title\">Coverage report</span>");
pw.println("<table>");
pw.println("<tr>");
pw.println("<td nowrap=\"nowrap\">");
pw.println("<a href=\"overview-summary.html\" target=\"classFrame\">Overview</a><br>");
pw.println("<a href=\"allclasses-frame.html\" target=\"packageFrame\">All classes</a>");
pw.println("</td>");
pw.println("</tr>");
pw.println("</table>");
pw.println("<p>");
pw.println("<table>");
pw.println("<tr>");
pw.println("<td nowrap=\"nowrap\"><span class=\"title2\">All packages</span></td>");
pw.println("</tr>");
pw.println("<tr>");
pw.println("<td nowrap=\"nowrap\">");
for (Iterator iter = coverage.getPackagesSortedByName().iterator(); iter.hasNext(); )
{
Package pkg = (Package) iter.next();
String url = pkg.getDirectory() + "/package-frame.html";
pw.println("<a href=\"" + url + "\" target=\"packageFrame\">" + pkg.getName() + "</a><br>");
}
pw.println("</td>");
pw.println("</tr>");
pw.println("</table>");
pw.println("</body>");
pw.println("</html>");
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("<html>");
pw.println("<head>");
pw.println("<title>unit tests coverage report</title>");
pw.println("<link rel =\"stylesheet\" type=\"text/css\" href=\"" + rootRef + "style.css\" title=\"Style\">");
pw.println("</head>");
pw.println("<body>");
if (pkg != null)
{
pw.println("<a href=\"package-summary.html\" target=\"classFrame\">" + pkg.getName() + "</a><br>");
pw.println("<p>");
}
pw.println("<span class=\"title\">All classes</span>");
pw.println("<table>");
pw.println("<tr>");
pw.println("<td nowrap=\"nowrap\">");
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("<a href=\"" + urlDirectory + "/" + classFilename + "\" target=\"classFrame\">" + theClass.getName() + "</a><span class=\"text_italic\">&nbsp;(" + getPercentValue(theClass.getLineRate()) + ")</span><br>");
}
}
pw.println("</td>");
pw.println("</tr>");
pw.println("</table>");
pw.println("</body>");
pw.println("</html>");
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("<html>");
pw.println("<head>");
pw.println("<title>unit tests coverage report</title>");
pw.println("<link rel =\"stylesheet\" type=\"text/css\" href=\"" + rootRef + "style.css\" title=\"Style\">");
pw.println("</head>");
pw.println("<body>");
pw.println("<span class=\"title\">Coverage report</span>");
pw.println("<p>");
pw.println("<table class=\"report\" cellpadding=\"0\" cellspacing=\"0\">");
pw.println("<tr class=\"report\">");
pw.println("<th class=\"report\">&nbsp;</th>");
pw.println("<th class=\"report\">Files</th>");
pw.println("<th class=\"report\">%line</th>");
pw.println("<th class=\"report\">%branch</th>");
pw.println("</tr>");
pw.println("<tr class=\"report\">");
if (thePackage != null)
{
pw.println("<td class=\"reportText\">" + thePackage.getName() + "</td>");
pw.println("<td class=\"reportValue\">" + thePackage.getClasses().size() + "</td>");
pw.println("<td class=\"reportValue\">" + generatePercentResult(getPercentValue(thePackage.getCoveredPercentLine())) + "</td>");
pw.println("<td class=\"reportValue\">" + generatePercentResult(getPercentValue(thePackage.getCoveredPercentBranch())) + "</td>");
}
else
{
pw.println("<td class=\"reportText\">Project</td>");
pw.println("<td class=\"reportValue\">" + coverage.getClasses().size() + "</td>");
pw.println("<td class=\"reportValue\">" + generatePercentResult(getPercentValue(coverage.getCoveredPercentLine())) + "</td>");
pw.println("<td class=\"reportValue\">" + generatePercentResult(getPercentValue(coverage.getCoveredPercentBranch())) + "</td>");
}
pw.println("</tr>");
List pkgList = null;
if (thePackage != null)
{
pkgList = coverage.getSubPackage(thePackage);
if (pkgList.size() > 0)
{
pw.println("<tr>");
pw.println("<td class=\"spacer\" colspan=\"4\"><span class=\"title2\">Packages</span></td>");
pw.println("</tr>");
for (Iterator iter = pkgList.iterator(); iter.hasNext(); )
{
Package pkg = (Package) iter.next();
pw.println("<tr class=\"report\">");
String subPkgDir = pkg.getDirectory().substring(thePackage.getDirectory().length() + 1);
pw.println("<td class=\"reportText\"><a href=\"" + subPkgDir + "/package-summary.html\">" + pkg.getName() + "</a></td>");
pw.println("<td class=\"reportValue\">" + pkg.getClasses().size() + "</td>");
pw.println("<td class=\"reportValue\">" + generatePercentResult(getPercentValue(pkg.getCoveredPercentLine())) + "</td>");
pw.println("<td class=\"reportValue\">" + generatePercentResult(getPercentValue(pkg.getCoveredPercentBranch())) + "</td>");
pw.println("</tr>");
}
}
if (thePackage.getClasses().size() > 0)
{
pw.println("<tr>");
pw.println("<td class=\"spacer\" colspan=\"4\"><span class=\"title2\">Classes</span></td>");
pw.println("</tr>");
for (Iterator it = thePackage.getClassesSortedByName().iterator(); it.hasNext(); )
{
Clazz cl = (Clazz) it.next();
pw.println("<tr class=\"report\">");
pw.println("<td class=\"reportText\" colspan=\"2\"><a href=\"" + cl.getName() + ".html\">" + cl.getName() + "</a></td>");
pw.println("<td class=\"reportValue\">" + generatePercentResult(getPercentValue(cl.getLineRate())) + "</td>");
pw.println("<td class=\"reportValue\">" + generatePercentResult(getPercentValue(cl.getBranchRate())) + "</td>");
pw.println("</tr>");
}
}
}
else
{
pkgList = coverage.getPackages();
if (pkgList.size() > 0)
{
pw.println("<tr>");
pw.println("<td class=\"spacer\" colspan=\"4\"><span class=\"title2\">Packages</span></td>");
pw.println("</tr>");
for (Iterator iter = coverage.getPackagesSortedByName().iterator(); iter.hasNext(); )
{
Package pkg = (Package) iter.next();
pw.println("<tr class=\"report\">");
pw.println("<td class=\"reportText\"><a href=\"" + pkg.getDirectory() + "/package-summary.html\">" + pkg.getName() + "</a></td>");
pw.println("<td class=\"reportValue\">" + pkg.getClasses().size() + "</td>");
pw.println("<td class=\"reportValue\">" + generatePercentResult(getPercentValue(pkg.getCoveredPercentLine())) + "</td>");
pw.println("<td class=\"reportValue\">" + generatePercentResult(getPercentValue(pkg.getCoveredPercentBranch())) + "</td>");
pw.println("</tr>");
}
}
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("<tr>");
pw.println("<td class=\"spacer\" colspan=\"4\"><span class=\"title2\">Classes</span></td>");
pw.println("</tr>");
for (Iterator iter = classesList.iterator(); iter.hasNext(); )
{
Clazz cl = (Clazz) iter.next();
pw.println("<tr class=\"report\">");
pw.println("<td class=\"reportText\" colspan=\"2\"><a href=\"" + cl.getName() + ".html\">" + cl.getName() + "</a></td>");
pw.println("<td class=\"reportValue\">" + generatePercentResult(getPercentValue(cl.getLineRate())) + "</td>");
pw.println("<td class=\"reportValue\">" + generatePercentResult(getPercentValue(cl.getBranchRate())) + "</td>");
pw.println("</tr>");
}
}
}
}
pw.println("</table>");
pw.println(generateFooter());
pw.println("</body>");
pw.println("</html>");
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("<html>");
pw.println("<head>");
pw.println("<title>unit tests coverage</title>");
String rootRef = getRelativePath(theClass.getPackageName());
pw.println("<link rel =\"stylesheet\" type=\"text/css\" href=\"" + rootRef + "style.css\" title=\"Style\">");
pw.println("</head>");
pw.println("<body>");
pw.println("<span class=\"title\">Coverage report</span>");
pw.println("<p>");
pw.println(" <table cellspacing=\"0\" cellpadding=\"0\" class=\"report\">");
pw.println(" <tr class=\"report\">");
pw.println(" <th class=\"report\">&nbsp;</th>");
pw.println(" <th class=\"report\">%line</th>");
pw.println(" <th class=\"report\">%branch</th>");
pw.println(" </tr>");
pw.println(" <tr class=\"report\">");
pw.println(" <td class=\"reportText\"><span class=\"text\">" + theClass.getPackageName() + "." + theClass.getName() + "</span></td>");
pw.println(" <td class=\"reportValue\">" + generatePercentResult(getPercentValue(theClass.getLineRate())) + "</td>");
pw.println(" <td class=\"reportValue\">" + generatePercentResult(getPercentValue(theClass.getBranchRate())) + "</td>");
pw.println(" </tr>");
pw.println(" </table>");
pw.println(" <p>");
pw.println(" <table cellspacing=\"0\" cellpadding=\"0\" class=\"src\">");
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(" <tr>");
if (theLine != null)
{
pw.println(" <td class=\"numLineCover\">&nbsp;" + numLigne + "</td>");
if (nbHits > 0)
{
pw.println(" <td class=\"nbHitsCovered\">&nbsp;" + theLine.getNbHits() + "</td>");
pw.println(" <td class=\"src\"><pre class=\"src\">&nbsp;" + JavaToHtml.syntaxHighlight(lineStr) + "</pre></td>");
}
else
{
pw.println(" <td class=\"nbHitsUncovered\">&nbsp;" + theLine.getNbHits() + "</td>");
pw.println(" <td class=\"src\"><pre class=\"src\"><span class=\"srcUncovered\">&nbsp;"+ JavaToHtml.syntaxHighlight(lineStr) + "</span></pre></td>");
}
}
else
{
pw.println(" <td class=\"numLine\">&nbsp;" + numLigne + "</td>");
pw.println(" <td class=\"nbHits\">&nbsp;</td>");
pw.println(" <td class=\"src\"><pre class=\"src\">&nbsp;" + JavaToHtml.syntaxHighlight(lineStr) + "</pre></td>");
}
pw.println(" </tr>");
numLigne++;
}
pw.println(" </table>");
pw.println(generateFooter());
pw.println("</body>");
pw.println("</html>");
pw.close();
}
private String generateFooter()
{
StringBuffer sb = new StringBuffer();
sb.append("<p>");
sb.append("<table cellpadding=\"0\" cellspacing=\"0\" class=\"report\">");
sb.append(" <tr class=\"report\">");
sb.append(" <td class=\"reportText\"><span class=\"text\">");
sb.append(" This report is generated by <a href=\"http://www.jcoverage.com\">jcoverage</a>, <a href=\"http://maven.apache.org\">Maven</a> and <a href=\"http://maven.apache.org/reference/plugins/jcoverage/\">Maven JCoverage Plugin</a>.");
sb.append(" </span></td>");
sb.append(" </tr>");
sb.append("</table>");
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("<table class=\"percentGraph\" cellpadding=\"0\" cellspacing=\"0\" align=\"right\">");
sb.append("<tr>");
sb.append("<td><span class=\"text\">" + percentValue + "%&nbsp;</span></td>");
sb.append("<td>");
sb.append("<table class=\"percentGraph\" cellpadding=\"0\" cellspacing=\"0\">");
sb.append("<tr>");
sb.append("<td class=\"percentCovered\" width=\"" + percentValue + "\"></td>");
sb.append("<td class=\"percentUnCovered\" width=\"" + String.valueOf(rest) + "\"></td>");
sb.append("</tr>");
sb.append("</table>");
sb.append("</td>");
sb.append("</tr>");
sb.append("</table>");
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);
}
}

View File

@ -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
* <http://www.apache.org/>.
*
* ====================================================================
*/
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>", "&lt;init&gt;", 0);
line = replace(line, "<clinit>", "&lt;clinit&gt;", 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;
}
}

View File

@ -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
* <http://www.apache.org/>.
*
* ====================================================================
*/
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;
}
}

View File

@ -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 = "<span class=\"comment\">";
private static String commentEnd = "</span>";
private static String stringStart = "<span class=\"string\">";
private static String stringEnd = "</span>";
private static String reservedWordStart = "<span class=\"keyword\">";
private static String reservedWordEnd = "</span>";
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, "&", "&#38;");
// replace the \\ with HTML escape sequences. fixes a problem when
// backslashes preceed quotes.
line = replace(line, "\\\\", "&#92;&#92;" );
// replace \" sequences with HTML escape sequences;
line = replace(line, "" + (char) 92 + (char) 34, "&#92;&#34");
// replace less-than signs which might be confused
// by HTML as tag angle-brackets;
line = replace(line, "<", "&#60;");
// replace greater-than signs which might be confused
// by HTML as tag angle-brackets;
line = replace(line, ">", "&#62;");
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" );
}
}

View File

@ -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
* <http://www.apache.org/>.
*
* ====================================================================
*/
/**
* @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;
}
}

View File

@ -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
* <http://www.apache.org/>.
*
* ====================================================================
*/
/**
* @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();
}
}

View File

@ -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
* <http://www.apache.org/>.
*
* ====================================================================
*/
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());
}
}

View File

@ -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
* <http://www.apache.org/>.
*
* ====================================================================
*/
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;
}
}
}

View File

@ -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;
}

View File

@ -0,0 +1 @@
stylesheets

40
jcoverage/xdocs/goals.xml Normal file
View File

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<document>
<properties>
<title>Maven JCoverage plugin Goals</title>
<author email="Dominik.Dahlem@cs.tcd.ie">Dominik Dahlem</author>
</properties>
<body>
<goals>
<goal>
<name>jcoverage</name>
<description>Generate HTML test coverage reports with JCoverage</description>
</goal>
<goal>
<name>jcoverage:html-report</name>
<description>Generate HTML test coverage reports with JCoverage</description>
</goal>
<goal>
<name>jcoverage:merge</name>
<description>Merge two or more instrumentation files into one</description>
</goal>
<goal>
<name>jcoverage:on</name>
<description>perform the coverage analysis</description>
</goal>
<goal>
<name>maven-jcoverage-plugin:deregister</name>
<description>Deregister the jcoverage plugin</description>
</goal>
<goal>
<name>maven-jcoverage-plugin:register</name>
<description>Register the maven-jcoverage-plugin.</description>
</goal>
<goal>
<name>maven-jcoverage-plugin:report</name>
<description>Run the default report (html).</description>
</goal>
</goals>
</body>
</document>

21
jcoverage/xdocs/index.xml Normal file
View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<document>
<properties>
<title>JCoverage Plugin</title>
<author email="Dominik.Dahlem@cs.tcd.ie">Dominik Dahlem</author>
</properties>
<body>
<section name="JCoverage Plugin">
<p>
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.
</p>
<p>
For more information regarding jcoverage check out the
<a href="http://www.jcoverage.com" target="_blank">
project homepage</a>.
</p>
</section>
</body>
</document>

View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<project>
<properties>
<author email="Dominik.Dahlem@cs.tcd.ie">Dominik Dahlem</author>
<title>JCoverage Plugin</title>
</properties>
<body>
<links>
<item name="Maven" href="http://maven.apache.org/"/>
<item name="JCoverage" href="http://www.jcoverage.com/"/>
</links>
<menu name="Home">
<item name="JCoverage plugin Project" href="/index.html"/>
</menu>
<menu name="Overview">
<item name="Properties" href="/properties.html"/>
<item name="Goals" href="/goals.html"/>
</menu>
<menu name="Downloads">
<item name="JCoverage Plugin 1.0" href="http://www.ibiblio.org/maven/maven/plugins/maven-jcoverage-plugin-1.0.jar"/>
</menu>
</body>
</project>

View File

@ -0,0 +1,77 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<document>
<properties>
<title>JCoverage Plugin Properties</title>
<author email="Dominik.Dahlem@cs.tcd.ie">Dominik Dahlem</author>
</properties>
<body>
<section name="Plugin's properties">
<table>
<tr>
<th>Property</th>
<th>Default</th>
<th>Optional?</th>
<th>Description</th>
</tr>
<tr>
<td>maven.jcoverage.dir</td>
<td>${maven.build.dir}/jcoverage</td>
<td>Yes</td>
<td>
Specifies the root directory for jcoverage output files.
</td>
</tr>
<tr>
<td>maven.jcoverage.instrumentation</td>
<td>${maven.jcoverage.dir}/classes</td>
<td>Yes</td>
<td>
Specifies the build directory for the instrumented classes.
</td>
</tr>
<!--tr>
<td>maven.jcoverage.database.dir</td>
<td>${maven.jcoverage.dir}/database</td>
<td>Yes</td>
<td>
Specifies the directory for the JCoverage database.
</td>
</tr-->
<tr>
<td>maven.jcoverage.junit.fork</td>
<td>yes</td>
<td>Yes</td>
<td>
Specifies the fork attribute for the JUnit test for the coverage analysis.
</td>
</tr>
<!--tr>
<td>maven.jcoverage.ignore.packages</td>
<td>org.apache.log4j.*</td>
<td>Yes</td>
<td>
Specifies a semi-colon separated list of packages which should be
ignored while instrumenting.
</td>
</tr-->
<tr>
<td>maven.jcoverage.merge.instrumentedFiles</td>
<td></td>
<td>Yes</td>
<td>
Specifies the instrumented files list to be merge. Values are separated with commas.
</td>
</tr>
<tr>
<td>maven.jcoverage.merge.outputDir</td>
<td></td>
<td>Yes</td>
<td>
Specifies the directory where the resulting jcoverage.ser will be output to.
</td>
</tr>
</table>
</section>
</body>
</document>