Skip to content
This repository has been archived by the owner on Apr 6, 2022. It is now read-only.

Commit

Permalink
[FIXED JENKINS-13458] Added an option to use previous build as a refe…
Browse files Browse the repository at this point in the history
…rence.
  • Loading branch information
uhafner committed Jan 5, 2015
1 parent 95b632e commit 0ae7469
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 44 deletions.
Expand Up @@ -85,7 +85,7 @@ private void initializeFields(final String defaultEncoding, final String high, f
@Override
public MavenAggregatedReport createAggregatedAction(final MavenModuleSetBuild build, final Map<MavenModule, List<MavenBuild>> moduleBuilds) {
return new MavenTasksResultAction(build, getHealthDescriptor(), defaultEncoding, high, normal, low,
new TasksResult(build, defaultEncoding, new TasksParserResult(), false, high, normal, low));
new TasksResult(build, defaultEncoding, new TasksParserResult(), false, false, high, normal, low));
}

@Override
Expand Down
20 changes: 13 additions & 7 deletions src/main/java/hudson/plugins/tasks/TasksAnnotationsAggregator.java
@@ -1,19 +1,19 @@
package hudson.plugins.tasks;

import java.io.IOException;

import org.apache.commons.lang.StringUtils;

import hudson.Launcher;
import hudson.matrix.MatrixAggregator;
import hudson.matrix.MatrixRun;
import hudson.matrix.MatrixBuild;
import hudson.matrix.MatrixRun;
import hudson.model.BuildListener;
import hudson.plugins.analysis.core.AnnotationsAggregator;
import hudson.plugins.analysis.core.HealthDescriptor;
import hudson.plugins.analysis.util.model.Priority;
import hudson.plugins.tasks.parser.TasksParserResult;

import java.io.IOException;

import org.apache.commons.lang.StringUtils;

/**
* Aggregates {@link TasksResultAction}s of {@link MatrixRun}s into
* {@link MatrixBuild}.
Expand All @@ -32,6 +32,7 @@ public class TasksAnnotationsAggregator extends MatrixAggregator {
private String normalTags = StringUtils.EMPTY;
/** Tag identifiers indicating low priority. */
private String lowTags = StringUtils.EMPTY;
private final boolean usePreviousBuildAsReference;
private final boolean useStableBuildAsReference;

/**
Expand All @@ -47,17 +48,21 @@ public class TasksAnnotationsAggregator extends MatrixAggregator {
* 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 TasksAnnotationsAggregator(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;
}

Expand All @@ -79,7 +84,8 @@ public boolean endRun(final MatrixRun run) throws InterruptedException, IOExcept

@Override
public boolean endBuild() throws InterruptedException, IOException {
TasksResult result = new TasksResult(build, defaultEncoding, totals, useStableBuildAsReference, highTags, normalTags, lowTags);
TasksResult result = new TasksResult(build, defaultEncoding, totals,
usePreviousBuildAsReference, useStableBuildAsReference, highTags, normalTags, lowTags);

build.addAction(new TasksResultAction(build, healthDescriptor, result));

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/hudson/plugins/tasks/TasksMavenResult.java
Expand Up @@ -35,7 +35,7 @@ public class TasksMavenResult extends TasksResult {
@SuppressWarnings("deprecation")
public TasksMavenResult(final AbstractBuild<?, ?> build, final String defaultEncoding, final TasksParserResult result,
final String highTags, final String normalTags, final String lowTags) {
super(build, defaultEncoding, result, false, highTags, normalTags, lowTags, MavenTasksResultAction.class);
super(build, defaultEncoding, result, false, false, highTags, normalTags, lowTags, MavenTasksResultAction.class);
}

@SuppressWarnings("deprecation")
Expand Down
17 changes: 9 additions & 8 deletions src/main/java/hudson/plugins/tasks/TasksMavenResultAction.java
@@ -1,21 +1,21 @@
package hudson.plugins.tasks;

import java.util.List;
import java.util.Map;

import com.google.common.collect.Lists;

import hudson.maven.MavenAggregatedReport;
import hudson.maven.MavenBuild;
import hudson.maven.MavenModule;
import hudson.maven.MavenModuleSet;
import hudson.maven.MavenModuleSetBuild;
import hudson.model.Action;
import hudson.model.AbstractBuild;
import hudson.model.Action;
import hudson.plugins.analysis.core.HealthDescriptor;
import hudson.plugins.analysis.core.MavenResultAction;
import hudson.plugins.tasks.parser.TasksParserResult;

import java.util.List;
import java.util.Map;

import com.google.common.collect.Lists;

/**
* A {@link TasksResultAction} for native Maven jobs. This action
* additionally provides result aggregation for sub-modules and for the main
Expand Down Expand Up @@ -77,7 +77,7 @@ private void initializeFields(final String high, final String normal, final Stri
@Override
public MavenAggregatedReport createAggregatedAction(final MavenModuleSetBuild build, final Map<MavenModule, List<MavenBuild>> moduleBuilds) {
return new TasksMavenResultAction(build, getHealthDescriptor(), getDefaultEncoding(), high, normal, low,
new TasksResult(build, high, new TasksParserResult(), false, high, normal, low));
new TasksResult(build, high, new TasksParserResult(), false, false, high, normal, low));
}

@Override
Expand All @@ -93,7 +93,8 @@ public Class<? extends MavenResultAction<TasksResult>> getIndividualActionType()
@Override
protected TasksResult createResult(final TasksResult existingResult, final TasksResult additionalResult) {
return new TasksReporterResult(getOwner(), additionalResult.getDefaultEncoding(),
aggregate(existingResult, additionalResult), existingResult.useOnlyStableBuildsAsReference(),
aggregate(existingResult, additionalResult),
existingResult.usePreviousBuildAsStable(), existingResult.useOnlyStableBuildsAsReference(),
high, normal, low);
}

Expand Down
19 changes: 12 additions & 7 deletions src/main/java/hudson/plugins/tasks/TasksPublisher.java
Expand Up @@ -96,6 +96,8 @@ public class TasksPublisher extends HealthAwarePublisher {
* 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
Expand Down Expand Up @@ -127,15 +129,16 @@ public TasksPublisher(final String healthy, final String unHealthy, final String
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 high, final String normal, final String low, final boolean ignoreCase, final boolean asRegexp,
final String pattern, final String excludePattern) {
final boolean canRunOnFailed, final boolean usePreviousBuildAsReference, final boolean useStableBuildAsReference,
final boolean shouldDetectModules, final boolean canComputeNew, final String high, final String normal, final String low,
final boolean ignoreCase, final boolean asRegexp, final String pattern, final String excludePattern) {
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, true, "TASKS");
canRunOnFailed, usePreviousBuildAsReference, useStableBuildAsReference,
shouldDetectModules, canComputeNew, true, "TASKS");
this.pattern = pattern;
this.excludePattern = excludePattern;
this.high = high;
Expand Down Expand Up @@ -224,8 +227,9 @@ protected BuildResult perform(final AbstractBuild<?, ?> build, final PluginLogge
logger.logLines(project.getLogMessages());
logger.log(String.format("Found %d open tasks.", project.getNumberOfAnnotations()));

TasksResult result = new TasksResult(build, getDefaultEncoding(), project, useOnlyStableBuildsAsReference(), high, normal, low);
build.getActions().add(new TasksResultAction(build, this, result));
TasksResult result = new TasksResult(build, getDefaultEncoding(), project,
usePreviousBuildAsReference(), useOnlyStableBuildsAsReference(), high, normal, low);
build.addAction(new TasksResultAction(build, this, result));

return result;
}
Expand All @@ -238,6 +242,7 @@ public TasksDescriptor getDescriptor() {
@Override
public MatrixAggregator createAggregator(final MatrixBuild build, final Launcher launcher,
final BuildListener listener) {
return new TasksAnnotationsAggregator(build, launcher, listener, this, getDefaultEncoding(), useOnlyStableBuildsAsReference());
return new TasksAnnotationsAggregator(build, launcher, listener, this, getDefaultEncoding(),
usePreviousBuildAsReference(), useOnlyStableBuildsAsReference());
}
}
12 changes: 7 additions & 5 deletions src/main/java/hudson/plugins/tasks/TasksReporter.java
Expand Up @@ -111,6 +111,8 @@ public class TasksReporter extends HealthAwareReporter<TasksResult> {
* if the identifiers should be treated as regular expression
* @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
Expand All @@ -126,15 +128,15 @@ public TasksReporter(final String pattern, final String excludePattern,
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 String high, final String normal, final String low,
final boolean ignoreCase, final boolean asRegexp, final boolean canRunOnFailed,
final boolean useStableBuildAsReference, final boolean canComputeNew) {
final String high, final String normal, final String low, final boolean ignoreCase, final boolean asRegexp,
final boolean canRunOnFailed, final boolean usePreviousBuildAsReference, final boolean useStableBuildAsReference,
final boolean canComputeNew) {
super(healthy, unHealthy, thresholdLimit, useDeltaValues,
unstableTotalAll, unstableTotalHigh, unstableTotalNormal, unstableTotalLow,
unstableNewAll, unstableNewHigh, unstableNewNormal, unstableNewLow,
failedTotalAll, failedTotalHigh, failedTotalNormal, failedTotalLow,
failedNewAll, failedNewHigh, failedNewNormal, failedNewLow,
canRunOnFailed, useStableBuildAsReference, canComputeNew, "TASKS");
canRunOnFailed, usePreviousBuildAsReference, useStableBuildAsReference, canComputeNew, "TASKS");
this.pattern = pattern;
this.excludePattern = excludePattern;
this.high = high;
Expand Down Expand Up @@ -234,7 +236,7 @@ excludePattern, getDefaultEncoding(), high, normal, low, ignoreCase, pom.getName
@edu.umd.cs.findbugs.annotations.SuppressWarnings("BC")
protected TasksResult createResult(final MavenBuild build, final ParserResult project) {
return new TasksReporterResult(build, getDefaultEncoding(), (TasksParserResult)project,
useOnlyStableBuildsAsReference(), high, normal, low);
usePreviousBuildAsStable(), useOnlyStableBuildsAsReference(), high, normal, low);
}

@Override
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/hudson/plugins/tasks/TasksReporterResult.java
Expand Up @@ -22,6 +22,8 @@ public class TasksReporterResult extends TasksResult {
* the default encoding to be used when reading and parsing files
* @param result
* the parsed annotations
* @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
Expand All @@ -33,8 +35,10 @@ public class TasksReporterResult extends TasksResult {
* tag identifiers indicating low priority
*/
public TasksReporterResult(final AbstractBuild<?, ?> build, final String defaultEncoding, final TasksParserResult result,
final boolean useStableBuildAsReference, final String highTags, final String normalTags, final String lowTags) {
super(build, defaultEncoding, result, useStableBuildAsReference, highTags, normalTags, lowTags, TasksMavenResultAction.class);
final boolean usePreviousBuildAsReference, final boolean useStableBuildAsReference,
final String highTags, final String normalTags, final String lowTags) {
super(build, defaultEncoding, result, usePreviousBuildAsReference, useStableBuildAsReference,
highTags, normalTags, lowTags, TasksMavenResultAction.class);
}

@Override
Expand Down
32 changes: 19 additions & 13 deletions src/main/java/hudson/plugins/tasks/TasksResult.java
@@ -1,19 +1,19 @@
package hudson.plugins.tasks; // NOPMD

import java.util.ArrayList;

import org.apache.commons.lang.StringUtils;

import com.thoughtworks.xstream.XStream;

import hudson.model.AbstractBuild;
import hudson.plugins.analysis.core.BuildHistory;
import hudson.plugins.analysis.core.ResultAction;
import hudson.plugins.analysis.core.BuildResult;
import hudson.plugins.analysis.core.ResultAction;
import hudson.plugins.analysis.util.model.Priority;
import hudson.plugins.tasks.parser.Task;
import hudson.plugins.tasks.parser.TasksParserResult;

import java.util.ArrayList;

import org.apache.commons.lang.StringUtils;

import com.thoughtworks.xstream.XStream;

/**
* Represents the results of the task scanner. One instance of this class is persisted for
* each build via an XML file.
Expand All @@ -38,6 +38,8 @@ public class TasksResult extends BuildResult {
* the default encoding to be used when reading and parsing files
* @param result
* the parsed annotations
* @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
Expand All @@ -48,10 +50,11 @@ public class TasksResult extends BuildResult {
* @param lowTags
* tag identifiers indicating low priority
*/
public TasksResult(final AbstractBuild<?, ?> build, final String defaultEncoding,
final TasksParserResult result, final boolean useStableBuildAsReference,
public TasksResult(final AbstractBuild<?, ?> build, final String defaultEncoding, final TasksParserResult result,
final boolean usePreviousBuildAsReference, final boolean useStableBuildAsReference,
final String highTags, final String normalTags, final String lowTags) {
this(build, defaultEncoding, result, useStableBuildAsReference, highTags, normalTags, lowTags, TasksResultAction.class);
this(build, defaultEncoding, result, usePreviousBuildAsReference, useStableBuildAsReference,
highTags, normalTags, lowTags, TasksResultAction.class);
}

/**
Expand All @@ -63,6 +66,8 @@ public TasksResult(final AbstractBuild<?, ?> build, final String defaultEncoding
* the default encoding to be used when reading and parsing files
* @param result
* the parsed annotations
* @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
Expand All @@ -76,12 +81,13 @@ public TasksResult(final AbstractBuild<?, ?> build, final String defaultEncoding
* the type of the result action
*/
// CHECKSTYLE:OFF
protected TasksResult(final AbstractBuild<?, ?> build, final String defaultEncoding,
final TasksParserResult result, final boolean useStableBuildAsReference,
protected TasksResult(final AbstractBuild<?, ?> build, final String defaultEncoding, final TasksParserResult result,
final boolean usePreviousBuildAsReference, final boolean useStableBuildAsReference,
final String highTags, final String normalTags, final String lowTags,
final Class<? extends ResultAction<TasksResult>> actionType) {
// CHECKSTYLE:ON
super(build, new BuildHistory(build, actionType, useStableBuildAsReference), result, defaultEncoding);
super(build, new BuildHistory(build, actionType, usePreviousBuildAsReference, useStableBuildAsReference),
result, defaultEncoding);

this.highTags = highTags;
this.normalTags = normalTags;
Expand Down

0 comments on commit 0ae7469

Please sign in to comment.