package hudson.plugins.tasks; import hudson.model.Action; import hudson.model.AbstractBuild; import hudson.model.AbstractProject; import hudson.plugins.analysis.core.BuildResult; import hudson.plugins.analysis.core.HealthAwarePublisher; import hudson.plugins.analysis.util.PluginLogger; import hudson.plugins.tasks.parser.TasksParserResult; import hudson.plugins.tasks.parser.WorkspaceScanner; import java.io.IOException; import org.apache.commons.lang.StringUtils; import org.kohsuke.stapler.DataBoundConstructor; /** * Publishes the results of the task scanner (freestyle project type). * * @author Ulli Hafner */ public class TasksPublisher extends HealthAwarePublisher { /** Unique ID of this class. */ private static final long serialVersionUID = 3787892530045641806L; /** Default files pattern. */ private static final String DEFAULT_PATTERN = "**/*.java"; /** Tag identifiers indicating high priority. */ private final String high; /** Tag identifiers indicating normal priority. */ private final String normal; /** Tag identifiers indicating low priority. */ private final String low; /** Tag identifiers indicating case sensitivity. */ private final boolean ignoreCase; /** Ant file-set pattern of files to work with. */ private final String pattern; /** Ant file-set pattern of files to exclude from work. */ private final String excludePattern; /** * Creates a new instance of <code>TasksPublisher</code>. * * @param pattern * Ant file-set pattern of files to scan for open tasks in * @param excludePattern * Ant file-set pattern of files to exclude from scan * @param threshold * Annotation threshold to be reached if a build should be considered as * unstable. * @param newThreshold * New annotations threshold to be reached if a build should be * considered as unstable. * @param failureThreshold * Annotation threshold to be reached if a build should be considered as * failure. * @param newFailureThreshold * New annotations threshold to be reached if a build should be * considered as failure. * @param healthy * Report health as 100% when the number of open tasks is less * than this value * @param unHealthy * Report health as 0% when the number of open tasks is greater * than this value * @param thresholdLimit * determines which warning priorities should be considered when * evaluating the build stability and health * @param high * tag identifiers indicating high priority * @param normal * tag identifiers indicating normal priority * @param low * tag identifiers indicating low priority * @param ignoreCase * if case should be ignored during matching * @param defaultEncoding * the default encoding to be used when reading and parsing files * @param useDeltaValues * determines whether the absolute annotations delta or the * actual annotations set difference should be used to evaluate * the build stability * @param canRunOnFailed * determines whether the plug-in can run for failed builds, too */ // CHECKSTYLE:OFF @SuppressWarnings("PMD.ExcessiveParameterList") @DataBoundConstructor public TasksPublisher(final String pattern, final String excludePattern, final String threshold, final String newThreshold, final String failureThreshold, final String newFailureThreshold, final String healthy, final String unHealthy, final String thresholdLimit, final String high, final String normal, final String low, final boolean ignoreCase, final String defaultEncoding, final boolean useDeltaValues, final boolean canRunOnFailed) { super(threshold, newThreshold, failureThreshold, newFailureThreshold, healthy, unHealthy, thresholdLimit, defaultEncoding, useDeltaValues, canRunOnFailed, "TASKS"); this.pattern = pattern; this.excludePattern = excludePattern; this.high = high; this.normal = normal; this.low = low; this.ignoreCase = ignoreCase; } // CHECKSTYLE:ON /** * Returns the Ant file-set pattern of files to work with. * * @return Ant file-set pattern of files to work with */ public String getPattern() { return pattern; } /** * Returns the Ant file-set pattern of files to exclude from work. * * @return Ant file-set pattern of files to exclude from work */ public String getExcludePattern() { return excludePattern; } /** * Returns the high priority task identifiers. * * @return the high priority task identifiers */ public String getHigh() { return high; } /** * Returns the normal priority task identifiers. * * @return the normal priority task identifiers */ public String getNormal() { return normal; } /** * Returns the low priority task identifiers. * * @return the low priority task identifiers */ public String getLow() { return low; } /** * Returns whether case should be ignored during the scanning. * * @return <code>true</code> if case should be ignored during the scanning */ public boolean getIgnoreCase() { return ignoreCase; } /** {@inheritDoc} */ @Override public Action getProjectAction(final AbstractProject<?, ?> project) { return new TasksProjectAction(project); } /** {@inheritDoc} */ @Override protected BuildResult perform(final AbstractBuild<?, ?> build, final PluginLogger logger) throws InterruptedException, IOException { TasksParserResult project; logger.log("Scanning workspace files for tasks..."); project = build.getWorkspace().act( new WorkspaceScanner(StringUtils.defaultIfEmpty(getPattern(), DEFAULT_PATTERN), getExcludePattern(), getDefaultEncoding(), high, normal, low, ignoreCase)); TasksResult result = new TasksResult(build, getDefaultEncoding(), project, high, normal, low); build.getActions().add(new TasksResultAction(build, this, result)); return result; } /** {@inheritDoc} */ @Override public TasksDescriptor getDescriptor() { return (TasksDescriptor)super.getDescriptor(); } }