net.sf.sanity4j.util.Tool Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sanity4j Show documentation
Show all versions of sanity4j Show documentation
Sanity4J was created to simplify running multiple static code
analysis tools on the Java projects. It provides a single entry
point to run all the selected tools and produce a consolidated
report, which presents all findings in an easily accessible
manner.
The newest version!
package net.sf.sanity4j.util;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/**
* This is a class rather than an enumeration
* as we need additional attributes.
*
* @author Yiannis Paschalidis
* @since Sanity4J 1.0
*/
public final class Tool
{
/** Checkstyle static source code analyser. */
public static final Tool CHECKSTYLE = new Tool("checkstyle", "Checkstyle");
/** Cobertura datafile merge tool. */
public static final Tool COBERTURA_MERGE = new Tool("cobertura-merge", "Cobertura Merge");
/** Cobertura unit test coverage analysis. */
public static final Tool COBERTURA = new Tool("cobertura", "Cobertura");
/** FindBugs static byte-code analyser. */
public static final Tool FINDBUGS = new Tool("findbugs", "FindBugs");
/** PMD static source code analyser. */
public static final Tool PMD = new Tool("pmd", "PMD");
/** PMD CPD copy & pasted source code detector. */
public static final Tool PMD_CPD = new Tool("pmd-cpd", "PMD CPD");
//public static final Tool JUNIT = new Tool("junit", "JUnit");
/** A Read-only list of all the tools which are supported by Sanity4J. */
public static final List TOOLS = Collections.unmodifiableList(Arrays.asList(new Tool[]
{
CHECKSTYLE,
COBERTURA_MERGE,
COBERTURA,
FINDBUGS,
//JUNIT,
PMD,
PMD_CPD
}));
/** The tool id, which is used to e.g. look up values in tools.properties. */
private final String toolId;
/** The human-readable tool name. */
private final String name;
/**
* Creates a tool with the given id and name.
* @param toolId the tool id
* @param name the tool name
*/
private Tool(final String toolId, final String name)
{
this.toolId = toolId;
this.name = name;
}
/** @return the id */
public String getId()
{
return toolId;
}
/** @return the name */
public String getName()
{
return name;
}
/** @return the id */
public String toString()
{
return toolId;
}
/**
* Retrieves the tool with the given id.
* @param toolId the tool id.
* @return the tool with the given id, or null if the tool does not exist.
*/
public static Tool get(final String toolId)
{
for (Tool tool : TOOLS)
{
if (tool.getId().equals(toolId))
{
return tool;
}
}
return null;
}
/**
* Indicates if the given object is equal to this tool.
* Two tools are considered equal if their IDs match.
*
* @param obj the object to test for equality.
* @return true if the object is equal to this tool.
*/
public boolean equals(final Object obj)
{
return obj instanceof Tool && ((Tool) obj).toolId.equals(toolId);
}
/** {@inheritDoc} */
public int hashCode()
{
return toolId.hashCode();
}
}