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 d92bd4c commit 77661da
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 80 deletions.

This file was deleted.

@@ -0,0 +1,78 @@
package hudson.plugins.findbugs;

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 java.util.List;
import java.util.Map;

/**
* A {@link FindBugsResultAction} for native Maven jobs. This action
* additionally provides result aggregation for sub-modules and for the main
* project.
*
* @author Ulli Hafner
*/
public class FindBugsMavenResultAction extends MavenResultAction<FindBugsResult> {
/**
* Creates a new instance of {@link FindBugsMavenResultAction}. 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
*/
public FindBugsMavenResultAction(final MavenModuleSetBuild owner, final HealthDescriptor healthDescriptor,
final String defaultEncoding) {
super(new FindBugsResultAction(owner, healthDescriptor), defaultEncoding);
}

/**
* Creates a new instance of {@link FindBugsMavenResultAction}.
*
* @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 result
* the result in this build
*/
public FindBugsMavenResultAction(final MavenBuild owner, final HealthDescriptor healthDescriptor,
final String defaultEncoding, final FindBugsResult result) {
super(new FindBugsResultAction(owner, healthDescriptor, result), defaultEncoding);
}

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

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

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

@Override
protected FindBugsResult createResult(final FindBugsResult existingResult, final ParserResult aggregatedAnnotations) {
return new FindBugsResult(getOwner(), existingResult.getDefaultEncoding(), aggregatedAnnotations);
}
}

Expand Up @@ -156,7 +156,7 @@ protected FindBugsResult createResult(final MavenBuild build, final ParserResult

@Override
protected MavenAggregatedReport createMavenAggregatedReport(final MavenBuild build, final FindBugsResult result) {
return new MavenFindBugsResultAction(build, this, getDefaultEncoding(), result);
return new FindBugsMavenResultAction(build, this, getDefaultEncoding(), result);
}

/**
Expand Down Expand Up @@ -185,8 +185,8 @@ public List<FindBugsProjectAction> getProjectActions(final MavenModule module) {
}

@Override
protected Class<MavenFindBugsResultAction> getResultActionClass() {
return MavenFindBugsResultAction.class;
protected Class<FindBugsMavenResultAction> getResultActionClass() {
return FindBugsMavenResultAction.class;
}

/** Ant file-set pattern of files to work with. @deprecated */
Expand Down
Expand Up @@ -8,10 +8,7 @@
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 java.util.List;
import java.util.Map;
Expand All @@ -23,6 +20,7 @@
*
* @author Ulli Hafner
*/
@Deprecated
public class MavenFindBugsResultAction extends FindBugsResultAction implements AggregatableAction, MavenAggregatedReport {
/** The default encoding to be used when reading and parsing files. */
private final String defaultEncoding;
Expand Down Expand Up @@ -89,43 +87,7 @@ public Class<? extends AggregatableAction> getIndividualActionType() {
* Newly completed build.
*/
public void update(final Map<MavenModule, List<MavenBuild>> moduleBuilds, final MavenBuild newBuild) {
MavenFindBugsResultAction additionalAction = newBuild.getAction(MavenFindBugsResultAction.class);
if (additionalAction != null) {
FindBugsResult existingResult = getResult();
FindBugsResult 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()));
}
}
}

/**
* 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 FindBugsResult aggregate(final FindBugsResult existingResult, final FindBugsResult additionalResult, final PluginLogger logger) {
ParserResult aggregatedAnnotations = new ParserResult();
aggregatedAnnotations.addAnnotations(existingResult.getAnnotations());
aggregatedAnnotations.addAnnotations(additionalResult.getAnnotations());

FindBugsResult createdResult = new FindBugsResult(getOwner(), existingResult.getDefaultEncoding(), aggregatedAnnotations);
createdResult.evaluateStatus(existingResult.getThresholds(), existingResult.canUseDeltaValues(), logger);
return createdResult;
// not used anymore
}

/** Backward compatibility. @deprecated */
Expand Down

0 comments on commit 77661da

Please sign in to comment.