Skip to content
This repository has been archived by the owner on Feb 26, 2020. 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 ac9535e commit 4282354
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 84 deletions.
42 changes: 2 additions & 40 deletions src/main/java/hudson/plugins/pmd/MavenPmdResultAction.java
Expand Up @@ -7,10 +7,7 @@
import hudson.maven.MavenModuleSet;
import hudson.maven.MavenModuleSetBuild;
import hudson.model.Action;
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 @@ -22,6 +19,7 @@
*
* @author Ulli Hafner
*/
@Deprecated
public class MavenPmdResultAction extends PmdResultAction implements AggregatableAction, MavenAggregatedReport {
/** The default encoding to be used when reading and parsing files. */
private final String defaultEncoding;
Expand Down Expand Up @@ -92,43 +90,7 @@ public Class<? extends AggregatableAction> getIndividualActionType() {
* Newly completed build.
*/
public void update(final Map<MavenModule, List<MavenBuild>> moduleBuilds, final MavenBuild newBuild) {
MavenPmdResultAction additionalAction = newBuild.getAction(MavenPmdResultAction.class);
if (additionalAction != null) {
PmdResult existingResult = getResult();
PmdResult 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 PmdResult aggregate(final PmdResult existingResult, final PmdResult additionalResult, final PluginLogger logger) {
ParserResult aggregatedAnnotations = new ParserResult();
aggregatedAnnotations.addAnnotations(existingResult.getAnnotations());
aggregatedAnnotations.addAnnotations(additionalResult.getAnnotations());

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

/** Backward compatibility. @deprecated */
Expand Down
42 changes: 0 additions & 42 deletions src/main/java/hudson/plugins/pmd/PmdMavenResult.java

This file was deleted.

78 changes: 78 additions & 0 deletions src/main/java/hudson/plugins/pmd/PmdMavenResultAction.java
@@ -0,0 +1,78 @@
package hudson.plugins.pmd;

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

/**
* Creates a new instance of {@link PmdMavenResultAction}.
*
* @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 PmdMavenResultAction(final MavenBuild owner, final HealthDescriptor healthDescriptor,
final String defaultEncoding, final PmdResult result) {
super(new PmdResultAction(owner, healthDescriptor, result), defaultEncoding);
}

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

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

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

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

4 changes: 2 additions & 2 deletions src/main/java/hudson/plugins/pmd/PmdReporter.java
Expand Up @@ -131,8 +131,8 @@ public List<PmdProjectAction> getProjectActions(final MavenModule module) {
}

@Override
protected Class<MavenPmdResultAction> getResultActionClass() {
return MavenPmdResultAction.class;
protected Class<PmdMavenResultAction> getResultActionClass() {
return PmdMavenResultAction.class;
}
}

0 comments on commit 4282354

Please sign in to comment.