Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

[FIXED JENKINS-13458] Added an option to use previous build as a refe…

…rence.
  • Loading branch information
uhafner committed Jan 5, 2015
1 parent 7169a63 commit bf11ab5a02fdbbae20a7503fad468723f6bee29b
@@ -23,7 +23,7 @@
<orderEntry type="module" module-name="analysis-core" />
<orderEntry type="library" name="Maven: de.java2html:java2html:5.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.3.2" 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: pmd:pmd:4.2.6" level="project" />
<orderEntry type="library" name="Maven: ant:ant:1.6" level="project" />
<orderEntry type="library" name="Maven: jaxen:jaxen:1.1.1" level="project" />
@@ -243,7 +243,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" name="Maven: xalan:xalan:2.7.1" level="project" />
@@ -43,7 +43,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>
<dependency>
@@ -29,25 +29,26 @@
* health descriptor
* @param defaultEncoding
* the default encoding to be used when reading and parsing files
* @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
* @param useStableBuildAsReference
* determines whether only stable builds should be used as
* reference builds or not
*/
public PmdAnnotationsAggregator(final MatrixBuild build, final Launcher launcher,
final BuildListener listener, final HealthDescriptor healthDescriptor, final String defaultEncoding,
final boolean useStableBuildAsReference,
final boolean usePreviousBuildAsReference) {
final boolean usePreviousBuildAsReference, final boolean useStableBuildAsReference) {
super(build, launcher, listener, healthDescriptor, defaultEncoding,
useStableBuildAsReference, usePreviousBuildAsReference);
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 PmdResultAction(build, healthDescriptor,
new PmdResult(build, defaultEncoding, aggregatedResult, useOnlyStableBuildsAsReference(), usePreviousBuildAsReference()));
new PmdResult(build, defaultEncoding, aggregatedResult,
usePreviousBuildAsReference(), useOnlyStableBuildsAsReference()));
}

@Override
@@ -29,7 +29,7 @@
@SuppressWarnings("deprecation")
public PmdMavenResult(final AbstractBuild<?, ?> build, final String defaultEncoding,
final ParserResult result) {
super(build, defaultEncoding, result, false, MavenPmdResultAction.class);
super(build, defaultEncoding, result, false, false, MavenPmdResultAction.class);
}

/**
@@ -1,19 +1,19 @@
package hudson.plugins.pmd;

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.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
@@ -58,7 +58,9 @@ public Action getProjectAction(final MavenModuleSet moduleSet) {
@Override
protected PmdResult createResult(final PmdResult existingResult, final PmdResult additionalResult) {
return new PmdReporterResult(getOwner(), additionalResult.getDefaultEncoding(),
aggregate(existingResult, additionalResult), existingResult.useOnlyStableBuildsAsReference());
aggregate(existingResult, additionalResult),
existingResult.usePreviousBuildAsStable(),
existingResult.useOnlyStableBuildsAsReference());
}
}

@@ -1,24 +1,24 @@
package hudson.plugins.pmd;

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.pmd.parser.PmdParser;

import java.io.IOException;

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

/**
* Publishes the results of the PMD analysis (freestyle project type).
*
@@ -107,18 +107,15 @@ 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 usePreviousBuildAsReference,
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,
usePreviousBuildAsReference,
useStableBuildAsReference, shouldDetectModules, canComputeNew, false, PLUGIN_NAME);
canRunOnFailed, usePreviousBuildAsReference, useStableBuildAsReference,
shouldDetectModules, canComputeNew, false, PLUGIN_NAME);
this.pattern = pattern;
}
// CHECKSTYLE:ON
@@ -145,8 +142,9 @@ 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(), getUsePreviousBuildAsReference());
build.getActions().add(new PmdResultAction(build, this, result));
PmdResult result = new PmdResult(build, getDefaultEncoding(), project,
usePreviousBuildAsReference(), useOnlyStableBuildsAsReference());
build.addAction(new PmdResultAction(build, this, result));

return result;
}
@@ -160,7 +158,6 @@ public PmdDescriptor getDescriptor() {
public MatrixAggregator createAggregator(final MatrixBuild build, final Launcher launcher,
final BuildListener listener) {
return new PmdAnnotationsAggregator(build, launcher, listener, this,
getDefaultEncoding(), useOnlyStableBuildsAsReference(),
getUsePreviousBuildAsReference());
getDefaultEncoding(), usePreviousBuildAsReference(), useOnlyStableBuildsAsReference());
}
}
@@ -1,23 +1,23 @@
package hudson.plugins.pmd;

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.pmd.parser.PmdParser;

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 PMD analysis (maven 2 project type).
*
@@ -122,7 +122,8 @@ public ParserResult perform(final MavenBuildProxy build, final MavenProject pom,

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

@Override
@@ -6,7 +6,7 @@
import hudson.plugins.analysis.core.BuildResult;

/**
* Represents the aggregated results of the PMD analysis in m2 jobs.
* Represents the aggregated results of the PMD analysis in maven jobs.
*
* @author Ulli Hafner
*/
@@ -22,13 +22,17 @@
* 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 PmdReporterResult(final AbstractBuild<?, ?> build, final String defaultEncoding,
final ParserResult result, final boolean useStableBuildAsReference) {
super(build, defaultEncoding, result, useStableBuildAsReference, PmdMavenResultAction.class);
public PmdReporterResult(final AbstractBuild<?, ?> build, final String defaultEncoding, final ParserResult result,
final boolean usePreviousBuildAsReference, final boolean useStableBuildAsReference) {
super(build, defaultEncoding, result, usePreviousBuildAsReference, useStableBuildAsReference,
PmdMavenResultAction.class);
}

@Override
@@ -1,14 +1,14 @@
package hudson.plugins.pmd;

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.pmd.parser.Bug;

import com.thoughtworks.xstream.XStream;

/**
* Represents the results of the PMD analysis. One instance of this class is persisted for
* each build via an XML file.
@@ -34,11 +34,8 @@
* determines whether only stable builds should be used as
* reference builds or not
*/
public PmdResult(final AbstractBuild<?, ?> build,
final String defaultEncoding,
final ParserResult result,
final boolean usePreviousBuildAsReference,
final boolean useStableBuildAsReference) {
public PmdResult(final AbstractBuild<?, ?> build, final String defaultEncoding, final ParserResult result,
final boolean usePreviousBuildAsReference, final boolean useStableBuildAsReference) {
this(build, defaultEncoding, result, usePreviousBuildAsReference, useStableBuildAsReference, PmdResultAction.class);
}

@@ -54,10 +51,10 @@ public PmdResult(final AbstractBuild<?, ?> build,
*/
protected PmdResult(final AbstractBuild<?, ?> build,
final String defaultEncoding, final ParserResult result,
boolean usePreviousBuildAsReference,
final boolean usePreviousBuildAsReference,
final boolean useStableBuildAsReference,
final Class<? extends ResultAction<PmdResult>> actionType) {
this(build, new BuildHistory(build, actionType, useStableBuildAsReference, usePreviousBuildAsReference), result, defaultEncoding, true);
this(build, new BuildHistory(build, actionType, usePreviousBuildAsReference, useStableBuildAsReference), result, defaultEncoding, true);
}

PmdResult(final AbstractBuild<?, ?> build, final BuildHistory history,
@@ -112,14 +112,7 @@ else if (warning.getPriority() > PMD_PRIORITY_MAPPED_TO_LOW_PRIORITY) {
bug.setModuleName(moduleName);
bug.setFileName(file.getName());
bug.setColumnPosition(warning.getBegincolumn(), warning.getEndcolumn());

try {
bug.setContextHashCode(createContextHashCode(file.getName(), warning.getBeginline()) * 31
+ warning.getRule().hashCode());
}
catch (IOException exception) {
// ignore and continue
}
bug.setContextHashCode(createContextHashCode(file.getName(), warning.getBeginline(), warning.getRule()));

annotations.add(bug);
}

0 comments on commit bf11ab5

Please sign in to comment.
You can’t perform that action at this time.