Skip to content
This repository has been archived by the owner on Apr 6, 2022. It is now read-only.

Commit

Permalink
[FIXED JENKINS-13458] Added an option to use previous build as a refe…
Browse files Browse the repository at this point in the history
…rence.
  • Loading branch information
uhafner committed Jan 5, 2015
1 parent 6bf70c3 commit ee4a8b6
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 48 deletions.
14 changes: 10 additions & 4 deletions src/main/java/hudson/plugins/dry/DryAnnotationsAggregator.java
Expand Up @@ -30,20 +30,26 @@ public class DryAnnotationsAggregator extends AnnotationsAggregator {
* health descriptor
* @param defaultEncoding
* the default encoding to be used when reading and parsing files
* @param usePreviousBuildAsReference
* determines whether the previous build should be used as the
* reference build
* @param useStableBuildAsReference
* determines whether only stable builds should be used as
* reference builds or not
*/
public DryAnnotationsAggregator(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 usePreviousBuildAsReference, final boolean useStableBuildAsReference) {
super(build, launcher, listener, healthDescriptor, defaultEncoding,
usePreviousBuildAsReference, useStableBuildAsReference);
}

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

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/hudson/plugins/dry/DryMavenResult.java
Expand Up @@ -29,7 +29,7 @@ public class DryMavenResult extends DryResult {
@SuppressWarnings("deprecation")
public DryMavenResult(final AbstractBuild<?, ?> build, final String defaultEncoding,
final ParserResult result) {
super(build, defaultEncoding, result, false, MavenDryResultAction.class);
super(build, defaultEncoding, result, false, false, MavenDryResultAction.class);
}

@SuppressWarnings("deprecation")
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/hudson/plugins/dry/DryMavenResultAction.java
Expand Up @@ -42,7 +42,7 @@ public DryMavenResultAction(final AbstractBuild<?, ?> owner, final HealthDescrip
@Override
public MavenAggregatedReport createAggregatedAction(final MavenModuleSetBuild build, final Map<MavenModule, List<MavenBuild>> moduleBuilds) {
return new DryMavenResultAction(build, getHealthDescriptor(), getDefaultEncoding(),
new DryResult(build, getDefaultEncoding(), new ParserResult(), false));
new DryResult(build, getDefaultEncoding(), new ParserResult(), false, false));
}

@Override
Expand All @@ -58,7 +58,9 @@ public Class<? extends MavenResultAction<DryResult>> getIndividualActionType() {
@Override
protected DryResult createResult(final DryResult existingResult, final DryResult additionalResult) {
return new DryReporterResult(getOwner(), additionalResult.getDefaultEncoding(),
aggregate(existingResult, additionalResult), existingResult.useOnlyStableBuildsAsReference());
aggregate(existingResult, additionalResult),
existingResult.usePreviousBuildAsStable(),
existingResult.useOnlyStableBuildsAsReference());
}
}

32 changes: 19 additions & 13 deletions src/main/java/hudson/plugins/dry/DryPublisher.java
@@ -1,24 +1,24 @@
package hudson.plugins.dry;

import java.io.IOException;

import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.DataBoundConstructor;

import hudson.Launcher;
import hudson.matrix.MatrixAggregator;
import hudson.matrix.MatrixBuild;
import hudson.model.Action;
import hudson.model.BuildListener;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Action;
import hudson.model.BuildListener;
import hudson.plugins.analysis.core.BuildResult;
import hudson.plugins.analysis.core.FilesParser;
import hudson.plugins.analysis.core.HealthAwarePublisher;
import hudson.plugins.analysis.core.ParserResult;
import hudson.plugins.analysis.core.BuildResult;
import hudson.plugins.analysis.util.PluginLogger;
import hudson.plugins.dry.parser.DuplicationParserRegistry;

import java.io.IOException;

import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.DataBoundConstructor;

/**
* Publishes the results of the duplicate code analysis (freestyle project type).
*
Expand Down Expand Up @@ -94,6 +94,8 @@ public class DryPublisher 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 shouldDetectModules
Expand All @@ -117,14 +119,16 @@ public DryPublisher(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, final int highThreshold, final int normalThreshold) {
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, true, PLUGIN_NAME);
canRunOnFailed, usePreviousBuildAsReference, useStableBuildAsReference, shouldDetectModules,
canComputeNew, true, PLUGIN_NAME);
this.pattern = pattern;
this.highThreshold = highThreshold;
this.normalThreshold = normalThreshold;
Expand Down Expand Up @@ -175,8 +179,9 @@ public BuildResult perform(final AbstractBuild<?, ?> build, final PluginLogger l
ParserResult project = build.getWorkspace().act(dryCollector);
logger.logLines(project.getLogMessages());

DryResult result = new DryResult(build, getDefaultEncoding(), project, useOnlyStableBuildsAsReference());
build.getActions().add(new DryResultAction(build, this, result));
DryResult result = new DryResult(build, getDefaultEncoding(), project,
usePreviousBuildAsReference(), useOnlyStableBuildsAsReference());
build.addAction(new DryResultAction(build, this, result));

return result;
}
Expand All @@ -189,6 +194,7 @@ public DryDescriptor getDescriptor() {
@Override
public MatrixAggregator createAggregator(final MatrixBuild build, final Launcher launcher,
final BuildListener listener) {
return new DryAnnotationsAggregator(build, launcher, listener, this, getDefaultEncoding(), useOnlyStableBuildsAsReference());
return new DryAnnotationsAggregator(build, launcher, listener, this, getDefaultEncoding(),
usePreviousBuildAsReference(), useOnlyStableBuildsAsReference());
}
}
29 changes: 16 additions & 13 deletions src/main/java/hudson/plugins/dry/DryReporter.java
@@ -1,23 +1,23 @@
package hudson.plugins.dry;

import java.io.IOException;
import java.util.Collections;
import java.util.List;

import org.apache.maven.project.MavenProject;
import org.kohsuke.stapler.DataBoundConstructor;

import hudson.maven.MavenAggregatedReport;
import hudson.maven.MavenBuildProxy;
import hudson.maven.MojoInfo;
import hudson.maven.MavenBuild;
import hudson.maven.MavenBuildProxy;
import hudson.maven.MavenModule;
import hudson.maven.MojoInfo;
import hudson.plugins.analysis.core.FilesParser;
import hudson.plugins.analysis.core.HealthAwareReporter;
import hudson.plugins.analysis.core.ParserResult;
import hudson.plugins.analysis.util.PluginLogger;
import hudson.plugins.dry.parser.DuplicationParserRegistry;

import java.io.IOException;
import java.util.Collections;
import java.util.List;

import org.apache.maven.project.MavenProject;
import org.kohsuke.stapler.DataBoundConstructor;

/**
* Publishes the results of the duplicate code analysis (maven 2 project type).
*
Expand Down Expand Up @@ -88,6 +88,8 @@ public class DryReporter extends HealthAwareReporter<DryResult> {
* 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 @@ -106,14 +108,14 @@ public DryReporter(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 int highThreshold, final int normalThreshold) {
final boolean canRunOnFailed, final boolean usePreviousBuildAsReference, final boolean useStableBuildAsReference,
final boolean canComputeNew, final int highThreshold, final int normalThreshold) {
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);
this.highThreshold = highThreshold;
this.normalThreshold = normalThreshold;
}
Expand Down Expand Up @@ -154,7 +156,8 @@ public ParserResult perform(final MavenBuildProxy build, final MavenProject pom,

@Override
protected DryResult createResult(final MavenBuild build, final ParserResult project) {
return new DryReporterResult(build, getDefaultEncoding(), project, useOnlyStableBuildsAsReference());
return new DryReporterResult(build, getDefaultEncoding(), project,
usePreviousBuildAsStable(), useOnlyStableBuildsAsReference());
}

@Override
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/hudson/plugins/dry/DryReporterResult.java
Expand Up @@ -22,13 +22,17 @@ public class DryReporterResult extends DryResult {
* 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 DryReporterResult(final AbstractBuild<?, ?> build, final String defaultEncoding,
final ParserResult result, final boolean useStableBuildAsReference) {
super(build, defaultEncoding, result, useStableBuildAsReference, DryMavenResultAction.class);
public DryReporterResult(final AbstractBuild<?, ?> build, final String defaultEncoding, final ParserResult result,
final boolean usePreviousBuildAsReference, final boolean useStableBuildAsReference) {
super(build, defaultEncoding, result, usePreviousBuildAsReference, useStableBuildAsReference,
DryMavenResultAction.class);
}

@Override
Expand Down
23 changes: 16 additions & 7 deletions src/main/java/hudson/plugins/dry/DryResult.java
@@ -1,14 +1,14 @@
package hudson.plugins.dry;

import com.thoughtworks.xstream.XStream;

import hudson.model.AbstractBuild;
import hudson.plugins.analysis.core.BuildHistory;
import hudson.plugins.analysis.core.BuildResult;
import hudson.plugins.analysis.core.ParserResult;
import hudson.plugins.analysis.core.ResultAction;
import hudson.plugins.analysis.core.BuildResult;
import hudson.plugins.dry.parser.DuplicateCode;

import com.thoughtworks.xstream.XStream;

/**
* Represents the results of the DRY analysis. One instance of this class is persisted for
* each build via an XML file.
Expand All @@ -27,13 +27,17 @@ public class DryResult 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 DryResult(final AbstractBuild<?, ?> build, final String defaultEncoding, final ParserResult result,
final boolean useStableBuildAsReference) {
this(build, defaultEncoding, result, useStableBuildAsReference, DryResultAction.class);
final boolean usePreviousBuildAsReference, final boolean useStableBuildAsReference) {
this(build, defaultEncoding, result, usePreviousBuildAsReference, useStableBuildAsReference,
DryResultAction.class);
}

/**
Expand All @@ -45,15 +49,20 @@ public DryResult(final AbstractBuild<?, ?> build, final String defaultEncoding,
* 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
* @param actionType
* the type of the result action
*/
protected DryResult(final AbstractBuild<?, ?> build, final String defaultEncoding, final ParserResult result,
final boolean useStableBuildAsReference, final Class<? extends ResultAction<DryResult>> actionType) {
this(build, new BuildHistory(build, actionType, useStableBuildAsReference), result, defaultEncoding, true);
final boolean usePreviousBuildAsReference, final boolean useStableBuildAsReference,
final Class<? extends ResultAction<DryResult>> actionType) {
this(build, new BuildHistory(build, actionType, usePreviousBuildAsReference, useStableBuildAsReference),
result, defaultEncoding, true);
}

DryResult(final AbstractBuild<?, ?> build, final BuildHistory history,
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/hudson/plugins/dry/MavenDryResultAction.java
@@ -1,19 +1,19 @@
package hudson.plugins.dry;

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

import hudson.maven.AggregatableAction;
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.model.AbstractBuild;
import hudson.model.Action;
import hudson.plugins.analysis.core.HealthDescriptor;
import hudson.plugins.analysis.core.ParserResult;

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

/**
* A {@link DryResultAction} for native maven jobs. This action
* additionally provides result aggregation for sub-modules and for the main
Expand Down Expand Up @@ -48,7 +48,7 @@ public MavenDryResultAction(final AbstractBuild<?, ?> owner, final HealthDescrip
@Override
public MavenAggregatedReport createAggregatedAction(final MavenModuleSetBuild build, final Map<MavenModule, List<MavenBuild>> moduleBuilds) {
return new MavenDryResultAction(build, getHealthDescriptor(), defaultEncoding,
new DryResult(build, defaultEncoding, new ParserResult(), false));
new DryResult(build, defaultEncoding, new ParserResult(), false, false));
}

@Override
Expand Down

0 comments on commit ee4a8b6

Please sign in to comment.