Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
[FIXED JENKINS-11761] Added option to skip the computation of new
warnings. When this option is activated, then the synchronization
of the publisher build step is removed (thus making the build faster).
  • Loading branch information
uhafner committed Dec 5, 2011
1 parent 436c5d1 commit 189a9f754c1bb8296ba0707c153f57d122a9a92a
Showing 13 changed files with 311 additions and 84 deletions.
@@ -1,11 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/resources"/>
<classpathentry kind="src" path="target/generated-sources/localizer"/>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="src" output="target/classes" path="target/generated-sources/localizer">
<attributes>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
@@ -4,7 +4,7 @@
<parent>
<groupId>org.jvnet.hudson.plugins</groupId>
<artifactId>analysis-pom</artifactId>
<version>1.31</version>
<version>1.33</version>
<relativePath>../analysis-pom/pom.xml</relativePath>
</parent>

@@ -1018,13 +1018,34 @@ public boolean isSuccessful() {
*/
// CHECKSTYLE:OFF
public void evaluateStatus(final Thresholds thresholds, final boolean useDeltaValues, final PluginLogger logger) {
evaluateStatus(thresholds, useDeltaValues, true, logger);
}

/**
* Updates the build status, i.e. sets this plug-in result status field to
* the corresponding {@link Result}. Additionally, the {@link Result} of the
* build that owns this instance of {@link BuildResult} will be also
* changed.
*
* @param thresholds
* the failure thresholds
* @param useDeltaValues
* the use delta values when computing the differences
* @param canComputeNew
* determines whether new warnings should be computed (with
* respect to baseline)
* @param logger
* the logger
*/
// CHECKSTYLE:OFF
public void evaluateStatus(final Thresholds thresholds, final boolean useDeltaValues, final boolean canComputeNew, final PluginLogger logger) {
// CHECKSTYLE:ON
this.thresholds = thresholds;
this.useDeltaValues = useDeltaValues;

BuildResultEvaluator resultEvaluator = new BuildResultEvaluator();
Result buildResult;
if (history.isEmpty()) {
if (history.isEmpty() || !canComputeNew) {
logger.log("Ignore new warnings since this is the first valid build");
buildResult = resultEvaluator.evaluateBuildResult(logger, thresholds, getAnnotations());
}
@@ -79,21 +79,25 @@ public abstract class HealthAwarePublisher extends Recorder implements HealthDes
* @since 1.4
*/
private final boolean useDeltaValues;

/**
* Thresholds for build status unstable and failed, resp. and priorities
* all, high, normal, and low, resp.
*
* @since 1.14
*/
private Thresholds thresholds = new Thresholds();

/**
* Determines whether module names should be derived from Maven POM or Ant build files.
*
* @since 1.19
*/
private final boolean shouldDetectModules;
/**
* Determines whether new warnings should be computed (with respect to baseline).
*
* @since 1.34
*/
private final boolean canComputeNew;

/**
* Creates a new instance of {@link HealthAwarePublisher}.
@@ -149,6 +153,8 @@ public abstract class HealthAwarePublisher extends Recorder implements HealthDes
* determines whether the plug-in can run for failed builds, too
* @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 pluginName
* the name of the plug-in
*/
@@ -160,14 +166,16 @@ public HealthAwarePublisher(final String healthy, final String unHealthy, final
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 String pluginName) {
final boolean canRunOnFailed, final boolean shouldDetectModules, final boolean canComputeNew,
final String pluginName) {
super();
this.healthy = healthy;
this.unHealthy = unHealthy;
this.thresholdLimit = thresholdLimit;
this.defaultEncoding = defaultEncoding;

this.useDeltaValues = useDeltaValues;
this.canComputeNew = canComputeNew;

thresholds.unstableTotalAll = unstableTotalAll;
thresholds.unstableTotalHigh = unstableTotalHigh;
@@ -191,6 +199,22 @@ public HealthAwarePublisher(final String healthy, final String unHealthy, final
this.pluginName = "[" + pluginName + "] ";
}

@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 shouldDetectModules, 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, shouldDetectModules, true, pluginName);
}

@Deprecated
@SuppressWarnings("PMD.ExcessiveParameterList")
public HealthAwarePublisher(final String healthy, final String unHealthy, final String thresholdLimit,
@@ -265,6 +289,7 @@ public HealthAwarePublisher(final String threshold, final String newThreshold,
this.defaultEncoding = defaultEncoding;
this.useDeltaValues = useDeltaValues;
this.canRunOnFailed = canRunOnFailed;
canComputeNew = true;
shouldDetectModules = false;
this.pluginName = "[" + pluginName + "] ";
}
@@ -318,7 +343,7 @@ public final boolean perform(final AbstractBuild<?, ?> build, final Launcher lau
}

if (new NullHealthDescriptor(this).isThresholdEnabled()) {
result.evaluateStatus(getThresholds(), useDeltaValues, logger);
result.evaluateStatus(getThresholds(), useDeltaValues, canComputeNew, logger);
}

copyFilesWithAnnotationsToBuildFolder(build.getRootDir(), launcher.getChannel(), result.getAnnotations());
@@ -409,10 +434,22 @@ private void logExceptionToFile(final IOException exception, final File masterFi
}
}

/**
* Returns whether new warnings should be computed (with respect to
* baseline).
*
* @return <code>true</code> if new warnings should be computed (with
* respect to baseline), <code>false</code> otherwise
*/
public boolean getCanComputeNew() {
return canComputeNew;
}

/**
* Returns whether this plug-in can run for failed builds, too.
*
* @return the can run on failed
* @return <code>true</code> if this plug-in can run for failed builds,
* <code>false</code> otherwise
*/
public boolean getCanRunOnFailed() {
return canRunOnFailed;
@@ -489,7 +526,9 @@ public Thresholds getThresholds() {
* Returns whether absolute annotations delta or the actual annotations set
* difference should be used to evaluate the build stability.
*
* @return the useDeltaValues
* @return <code>true</code> if the annotation count should be used,
* <code>false</code> if the actual (set) difference should be
* computed
*/
public boolean getUseDeltaValues() {
return useDeltaValues;
@@ -578,7 +617,7 @@ public String getThresholdLimit() {

/** {@inheritDoc} */
public BuildStepMonitor getRequiredMonitorService() {
return BuildStepMonitor.STEP;
return canComputeNew ? BuildStepMonitor.STEP : BuildStepMonitor.NONE;
}

/** Annotation threshold to be reached if a build should be considered as unstable. */
@@ -85,6 +85,12 @@
* @since 1.20
*/
private Thresholds thresholds = new Thresholds();
/**
* Determines whether new warnings should be computed (with respect to baseline).
*
* @since 1.34
*/
private final boolean canComputeNew;

/**
* Creates a new instance of <code>HealthReportingMavenReporter</code>.
@@ -136,6 +142,8 @@
* 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
*/
@@ -146,12 +154,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 String pluginName) {
final boolean canRunOnFailed, final boolean canComputeNew,
final String pluginName) {
super();
this.healthy = healthy;
this.unHealthy = unHealthy;
this.thresholdLimit = thresholdLimit;
this.canRunOnFailed = canRunOnFailed;
this.canComputeNew = canComputeNew;
this.pluginName = "[" + pluginName + "] ";

this.useDeltaValues = useDeltaValues;
@@ -177,11 +187,43 @@ public HealthAwareReporter(final String healthy, final String unHealthy, final S
}
// CHECKSTYLE:ON


// 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 String pluginName) {
this(healthy, unHealthy, thresholdLimit, useDeltaValues,
unstableTotalAll, unstableTotalHigh, unstableTotalNormal, unstableTotalLow,
unstableNewAll, unstableNewHigh, unstableNewNormal, unstableNewLow,
failedTotalAll, failedTotalHigh, failedTotalNormal, failedTotalLow,
failedNewAll, failedNewHigh, failedNewNormal, failedNewLow,
canRunOnFailed, true, pluginName);
}
// CHECKSTYLE:ON

/**
* Returns whether new warnings should be computed (with respect to
* baseline).
*
* @return <code>true</code> if new warnings should be computed (with
* respect to baseline), <code>false</code> otherwise
*/
public boolean getCanComputeNew() {
return canComputeNew;
}

/**
* Returns whether absolute annotations delta or the actual annotations set
* difference should be used to evaluate the build stability.
*
* @return the useDeltaValues
* @return <code>true</code> if the annotation count should be used,
* <code>false</code> if the actual (set) difference should be
* computed
*/
public boolean getUseDeltaValues() {
return useDeltaValues;
@@ -284,7 +326,7 @@ private String registerResults(final ParserResult result, final MavenBuild maven
T buildResult = createResult(mavenBuild, result);

StringPluginLogger pluginLogger = new StringPluginLogger(pluginName);
buildResult.evaluateStatus(thresholds, useDeltaValues, pluginLogger);
buildResult.evaluateStatus(thresholds, useDeltaValues, canComputeNew, pluginLogger);
mavenBuild.getActions().add(createMavenAggregatedReport(mavenBuild, buildResult));
mavenBuild.registerAsProjectAction(HealthAwareReporter.this);
return pluginLogger.toString();
@@ -332,7 +374,8 @@ private Result getCurrentResult(final MavenBuildProxy build) throws IOException,
/**
* Returns whether this plug-in can run for failed builds, too.
*
* @return the can run on failed
* @return <code>true</code> if this plug-in can run for failed builds,
* <code>false</code> otherwise
*/
public boolean getCanRunOnFailed() {
return canRunOnFailed;
@@ -2,8 +2,11 @@

import java.io.IOException;

import net.sf.json.JSONObject;

import org.kohsuke.stapler.AncestorInPath;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;

import hudson.FilePath;
import hudson.maven.AbstractMavenProject;
@@ -24,6 +27,34 @@
* @author Ulli Hafner
*/
public abstract class PluginDescriptor extends BuildStepDescriptor<Publisher> {
private static final String NEW_SECTION_KEY = "canComputeNew";

/**
* Converts the hierarchical JSON object that contains a sub-section for
* {@value #NEW_SECTION_KEY} to a corresponding flat JSON object.
*
* @param hierarchical
* the JSON object containing a sub-section
* @return the flat structure
*/
static JSONObject convertHierarchicalFormData(final JSONObject hierarchical) {
if (hierarchical.containsKey(NEW_SECTION_KEY)) {
JSONObject newSection = hierarchical.getJSONObject(NEW_SECTION_KEY);

JSONObject output = JSONObject.fromObject(hierarchical);
output.remove(NEW_SECTION_KEY);
for (Object key : newSection.keySet()) {
output.put((String)key, newSection.get(key));
}
output.put(NEW_SECTION_KEY, true);

return output;
}
else {
return hierarchical;
}
}

/**
* Creates a new instance of <code>PluginDescriptor</code>.
*
@@ -34,6 +65,12 @@ public PluginDescriptor(final Class<? extends Publisher> clazz) {
super(clazz);
}

@Override
public Publisher newInstance(final StaplerRequest req, final JSONObject formData)
throws hudson.model.Descriptor.FormException {
return super.newInstance(req, convertHierarchicalFormData(formData));
}

/** {@inheritDoc} */
@Override
public final String getHelpFile() {
@@ -1,5 +1,2 @@
File=Datei
Line=Zeile
Type=Typ
Priority=Priorit&auml;t
Priority=Priorität
Category=Kategorie
@@ -1,5 +1,4 @@
Modules=Projekte
Packages=Packages
Files=Dateien
Categories=Kategorien
Types=Typen
@@ -2,3 +2,4 @@ description.detectModules=Bestimmt ob Dateien, die Warnungen enthalten, nach Pro
Die Projektnamen werden aus den Ant oder Maven Konfigurationsdateien ermittelt und den Warnungen zugeordnet. \
Da dazu der gesamte Arbeitsbereich nach ''build.xml'' oder ''pom.xml'' Dateien durchsucht wird, kann je \
nach Größe des Arbeitsbereichs die Dauer eines Builds erheblich erhöht werden.
Detect\ modules=Projekte automatisch erkennen

0 comments on commit 189a9f7

Please sign in to comment.