Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
[JENKINS-12424] Added links to new and priority warnings.
  • Loading branch information
uhafner committed May 14, 2012
1 parent 9238b39 commit b72cda9a98a5d11b5b4be355bf87d9aa30f55e86
@@ -1,29 +1,21 @@
package hudson.plugins.analysis.core;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.StaplerProxy;

import edu.umd.cs.findbugs.annotations.SuppressWarnings;
import hudson.FilePath;
import hudson.maven.MavenBuild;
import hudson.maven.MavenModule;

import hudson.model.HealthReport;
import hudson.model.HealthReportingAction;
import hudson.model.Result;
import hudson.model.AbstractBuild;

import hudson.plugins.analysis.Messages;
import hudson.plugins.analysis.util.PluginLogger;
import hudson.plugins.analysis.util.ToolTipProvider;
import hudson.plugins.analysis.util.model.AbstractAnnotation;

/**
* Controls the live cycle of the results in a job. This action persists the results
@@ -242,15 +234,8 @@ public boolean isSuccessful() {
* @deprecated replaced by {@link MavenResultAction}
*/
@Deprecated
@java.lang.SuppressWarnings("deprecation")
protected ParserResult createAggregatedResult(final Map<MavenModule, List<MavenBuild>> moduleBuilds) {
ParserResult project = createResult();
for (List<MavenBuild> builds : moduleBuilds.values()) {
if (!builds.isEmpty()) {
addModule(project, builds);
}
}
return project;
return new ParserResult();
}

/**
@@ -265,14 +250,7 @@ protected ParserResult createAggregatedResult(final Map<MavenModule, List<MavenB
*/
@Deprecated
protected void updateBuildHealth(final MavenBuild build, final BuildResult buildResult) {
PluginLogger logger = new PluginLogger(System.out, "[" + getDisplayName() + "] "); // NOCHECKSTYLE
@java.lang.SuppressWarnings("deprecation")
Result hudsonResult = new BuildResultEvaluator().evaluateBuildResult(
logger, getHealthDescriptor().getThresholds(),
buildResult.getAnnotations(), buildResult.getNewWarnings());
if (hudsonResult != Result.SUCCESS) {
build.getParentBuild().setResult(hudsonResult);
}
// does nothing
}

/**
@@ -286,25 +264,8 @@ logger, getHealthDescriptor().getThresholds(),
* @deprecated replaced by {@link MavenResultAction}
*/
@Deprecated
@java.lang.SuppressWarnings("unchecked")
protected void addModule(final ParserResult aggregatedResult, final List<MavenBuild> builds) {
MavenBuild mavenBuild = builds.get(0);
AbstractResultAction<T> action = mavenBuild.getAction(getClass());
if (action != null) {
aggregatedResult.addAnnotations(action.getResult().getAnnotations());
aggregatedResult.addModules(action.getResult().getModules());
aggregatedResult.addErrors(action.getResult().getErrors());
FilePath filePath = new FilePath(new File(mavenBuild.getRootDir(), AbstractAnnotation.WORKSPACE_FILES));
try {
filePath.copyRecursiveTo("*.tmp", new FilePath(new File(getOwner().getRootDir(), AbstractAnnotation.WORKSPACE_FILES)));
}
catch (IOException exception) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, "Can't copy workspace files: ", exception);
}
catch (InterruptedException exception) {
// ignore, user canceled the operation
}
}
// does nothing
}

/** Backward compatibility. @deprecated */
@@ -1022,10 +1022,12 @@ public boolean isSuccessful() {
* the use delta values when computing the differences
* @param logger
* the logger
* @param url
* the URL of the results
*/
// CHECKSTYLE:OFF
public void evaluateStatus(final Thresholds thresholds, final boolean useDeltaValues, final PluginLogger logger) {
evaluateStatus(thresholds, useDeltaValues, true, logger);
public void evaluateStatus(final Thresholds thresholds, final boolean useDeltaValues, final PluginLogger logger, final String url) {
evaluateStatus(thresholds, useDeltaValues, true, logger, url);
}

/**
@@ -1043,14 +1045,17 @@ public void evaluateStatus(final Thresholds thresholds, final boolean useDeltaVa
* respect to baseline)
* @param logger
* the logger
* @param url
* the URL of the results
*/
// CHECKSTYLE:OFF
public void evaluateStatus(final Thresholds thresholds, final boolean useDeltaValues, final boolean canComputeNew, final PluginLogger logger) {
public void evaluateStatus(final Thresholds thresholds, final boolean useDeltaValues, final boolean canComputeNew,
final PluginLogger logger, final String url) {
// CHECKSTYLE:ON
this.thresholds = thresholds;
this.useDeltaValues = useDeltaValues;

BuildResultEvaluator resultEvaluator = new BuildResultEvaluator();
BuildResultEvaluator resultEvaluator = new BuildResultEvaluator(url);
Result buildResult;
StringBuilder messages = new StringBuilder();
if (history.isEmpty() || !canComputeNew) {
@@ -17,6 +17,18 @@
* @author Ulli Hafner
*/
public class BuildResultEvaluator {
private final String url;

/**
* Creates a new instance of {@link BuildResultEvaluator}.
*
* @param url
* the url of the build results
*/
public BuildResultEvaluator(final String url) {
this.url = url;
}

/**
* Evaluates the build result. The build is marked as unstable or failed if
* one of the thresholds has been exceeded.
@@ -194,24 +206,29 @@ private boolean checkThresholds(final StringBuilder logger, final int annotation
int delta = annotationCount - convert(threshold);
if (isTotals) {
if (priorities.length == 1) {
logger.append(Messages.BuildResultEvaluator_failure_all_priority(
Priority priority = priorities[0];
logger.append(Messages.BuildResultEvaluator_unstable_all_priority(
annotationCount, threshold, delta,
priorities[0].getLongLocalizedString()));
priorities[0].getLongLocalizedString(),
url, getPriorityUrl(priority)));
}
else {
logger.append(Messages.BuildResultEvaluator_failure_all(annotationCount,
threshold, delta));
logger.append(Messages.BuildResultEvaluator_unstable_all(annotationCount,
threshold, delta, url));
}
}
else {
String newUrl = url + "/new";
if (priorities.length == 1) {
logger.append(Messages.BuildResultEvaluator_failure_new_priority(
Priority priority = priorities[0];
logger.append(Messages.BuildResultEvaluator_unstable_new_priority(
annotationCount, threshold, delta,
priorities[0].getLongLocalizedString()));
priorities[0].getLongLocalizedString(),
newUrl, getPriorityUrl(priority)));
}
else {
logger.append(Messages.BuildResultEvaluator_failure_new(annotationCount,
threshold, delta));
logger.append(Messages.BuildResultEvaluator_unstable_new(annotationCount,
threshold, delta, newUrl));
}

}
@@ -220,6 +237,10 @@ private boolean checkThresholds(final StringBuilder logger, final int annotation
return false;
}

private String getPriorityUrl(final Priority priority) {
return url + "/" + priority.name();
}

/**
* Extracts the relevant annotations from the specified collection of
* annotations. A annotation is relevant, if its priority is greater or
@@ -348,7 +348,8 @@ public final boolean perform(final AbstractBuild<?, ?> build, final Launcher lau
}

if (new NullHealthDescriptor(this).isThresholdEnabled()) {
result.evaluateStatus(getThresholds(), useDeltaValues, canComputeNew(), logger);
String baseUrl = getDescriptor().getPluginResultUrlName();
result.evaluateStatus(getThresholds(), useDeltaValues, canComputeNew(), logger, baseUrl);
}

copyFilesWithAnnotationsToBuildFolder(build.getRootDir(), launcher.getChannel(), result.getAnnotations());
@@ -359,6 +360,11 @@ public final boolean perform(final AbstractBuild<?, ?> build, final Launcher lau
return true;
}

@Override
public PluginDescriptor getDescriptor() {
return (PluginDescriptor)super.getDescriptor();
}

/**
* Copies all files with annotations from the workspace to the build folder.
*
@@ -338,7 +338,8 @@ private String registerResults(final ParserResult result, final MavenBuild maven

StringPluginLogger pluginLogger = new StringPluginLogger(pluginName);
if (new NullHealthDescriptor(this).isThresholdEnabled()) {
buildResult.evaluateStatus(thresholds, useDeltaValues, canComputeNew(), pluginLogger);
String baseUrl = getDescriptor().getPluginResultUrlName();
buildResult.evaluateStatus(thresholds, useDeltaValues, canComputeNew(), pluginLogger, baseUrl);
}
mavenBuild.getActions().add(createMavenAggregatedReport(mavenBuild, buildResult));
mavenBuild.registerAsProjectAction(HealthAwareReporter.this);
@@ -349,6 +350,12 @@ private String registerResults(final ParserResult result, final MavenBuild maven
return pluginLogger.toString();
}

/** {@inheritDoc} */
@Override
public ReporterDescriptor getDescriptor() {
return (ReporterDescriptor)super.getDescriptor();
}

/**
* Since aggregation is done in background we still need to log all messages
* of that step to the log.
@@ -126,7 +126,8 @@ private void copySourceFilesToModuleBuildFolder(final MavenBuild newBuild) {
private T createAggregatedResult(@CheckForNull final T existingResult, final T additionalResult) {
T createdResult = createResult(existingResult, additionalResult);
if (new NullHealthDescriptor(delegate.getHealthDescriptor()).isThresholdEnabled()) {
createdResult.evaluateStatus(additionalResult.getThresholds(), additionalResult.canUseDeltaValues(), getLogger());
createdResult.evaluateStatus(additionalResult.getThresholds(), additionalResult.canUseDeltaValues(),
getLogger(), getUrlName());
}
return createdResult;
}
@@ -49,6 +49,15 @@ public final PluginDescriptor getPublisherDescriptor() {
return publisherDescriptor;
}

/**
* Returns the name of the plug-in.
*
* @return the name of the plug-in
*/
public final String getPluginResultUrlName() {
return publisherDescriptor.getPluginResultUrlName();
}

/**
* Performs on-the-fly validation on the annotations threshold.
*
@@ -82,7 +82,9 @@ ResultAction.OneFile=from one analysis.
ResultAction.MultipleFiles=from {0} analyses.

BuildResultEvaluator.success=no threshold has been exceeded
BuildResultEvaluator.failure.new.priority={0} new warnings of priority {3} exceed the threshold of {1} by {2}
BuildResultEvaluator.failure.all.priority={0} warnings of priority {3} exceed the threshold of {1} by {2}
BuildResultEvaluator.failure.new={0} new warnings exceed the threshold of {1} by {2}
BuildResultEvaluator.failure.all={0} warnings exceed the threshold of {1} by {2}

BuildResultEvaluator.unstable.new.priority=<a href="{4}">{0} new warnings</a> of <a href="{5}">priority {3}</a> exceed the threshold of {1} by {2}
BuildResultEvaluator.unstable.all.priority=<a href="{4}">{0} warnings</a> of <a href="{5}">priority {3}</a> exceed the threshold of {1} by {2}
BuildResultEvaluator.unstable.new=<a href="{3}">{0} new warnings</a> exceed the threshold of {1} by {2}
BuildResultEvaluator.unstable.all=<a href="{3}">{0} warnings</a> exceed the threshold of {1} by {2}

@@ -84,7 +84,7 @@ ResultAction.OneFile=aus einer Analyse.
ResultAction.MultipleFiles=aus {0} Analysen.

BuildResultEvaluator.success=Kein Grenzwert wurde überschritten
BuildResultEvaluator.failure.new.priority={0} neue Warnungen der Priorität {3} haben die erlaubte Obergrenze von {1} um {2} überschritten
BuildResultEvaluator.failure.all.priority={0} Warnungen der Priorität {3} haben die erlaubte Obergrenze von {1} um {2} überschritten
BuildResultEvaluator.failure.new={0} neue Warnungen haben die erlaubte Obergrenze von {1} um {2} überschritten
BuildResultEvaluator.failure.all={0} Warnungen haben die erlaubte Obergrenze von {1} um {2} überschritten
BuildResultEvaluator.unstable.new.priority=<a href="{4}">{0} neue Warnungen</a> der <a href="{5}">Priorität {3}</a> haben die erlaubte Obergrenze von {1} um {2} überschritten
BuildResultEvaluator.unstable.all.priority=<a href="{4}">{0} Warnungen</a> der <a href="{5}">Priorität {3}</a> haben die erlaubte Obergrenze von {1} um {2} überschritten
BuildResultEvaluator.unstable.new=<a href="{3}">{0} neue Warnungen</a> haben die erlaubte Obergrenze von {1} um {2} überschritten
BuildResultEvaluator.unstable.all=<a href="{3}">{0} Warnungen</a> haben die erlaubte Obergrenze von {1} um {2} überschritten
@@ -23,6 +23,10 @@
* @author Ulli Hafner
*/
public class BuildResultEvaluatorTest {
/**
* FIXME: Document field URL
*/
private static final String URL = "url";
/** Error message. */
private static final String WRONG_BUILD_RESULT = "Wrong build result";
/** Error message. */
@@ -33,7 +37,7 @@ public class BuildResultEvaluatorTest {
*/
@Test
public void checkThresholds() {
BuildResultEvaluator parser = new BuildResultEvaluator();
BuildResultEvaluator parser = new BuildResultEvaluator(URL);

assertFalse(WRONG_BUILD_FAILURE_STATE, parser.isAnnotationCountExceeded(0, ""));
assertFalse(WRONG_BUILD_FAILURE_STATE, parser.isAnnotationCountExceeded(0, "0"));
@@ -63,7 +67,7 @@ public void checkThresholds() {
*/
@Test
public void checkResultComputation() {
BuildResultEvaluator parser = new BuildResultEvaluator();
BuildResultEvaluator parser = new BuildResultEvaluator(URL);
List<FileAnnotation> allAnnotations = new ArrayList<FileAnnotation>();
List<FileAnnotation> newAnnotations = new ArrayList<FileAnnotation>();

@@ -114,7 +118,7 @@ public void checkResultComputation() {
public void checkMessages() {
Locale.setDefault(Locale.ENGLISH);

BuildResultEvaluator parser = new BuildResultEvaluator();
BuildResultEvaluator parser = new BuildResultEvaluator(URL);
List<FileAnnotation> allAnnotations = new ArrayList<FileAnnotation>();
List<FileAnnotation> newAnnotations = new ArrayList<FileAnnotation>();

@@ -130,13 +134,14 @@ public void checkMessages() {
allAnnotations.add(createAnnotation());

checkMessage(parser, allAnnotations, newAnnotations,
newDescriptor("0", "", "", ""), Messages._BuildResultEvaluator_failure_all(4, 0, 4));
newDescriptor("0", "", "", ""), Messages._BuildResultEvaluator_unstable_all(4, 0, 4, URL));
checkMessage(parser, allAnnotations, newAnnotations,
newDescriptor("2", "", "", ""), Messages._BuildResultEvaluator_failure_all(4, 2, 2));
newDescriptor("2", "", "", ""), Messages._BuildResultEvaluator_unstable_all(4, 2, 2, URL));
String newUrl = URL + "/new";
checkMessage(parser, newAnnotations, allAnnotations,
newDescriptor("", "", "0", ""), Messages._BuildResultEvaluator_failure_new(4, 0, 4));
newDescriptor("", "", "0", ""), Messages._BuildResultEvaluator_unstable_new(4, 0, 4, newUrl));
checkMessage(parser, newAnnotations, allAnnotations,
newDescriptor("", "", "2", ""), Messages._BuildResultEvaluator_failure_new(4, 2, 2));
newDescriptor("", "", "2", ""), Messages._BuildResultEvaluator_unstable_new(4, 2, 2, newUrl));
}

private void checkMessage(final BuildResultEvaluator parser, final List<FileAnnotation> allAnnotations,

0 comments on commit b72cda9

Please sign in to comment.