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

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #26 from tom-saunders/master
[JENKINS-13458] Added option to use the previous build as reference.
  • Loading branch information
uhafner committed Nov 19, 2014
2 parents e001040 + 4b277be commit b8712ca
Show file tree
Hide file tree
Showing 7 changed files with 224 additions and 14 deletions.
Expand Up @@ -29,6 +29,12 @@ public abstract class AnnotationsAggregator extends MatrixAggregator {
* @since 1.48
*/
private final boolean useStableBuildAsReference;
/**
* Determines whether to always use the previous build as the reference build.
*
* @since 1.66
*/
private final boolean usePreviousBuildAsReference;

/**
* Creates a new instance of {@link AnnotationsAggregator}.
Expand All @@ -43,16 +49,23 @@ public abstract class AnnotationsAggregator 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
* @since 1.66
*/
public AnnotationsAggregator(final MatrixBuild build, final Launcher launcher, final BuildListener listener,
final HealthDescriptor healthDescriptor, final String defaultEncoding, final boolean useStableBuildAsReference) {
final HealthDescriptor healthDescriptor, final String defaultEncoding,
final boolean usePreviousBuildAsReference,
final boolean useStableBuildAsReference) {
super(build, launcher, listener);

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

Expand Down Expand Up @@ -96,6 +109,18 @@ public boolean useOnlyStableBuildsAsReference() {
return useStableBuildAsReference;
}

/**
* Determines whether to always use the previous build as the reference
* build.
*
* @return <code>true</code> if the previous build should always be used as
* the reference build.
* @since 1.66
*/
public boolean usePreviousBuildAsReference() {
return usePreviousBuildAsReference;
}

/**
* Returns the annotations of the specified run.
*
Expand All @@ -121,6 +146,31 @@ public boolean useOnlyStableBuildsAsReference() {
@SuppressWarnings("hiding")
protected abstract Action createAction(HealthDescriptor healthDescriptor, String defaultEncoding, ParserResult aggregatedResult);

/**
* Creates a new instance of {@link AnnotationsAggregator}.
*
* @param build
* the matrix build
* @param launcher
* the launcher
* @param listener
* the build listener
* @param healthDescriptor
* 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
* @deprecated use {@link #AnnotationsAggregator(MatrixBuild, Launcher,
* BuildListener, HealthDescriptor, String, boolean, boolean)}
*/
@Deprecated
public AnnotationsAggregator(final MatrixBuild build, final Launcher launcher, final BuildListener listener,
final HealthDescriptor healthDescriptor, final String defaultEncoding, final boolean useStableBuildAsReference)
{
this(build, launcher, listener, healthDescriptor, defaultEncoding, false, useStableBuildAsReference);
}
/**
* Creates a new instance of {@link AnnotationsAggregator}.
*
Expand Down
36 changes: 34 additions & 2 deletions src/main/java/hudson/plugins/analysis/core/BuildHistory.java
Expand Up @@ -28,6 +28,10 @@ public class BuildHistory {
private final Class<? extends ResultAction<? extends BuildResult>> type;
/** Determines whether only stable builds should be used as reference builds or not. */
private final boolean useStableBuildAsReference;
/** Determines if the previous build should always be used as the reference build.
* @since 1.66
*/
private final boolean usePreviousBuildAsReference;

/**
* Creates a new instance of {@link BuildHistory}.
Expand All @@ -36,18 +40,43 @@ public class BuildHistory {
* the build to start the history from
* @param type
* type of the action that contains the build results
* @param usePreviousBuildAsReference
* determines whether the previous build should always be used
* as the reference build
* @param useStableBuildAsReference
* determines whether only stable builds should be used as
* reference builds or not
* @since 1.47
* @since 1.66
*/
public BuildHistory(final AbstractBuild<?, ?> baseline, final Class<? extends ResultAction<? extends BuildResult>> type,
public BuildHistory(final AbstractBuild<?, ?> baseline,
final Class<? extends ResultAction<? extends BuildResult>> type,
final boolean usePreviousBuildAsReference,
final boolean useStableBuildAsReference) {
this.baseline = baseline;
this.type = type;
this.usePreviousBuildAsReference = usePreviousBuildAsReference;
this.useStableBuildAsReference = useStableBuildAsReference;
}

/**
* Creates a new instance of {@link BuildHistory}.
*
* @param baseline
* the build to start the history from
* @param type
* type of the action that contains the build results
* @param useStableBuildAsReference
* determines whether only stable builds should be used as
* reference builds or not
* @since 1.47
* @deprecated
*/
@Deprecated
public BuildHistory(final AbstractBuild<?, ?> baseline, final Class<? extends ResultAction<? extends BuildResult>> type,
final boolean useStableBuildAsReference) {
this(baseline, type, false, useStableBuildAsReference);
}

/**
* Determines whether only stable builds should be used as reference builds
* or not.
Expand Down Expand Up @@ -95,6 +124,9 @@ public AnnotationContainer getReferenceAnnotations() {
* such build exists
*/
private ResultAction<? extends BuildResult> getReferenceAction() {
if (usePreviousBuildAsReference) {
return getPreviousAction();
}
ResultAction<? extends BuildResult> action = getAction(true, useStableBuildAsReference);
if (action == null) {
return getPreviousAction(); // fallback, use action of previous build regardless of result
Expand Down
Expand Up @@ -29,6 +29,7 @@
public abstract class HealthAwarePublisher extends HealthAwareRecorder {
private static final long serialVersionUID = -4225952809165635796L;


/**
* Creates a new instance of {@link HealthAwarePublisher}.
*
Expand Down Expand Up @@ -81,6 +82,9 @@ public abstract class HealthAwarePublisher extends HealthAwareRecorder {
* annotation threshold
* @param canRunOnFailed
* determines whether the plug-in can run for failed builds, too
* @param usePreviousBuildAsReference
* determine if the previous build should always be used as the
* reference build, no matter its overall result.
* @param useStableBuildAsReference
* determines whether only stable builds should be used as
* reference builds or not
Expand All @@ -96,7 +100,7 @@ public abstract class HealthAwarePublisher extends HealthAwareRecorder {
* workspace for matching files.
* @param pluginName
* the name of the plug-in
* @since 1.48
* @since 1.66
*/
@SuppressWarnings("PMD")
public HealthAwarePublisher(final String healthy, final String unHealthy,
Expand All @@ -108,15 +112,20 @@ public HealthAwarePublisher(final String healthy, final String unHealthy,
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 canRunOnFailed,
final boolean usePreviousBuildAsReference,
final boolean useStableBuildAsReference,
final boolean shouldDetectModules, final boolean canComputeNew,
final boolean canResolveRelativePaths, final String pluginName) {
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, pluginName);
super(healthy, unHealthy, thresholdLimit, defaultEncoding,
useDeltaValues, unstableTotalAll, unstableTotalHigh,
unstableTotalNormal, unstableTotalLow, unstableNewAll,
unstableNewHigh, unstableNewNormal, unstableNewLow,
failedTotalAll, failedTotalHigh, failedTotalNormal,
failedTotalLow, failedNewAll, failedNewHigh, failedNewNormal,
failedNewLow, canRunOnFailed, usePreviousBuildAsReference,
useStableBuildAsReference, shouldDetectModules, canComputeNew,
canResolveRelativePaths, pluginName);
}

/**
Expand Down Expand Up @@ -255,6 +264,35 @@ public HealthAwarePublisher(final String threshold, final String newThreshold,
thresholdLimit, defaultEncoding, useDeltaValues, canRunOnFailed, pluginName);
}

/** Backwards compatibility.
* @deprecated
*/
@Deprecated
public HealthAwarePublisher(final String healthy, final String unHealthy,
final String thresholdLimit, final String defaultEncoding,
final boolean useDeltaValues, final String unstableTotalAll,
final String unstableTotalHigh, final String unstableTotalNormal,
final String unstableTotalLow, 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 boolean canResolveRelativePaths, final String pluginName) {
this(healthy, unHealthy, thresholdLimit, defaultEncoding,
useDeltaValues, unstableTotalAll, unstableTotalHigh,
unstableTotalNormal, unstableTotalLow, unstableNewAll,
unstableNewHigh, unstableNewNormal, unstableNewLow,
failedTotalAll, failedTotalHigh, failedTotalNormal,
failedTotalLow, failedNewAll, failedNewHigh, failedNewNormal,
failedNewLow, canRunOnFailed, false, useStableBuildAsReference,
shouldDetectModules, canComputeNew, canResolveRelativePaths,
pluginName);
}

@SuppressWarnings({"PMD","javadoc"})
@Deprecated
public HealthAwarePublisher(final String healthy, final String unHealthy,
Expand Down
Expand Up @@ -63,6 +63,11 @@ public abstract class HealthAwareRecorder extends Recorder implements HealthDesc
* @since 1.6
*/
private final boolean canRunOnFailed;
/** Determines whether the previous build should always be used as the
* reference build.
* @since 1.66
*/
private final boolean usePreviousBuildAsReference;
/**
* Determines whether only stable builds should be used as reference builds
* or not.
Expand Down Expand Up @@ -160,6 +165,9 @@ public abstract class HealthAwareRecorder extends Recorder implements HealthDesc
* annotation threshold
* @param canRunOnFailed
* determines whether the plug-in can run for failed builds, too
* @param usePreviousBuildAsReference
* determine if the previous build should always be used as the
* reference build, no matter its overall result.
* @param useStableBuildAsReference
* determines whether only stable builds should be used as
* reference builds or not
Expand Down Expand Up @@ -187,7 +195,8 @@ public HealthAwareRecorder(final String healthy, final String unHealthy,
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 canRunOnFailed, final boolean usePreviousBuildAsReference,
final boolean useStableBuildAsReference,
final boolean shouldDetectModules, final boolean canComputeNew,
final boolean canResolveRelativePaths, final String pluginName) {
super();
Expand Down Expand Up @@ -218,6 +227,7 @@ public HealthAwareRecorder(final String healthy, final String unHealthy,
thresholds.failedNewLow = failedNewLow;

this.canRunOnFailed = canRunOnFailed;
this.usePreviousBuildAsReference = usePreviousBuildAsReference;
this.useStableBuildAsReference = useStableBuildAsReference;
this.shouldDetectModules = shouldDetectModules;
this.pluginName = "[" + pluginName + "] ";
Expand Down Expand Up @@ -259,6 +269,10 @@ protected boolean isThresholdEnabled() {
return new NullHealthDescriptor(this).isThresholdEnabled();
}

public boolean getUsePreviousBuildAsReference() {
return usePreviousBuildAsReference;
}

/**
* Determines whether only stable builds should be used as reference builds
* or not.
Expand Down Expand Up @@ -659,6 +673,36 @@ public BuildStepMonitor getRequiredMonitorService() {
@Deprecated
private transient String height;

/** Backwards compatibility.
* @deprecated
*/
@Deprecated
@SuppressWarnings("PMD")
public HealthAwareRecorder(final String healthy, final String unHealthy,
final String thresholdLimit, final String defaultEncoding,
final boolean useDeltaValues, final String unstableTotalAll,
final String unstableTotalHigh, final String unstableTotalNormal,
final String unstableTotalLow, 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 boolean canResolveRelativePaths, final String pluginName) {
this(healthy, unHealthy, thresholdLimit, defaultEncoding,
useDeltaValues, unstableTotalAll, unstableTotalHigh,
unstableTotalNormal, unstableTotalLow, unstableNewAll,
unstableNewHigh, unstableNewNormal, unstableNewLow,
failedTotalAll, failedTotalHigh, failedTotalNormal,
failedTotalLow, failedNewAll, failedNewHigh, failedNewNormal,
failedNewLow, canRunOnFailed, false, useStableBuildAsReference,
shouldDetectModules, canComputeNew, canResolveRelativePaths,
pluginName);
}

/** Backward compatibility. @deprecated */
@SuppressWarnings({"PMD","javadoc"})
@Deprecated
Expand All @@ -680,6 +724,7 @@ public HealthAwareRecorder(final String threshold, final String newThreshold,
this.defaultEncoding = defaultEncoding;
this.useDeltaValues = useDeltaValues;
this.canRunOnFailed = canRunOnFailed;
this.usePreviousBuildAsReference = false;
useStableBuildAsReference = false;
dontComputeNew = false;
shouldDetectModules = false;
Expand Down

0 comments on commit b8712ca

Please sign in to comment.