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 b8712ca commit 1a2ebe2a80da6cdf429a442cc3b2be8494337441
@@ -9,6 +9,7 @@
import java.util.Collection;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.builder.HashCodeBuilder;

import hudson.plugins.analysis.util.ContextHashCode;
import hudson.plugins.analysis.util.model.AbstractAnnotation;
@@ -96,8 +97,35 @@ protected final String getDefaultEncoding() {
* the line of the warning
* @return a has code of the source code
* @throws IOException if the contents of the file could not be read
* @deprecated use {@link AbstractAnnotationParser#createContextHashCode(String, int, String)}
*/
@Deprecated
protected int createContextHashCode(final String fileName, final int line) throws IOException {
return new ContextHashCode().create(fileName, line, defaultEncoding);
}

/**
* Creates a hash code from the source code of the warning line and the
* surrounding context. If the source file could not be read then the hashcode is computed from the filename and line.
*
* @param fileName
* the absolute path of the file to read
* @param line
* the line of the warning
* @param warningType
* the type of the warning
* @return a hashcode of the source code
* @since 1.66
*/
protected int createContextHashCode(final String fileName, final int line, final String warningType) {
HashCodeBuilder builder = new HashCodeBuilder();
try {
builder.append(new ContextHashCode().create(fileName, line, defaultEncoding));
}
catch (IOException exception) {
builder.append(fileName).append(line);
}
builder.append(warningType);
return builder.toHashCode();
}
}
@@ -1,16 +1,14 @@
package hudson.plugins.analysis.core;

import javax.annotation.CheckForNull;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.NoSuchElementException;
import java.util.Set;

import javax.annotation.CheckForNull;

import hudson.model.Result;
import hudson.model.AbstractBuild;

import hudson.model.Result;
import hudson.plugins.analysis.util.model.AnnotationContainer;
import hudson.plugins.analysis.util.model.DefaultAnnotationContainer;
import hudson.plugins.analysis.util.model.FileAnnotation;
@@ -28,7 +26,8 @@
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.
/**
* Determines if the previous build should always be used as the reference build.
* @since 1.66
*/
private final boolean usePreviousBuildAsReference;
@@ -58,25 +57,6 @@ public BuildHistory(final AbstractBuild<?, ?> baseline,
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.
@@ -87,6 +67,15 @@ public boolean useOnlyStableBuildsAsReference() {
return useStableBuildAsReference;
}

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

/**
* Returns the time of the baseline build.
*
@@ -334,7 +323,26 @@ public AbstractHealthDescriptor getHealthDescriptor() {
* the build to start the history from
* @param type
* type of the action that contains the build results
* @deprecated use {@link #BuildHistory(AbstractBuild, Class, boolean)}
* @param useStableBuildAsReference
* determines whether only stable builds should be used as
* reference builds or not
* @since 1.47
* @deprecated use {@link #BuildHistory(AbstractBuild, Class, boolean, boolean)}
*/
@Deprecated
public BuildHistory(final AbstractBuild<?, ?> baseline, final Class<? extends ResultAction<? extends BuildResult>> type,
final boolean useStableBuildAsReference) {
this(baseline, type, false, 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 use {@link #BuildHistory(AbstractBuild, Class, boolean, boolean)}
*/
@Deprecated
public BuildHistory(final AbstractBuild<?, ?> baseline, final Class<? extends ResultAction<? extends BuildResult>> type) {
@@ -13,8 +13,6 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import jenkins.model.Jenkins;

import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateUtils;
@@ -26,14 +24,14 @@

import com.thoughtworks.xstream.XStream;

import hudson.XmlFile;
import jenkins.model.Jenkins;

import hudson.model.ModelObject;
import hudson.model.Result;
import hudson.XmlFile;
import hudson.model.AbstractBuild;
import hudson.model.Api;
import hudson.model.Hudson;

import hudson.model.ModelObject;
import hudson.model.Result;
import hudson.plugins.analysis.Messages;
import hudson.plugins.analysis.util.HtmlPrinter;
import hudson.plugins.analysis.util.PluginLogger;
@@ -239,6 +237,15 @@ public boolean useOnlyStableBuildsAsReference() {
return history.useOnlyStableBuildsAsReference();
}

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

/**
* Initializes this new instance of {@link BuildResult}.
*
@@ -1134,7 +1141,7 @@ else if (useDeltaValues) {

// CHECKSTYLE:OFF
/**
* @deprecated use {@link #evaluateStatus(Thresholds, boolean, PluginLogger)}
* @deprecated use {@link #evaluateStatus(Thresholds, boolean, boolean, PluginLogger, String)}
*/
@SuppressWarnings("javadoc")
@Deprecated
@@ -29,7 +29,6 @@
public abstract class HealthAwarePublisher extends HealthAwareRecorder {
private static final long serialVersionUID = -4225952809165635796L;


/**
* Creates a new instance of {@link HealthAwarePublisher}.
*
@@ -269,6 +269,20 @@ protected boolean isThresholdEnabled() {
return new NullHealthDescriptor(this).isThresholdEnabled();
}

/**
* Determines if the previous build should always be used as the reference build, no matter its overall result.
*
* @return <code>true</code> the previous build should always be used
*/
public boolean usePreviousBuildAsReference() {
return getUsePreviousBuildAsReference();
}

/**
* Determines if the previous build should always be used as the reference build, no matter its overall result.
*
* @return <code>true</code> the previous build should always be used
*/
public boolean getUsePreviousBuildAsReference() {
return usePreviousBuildAsReference;
}
@@ -240,6 +240,14 @@ public boolean getUsePreviousBuildAsStable() {
return usePreviousBuildAsReference;
}

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

/**
* Determines whether only stable builds should be used as reference builds or not.
@@ -130,11 +130,10 @@
</tbody>
</table>
</f:entry>
<f:entry title="${%Use delta for new warnings}"
description="${%description.useDeltaValues}">
<f:entry title="${%Use delta for new warnings}" description="${%description.useDeltaValues}">
<f:checkbox name="useDeltaValues" checked="${instance.useDeltaValues}" />
</f:entry>
<f:entry title="${%title.usePreviousBuildAsReference}">
<f:entry title="${%title.usePreviousBuildAsReference}" description="${%description.useDeltaValues}">
<f:checkbox name="usePreviousBuildAsReference"
checked="${instance.usePreviousBuildAsReference}" />
</f:entry>
@@ -25,6 +25,8 @@ description.onlyUseStableBuildsAsReference=The number of new warnings will be ca
stable build, allowing reverts of unstable builds where the number of warnings was decreased. \
Note that the last stable build is evaluated only by inspecting the unit test failures. The \
static analysis results are not considered.
title.usePreviousBuildAsReference=Always use the previous build as the reference build.

title.usePreviousBuildAsReference=Use previous build as reference
description.usePreviousBuildAsReference=If set then the number of new warnings will always be calculated based on the \
previous build. Otherwise the reference build (i.e., the build that introduced the new warnings) is used \
to calculate the new warnings.
compute.new.title=Compute new warnings (based on reference build)
@@ -31,3 +31,7 @@ description.onlyUseStableBuildsAsReference=Die Anzahl der neuen Warnungen wird a
bestimmt (Achtung: die Stabilität bezieht sich nicht auf die statische Analyse sondern nur auf die Ergebnisse \
der Unit Tests). Dadurch lässt sich ein instabiler Build rückgängig machen, ohne dass die Berechnung der Warnungen \
beeinflusst wird.
title.usePreviousBuildAsReference=Letzten Build als Referenz nutzen
description.usePreviousBuildAsReference=Falls aktiviert, wird die Anzahl der neuen Warnungen auf Basis des letzten Builds \
bestimmt. Normalerweise wird die Anzahl der neuen Warnungen durch einen Vergleich mit dem Referenzbuild ermittelt,\
d.h. mit dem Build, bei dem die neuen Warnungen das erste Mal erschienen sind.

0 comments on commit 1a2ebe2

Please sign in to comment.