Skip to content
Permalink
Browse files

[FIXED JENKINS-13458] Added an option to use previous build as a refe…

…rence.
  • Loading branch information
uhafner committed Jan 5, 2015
1 parent 8289b23 commit 96c2df676a21dc3c3368f8e91e7c188d2946403e
@@ -27,6 +27,7 @@
private final HealthDescriptor healthDescriptor;
private final String defaultEncoding;
private final Map<String, ParserResult> totalsPerParser = Maps.newHashMap();
private final boolean usePreviousBuildAsReference;
private final boolean useStableBuildAsReference;

/**
@@ -42,17 +43,21 @@
* health descriptor
* @param defaultEncoding
* the default encoding to be used when reading and parsing files
* @param usePreviousBuildAsReference
* determines whether the previous build should be used as the
* reference build
* @param useStableBuildAsReference
* determines whether only stable builds should be used as
* reference builds or not
*/
public WarningsAnnotationsAggregator(final MatrixBuild build, final Launcher launcher, final BuildListener listener,
final HealthDescriptor healthDescriptor, final String defaultEncoding,
final boolean useStableBuildAsReference) {
final boolean usePreviousBuildAsReference, final boolean useStableBuildAsReference) {
super(build, launcher, listener);

this.healthDescriptor = healthDescriptor;
this.defaultEncoding = defaultEncoding;
this.usePreviousBuildAsReference = usePreviousBuildAsReference;
this.useStableBuildAsReference = useStableBuildAsReference;
}

@@ -80,15 +85,17 @@ private void createTotalsAction() {
for (ParserResult result : totalsPerParser.values()) {
totals.addProject(result);
}
BuildHistory history = new BuildHistory(build, AggregatedWarningsResultAction.class, useStableBuildAsReference);
BuildHistory history = new BuildHistory(build, AggregatedWarningsResultAction.class,
usePreviousBuildAsReference, useStableBuildAsReference);
AggregatedWarningsResult result = new AggregatedWarningsResult(build, history, totals, defaultEncoding);
build.getActions().add(new AggregatedWarningsResultAction(build, result));
build.addAction(new AggregatedWarningsResultAction(build, result));
}

@Override
public boolean endBuild() throws InterruptedException, IOException {
for (String parser : totalsPerParser.keySet()) {
WarningsBuildHistory history = new WarningsBuildHistory(build, parser, useStableBuildAsReference);
WarningsBuildHistory history = new WarningsBuildHistory(build, parser,
usePreviousBuildAsReference, useStableBuildAsReference);
WarningsResult result = new WarningsResult(build, history, totalsPerParser.get(parser), defaultEncoding, parser);
build.addAction(new WarningsResultAction(build, healthDescriptor, result, parser));
}
@@ -1,11 +1,9 @@
package hudson.plugins.warnings;

import java.util.List;

import javax.annotation.CheckForNull;
import java.util.List;

import hudson.model.AbstractBuild;

import hudson.plugins.analysis.core.BuildHistory;

/**
@@ -23,13 +21,16 @@
* the last finished build
* @param group
* the parser group
* @param usePreviousBuildAsReference
* determines whether to use the previous build as the reference
* build
* @param useStableBuildAsReference
* determines whether only stable builds should be used as
* reference builds or not
*/
public WarningsBuildHistory(final AbstractBuild<?, ?> lastFinishedBuild, @CheckForNull final String group,
final boolean useStableBuildAsReference) {
super(lastFinishedBuild, WarningsResultAction.class, useStableBuildAsReference);
final boolean usePreviousBuildAsReference, final boolean useStableBuildAsReference) {
super(lastFinishedBuild, WarningsResultAction.class, usePreviousBuildAsReference, useStableBuildAsReference);

this.group = group;
}
@@ -1,22 +1,20 @@
package hudson.plugins.warnings;

import java.util.List;

import javax.annotation.CheckForNull;
import java.util.List;

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

import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;

import hudson.plugins.analysis.core.AbstractProjectAction;
import hudson.plugins.analysis.core.BuildHistory;
import hudson.plugins.analysis.core.NullBuildHistory;
import hudson.plugins.analysis.core.AbstractProjectAction;
import hudson.plugins.analysis.graph.BuildResultGraph;
import hudson.plugins.analysis.graph.DefaultGraphConfigurationView;
import hudson.plugins.analysis.graph.UserGraphConfigurationView;
import hudson.plugins.analysis.graph.GraphConfigurationView;
import hudson.plugins.analysis.graph.UserGraphConfigurationView;
import hudson.plugins.warnings.parser.ParserRegistry;

/**
@@ -105,7 +103,7 @@ protected BuildHistory createBuildHistory() {
}

private WarningsBuildHistory createHistory(final AbstractBuild<?, ?> build) {
return new WarningsBuildHistory(build, parser, false);
return new WarningsBuildHistory(build, parser, false, false);
}
}

@@ -112,6 +112,8 @@
* annotation threshold
* @param canRunOnFailed
* determines whether the plug-in can run for failed builds, too
* @param usePreviousBuildAsReference
* determines whether to always use the previous build as the reference build
* @param useStableBuildAsReference
* determines whether only stable builds should be used as reference builds or not
* @param canComputeNew
@@ -142,15 +144,16 @@ public WarningsPublisher(final String healthy, final String unHealthy, final Str
final String unstableNewAll, final String unstableNewHigh, final String unstableNewNormal, final String unstableNewLow,
final String failedTotalAll, final String failedTotalHigh, final String failedTotalNormal, final String failedTotalLow,
final String failedNewAll, final String failedNewHigh, final String failedNewNormal, final String failedNewLow,
final boolean canRunOnFailed, final boolean useStableBuildAsReference, final boolean shouldDetectModules,
final boolean canComputeNew, final String includePattern, final String excludePattern, final boolean canResolveRelativePaths,
final List<ParserConfiguration> parserConfigurations, final List<ConsoleParser> consoleParsers) {
final boolean canRunOnFailed, final boolean usePreviousBuildAsReference, final boolean useStableBuildAsReference,
final boolean shouldDetectModules, final boolean canComputeNew, final String includePattern, final String excludePattern,
final boolean canResolveRelativePaths, final List<ParserConfiguration> parserConfigurations, final List<ConsoleParser> consoleParsers) {
super(healthy, unHealthy, thresholdLimit, defaultEncoding, useDeltaValues,
unstableTotalAll, unstableTotalHigh, unstableTotalNormal, unstableTotalLow,
unstableNewAll, unstableNewHigh, unstableNewNormal, unstableNewLow,
failedTotalAll, failedTotalHigh, failedTotalNormal, failedTotalLow,
failedNewAll, failedNewHigh, failedNewNormal, failedNewLow,
canRunOnFailed, useStableBuildAsReference, shouldDetectModules, canComputeNew, canResolveRelativePaths, PLUGIN_NAME);
canRunOnFailed, usePreviousBuildAsReference, useStableBuildAsReference,
shouldDetectModules, canComputeNew, canResolveRelativePaths, PLUGIN_NAME);
this.includePattern = StringUtils.stripToNull(includePattern);
this.excludePattern = StringUtils.stripToNull(excludePattern);
if (consoleParsers != null) {
@@ -324,9 +327,10 @@ protected BuildResult perform(final AbstractBuild<?, ?> build, final PluginLogge
add(totals, consoleResults);
add(totals, fileResults);

BuildHistory history = new BuildHistory(build, AggregatedWarningsResultAction.class, useOnlyStableBuildsAsReference());
BuildHistory history = new BuildHistory(build, AggregatedWarningsResultAction.class,
usePreviousBuildAsReference(), useOnlyStableBuildsAsReference());
AggregatedWarningsResult result = new AggregatedWarningsResult(build, history, totals, getDefaultEncoding());
build.getActions().add(new AggregatedWarningsResultAction(build, result));
build.addAction(new AggregatedWarningsResultAction(build, result));

return result;
}
@@ -344,21 +348,6 @@ private BuildResult emptyBuildResult(final AbstractBuild<?, ?> build, final Plug
return new AggregatedWarningsResult(build, new NullBuildHistory(), new ParserResult(), getDefaultEncoding());
}

private void evaluateBuildHealth(final AbstractBuild<?, ?> build, final PluginLogger logger) {
for (WarningsResultAction action : build.getActions(WarningsResultAction.class)) {
WarningsBuildHistory history = new WarningsBuildHistory(build, action.getParser(), useOnlyStableBuildsAsReference());
AbstractBuild<?, ?> referenceBuild = history.getReferenceBuild();
if (referenceBuild == null) {
logger.log("Skipping warning delta computation since no reference build is found");
}
else {
logger.log("Computing warning deltas based on reference build " + referenceBuild.getDisplayName());
action.getResult().evaluateStatus(getThresholds(), getUseDeltaValues(), canComputeNew(),
logger, action.getUrlName());
}
}
}

private boolean hasFileParsers() {
return getParserConfigurations().length > 0;
}
@@ -466,9 +455,10 @@ private ParserResult annotate(final AbstractBuild<?, ?> build, final ParserResul
for (FileAnnotation annotation : output.getAnnotations()) {
annotation.setPathName(build.getWorkspace().getRemote());
}
WarningsBuildHistory history = new WarningsBuildHistory(build, parserName, useOnlyStableBuildsAsReference());
WarningsBuildHistory history = new WarningsBuildHistory(build, parserName,
usePreviousBuildAsReference(), useOnlyStableBuildsAsReference());
WarningsResult result = new WarningsResult(build, history, output, getDefaultEncoding(), parserName);
build.getActions().add(new WarningsResultAction(build, this, result, parserName));
build.addAction(new WarningsResultAction(build, this, result, parserName));

return output;
}
@@ -489,7 +479,8 @@ public WarningsDescriptor getDescriptor() {

@Override
public MatrixAggregator createAggregator(final MatrixBuild build, final Launcher launcher, final BuildListener listener) {
return new WarningsAnnotationsAggregator(build, launcher, listener, this, getDefaultEncoding(), useOnlyStableBuildsAsReference());
return new WarningsAnnotationsAggregator(build, launcher, listener, this, getDefaultEncoding(),
usePreviousBuildAsReference(), useOnlyStableBuildsAsReference());
}

/** Name of parsers to use for scanning the logs. */
@@ -60,7 +60,7 @@ public WarningsResult(final AbstractBuild<?, ?> build, final BuildHistory histor

@Override
protected BuildHistory createHistory(final AbstractBuild<?, ?> build) {
return new WarningsBuildHistory(build, group, false);
return new WarningsBuildHistory(build, group, false, false);
}

@Override
@@ -77,13 +77,15 @@ public void testIssue14615File() {
}

private void checkFileOrder(final List<ParserConfiguration> fileParsers, final List<String> expected) {
WarningsPublisher publisher = new WarningsPublisher(null, null, null, null, false, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, false, false, false, false, null, null, false,
WarningsPublisher publisher = new WarningsPublisher(null, null, null, null, false, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null, false, false, false, false, false, null, null, false,
fileParsers, null);
checkOrder(expected, publisher);
}

private void checkConsoleOrder(final List<ConsoleParser> consoleParsers, final List<String> expected) {
WarningsPublisher publisher = new WarningsPublisher(null, null, null, null, false, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, false, false, false, false, null, null, false,
WarningsPublisher publisher = new WarningsPublisher(null, null, null, null, false, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null, false, false, false, false, false, null, null, false,
null, consoleParsers);
checkOrder(expected, publisher);
}

0 comments on commit 96c2df6

Please sign in to comment.
You can’t perform that action at this time.