
org.jboss.maven.plugin.coverage.HtmlPrinter Maven / Gradle / Ivy
/*
* JBoss, Home of Professional Open Source
* Copyright 2015 Red Hat Inc. and/or its affiliates and other
* contributors as indicated by the @author tags. All rights reserved.
* See the copyright.txt in the distribution for a full listing of
* individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.maven.plugin.coverage;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.util.Map;
import java.util.Set;
/**
* @author Ales Justin
* @author Marko Luksa
*/
class HtmlPrinter implements Printer {
private Configuration configuration;
private File baseDir;
private File index;
private String module;
HtmlPrinter(Configuration configuration, File baseDir, File index, String module) {
this.configuration = configuration;
this.baseDir = baseDir;
this.index = index;
this.module = module;
}
@SuppressWarnings("ResultOfMethodCallIgnored")
public void print(Map>> report) throws Exception {
if (index.exists()) index.delete();
try (BufferedWriter writer = new BufferedWriter(new FileWriter(index))) {
writer.write("\n" +
"" +
"" + configuration.getCoverageTitle() + " Code Coverage " +
" \n" +
"\n" +
"");
writer.write("" + baseDir.getName() + "
");
for (String iface : report.keySet()) {
writer.append("");
writer.append("").append(iface).append("
");
Map> map = report.get(iface);
writer.write("");
for (Map.Entry> entry : map.entrySet()) {
String methodSignature = SignatureConverter.convertMethodSignature(entry.getKey().getMethodName(), entry.getKey().getMethodDesc());
String fullMethodSignature = SignatureConverter.convertFullMethodSignature(entry.getKey().getMethodName(), entry.getKey().getMethodDesc());
String methodJavaDocUrl = configuration.getJavadocRoot() + iface.replace('.', '/').replace('$', '.') + "#" + methodSignature;
writer.append("- ").append("").append("
").append(esc(fullMethodSignature)).append("
");
writer.append("");
Set value = entry.getValue();
if (value.isEmpty()) {
writer.append("- ").append("MISSING -- TODO?").append("
");
} else {
for (CodeLine cl : value) {
writer.append("- ").append(toLink(cl)).append("
");
}
}
writer.append("
");
writer.append(" ");
writer.newLine();
}
writer.write("
");
writer.write(" ");
}
writer.write("");
}
}
protected String toLink(CodeLine cl) {
String url = createGitHubUrl(
configuration.getRepositoryHost(),
configuration.getRepositoryUser(),
configuration.getRepositoryProject(),
configuration.getRepositoryBranch(),
getPath(cl),
cl.getLine()
);
StringBuilder sb = new StringBuilder(cl.getSimpleClassName());
sb.append(cl.getExt());
if (cl.getLine() > 0) {
sb.append(":");
sb.append(cl.getLine());
}
String text = esc(sb.toString());
return esc(cl.getClassName() + "." + cl.getMethodName()) + " (" + esc(text) + ")";
}
private String getPath(CodeLine cl) {
String className = cl.getClassName();
int p = className.indexOf("$"); // ignore inner classes
if (p > 0) {
className = className.substring(0, p);
}
return "/" + module + "/" + baseDir.getName() + "/src/test/" + cl.getType() + "/" + className.replace('.', '/') + cl.getExt();
}
private static String createGitHubUrl(String host, String user, String project, String branch, String path, int lineNumber) {
StringBuilder link = new StringBuilder("http://" + host + "/" + user + "/" + project + "/blob/" + branch + path);
if (lineNumber > 0) {
link.append("#L").append(lineNumber);
}
return link.toString();
}
static String esc(String token) {
token = token.replace("<", "<");
token = token.replace(">", ">");
return token;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy