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
[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 189a9f7
Show file tree
Hide file tree
Showing 13 changed files with 311 additions and 84 deletions.
10 changes: 7 additions & 3 deletions .classpath
@@ -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>
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -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>

Expand Down
23 changes: 22 additions & 1 deletion src/main/java/hudson/plugins/analysis/core/BuildResult.java
Expand Up @@ -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());
}
Expand Down
Expand Up @@ -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}.
Expand Down Expand Up @@ -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
*/
Expand All @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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 + "] ";
}
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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. */
Expand Down
Expand Up @@ -85,6 +85,12 @@ public abstract class HealthAwareReporter<T extends BuildResult> extends MavenRe
* @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>.
Expand Down Expand Up @@ -136,6 +142,8 @@ public abstract class HealthAwareReporter<T extends BuildResult> extends MavenRe
* 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
*/
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/hudson/plugins/analysis/core/PluginDescriptor.java
Expand Up @@ -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;
Expand All @@ -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>.
*
Expand All @@ -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() {
Expand Down
@@ -1,5 +1,2 @@
File=Datei
Line=Zeile
Type=Typ
Priority=Priorit&auml;t
Priority=Priorität
Category=Kategorie
1 change: 0 additions & 1 deletion src/main/resources/result/main_de.properties
@@ -1,5 +1,4 @@
Modules=Projekte
Packages=Packages
Files=Dateien
Categories=Kategorien
Types=Typen
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/util/advanced_de.properties
Expand Up @@ -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.