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 067654f commit 369e5fb
Show file tree
Hide file tree
Showing 16 changed files with 150 additions and 54 deletions.
4 changes: 2 additions & 2 deletions checkstyle.iml
Expand Up @@ -30,7 +30,7 @@
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.1.1" level="project" />
<orderEntry type="library" name="Maven: xerces:xercesImpl:2.11.0" level="project" />
<orderEntry type="library" name="Maven: xml-apis:xml-apis:1.4.01" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.jvnet.hudson.plugins:analysis-test:1.9" level="project" />
<orderEntry type="module" module-name="analysis-test" scope="TEST" />
<orderEntry type="library" name="Maven: org.jenkins-ci.main:maven-plugin:2.4" level="project" />
<orderEntry type="library" name="Maven: org.jenkins-ci.plugins:javadoc:1.0" level="project" />
<orderEntry type="library" name="Maven: org.jenkins-ci.plugins:mailer:1.7" level="project" />
Expand Down Expand Up @@ -237,7 +237,7 @@
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-library:1.3" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.jenkins-ci:htmlunit:2.6-jenkins-6" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.jvnet.hudson:htmlunit-core-js:2.6-hudson-1" level="project" />
<orderEntry type="library" name="Maven: net.sourceforge.nekohtml:nekohtml:1.9.13" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: net.sourceforge.nekohtml:nekohtml:1.9.13" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: net.sourceforge.cssparser:cssparser:0.9.5" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.w3c.css:sac:1.3" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: xalan:xalan:2.7.1" level="project" />
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -49,7 +49,7 @@
<dependency>
<groupId>org.jvnet.hudson.plugins</groupId>
<artifactId>analysis-test</artifactId>
<version>1.9</version>
<version>1.11-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Expand Up @@ -29,20 +29,25 @@ public class CheckStyleAnnotationsAggregator 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 CheckStyleAnnotationsAggregator(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) {
return new CheckStyleResultAction(build, healthDescriptor,
new CheckStyleResult(build, defaultEncoding, aggregatedResult, useOnlyStableBuildsAsReference()));
new CheckStyleResult(build, defaultEncoding, aggregatedResult,
usePreviousBuildAsReference(), useOnlyStableBuildsAsReference()));
}

@Override
Expand Down
Expand Up @@ -29,7 +29,7 @@ public class CheckStyleMavenResult extends CheckStyleResult {
@SuppressWarnings("deprecation")
public CheckStyleMavenResult(final AbstractBuild<?, ?> build, final String defaultEncoding,
final ParserResult result) {
super(build, defaultEncoding, result, false, MavenCheckStyleResultAction.class);
super(build, defaultEncoding, result, false, false, MavenCheckStyleResultAction.class);
}

@SuppressWarnings("deprecation")
Expand Down
@@ -1,18 +1,18 @@
package hudson.plugins.checkstyle;

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

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 hudson.plugins.analysis.core.MavenResultAction;

import java.util.List;
import java.util.Map;
import hudson.plugins.analysis.core.ParserResult;

/**
* A {@link CheckStyleResultAction} for native Maven jobs. This action
Expand Down Expand Up @@ -42,7 +42,7 @@ public CheckStyleMavenResultAction(final AbstractBuild<?, ?> owner, final Health
@Override
public MavenAggregatedReport createAggregatedAction(final MavenModuleSetBuild build, final Map<MavenModule, List<MavenBuild>> moduleBuilds) {
return new CheckStyleMavenResultAction(build, getHealthDescriptor(), getDefaultEncoding(),
new CheckStyleResult(build, getDefaultEncoding(), new ParserResult(), false));
new CheckStyleResult(build, getDefaultEncoding(), new ParserResult(), false, false));
}

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

34 changes: 19 additions & 15 deletions src/main/java/hudson/plugins/checkstyle/CheckStylePublisher.java
@@ -1,24 +1,24 @@
package hudson.plugins.checkstyle;

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.checkstyle.parser.CheckStyleParser;

import java.io.IOException;

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

/**
* Publishes the results of the Checkstyle analysis (freestyle project type).
*
Expand Down Expand Up @@ -87,6 +87,8 @@ public class CheckStylePublisher 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 @@ -106,15 +108,15 @@ public CheckStylePublisher(final String healthy, final String unHealthy, final S
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 canComputeNew, final String pattern) {
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,
true, PLUGIN_NAME);
canRunOnFailed, usePreviousBuildAsReference, useStableBuildAsReference,
shouldDetectModules, canComputeNew, false, PLUGIN_NAME);
this.pattern = pattern;
}
// CHECKSTYLE:ON
Expand Down Expand Up @@ -143,8 +145,9 @@ public BuildResult perform(final AbstractBuild<?, ?> build, final PluginLogger l
ParserResult project = build.getWorkspace().act(parser);
logger.logLines(project.getLogMessages());

CheckStyleResult result = new CheckStyleResult(build, getDefaultEncoding(), project, getUseStableBuildAsReference());
build.getActions().add(new CheckStyleResultAction(build, this, result));
CheckStyleResult result = new CheckStyleResult(build, getDefaultEncoding(), project,
usePreviousBuildAsReference(), useOnlyStableBuildsAsReference());
build.addAction(new CheckStyleResultAction(build, this, result));

return result;
}
Expand All @@ -157,6 +160,7 @@ public CheckStyleDescriptor getDescriptor() {
@Override
public MatrixAggregator createAggregator(final MatrixBuild build, final Launcher launcher,
final BuildListener listener) {
return new CheckStyleAnnotationsAggregator(build, launcher, listener, this, getDefaultEncoding(), useOnlyStableBuildsAsReference());
return new CheckStyleAnnotationsAggregator(build, launcher, listener, this, getDefaultEncoding(),
usePreviousBuildAsReference(), useOnlyStableBuildsAsReference());
}
}
10 changes: 7 additions & 3 deletions src/main/java/hudson/plugins/checkstyle/CheckStyleReporter.java
Expand Up @@ -88,6 +88,8 @@ public class CheckStyleReporter extends HealthAwareReporter<CheckStyleResult> {
* 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 @@ -102,13 +104,14 @@ public CheckStyleReporter(final String healthy, final String unHealthy, final St
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 Expand Up @@ -141,7 +144,8 @@ private FilePath getFileName(final MojoInfo mojo, final MavenProject pom) {

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

@Override
Expand Down
Expand Up @@ -22,13 +22,17 @@ public class CheckStyleReporterResult extends CheckStyleResult {
* 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 CheckStyleReporterResult(final AbstractBuild<?, ?> build, final String defaultEncoding, final ParserResult result,
final boolean useStableBuildAsReference) {
super(build, defaultEncoding, result, useStableBuildAsReference, CheckStyleMavenResultAction.class);
final boolean usePreviousBuildAsReference, final boolean useStableBuildAsReference) {
super(build, defaultEncoding, result, usePreviousBuildAsReference, useStableBuildAsReference,
CheckStyleMavenResultAction.class);
}

@Override
Expand Down
20 changes: 13 additions & 7 deletions src/main/java/hudson/plugins/checkstyle/CheckStyleResult.java
@@ -1,14 +1,14 @@
package hudson.plugins.checkstyle;

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.checkstyle.parser.Warning;

import com.thoughtworks.xstream.XStream;

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

/**
Expand All @@ -52,8 +56,10 @@ public CheckStyleResult(final AbstractBuild<?, ?> build, final String defaultEnc
* the type of the result action
*/
protected CheckStyleResult(final AbstractBuild<?, ?> build, final String defaultEncoding, final ParserResult result,
final boolean useStableBuildAsReference, final Class<? extends ResultAction<CheckStyleResult>> actionType) {
this(build, new BuildHistory(build, actionType, useStableBuildAsReference), result, defaultEncoding, true);
final boolean usePreviousBuildAsReference, final boolean useStableBuildAsReference,
final Class<? extends ResultAction<CheckStyleResult>> actionType) {
this(build, new BuildHistory(build, actionType, usePreviousBuildAsReference, useStableBuildAsReference),
result, defaultEncoding, true);
}

CheckStyleResult(final AbstractBuild<?, ?> build, final BuildHistory history,
Expand Down
@@ -1,19 +1,19 @@
package hudson.plugins.checkstyle;

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 CheckStyleResultAction} for native maven jobs. This action
* additionally provides result aggregation for sub-modules and for the main
Expand All @@ -39,7 +39,7 @@ public class MavenCheckStyleResultAction extends CheckStyleResultAction implemen
*/
public MavenCheckStyleResultAction(final AbstractBuild<?, ?> owner, final HealthDescriptor healthDescriptor,
final String defaultEncoding) {
super(owner, healthDescriptor, new CheckStyleResult(owner, defaultEncoding, new ParserResult(), false));
super(owner, healthDescriptor, new CheckStyleResult(owner, defaultEncoding, new ParserResult(), false, false));
this.defaultEncoding = defaultEncoding;
}

Expand Down
Expand Up @@ -118,14 +118,7 @@ else if ("info".equalsIgnoreCase(error.getSeverity())) {
warning.setFileName(file.getName());
warning.setPackageName(packageName);
warning.setColumnPosition(error.getColumn());

try {
warning.setContextHashCode(createContextHashCode(file.getName(), error.getLine()) * 31
+ type.hashCode());
}
catch (IOException exception) {
// ignore and continue
}
warning.setContextHashCode(createContextHashCode(file.getName(), error.getLine(), type));
annotations.add(warning);
}
}
Expand Down

0 comments on commit 369e5fb

Please sign in to comment.