Skip to content
This repository has been archived by the owner on Feb 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #2 from tom-saunders/master
Browse files Browse the repository at this point in the history
[JENKINS-13458] Added option to use the previous build always as reference.
  • Loading branch information
uhafner committed Nov 19, 2014
2 parents 0724a86 + 68d6cfd commit 9494c74
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/main/java/hudson/plugins/pmd/MavenPmdResultAction.java
Expand Up @@ -49,7 +49,7 @@ public MavenPmdResultAction(final AbstractBuild<?, ?> owner, final HealthDescrip
@Override
public MavenAggregatedReport createAggregatedAction(final MavenModuleSetBuild build, final Map<MavenModule, List<MavenBuild>> moduleBuilds) {
return new MavenPmdResultAction(build, getHealthDescriptor(), defaultEncoding,
new PmdResult(build, defaultEncoding, new ParserResult(), false));
new PmdResult(build, defaultEncoding, new ParserResult(), false, false));
}

@Override
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/hudson/plugins/pmd/PmdAnnotationsAggregator.java
Expand Up @@ -32,17 +32,22 @@ public class PmdAnnotationsAggregator extends AnnotationsAggregator {
* @param useStableBuildAsReference
* determines whether only stable builds should be used as
* reference builds or not
* @param usePreviousBuildAsReference
* determines whether the previous build should be used as the
* reference build
*/
public PmdAnnotationsAggregator(final MatrixBuild build, final Launcher launcher,
final BuildListener listener, final HealthDescriptor healthDescriptor, final String defaultEncoding,
final boolean useStableBuildAsReference) {
super(build, launcher, listener, healthDescriptor, defaultEncoding, useStableBuildAsReference);
final boolean useStableBuildAsReference,
final boolean usePreviousBuildAsReference) {
super(build, launcher, listener, healthDescriptor, defaultEncoding,
useStableBuildAsReference, usePreviousBuildAsReference);
}

@Override
protected Action createAction(final HealthDescriptor healthDescriptor, final String defaultEncoding, final ParserResult aggregatedResult) {
return new PmdResultAction(build, healthDescriptor,
new PmdResult(build, defaultEncoding, aggregatedResult, useOnlyStableBuildsAsReference()));
new PmdResult(build, defaultEncoding, aggregatedResult, useOnlyStableBuildsAsReference(), usePreviousBuildAsReference()));
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/hudson/plugins/pmd/PmdMavenResultAction.java
Expand Up @@ -42,7 +42,7 @@ public PmdMavenResultAction(final AbstractBuild<?, ?> owner, final HealthDescrip
@Override
public MavenAggregatedReport createAggregatedAction(final MavenModuleSetBuild build, final Map<MavenModule, List<MavenBuild>> moduleBuilds) {
return new PmdMavenResultAction(build, getHealthDescriptor(), getDefaultEncoding(),
new PmdResult(build, getDefaultEncoding(), new ParserResult(), false));
new PmdResult(build, getDefaultEncoding(), new ParserResult(), false, false));
}

@Override
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/hudson/plugins/pmd/PmdPublisher.java
Expand Up @@ -86,6 +86,8 @@ public class PmdPublisher extends HealthAwarePublisher {
* annotation threshold
* @param canRunOnFailed
* determines whether the plug-in can run for failed builds, too
* @param usePreviousBuildAsReference
* determines whether to always use the previous build as the reference build
* @param useStableBuildAsReference
* determines whether only stable builds should be used as reference builds or not
* @param canComputeNew
Expand All @@ -105,14 +107,18 @@ public PmdPublisher(final String healthy, final String unHealthy, final String t
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 boolean canRunOnFailed, final boolean useStableBuildAsReference, final boolean shouldDetectModules,
final boolean canRunOnFailed,
final boolean usePreviousBuildAsReference,
final boolean useStableBuildAsReference, final boolean shouldDetectModules,
final boolean canComputeNew, final String pattern) {
super(healthy, unHealthy, thresholdLimit, defaultEncoding, useDeltaValues,
unstableTotalAll, unstableTotalHigh, unstableTotalNormal, unstableTotalLow,
unstableNewAll, unstableNewHigh, unstableNewNormal, unstableNewLow,
failedTotalAll, failedTotalHigh, failedTotalNormal, failedTotalLow,
failedNewAll, failedNewHigh, failedNewNormal, failedNewLow,
canRunOnFailed, useStableBuildAsReference, shouldDetectModules, canComputeNew, false, PLUGIN_NAME);
canRunOnFailed,
usePreviousBuildAsReference,
useStableBuildAsReference, shouldDetectModules, canComputeNew, false, PLUGIN_NAME);
this.pattern = pattern;
}
// CHECKSTYLE:ON
Expand All @@ -139,7 +145,7 @@ public BuildResult perform(final AbstractBuild<?, ?> build, final PluginLogger l
ParserResult project = build.getWorkspace().act(pmdCollector);
logger.logLines(project.getLogMessages());

PmdResult result = new PmdResult(build, getDefaultEncoding(), project, useOnlyStableBuildsAsReference());
PmdResult result = new PmdResult(build, getDefaultEncoding(), project, useOnlyStableBuildsAsReference(), getUsePreviousBuildAsReference());
build.getActions().add(new PmdResultAction(build, this, result));

return result;
Expand All @@ -153,6 +159,8 @@ public PmdDescriptor getDescriptor() {
@Override
public MatrixAggregator createAggregator(final MatrixBuild build, final Launcher launcher,
final BuildListener listener) {
return new PmdAnnotationsAggregator(build, launcher, listener, this, getDefaultEncoding(), useOnlyStableBuildsAsReference());
return new PmdAnnotationsAggregator(build, launcher, listener, this,
getDefaultEncoding(), useOnlyStableBuildsAsReference(),
getUsePreviousBuildAsReference());
}
}
7 changes: 5 additions & 2 deletions src/main/java/hudson/plugins/pmd/PmdReporter.java
Expand Up @@ -80,6 +80,8 @@ public class PmdReporter extends HealthAwareReporter<PmdResult> {
* annotation threshold
* @param canRunOnFailed
* determines whether the plug-in can run for failed builds, too
* @param usePreviousBuildAsReference
* determines whether to always use the previous build as the reference build
* @param useStableBuildAsReference
* determines whether only stable builds should be used as reference builds or not
* @param canComputeNew
Expand All @@ -94,13 +96,14 @@ public PmdReporter(final String healthy, final String unHealthy, final String th
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 boolean canRunOnFailed, final boolean useStableBuildAsReference, final boolean canComputeNew) {
final boolean canRunOnFailed, final boolean usePreviousBuildAsReference,
final boolean useStableBuildAsReference, final boolean canComputeNew) {
super(healthy, unHealthy, thresholdLimit, useDeltaValues,
unstableTotalAll, unstableTotalHigh, unstableTotalNormal, unstableTotalLow,
unstableNewAll, unstableNewHigh, unstableNewNormal, unstableNewLow,
failedTotalAll, failedTotalHigh, failedTotalNormal, failedTotalLow,
failedNewAll, failedNewHigh, failedNewNormal, failedNewLow,
canRunOnFailed, useStableBuildAsReference, canComputeNew, PLUGIN_NAME);
canRunOnFailed, usePreviousBuildAsReference, useStableBuildAsReference, canComputeNew, PLUGIN_NAME);
}
// CHECKSTYLE:ON

Expand Down
38 changes: 21 additions & 17 deletions src/main/java/hudson/plugins/pmd/PmdResult.java
Expand Up @@ -27,33 +27,37 @@ public class PmdResult extends BuildResult {
* the default encoding to be used when reading and parsing files
* @param result
* the parsed result with all annotations
* @param usePreviousBuildAsReference
* determines whether to use the previous build as the reference
* build
* @param useStableBuildAsReference
* determines whether only stable builds should be used as
* reference builds or not
*/
public PmdResult(final AbstractBuild<?, ?> build, final String defaultEncoding, final ParserResult result,
public PmdResult(final AbstractBuild<?, ?> build,
final String defaultEncoding,
final ParserResult result,
final boolean usePreviousBuildAsReference,
final boolean useStableBuildAsReference) {
this(build, defaultEncoding, result, useStableBuildAsReference, PmdResultAction.class);
this(build, defaultEncoding, result, usePreviousBuildAsReference, useStableBuildAsReference, PmdResultAction.class);
}

/**
* Creates a new instance of {@link PmdResult}.
*
* @param build
* the current build as owner of this action
* @param defaultEncoding
* the default encoding to be used when reading and parsing files
* @param result
* the parsed result with all annotations
* @param useStableBuildAsReference
* determines whether only stable builds should be used as
* reference builds or not
* @param actionType
* the type of the result action
* @param build the current build as owner of this action
* @param defaultEncoding the default encoding to be used when reading and parsing files
* @param result the parsed result with all annotations
* @param usePreviousBuildAsReference the value of usePreviousBuildAsReference
* @param useStableBuildAsReference determines whether only stable builds should be used as
reference builds or not
* @param actionType the type of the result action
*/
protected PmdResult(final AbstractBuild<?, ?> build, final String defaultEncoding, final ParserResult result,
final boolean useStableBuildAsReference, final Class<? extends ResultAction<PmdResult>> actionType) {
this(build, new BuildHistory(build, actionType, useStableBuildAsReference), result, defaultEncoding, true);
protected PmdResult(final AbstractBuild<?, ?> build,
final String defaultEncoding, final ParserResult result,
boolean usePreviousBuildAsReference,
final boolean useStableBuildAsReference,
final Class<? extends ResultAction<PmdResult>> actionType) {
this(build, new BuildHistory(build, actionType, useStableBuildAsReference, usePreviousBuildAsReference), result, defaultEncoding, true);
}

PmdResult(final AbstractBuild<?, ?> build, final BuildHistory history,
Expand Down

0 comments on commit 9494c74

Please sign in to comment.