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:
1 parent
eb2f2555ab
commit
d6f346f0b3
23 files changed
+2686
No files matched your search
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -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\"> (" + 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\"> </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\"> </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\"> " + numLigne + "</td>");
|
||||
if (nbHits > 0)
|
||||
{
|
||||
pw.println(" <td class=\"nbHitsCovered\"> " + theLine.getNbHits() + "</td>");
|
||||
pw.println(" <td class=\"src\"><pre class=\"src\"> " + JavaToHtml.syntaxHighlight(lineStr) + "</pre></td>");
|
||||
}
|
||||
else
|
||||
{
|
||||
pw.println(" <td class=\"nbHitsUncovered\"> " + theLine.getNbHits() + "</td>");
|
||||
pw.println(" <td class=\"src\"><pre class=\"src\"><span class=\"srcUncovered\"> "+ JavaToHtml.syntaxHighlight(lineStr) + "</span></pre></td>");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pw.println(" <td class=\"numLine\"> " + numLigne + "</td>");
|
||||
pw.println(" <td class=\"nbHits\"> </td>");
|
||||
pw.println(" <td class=\"src\"><pre class=\"src\"> " + 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 + "% </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);
|
||||
}
|
||||
}
|
||||
@@ -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>", "<init>", 0);
|
||||
line = replace(line, "<clinit>", "<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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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, "&", "&");
|
||||
|
||||
// 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" );
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
Reference in new issue
Block a user