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 e59aa3a commit d49cbea
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 81 deletions.
38 changes: 0 additions & 38 deletions src/main/java/hudson/plugins/checkstyle/CheckStyleMavenResult.java

This file was deleted.

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

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

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

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

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

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

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

Expand Up @@ -120,7 +120,7 @@ protected CheckStyleResult createResult(final MavenBuild build, final ParserResu

@Override
protected MavenAggregatedReport createMavenAggregatedReport(final MavenBuild build, final CheckStyleResult result) {
return new MavenCheckStyleResultAction(build, this, getDefaultEncoding(), result);
return new CheckStyleMavenResultAction(build, this, getDefaultEncoding(), result);
}

@Override
Expand All @@ -129,8 +129,8 @@ public List<CheckStyleProjectAction> getProjectActions(final MavenModule module)
}

@Override
protected Class<MavenCheckStyleResultAction> getResultActionClass() {
return MavenCheckStyleResultAction.class;
protected Class<CheckStyleMavenResultAction> getResultActionClass() {
return CheckStyleMavenResultAction.class;
}
}

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 MavenCheckStyleResultAction extends CheckStyleResultAction 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) {
MavenCheckStyleResultAction additionalAction = newBuild.getAction(MavenCheckStyleResultAction.class);
if (additionalAction != null) {
CheckStyleResult existingResult = getResult();
CheckStyleResult 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 CheckStyleResult aggregate(final CheckStyleResult existingResult, final CheckStyleResult additionalResult, final PluginLogger logger) {
ParserResult aggregatedAnnotations = new ParserResult();
aggregatedAnnotations.addAnnotations(existingResult.getAnnotations());
aggregatedAnnotations.addAnnotations(additionalResult.getAnnotations());

CheckStyleResult createdResult = new CheckStyleResult(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 d49cbea

Please sign in to comment.