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

Commit

Permalink
[JENKINS-29648] Workflow compatible. Added new tests (workflow specific)
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Recena authored and recena committed Aug 24, 2015
1 parent d289a26 commit b2de9b3
Show file tree
Hide file tree
Showing 7 changed files with 254 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -1 +1,3 @@
target
.idea/
work/
32 changes: 29 additions & 3 deletions pom.xml
Expand Up @@ -4,8 +4,7 @@
<parent>
<groupId>org.jvnet.hudson.plugins</groupId>
<artifactId>analysis-pom</artifactId>
<version>1.59</version>
<relativePath>../analysis-pom/pom.xml</relativePath>
<version>1.63</version>
</parent>

<artifactId>checkstyle</artifactId>
Expand All @@ -17,6 +16,10 @@
Checkstyle, an open source static code analysis program.
</description>

<properties>
<workflow-jenkins-plugin.version>1.4</workflow-jenkins-plugin.version>
</properties>

<licenses>
<license>
<name>MIT license</name>
Expand All @@ -34,7 +37,7 @@
<dependency>
<groupId>org.jvnet.hudson.plugins</groupId>
<artifactId>analysis-core</artifactId>
<version>1.73-SNAPSHOT</version>
<version>1.73-beta-SNAPSHOT</version><!-- TODO: change to 1.73 before release -->
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
Expand All @@ -46,12 +49,35 @@
<artifactId>xercesImpl</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>matrix-project</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.jvnet.hudson.plugins</groupId>
<artifactId>analysis-test</artifactId>
<version>1.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-job</artifactId>
<version>${workflow-jenkins-plugin.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-cps</artifactId>
<version>${workflow-jenkins-plugin.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-basic-steps</artifactId>
<version>${workflow-jenkins-plugin.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<scm>
Expand Down
44 changes: 35 additions & 9 deletions src/main/java/hudson/plugins/checkstyle/CheckStylePublisher.java
Expand Up @@ -2,25 +2,29 @@

import java.io.IOException;

import hudson.FilePath;
import hudson.model.AbstractProject;
import hudson.model.Action;
import hudson.model.BuildListener;
import hudson.model.Run;
import net.sf.json.JSONObject;
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.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.util.PluginLogger;
import hudson.plugins.checkstyle.parser.CheckStyleParser;
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.StaplerRequest;

/**
* Publishes the results of the Checkstyle analysis (freestyle project type).
* Publishes the results of the Checkstyle analysis (freestyle project type).
*
* @author Ulli Hafner
*/
Expand All @@ -33,7 +37,7 @@ public class CheckStylePublisher extends HealthAwarePublisher {
/** Default Checkstyle pattern. */
private static final String DEFAULT_PATTERN = "**/checkstyle-result.xml";
/** Ant file-set pattern of files to work with. */
private final String pattern;
private String pattern;

/**
* Creates a new instance of <code>CheckstylePublisher</code>.
Expand Down Expand Up @@ -98,10 +102,12 @@ public class CheckStylePublisher extends HealthAwarePublisher {
* respect to baseline)
* @param pattern
* Ant file-set pattern to scan for Checkstyle files
*
* @deprecated see {@link #CheckStylePublisher()}
*/
// CHECKSTYLE:OFF
@SuppressWarnings("PMD.ExcessiveParameterList")
@DataBoundConstructor
@Deprecated
public CheckStylePublisher(final String healthy, final String unHealthy, final String thresholdLimit,
final String defaultEncoding, final boolean useDeltaValues,
final String unstableTotalAll, final String unstableTotalHigh, final String unstableTotalNormal, final String unstableTotalLow,
Expand All @@ -121,6 +127,16 @@ public CheckStylePublisher(final String healthy, final String unHealthy, final S
}
// CHECKSTYLE:ON


/**
* Constructor used from methods like {@link StaplerRequest#bindJSON(Class, JSONObject)} and
* {@link StaplerRequest#bindParameters(Class, String)}.
*/
@DataBoundConstructor
public CheckStylePublisher() {
super(PLUGIN_NAME);
}

/**
* Returns the Ant file-set pattern of files to work with.
*
Expand All @@ -130,19 +146,29 @@ public String getPattern() {
return pattern;
}

/**
* Sets the Ant file-set pattern of files to work with.
*/
@DataBoundSetter
public void setPattern(final String pattern) {
this.pattern = pattern;
}

@Override
public Action getProjectAction(final AbstractProject<?, ?> project) {
return new CheckStyleProjectAction(project);
}

@Override
public BuildResult perform(final AbstractBuild<?, ?> build, final PluginLogger logger) throws InterruptedException, IOException {
public BuildResult perform(final Run<?, ?> build, final FilePath workspace, final PluginLogger logger) throws
InterruptedException, IOException {
logger.log("Collecting checkstyle analysis files...");

FilesParser parser = new FilesParser(PLUGIN_NAME, StringUtils.defaultIfEmpty(getPattern(), DEFAULT_PATTERN),
new CheckStyleParser(getDefaultEncoding()),
shouldDetectModules(), isMavenBuild(build));
ParserResult project = build.getWorkspace().act(parser);

ParserResult project = workspace.act(parser);
logger.logLines(project.getLogMessages());

CheckStyleResult result = new CheckStyleResult(build, getDefaultEncoding(), project,
Expand Down
@@ -1,6 +1,7 @@
package hudson.plugins.checkstyle;

import hudson.model.AbstractBuild;
import hudson.model.Run;
import hudson.plugins.analysis.core.ParserResult;
import hudson.plugins.analysis.core.ResultAction;
import hudson.plugins.analysis.core.BuildResult;
Expand All @@ -13,6 +14,31 @@
public class CheckStyleReporterResult extends CheckStyleResult {
private static final long serialVersionUID = 6414012312137436141L;

/**
* Creates a new instance of {@link CheckStyleReporterResult}.
*
* @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
* 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
*
* @deprecated see {@link #CheckStyleReporterResult(Run, String, ParserResult, boolean, boolean)}
*/
@Deprecated
public CheckStyleReporterResult(final AbstractBuild<?, ?> build, final String defaultEncoding,
final ParserResult result, final boolean usePreviousBuildAsReference,
final boolean useStableBuildAsReference) {
this((Run<?, ?>) build, defaultEncoding, result, usePreviousBuildAsReference, useStableBuildAsReference);
}

/**
* Creates a new instance of {@link CheckStyleReporterResult}.
*
Expand All @@ -29,7 +55,7 @@ public class CheckStyleReporterResult extends CheckStyleResult {
* determines whether only stable builds should be used as
* reference builds or not
*/
public CheckStyleReporterResult(final AbstractBuild<?, ?> build, final String defaultEncoding, final ParserResult result,
public CheckStyleReporterResult(final Run<?, ?> build, final String defaultEncoding, final ParserResult result,
final boolean usePreviousBuildAsReference, final boolean useStableBuildAsReference) {
super(build, defaultEncoding, result, usePreviousBuildAsReference, useStableBuildAsReference,
CheckStyleMavenResultAction.class);
Expand Down
65 changes: 63 additions & 2 deletions src/main/java/hudson/plugins/checkstyle/CheckStyleResult.java
Expand Up @@ -3,6 +3,7 @@
import com.thoughtworks.xstream.XStream;

import hudson.model.AbstractBuild;
import hudson.model.Run;
import hudson.plugins.analysis.core.BuildHistory;
import hudson.plugins.analysis.core.BuildResult;
import hudson.plugins.analysis.core.ParserResult;
Expand Down Expand Up @@ -33,9 +34,34 @@ public class CheckStyleResult extends BuildResult {
* @param useStableBuildAsReference
* determines whether only stable builds should be used as
* reference builds or not
*
* @deprecated use {@link #CheckStyleResult(Run, String, ParserResult, boolean, boolean, Class)}
*/
@Deprecated
public CheckStyleResult(final AbstractBuild<?, ?> build, final String defaultEncoding, final ParserResult result,
final boolean usePreviousBuildAsReference, final boolean useStableBuildAsReference) {
this((Run<?, ?>) build, defaultEncoding, result, usePreviousBuildAsReference, useStableBuildAsReference);
}


/**
* Creates a new instance of {@link CheckStyleResult}.
*
* @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
* 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 Run<?, ?> build, final String defaultEncoding, final ParserResult result,
final boolean usePreviousBuildAsReference, final boolean useStableBuildAsReference) {
this(build, defaultEncoding, result, usePreviousBuildAsReference, useStableBuildAsReference,
CheckStyleResultAction.class);
}
Expand All @@ -54,16 +80,51 @@ public CheckStyleResult(final AbstractBuild<?, ?> build, final String defaultEnc
* reference builds or not
* @param actionType
* the type of the result action
*
* @deprecated use {@link #CheckStyleResult(Run, String, ParserResult, boolean, boolean, Class)}
*/
@Deprecated
protected CheckStyleResult(final AbstractBuild<?, ?> build, final String defaultEncoding, final ParserResult result,
final boolean usePreviousBuildAsReference, final boolean useStableBuildAsReference,
final Class<? extends ResultAction<CheckStyleResult>> actionType) {
this((Run<?, ?>) build, defaultEncoding, result, usePreviousBuildAsReference, useStableBuildAsReference,
actionType);

}

/**
* Creates a new instance of {@link CheckStyleResult}.
*
* @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
*/
protected CheckStyleResult(final Run<?, ?> build, final String defaultEncoding, final ParserResult result,
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,
final ParserResult result, final String defaultEncoding, final boolean canSerialize) {
/**
* @deprecated use {@link #CheckStyleResult(Run, BuildHistory, ParserResult, String, boolean)}
*/
@Deprecated
CheckStyleResult(final AbstractBuild<?, ?> build, final BuildHistory history, final ParserResult result,
final String defaultEncoding, final boolean canSerialize) {
this((Run<?, ?>) build, history, result, defaultEncoding, canSerialize);
}

CheckStyleResult(final Run<?, ?> build, final BuildHistory history,
final ParserResult result, final String defaultEncoding, final boolean canSerialize) {
super(build, history, result, defaultEncoding);

if (canSerialize) {
Expand Down
@@ -1,6 +1,7 @@
package hudson.plugins.checkstyle;

import hudson.model.AbstractBuild;
import hudson.model.Run;
import hudson.plugins.analysis.core.AbstractResultAction;
import hudson.plugins.analysis.core.HealthDescriptor;
import hudson.plugins.analysis.core.PluginDescriptor;
Expand All @@ -17,6 +18,24 @@
* @author Ulli Hafner
*/
public class CheckStyleResultAction extends AbstractResultAction<CheckStyleResult> {
/**
* Creates a new instance of <code>CheckStyleResultAction</code>.
*
* @param owner
* the associated build of this action
* @param healthDescriptor
* health descriptor
* @param result
* the result in this build
*
* @deprecated see use {@link #CheckStyleResultAction(Run, HealthDescriptor, CheckStyleResult)}
*/
@Deprecated
public CheckStyleResultAction(final AbstractBuild<?, ?> owner, final HealthDescriptor healthDescriptor,
final CheckStyleResult result) {
this((Run<?, ?>) owner, new CheckStyleHealthDescriptor(healthDescriptor), result);
}

/**
* Creates a new instance of <code>CheckStyleResultAction</code>.
*
Expand All @@ -27,7 +46,8 @@ public class CheckStyleResultAction extends AbstractResultAction<CheckStyleResul
* @param result
* the result in this build
*/
public CheckStyleResultAction(final AbstractBuild<?, ?> owner, final HealthDescriptor healthDescriptor, final CheckStyleResult result) {
public CheckStyleResultAction(final Run<?, ?> owner, final HealthDescriptor healthDescriptor,
final CheckStyleResult result) {
super(owner, new CheckStyleHealthDescriptor(healthDescriptor), result);
}

Expand Down

0 comments on commit b2de9b3

Please sign in to comment.