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

Commit

Permalink
[JENKINS-4912] Added build health/threshold evaluation for m2 jobs.
Browse files Browse the repository at this point in the history
Totally refactored the calculation code, introduced new parent class.
  • Loading branch information
uhafner committed May 11, 2011
1 parent 11ccc22 commit bb911e9
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 26 deletions.
47 changes: 41 additions & 6 deletions src/main/java/hudson/plugins/tasks/MavenTasksResultAction.java
Expand Up @@ -8,8 +8,11 @@
import hudson.maven.MavenModuleSetBuild;
import hudson.model.Action;
import hudson.model.AbstractBuild;
import hudson.plugins.analysis.core.BuildResult;
import hudson.plugins.analysis.core.HealthDescriptor;
import hudson.plugins.analysis.core.ParserResult;
import hudson.plugins.analysis.util.PluginLogger;
import hudson.plugins.analysis.util.model.Priority;
import hudson.plugins.tasks.parser.TasksParserResult;

import java.util.List;
Expand Down Expand Up @@ -119,7 +122,7 @@ public Class<? extends AggregatableAction> getIndividualActionType() {

/**
* Called whenever a new module build is completed, to update the aggregated
* report. When multiple builds complete simultaneously, Hudson serializes
* report. When multiple builds complete simultaneously, Jenkins serializes
* the execution of this method, so this method needs not be
* concurrency-safe.
*
Expand All @@ -130,15 +133,47 @@ public Class<? extends AggregatableAction> getIndividualActionType() {
* Newly completed build.
*/
public void update(final Map<MavenModule, List<MavenBuild>> moduleBuilds, final MavenBuild newBuild) {
ParserResult result = createAggregatedResult(moduleBuilds);
MavenTasksResultAction additionalAction = newBuild.getAction(MavenTasksResultAction.class);
if (additionalAction != null) {
TasksResult existingResult = getResult();
TasksResult additionalResult = additionalAction.getResult();

if (result instanceof TasksParserResult) {
TasksMavenResult mavenResult = new TasksMavenResult(getOwner(), defaultEncoding, (TasksParserResult)result, high, normal, low);
setResult(mavenResult);
updateBuildHealth(newBuild, mavenResult);
log("Aggregating results of " + newBuild.getProject().getDisplayName());

if (existingResult == null) {
setResult(additionalResult);
getOwner().setResult(additionalResult.getPluginResult());
}
else {
setResult(aggregate(existingResult, additionalResult, getLogger()));
}
}
}

/**
* Creates a new instance of {@link BuildResult} that contains the aggregated
* results of this result and the provided additional result.
*
* @param existingResult
* the existing result
* @param additionalResult
* the result that will be added to the existing result
* @param logger
* the plug-in logger
* @return the aggregated result
*/
public TasksResult aggregate(final TasksResult existingResult, final TasksResult additionalResult, final PluginLogger logger) {
TasksParserResult aggregatedAnnotations = new TasksParserResult();
aggregatedAnnotations.addAnnotations(existingResult.getAnnotations());
aggregatedAnnotations.addScannedFiles(existingResult.getNumberOfFiles());
aggregatedAnnotations.addAnnotations(additionalResult.getAnnotations());
aggregatedAnnotations.addScannedFiles(additionalResult.getNumberOfFiles());

TasksResult createdResult = new TasksResult(getOwner(), existingResult.getDefaultEncoding(), aggregatedAnnotations,
existingResult.getTags(Priority.HIGH), existingResult.getTags(Priority.NORMAL), existingResult.getTags(Priority.LOW));
createdResult.evaluateStatus(existingResult.getThresholds(), existingResult.canUseDeltaValues(), logger);
return createdResult;
}
/** {@inheritDoc} */
@Override
protected ParserResult createResult() {
Expand Down
36 changes: 16 additions & 20 deletions src/main/java/hudson/plugins/tasks/TasksReporter.java
@@ -1,13 +1,12 @@
package hudson.plugins.tasks;

import hudson.FilePath;
import hudson.maven.MavenAggregatedReport;
import hudson.maven.MavenBuildProxy;
import hudson.maven.MojoInfo;
import hudson.maven.MavenBuild;
import hudson.maven.MavenModule;
import hudson.model.Action;
import hudson.plugins.analysis.core.BuildResult;
import hudson.plugins.analysis.core.HealthAwareMavenReporter;
import hudson.plugins.analysis.core.HealthAwareReporter;
import hudson.plugins.analysis.core.ParserResult;
import hudson.plugins.analysis.util.PluginLogger;
import hudson.plugins.tasks.parser.TasksParserResult;
Expand All @@ -29,7 +28,7 @@
* @author Ulli Hafner
*/
// CHECKSTYLE:COUPLING-OFF
public class TasksReporter extends HealthAwareMavenReporter {
public class TasksReporter extends HealthAwareReporter<TasksResult> {
/** Unique identifier of this class. */
private static final long serialVersionUID = -4159947472293502606L;

Expand Down Expand Up @@ -64,6 +63,10 @@ public class TasksReporter extends HealthAwareMavenReporter {
* @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
Expand Down Expand Up @@ -111,14 +114,14 @@ public class TasksReporter extends HealthAwareMavenReporter {
@SuppressWarnings("PMD.ExcessiveParameterList")
@DataBoundConstructor
public TasksReporter(final String pattern, final String excludePattern,
final String healthy, final String unHealthy, final String thresholdLimit,
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 String high, final String normal, final String low,
final boolean ignoreCase, final boolean canRunOnFailed) {
super(healthy, unHealthy, thresholdLimit,
super(healthy, unHealthy, thresholdLimit, useDeltaValues,
unstableTotalAll, unstableTotalHigh, unstableTotalNormal, unstableTotalLow,
unstableNewAll, unstableNewHigh, unstableNewNormal, unstableNewLow,
failedTotalAll, failedTotalHigh, failedTotalNormal, failedTotalLow,
Expand Down Expand Up @@ -187,13 +190,11 @@ public boolean getIgnoreCase() {
return ignoreCase;
}

/** {@inheritDoc} */
@Override
protected boolean acceptGoal(final String goal) {
return true;
}

/** {@inheritDoc} */
@SuppressWarnings("PMD.AvoidFinalLocalVariable")
@Override
public TasksParserResult perform(final MavenBuildProxy build, final MavenProject pom, final MojoInfo mojo, final PluginLogger logger) throws InterruptedException, IOException {
Expand Down Expand Up @@ -235,28 +236,23 @@ public TasksParserResult perform(final MavenBuildProxy build, final MavenProject
return project;
}

/** {@inheritDoc} */
@edu.umd.cs.findbugs.annotations.SuppressWarnings("BC")
@Override
protected BuildResult persistResult(final ParserResult project, final MavenBuild build) {
TasksResult result = new TasksResult(build, getDefaultEncoding(), (TasksParserResult)project,
high, normal, low);

build.getActions().add(new MavenTasksResultAction(build, this, getDefaultEncoding(), high, normal, low, result));
build.registerAsProjectAction(TasksReporter.this);
protected TasksResult createResult(final MavenBuild build, final ParserResult project) {
return new TasksResult(build, getDefaultEncoding(), (TasksParserResult)project, high, normal, low);
}

return result;
@Override
protected MavenAggregatedReport createMavenAggregatedReport(final MavenBuild build, final TasksResult result) {
return new MavenTasksResultAction(build, this, getDefaultEncoding(), high, normal, low, result);
}

/** {@inheritDoc} */
@Override
public List<TasksProjectAction> getProjectActions(final MavenModule module) {
return Collections.singletonList(new TasksProjectAction(module));
}

/** {@inheritDoc} */
@Override
protected Class<? extends Action> getResultActionClass() {
protected Class<MavenTasksResultAction> getResultActionClass() {
return MavenTasksResultAction.class;
}

Expand Down

0 comments on commit bb911e9

Please sign in to comment.