mockit.coverage.reporting.OutputFile Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jmockit Show documentation
Show all versions of jmockit Show documentation
JMockit is a Java toolkit for automated developer testing.
It contains APIs for the creation of the objects to be tested, for mocking dependencies, and for faking external
APIs; JUnit (4 & 5) and TestNG test runners are supported.
It also contains an advanced code coverage tool.
/*
* Copyright (c) 2006 Rogério Liesenfeld
* This file is subject to the terms of the MIT license (see LICENSE.txt).
*/
package mockit.coverage.reporting;
import java.io.*;
import java.util.regex.*;
import javax.annotation.*;
public final class OutputFile extends PrintWriter
{
private static final Pattern PATH_SEPARATOR = Pattern.compile("/");
@Nonnull private final String relPathToOutDir;
private final boolean withPrettyPrint;
public OutputFile(@Nonnull File file) throws IOException
{
super(file, "UTF-8");
relPathToOutDir = "";
withPrettyPrint = false;
}
public OutputFile(@Nonnull String outputDir, @Nonnull String sourceFilePath) throws IOException
{
super(getOutputFileCreatingDirIfNeeded(outputDir, sourceFilePath));
relPathToOutDir = getRelativeSubPathToOutputDir(sourceFilePath);
withPrettyPrint = true;
}
@Nonnull
private static File getOutputFileCreatingDirIfNeeded(@Nonnull String outputDir, @Nonnull String sourceFilePath)
{
File outputFile = getOutputFile(outputDir, sourceFilePath);
File parentDir = outputFile.getParentFile();
if (!parentDir.exists()) {
boolean outputDirCreated = parentDir.mkdirs();
assert outputDirCreated : "Failed to create output dir: " + outputDir;
}
return outputFile;
}
@Nonnull
static File getOutputFile(@Nonnull String outputDir, @Nonnull String sourceFilePath)
{
int p = sourceFilePath.lastIndexOf('.');
String outputFileName = sourceFilePath.substring(0, p) + ".html";
File outputFile = new File(outputDir, outputFileName);
return outputFile;
}
@Nonnull
private static String getRelativeSubPathToOutputDir(@Nonnull String filePath)
{
StringBuilder cssRelPath = new StringBuilder();
int n = PATH_SEPARATOR.split(filePath).length;
for (int i = 1; i < n; i++) {
cssRelPath.append("../");
}
return cssRelPath.toString();
}
public void writeCommonHeader(@Nonnull String pageTitle)
{
println("");
println("");
println("");
println(" " + pageTitle + " ");
println(" ");
println(" ");
println(" ");
println(" ");
if (withPrettyPrint) {
println(" ");
}
println("");
println(withPrettyPrint ? "" : "");
}
public void writeCommonFooter()
{
println("");
println("");
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy