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
[JENKINS-4912] Created new action base class for maven aggregation.
  • Loading branch information
uhafner committed May 11, 2011
1 parent bb911e9 commit 39d025d
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 90 deletions.
44 changes: 2 additions & 42 deletions src/main/java/hudson/plugins/tasks/MavenTasksResultAction.java
Expand Up @@ -8,11 +8,8 @@
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 All @@ -25,6 +22,7 @@
*
* @author Ulli Hafner
*/
@Deprecated
public class MavenTasksResultAction extends TasksResultAction implements AggregatableAction, MavenAggregatedReport {
/** Tag identifiers indicating high priority. */
private String high;
Expand Down Expand Up @@ -133,47 +131,9 @@ public Class<? extends AggregatableAction> getIndividualActionType() {
* Newly completed build.
*/
public void update(final Map<MavenModule, List<MavenBuild>> moduleBuilds, final MavenBuild newBuild) {
MavenTasksResultAction additionalAction = newBuild.getAction(MavenTasksResultAction.class);
if (additionalAction != null) {
TasksResult existingResult = getResult();
TasksResult additionalResult = additionalAction.getResult();

log("Aggregating results of " + newBuild.getProject().getDisplayName());

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

/**
* 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
45 changes: 0 additions & 45 deletions src/main/java/hudson/plugins/tasks/TasksMavenResult.java

This file was deleted.

120 changes: 120 additions & 0 deletions src/main/java/hudson/plugins/tasks/TasksMavenResultAction.java
@@ -0,0 +1,120 @@
package hudson.plugins.tasks;

import hudson.maven.MavenAggregatedReport;
import hudson.maven.MavenBuild;
import hudson.maven.MavenModule;
import hudson.maven.MavenModuleSet;
import hudson.maven.MavenModuleSetBuild;
import hudson.model.Action;
import hudson.plugins.analysis.core.HealthDescriptor;
import hudson.plugins.analysis.core.MavenResultAction;
import hudson.plugins.analysis.core.ParserResult;
import hudson.plugins.tasks.parser.TasksParserResult;

import java.util.List;
import java.util.Map;

/**
* A {@link TasksResultAction} for native Maven jobs. This action
* additionally provides result aggregation for sub-modules and for the main
* project.
*
* @author Ulli Hafner
*/
public class TasksMavenResultAction extends MavenResultAction<TasksResult> {
/** Tag identifiers indicating high priority. */
private String high;
/** Tag identifiers indicating normal priority. */
private String normal;
/** Tag identifiers indicating low priority. */
private String low;

/**
* Creates a new instance of {@link TasksMavenResultAction}. This instance
* will have no result set in the beginning. The result will be set
* successively after each of the modules are build.
*
* @param owner
* the associated build of this action
* @param healthDescriptor
* health descriptor to use
* @param defaultEncoding
* the default encoding to be used when reading and parsing files
* @param high
* tag identifiers indicating high priority
* @param normal
* tag identifiers indicating normal priority
* @param low
* tag identifiers indicating low priority
*/
public TasksMavenResultAction(final MavenModuleSetBuild owner, final HealthDescriptor healthDescriptor,
final String defaultEncoding, final String high, final String normal, final String low) {
super(new TasksResultAction(owner, healthDescriptor), defaultEncoding);

initializeFields(high, normal, low);
}

/**
* Creates a new instance of {@link TasksMavenResultAction}.
*
* @param owner
* the associated build of this action
* @param healthDescriptor
* health descriptor to use
* @param defaultEncoding
* the default encoding to be used when reading and parsing files
* @param high
* tag identifiers indicating high priority
* @param normal
* tag identifiers indicating normal priority
* @param low
* tag identifiers indicating low priority
* @param result
* the result in this build
*/
public TasksMavenResultAction(final MavenBuild owner, final HealthDescriptor healthDescriptor,
final String defaultEncoding, final String high, final String normal, final String low, final TasksResult result) {
super(new TasksResultAction(owner, healthDescriptor, result), defaultEncoding);

initializeFields(high, normal, low);
}

/**
* Initializes the fields of this action.
* @param high
* tag identifiers indicating high priority
* @param normal
* tag identifiers indicating normal priority
* @param low
* tag identifiers indicating low priority
*/
// CHECKSTYLE:OFF
@SuppressWarnings("hiding")
private void initializeFields(final String high, final String normal, final String low) {
this.high = high;
this.normal = normal;
this.low = low;
}
// CHECKSTYLE:ON

/** {@inheritDoc} */
public MavenAggregatedReport createAggregatedAction(final MavenModuleSetBuild build, final Map<MavenModule, List<MavenBuild>> moduleBuilds) {
return new TasksMavenResultAction(build, getHealthDescriptor(), getDisplayName(), high, normal, low);
}

/** {@inheritDoc} */
public Action getProjectAction(final MavenModuleSet moduleSet) {
return new TasksProjectAction(moduleSet);
}

@Override
public Class<? extends MavenResultAction<TasksResult>> getIndividualActionType() {
return TasksMavenResultAction.class;
}

@Override
protected TasksResult createResult(final TasksResult existingResult, final ParserResult aggregatedAnnotations) {
return new TasksResult(getOwner(), existingResult.getDefaultEncoding(), (TasksParserResult) aggregatedAnnotations, high, normal, low);
}
}

6 changes: 3 additions & 3 deletions src/main/java/hudson/plugins/tasks/TasksReporter.java
Expand Up @@ -243,7 +243,7 @@ protected TasksResult createResult(final MavenBuild build, final ParserResult pr

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

@Override
Expand All @@ -252,8 +252,8 @@ public List<TasksProjectAction> getProjectActions(final MavenModule module) {
}

@Override
protected Class<MavenTasksResultAction> getResultActionClass() {
return MavenTasksResultAction.class;
protected Class<TasksMavenResultAction> getResultActionClass() {
return TasksMavenResultAction.class;
}

// Backward compatibility. Do not remove.
Expand Down

0 comments on commit 39d025d

Please sign in to comment.