Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Merge pull request #14 from davidparsson/master
[FIXED JENKINS-15037] Added flag to consider only stable reference builds.
  • Loading branch information
uhafner committed Sep 17, 2012
2 parents 37339d9 + f739580 commit b4bf0441cd3ec069687ea06ee2d9acff22b687af
Showing 6 changed files with 305 additions and 18 deletions.
@@ -26,6 +26,8 @@ public class BuildHistory {
private final AbstractBuild<?, ?> baseline;
/** Type of the action that contains the build results. */
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;

/**
* Creates a new instance of {@link BuildHistory}.
@@ -34,10 +36,29 @@ public class BuildHistory {
* 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
*/
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 useStableBuildAsReference) {
this.baseline = baseline;
this.type = type;
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
*/
@Deprecated
public BuildHistory(final AbstractBuild<?, ?> baseline, final Class<? extends ResultAction<? extends BuildResult>> type) {
this(baseline, type, false);
}

/**
@@ -77,7 +98,7 @@ public AnnotationContainer getReferenceAnnotations() {
* such build exists
*/
private ResultAction<? extends BuildResult> getReferenceAction() {
ResultAction<? extends BuildResult> action = getAction(true);
ResultAction<? extends BuildResult> action = getAction(true, useStableBuildAsReference);
if (action == null) {
return getPreviousAction(); // fallback, use action of previous build regardless of result
}
@@ -87,8 +108,12 @@ private ResultAction<? extends BuildResult> getReferenceAction() {
}

private ResultAction<? extends BuildResult> getAction(final boolean isStatusRelevant) {
return getAction(isStatusRelevant, false);
}

private ResultAction<? extends BuildResult> getAction(final boolean isStatusRelevant, final boolean mustBeStable) {
for (AbstractBuild<?, ?> build = baseline.getPreviousBuild(); build != null; build = build.getPreviousBuild()) {
if (hasValidResult(build)) {
if (hasValidResult(build, mustBeStable)) {
ResultAction<? extends BuildResult> action = getResultAction(build);
if (action != null && (action.isSuccessful() || !isStatusRelevant)) {
return action;
@@ -143,9 +168,18 @@ private ResultAction<? extends BuildResult> getPreviousAction() {
}

private boolean hasValidResult(final AbstractBuild<?, ?> build) {
return hasValidResult(build, false);
}
private boolean hasValidResult(final AbstractBuild<?, ?> build, final boolean mustBeStable) {
Result result = build.getResult();

return result != null && build.getResult().isBetterThan(Result.FAILURE);
if (result == null) {
return false;
}
if (mustBeStable) {
return result == Result.SUCCESS;
}
return build.getResult().isBetterThan(Result.FAILURE);
}

/**
@@ -27,6 +27,101 @@
*/
// CHECKSTYLE:OFF
public abstract class HealthAwarePublisher extends HealthAwareRecorder {

private final boolean useStableBuildAsReference;

/**
* Creates a new instance of {@link HealthAwarePublisher}.
*
* @param healthy
* Report health as 100% when the number of open tasks is less
* than this value
* @param unHealthy
* Report health as 0% when the number of open tasks is greater
* than this value
* @param thresholdLimit
* determines which warning priorities should be considered when
* evaluating the build stability and health
* @param defaultEncoding
* the default encoding to be used when reading and parsing files
* @param useDeltaValues
* determines whether the absolute annotations delta or the
* actual annotations set difference should be used to evaluate
* the build stability
* @param unstableTotalAll
* annotation threshold
* @param unstableTotalHigh
* annotation threshold
* @param unstableTotalNormal
* annotation threshold
* @param unstableTotalLow
* annotation threshold
* @param unstableNewAll
* annotation threshold
* @param unstableNewHigh
* annotation threshold
* @param unstableNewNormal
* annotation threshold
* @param unstableNewLow
* annotation threshold
* @param failedTotalAll
* annotation threshold
* @param failedTotalHigh
* annotation threshold
* @param failedTotalNormal
* annotation threshold
* @param failedTotalLow
* annotation threshold
* @param failedNewAll
* annotation threshold
* @param failedNewHigh
* annotation threshold
* @param failedNewNormal
* annotation threshold
* @param failedNewLow
* 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 shouldDetectModules
* determines whether module names should be derived from Maven
* POM or Ant build files
* @param canComputeNew
* determines whether new warnings should be computed (with
* respect to baseline)
* @param canResolveRelativePaths
* determines whether relative paths in warnings should be
* resolved using a time expensive operation that scans the whole
* workspace for matching files.
* @param pluginName
* the name of the plug-in
* @since 1.47
*/
@SuppressWarnings("PMD")
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) {
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, pluginName);
this.useStableBuildAsReference = useStableBuildAsReference;

}

/**
* Creates a new instance of {@link HealthAwarePublisher}.
*
@@ -105,11 +200,11 @@ public HealthAwarePublisher(final String healthy, final String unHealthy,
final boolean canRunOnFailed, final boolean shouldDetectModules,
final boolean canComputeNew, final boolean canResolveRelativePaths,
final String pluginName) {
super(healthy, unHealthy, thresholdLimit, defaultEncoding, useDeltaValues,
this(healthy, unHealthy, thresholdLimit, defaultEncoding, useDeltaValues,
unstableTotalAll, unstableTotalHigh, unstableTotalNormal, unstableTotalLow,
unstableNewAll, unstableNewHigh, unstableNewNormal, unstableNewLow, failedTotalAll,
failedTotalHigh, failedTotalNormal, failedTotalLow, failedNewAll, failedNewHigh,
failedNewNormal, failedNewLow, canRunOnFailed, shouldDetectModules, canComputeNew,
failedNewNormal, failedNewLow, canRunOnFailed, false, shouldDetectModules, canComputeNew,
canResolveRelativePaths, pluginName);
}

@@ -280,6 +375,14 @@ protected void updateBuildResult(final BuildResult result, final PluginLogger lo
protected abstract BuildResult perform(AbstractBuild<?, ?> build, PluginLogger logger)
throws InterruptedException, IOException;

/**
* Determines whether only stable builds should be used as reference builds or not
* @return <code>true</code> if only stable builds should be used
*/
public boolean getUseStableBuildAsReference() {
return useStableBuildAsReference;
}

// CHECKSTYLE:OFF
@Deprecated
@SuppressWarnings({"PMD.ExcessiveParameterList","javadoc"})
@@ -328,5 +431,6 @@ public HealthAwarePublisher(final String threshold, final String newThreshold,
final boolean useDeltaValues, final boolean canRunOnFailed, final String pluginName) {
super(threshold, newThreshold, failureThreshold, newFailureThreshold, healthy, unHealthy,
thresholdLimit, defaultEncoding, useDeltaValues, canRunOnFailed, pluginName);
useStableBuildAsReference = false;
}
}
@@ -92,6 +92,12 @@
* @since 1.34
*/
private final boolean dontComputeNew;
/**
* Determines whether only stable builds should be used as reference builds or not
*
* @since 1.47
*/
private final boolean useStableBuildAsReference;

/**
* Creates a new instance of <code>HealthReportingMavenReporter</code>.
@@ -143,6 +149,8 @@
* 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)
* @param pluginName
@@ -155,13 +163,14 @@ public HealthAwareReporter(final String healthy, final String unHealthy, final S
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 canComputeNew,
final boolean canRunOnFailed, final boolean useStableBuildAsReference, final boolean canComputeNew,
final String pluginName) {
super();
this.healthy = healthy;
this.unHealthy = unHealthy;
this.thresholdLimit = thresholdLimit;
this.canRunOnFailed = canRunOnFailed;
this.useStableBuildAsReference = useStableBuildAsReference;
this.dontComputeNew = !canComputeNew;
this.pluginName = "[" + pluginName + "] ";

@@ -188,6 +197,81 @@ public HealthAwareReporter(final String healthy, final String unHealthy, final S
}
// CHECKSTYLE:ON

/**
* Creates a new instance of <code>HealthReportingMavenReporter</code>.
*
* @param healthy
* Report health as 100% when the number of warnings is less than
* this value
* @param unHealthy
* Report health as 0% when the number of warnings is greater
* than this value
* @param thresholdLimit
* determines which warning priorities should be considered when
* evaluating the build stability and health
* @param useDeltaValues
* determines whether the absolute annotations delta or the
* actual annotations set difference should be used to evaluate
* the build stability
* @param unstableTotalAll
* annotation threshold
* @param unstableTotalHigh
* annotation threshold
* @param unstableTotalNormal
* annotation threshold
* @param unstableTotalLow
* annotation threshold
* @param unstableNewAll
* annotation threshold
* @param unstableNewHigh
* annotation threshold
* @param unstableNewNormal
* annotation threshold
* @param unstableNewLow
* annotation threshold
* @param failedTotalAll
* annotation threshold
* @param failedTotalHigh
* annotation threshold
* @param failedTotalNormal
* annotation threshold
* @param failedTotalLow
* annotation threshold
* @param failedNewAll
* annotation threshold
* @param failedNewHigh
* annotation threshold
* @param failedNewNormal
* annotation threshold
* @param failedNewLow
* annotation threshold
* @param canRunOnFailed
* determines whether the plug-in can run for failed builds, too
* @param canComputeNew
* determines whether new warnings should be computed (with respect to baseline)
* @param pluginName
* the name of the plug-in
*/
// CHECKSTYLE:OFF
@SuppressWarnings("PMD.ExcessiveParameterList")
@Deprecated
public HealthAwareReporter(final String healthy, final String unHealthy, final String thresholdLimit, 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 canComputeNew,
final String pluginName) {
this(healthy, unHealthy, thresholdLimit, useDeltaValues,
unstableTotalAll, unstableTotalHigh, unstableTotalNormal, unstableTotalLow,
unstableNewAll, unstableNewHigh, unstableNewNormal, unstableNewLow,
failedTotalAll, failedTotalHigh, failedTotalNormal, failedTotalLow,
failedNewAll, failedNewHigh, failedNewNormal, failedNewLow,
canRunOnFailed, false, canComputeNew,
pluginName);
}
// CHECKSTYLE:ON


// CHECKSTYLE:OFF
@SuppressWarnings({"PMD.ExcessiveParameterList","javadoc"})
@@ -241,6 +325,15 @@ public boolean getUseDeltaValues() {
return useDeltaValues;
}

/**
* Determines whether only stable builds should be used as reference builds or not
*
* @return <code>true</code> if only stable builds should be used
*/
public boolean getUseStableBuildAsReference() {
return useStableBuildAsReference;
}

/** {@inheritDoc} */
public Thresholds getThresholds() {
return thresholds;
@@ -1,8 +1,8 @@
<?jelly escape-by-default='true'?>
<!--
Section header
<%@attribute name="id" required="true" %>
<!--
Section header
<%@attribute name="id" required="true" %>
-->
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define"
@@ -134,6 +134,10 @@
description="${%description.useDeltaValues}">
<f:checkbox name="useDeltaValues" checked="${instance.useDeltaValues}" />
</f:entry>
<f:entry title="${%Only use stable builds as reference}"
description="${%description.onlyUseStableBuildsAsReference}">
<f:checkbox name="useStableBuildAsReference" checked="${instance.useStableBuildAsReference}" />
</f:entry>
</f:optionalBlock>
</table>
</f:block>

0 comments on commit b4bf044

Please sign in to comment.