com.github.sanity4j.workflow.tool.CheckStyleResultReader Maven / Gradle / Ivy
package com.github.sanity4j.workflow.tool;
import java.io.File;
import java.io.IOException;
import java.math.BigInteger;
import java.util.List;
import java.util.Properties;
import com.github.sanity4j.model.diagnostic.Diagnostic;
import com.github.sanity4j.model.diagnostic.DiagnosticFactory;
import com.github.sanity4j.model.diagnostic.DiagnosticSet;
import com.github.sanity4j.util.ExtractStats;
import com.github.sanity4j.util.JaxbMarshaller;
import com.github.sanity4j.util.QAException;
import com.github.sanity4j.gen.checkstyle_4_4.Checkstyle;
import com.github.sanity4j.gen.checkstyle_4_4.Error;
/**
* CheckStyleResultReader - Translates CheckStyle results into the common format used by the QA tool.
*
* @author Yiannis Paschalidis
* @since Sanity4J 1.0
*/
public final class CheckStyleResultReader implements ResultReader
{
/** The properties used to configure the {@link CheckStyleResultReader}. */
private final Properties properties = new Properties();
/** The ExtractStats to add the results to. */
private ExtractStats stats;
/** The CheckStyle XML result file to read from. */
private File checkStyleResultFile;
/** {@inheritDoc} */
public void setProperties(final Properties properties)
{
this.properties.putAll(properties);
}
/** {@inheritDoc} */
public void setResultFile(final File resultFile)
{
this.checkStyleResultFile = resultFile;
}
/** {@inheritDoc} */
public void setStats(final ExtractStats stats)
{
this.stats = stats;
}
/**
* Extracts CheckStyle statistics from the given file.
*/
public void run()
{
DiagnosticFactory diagnosticFactory = DiagnosticFactory.getInstance(properties);
DiagnosticSet diagnostics = stats.getDiagnostics();
Checkstyle result = (Checkstyle) JaxbMarshaller.unmarshal(checkStyleResultFile,
"com.github.sanity4j.gen.checkstyle_4_4",
"http://com.github.sanity4j/namespace/checkstyle-4.4");
List files = result.getFile();
for (com.github.sanity4j.gen.checkstyle_4_4.File file : files)
{
List