The Cobertura HTMLReport.java source code
/*
* Cobertura - http://cobertura.sourceforge.net/
*
* Copyright (C) 2005 Mark Doliner
* Copyright (C) 2005 Grzegorz Lukasik
* Copyright (C) 2005 Jeremy Thomerson
* Copyright (C) 2006 Naoki Iwami
* Copyright (C) 2009 Charlie Squires
* Copyright (C) 2009 John Lewis
*
* Cobertura is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation; either version 2 of the License,
* or (at your option) any later version.
*
* Cobertura is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Cobertura; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
package net.sourceforge.cobertura.reporting.html;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.Vector;
import net.sourceforge.cobertura.coveragedata.ClassData;
import net.sourceforge.cobertura.coveragedata.CoverageData;
import net.sourceforge.cobertura.coveragedata.LineData;
import net.sourceforge.cobertura.coveragedata.PackageData;
import net.sourceforge.cobertura.coveragedata.ProjectData;
import net.sourceforge.cobertura.coveragedata.SourceFileData;
import net.sourceforge.cobertura.reporting.ComplexityCalculator;
import net.sourceforge.cobertura.reporting.html.files.CopyFiles;
import net.sourceforge.cobertura.util.FileFinder;
import net.sourceforge.cobertura.util.Header;
import net.sourceforge.cobertura.util.IOUtil;
import net.sourceforge.cobertura.util.Source;
import net.sourceforge.cobertura.util.StringUtil;
import org.apache.log4j.Logger;
public class HTMLReport
{
private static final Logger LOGGER = Logger.getLogger(HTMLReport.class);
private File destinationDir;
private FileFinder finder;
private ComplexityCalculator complexity;
private ProjectData projectData;
private String encoding;
/**
* Create a coverage report
* @param encoding
*/
public HTMLReport(ProjectData projectData, File outputDir,
FileFinder finder, ComplexityCalculator complexity, String encoding)
throws Exception
{
this.destinationDir = outputDir;
this.finder = finder;
this.complexity = complexity;
this.projectData = projectData;
this.encoding = encoding;
CopyFiles.copy(outputDir);
generatePackageList();
generateSourceFileLists();
generateOverviews();
generateSourceFiles();
}
private String generatePackageName(PackageData packageData)
{
if (packageData.getName().equals(""))
return "(default)";
return packageData.getName();
}
private void generatePackageList() throws IOException
{
File file = new File(destinationDir, "frame-packages.html");
PrintWriter out = null;
try
{
out = IOUtil.getPrintWriter(file);
out
.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"");
out
.println(" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
out
.println("<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">");
out.println("<head>");
out
.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />");
out.println("<title>Coverage Report");
out
.println("<link title=\"Style\" type=\"text/css\" rel=\"stylesheet\" href=\"css/main.css\" />");
out.println("</head>");
out.println("<body>");
out.println("<h5>Packages");
out.println("<table width=\"100%\">");
out.println("<tr>");
out
.println("<td nowrap=\"nowrap\">All