Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
[JENKINS-15037]: Upgrade to new API in order to compute warnings only
for stable builds (if option is checked).
  • Loading branch information
uhafner committed Sep 28, 2012
1 parent 5fb9ddf commit 559c94f82212c265803bd14efa5fe5c3d00f172d
@@ -24,6 +24,7 @@ public class WarningsAnnotationsAggregator extends MatrixAggregator {
private final HealthDescriptor healthDescriptor;
private final String defaultEncoding;
private final Map<String, ParserResult> totalsPerParser = Maps.newHashMap();
private final boolean useStableBuildAsReference;

/**
* Creates a new instance of {@link WarningsAnnotationsAggregator}.
@@ -38,13 +39,18 @@ public class WarningsAnnotationsAggregator extends MatrixAggregator {
* health descriptor
* @param defaultEncoding
* the default encoding to be used when reading and parsing files
* @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 HealthDescriptor healthDescriptor, final String defaultEncoding,
final boolean useStableBuildAsReference) {
super(build, launcher, listener);

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

@Override
@@ -67,7 +73,7 @@ public boolean endRun(final MatrixRun run) throws InterruptedException, IOExcept
@Override
public boolean endBuild() throws InterruptedException, IOException {
for (String parser : totalsPerParser.keySet()) {
WarningsBuildHistory history = new WarningsBuildHistory(build, parser);
WarningsBuildHistory history = new WarningsBuildHistory(build, parser, useStableBuildAsReference);
WarningsResult result = new WarningsResult(build, history, totalsPerParser.get(parser), defaultEncoding, parser);
build.addAction(new WarningsResultAction(build, healthDescriptor, result, parser));
}
@@ -22,9 +22,13 @@ public class WarningsBuildHistory extends BuildHistory {
* the last finished build
* @param group
* the parser group
* @param useStableBuildAsReference
* determines whether only stable builds should be used as
* reference builds or not
*/
public WarningsBuildHistory(final AbstractBuild<?, ?> lastFinishedBuild, @CheckForNull final String group) {
super(lastFinishedBuild, WarningsResultAction.class);
public WarningsBuildHistory(final AbstractBuild<?, ?> lastFinishedBuild, @CheckForNull final String group,
final boolean useStableBuildAsReference) {
super(lastFinishedBuild, WarningsResultAction.class, useStableBuildAsReference);

this.group = group;
}
@@ -105,7 +105,7 @@ protected BuildHistory createBuildHistory() {
}

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

@@ -106,6 +106,8 @@ public class WarningsPublisher extends HealthAwareRecorder {
* annotation threshold
* @param canRunOnFailed
* determines whether the plug-in can run for failed builds, too
* @param useStableBuildAsReference
* determines whether only stable builds should be used as reference builds or not
* @param canComputeNew
* determines whether new warnings should be computed (with
* respect to baseline)
@@ -134,15 +136,15 @@ 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 shouldDetectModules, final boolean canComputeNew,
final String includePattern, final String excludePattern, final boolean canResolveRelativePaths,
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) {
super(healthy, unHealthy, thresholdLimit, defaultEncoding, useDeltaValues,
unstableTotalAll, unstableTotalHigh, unstableTotalNormal, unstableTotalLow,
unstableNewAll, unstableNewHigh, unstableNewNormal, unstableNewLow,
failedTotalAll, failedTotalHigh, failedTotalNormal, failedTotalLow,
failedNewAll, failedNewHigh, failedNewNormal, failedNewLow,
canRunOnFailed, shouldDetectModules, canComputeNew, canResolveRelativePaths, PLUGIN_NAME);
canRunOnFailed, useStableBuildAsReference, shouldDetectModules, canComputeNew, canResolveRelativePaths, PLUGIN_NAME);
this.includePattern = StringUtils.stripToNull(includePattern);
this.excludePattern = StringUtils.stripToNull(excludePattern);
if (consoleParsers != null) {
@@ -303,7 +305,7 @@ private boolean stopParsing(final PluginLogger logger, final Exception exception

private void evaluateBuildHealth(final AbstractBuild<?, ?> build, final PluginLogger logger) {
for (WarningsResultAction action : build.getActions(WarningsResultAction.class)) {
WarningsBuildHistory history = new WarningsBuildHistory(build, action.getParser());
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");
@@ -403,7 +405,7 @@ private ParserResult annotate(final AbstractBuild<?, ?> build, final ParserResul
for (FileAnnotation annotation : output.getAnnotations()) {
annotation.setPathName(build.getWorkspace().getRemote());
}
WarningsResult result = new WarningsResult(build, new WarningsBuildHistory(build, parserName),
WarningsResult result = new WarningsResult(build, new WarningsBuildHistory(build, parserName, useOnlyStableBuildsAsReference()),
output, getDefaultEncoding(), parserName);
build.getActions().add(new WarningsResultAction(build, this, result, parserName));

@@ -426,7 +428,7 @@ public WarningsDescriptor getDescriptor() {

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

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

WarningsResult(final AbstractBuild<?, ?> build, final BuildHistory history,
final ParserResult result, final String defaultEncoding, final String group,
final boolean canSerialize) {
final ParserResult result, final String defaultEncoding,
final String group, final boolean canSerialize) {
super(build, history, result, defaultEncoding);

this.group = group;
@@ -59,7 +59,7 @@ public WarningsResult(final AbstractBuild<?, ?> build, final BuildHistory histor

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

@Override
@@ -1,39 +1,38 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define"
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:u="/util" xmlns:w="/warnings">
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout"
xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:u="/util" xmlns:w="/warnings">

<j:invokeStatic var="allParsers" className="hudson.plugins.warnings.parser.ParserRegistry"
method="getAvailableParsers" />

<j:invokeStatic var="allParsers" className="hudson.plugins.warnings.parser.ParserRegistry" method="getAvailableParsers"/>

<f:entry title="${%Scan console log}" description="${%description.consoleLogParsers}">
<f:repeatableProperty field="consoleParsers"/>
<f:repeatableProperty field="consoleParsers" />
</f:entry>

<f:entry title="${%Scan workspace files}" description="${%description.logFilesParsers}">
<f:repeatableProperty field="parserConfigurations"/>
<f:repeatableProperty field="parserConfigurations" />
</f:entry>

<f:advanced>
<f:entry title="${%Warnings to include}" field="includePattern"
description="${%description.includePattern}">
<f:textbox/>
<f:entry title="${%Warnings to include}" field="includePattern" description="${%description.includePattern}">
<f:textbox />
</f:entry>
<f:entry title="${%Warnings to ignore}" field="excludePattern"
description="${%description.excludePattern}">
<f:textbox/>
<f:entry title="${%Warnings to ignore}" field="excludePattern" description="${%description.excludePattern}">
<f:textbox />
</f:entry>

<u:failed/>
<u:failed />

<f:entry title="${%Detect modules}" description="${%description.detectModules}">
<f:checkbox name="shouldDetectModules" checked="${instance.shouldDetectModules}"/>
<f:checkbox name="shouldDetectModules" checked="${instance.shouldDetectModules}" />
</f:entry>
<f:entry title="${%Resolve relative paths}" description="${%description.resolveRelativePaths}">
<f:checkbox name="canResolveRelativePaths" checked="${instance.canResolveRelativePaths}"/>
<f:checkbox name="canResolveRelativePaths" checked="${instance.canResolveRelativePaths}" />
</f:entry>

<u:health id="warnings"/>
<u:thresholds id="warnings"/>
<u:defaultEncoding id="warnings"/>
<u:health id="warnings" />
<u:thresholds id="warnings" />
<u:defaultEncoding id="warnings" />
<f:entry title="${%Trend graph}">
<a href="descriptorByName/WarningsPublisher/configureDefaults">${%configure}</a>
</f:entry>
@@ -71,13 +71,13 @@ private List<String> createExpectedResult() {
}

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, 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, 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, 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, null, null, false,
null, consoleParsers);
checkOrder(expected, publisher);
}

0 comments on commit 559c94f

Please sign in to comment.