Skip to content
This repository has been archived by the owner on Jan 16, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-29870] Workflow compatible. Added new tests (workflow specific)
  • Loading branch information
recena committed Aug 23, 2015
1 parent 8c5f5fc commit ec7b381
Show file tree
Hide file tree
Showing 11 changed files with 243 additions and 42 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -1,2 +1,4 @@
target
work

.idea
28 changes: 25 additions & 3 deletions pom.xml
Expand Up @@ -4,8 +4,7 @@
<parent>
<groupId>org.jvnet.hudson.plugins</groupId>
<artifactId>analysis-pom</artifactId>
<version>1.52</version>
<relativePath>../analysis-pom/pom.xml</relativePath>
<version>1.63</version>
</parent>

<artifactId>android-lint</artifactId>
Expand All @@ -14,6 +13,11 @@
<version>2.3-SNAPSHOT</version>
<url>https://wiki.jenkins-ci.org/display/JENKINS/Android+Lint+Plugin</url>
<description>Parses Android Lint output and displays the results for analysis.</description>

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

<developers>
<developer>
<id>orrc</id>
Expand All @@ -27,7 +31,25 @@
<dependency>
<groupId>org.jvnet.hudson.plugins</groupId>
<artifactId>analysis-core</artifactId>
<version>1.61</version>
<version>1.73-beta-SNAPSHOT</version><!-- TODO: change to 1.73 before release -->
</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>

Expand Down
Expand Up @@ -64,10 +64,9 @@ public Class<? extends MavenResultAction<LintResult>> getIndividualActionType()
}

@Override
protected LintResult createResult(final LintResult existingResult,
final LintResult additionalResult) {
return new LintReporterResult(getOwner(), additionalResult.getDefaultEncoding(),
aggregate(existingResult, additionalResult));
protected LintResult createResult(final LintResult existingResult, final LintResult additionalResult) {
return new LintReporterResult(getOwner(), additionalResult.getDefaultEncoding(), aggregate(existingResult,
additionalResult), false, false);
}

}
39 changes: 27 additions & 12 deletions src/main/java/org/jenkinsci/plugins/android_lint/LintPublisher.java
@@ -1,12 +1,10 @@
package org.jenkinsci.plugins.android_lint;

import hudson.FilePath;
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.*;
import hudson.plugins.analysis.core.BuildResult;
import hudson.plugins.analysis.core.FilesParser;
import hudson.plugins.analysis.core.HealthAwarePublisher;
Expand All @@ -18,6 +16,7 @@
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.plugins.android_lint.parser.LintParser;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;

/** Publishes the results of parsing an Android lint file. */
public class LintPublisher extends HealthAwarePublisher {
Expand All @@ -31,7 +30,7 @@ public class LintPublisher extends HealthAwarePublisher {
private static final long serialVersionUID = 3435696173660003622L;

/** Ant fileset pattern of files to work with. */
private final String pattern;
private String pattern;

/**
* Constructor.
Expand Down Expand Up @@ -63,10 +62,12 @@ public class LintPublisher extends HealthAwarePublisher {
* @param shouldDetectModules Determines whether module names should be derived from Maven POM
* or Ant build files.
* @param canComputeNew determines whether new warnings should be computed (with
* respect to baseline)
* respect to baseline)
* @param pattern Ant fileset pattern used to scan for Lint files.
*
* @deprecated see {@link #LintPublisher()}
*/
@DataBoundConstructor
@Deprecated
public LintPublisher(final String healthy, final String unHealthy, final String thresholdLimit,
final String defaultEncoding, final boolean useDeltaValues,
final String unstableTotalAll, final String unstableTotalHigh,
Expand All @@ -87,6 +88,11 @@ public LintPublisher(final String healthy, final String unHealthy, final String
this.pattern = pattern;
}

@DataBoundConstructor
public LintPublisher() {
super(PLUGIN_NAME);
}

/**
* Returns the Ant fileset pattern of files to work with.
*
Expand All @@ -96,23 +102,32 @@ 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 LintProjectAction(project);
}

@Override
public BuildResult perform(final AbstractBuild<?, ?> build, final PluginLogger logger)
public BuildResult perform(final Run<?, ?> build, final FilePath workspace, final PluginLogger logger)
throws InterruptedException, IOException {
logger.log(Messages.AndroidLint_Publisher_CollectingFiles());
FilesParser lintCollector = new FilesParser(PLUGIN_NAME,
FilesParser parser = new FilesParser(PLUGIN_NAME,
StringUtils.defaultIfEmpty(getPattern(), DEFAULT_PATTERN),
new LintParser(getDefaultEncoding()), shouldDetectModules(), isMavenBuild(build));
ParserResult project = build.getWorkspace().act(lintCollector);

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

LintResult result = new LintResult(build, getDefaultEncoding(), project);
build.getActions().add(new LintResultAction(build, this, result));
LintResult result = new LintResult(build, getDefaultEncoding(), project, false, false);
build.addAction(new LintResultAction(build, this, result));

return result;
}
Expand Down
@@ -1,11 +1,14 @@
package org.jenkinsci.plugins.android_lint;

import hudson.model.AbstractBuild;
import hudson.model.Run;
import hudson.plugins.analysis.core.BuildResult;
import hudson.plugins.analysis.core.ParserResult;
import hudson.plugins.analysis.core.ResultAction;

/** Represents the aggregated results of Lint results in an m2 build. */
/**
* Represents the aggregated results of Lint results in an m2 build.
*/
public class LintReporterResult extends LintResult {

private static final long serialVersionUID = 1693573220866799558L;
Expand All @@ -14,10 +17,23 @@ public class LintReporterResult extends LintResult {
* @param build The current build as owner of this action.
* @param defaultEncoding The default encoding to be used when reading files.
* @param result The parsed result with all annotations.
*
* @deprecated see {@link #LintReporterResult(Run, String, ParserResult, boolean, boolean)}
*/
public LintReporterResult(final AbstractBuild<?, ?> build, final String defaultEncoding,
final ParserResult result) {
super(build, defaultEncoding, result);
@Deprecated
public LintReporterResult(final AbstractBuild<?, ?> build, final String defaultEncoding, final ParserResult result) {
this((Run<?, ?>) build, defaultEncoding, result, false, false);
}

/**
* @param build The current build as owner of this action.
* @param defaultEncoding The default encoding to be used when reading files.
* @param result The parsed result with all annotations.
* @param usePreviousBuildAsReference Determines whether to use the previous build as the reference
* @param useStableBuildAsReference Determines whether only stable builds should be used as reference builds or not
*/
public LintReporterResult(final Run<?, ?> build, final String defaultEncoding, final ParserResult result, final boolean usePreviousBuildAsReference, final boolean useStableBuildAsReference) {
super(build, defaultEncoding, result, usePreviousBuildAsReference, useStableBuildAsReference);
}

@Override
Expand Down
55 changes: 47 additions & 8 deletions src/main/java/org/jenkinsci/plugins/android_lint/LintResult.java
@@ -1,16 +1,15 @@
package org.jenkinsci.plugins.android_lint;

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

import org.jenkinsci.plugins.android_lint.parser.LintAnnotation;
import org.jenkinsci.plugins.android_lint.parser.Location;

import com.thoughtworks.xstream.XStream;

/**
* Represents the results of a Lint analysis.
* <p>
Expand All @@ -27,9 +26,30 @@ public class LintResult extends BuildResult {
* @param defaultEncoding The default encoding to be used when reading files.
* @param result The parsed result with all annotations.
*/
public LintResult(final AbstractBuild<?, ?> build, final String defaultEncoding,
final ParserResult result) {
super(build, defaultEncoding, result);
@Deprecated
public LintResult(final AbstractBuild<?, ?> build, final String defaultEncoding, final ParserResult result) {
this(build, defaultEncoding, result, false, false, LintResultAction.class);
}

/**
* Creates a new instance of {@link LintResult}.
*
* @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 LintResult(final Run<?, ?> build, final String defaultEncoding, final ParserResult result,
final boolean usePreviousBuildAsReference, final boolean useStableBuildAsReference) {
this(build, defaultEncoding, result, usePreviousBuildAsReference, useStableBuildAsReference, LintResultAction.class);
}

/**
Expand All @@ -40,9 +60,28 @@ public LintResult(final AbstractBuild<?, ?> build, final String defaultEncoding,
* @param result The parsed result with all annotations.
* @param history Build result history for this plugin.
*/
public LintResult(final AbstractBuild<?, ?> build, final String defaultEncoding,
@Deprecated
protected LintResult(final AbstractBuild<?, ?> build, final String defaultEncoding,
final ParserResult result, final BuildHistory history) {
super(build, defaultEncoding, result, history);
super((Run<?, ?>) build, history, result, defaultEncoding);
}

/**
* Creates a new instance of {@link LintResult}.
*
* @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 LintResult(final Run<?, ?> build,
final String defaultEncoding, final ParserResult result,
final boolean usePreviousBuildAsReference,
final boolean useStableBuildAsReference,
final Class<? extends ResultAction<LintResult>> actionType) {
super(build, new BuildHistory(build, actionType, usePreviousBuildAsReference, useStableBuildAsReference), result, defaultEncoding);
}

@Override
Expand Down
@@ -1,6 +1,7 @@
package org.jenkinsci.plugins.android_lint;

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 @@ -23,9 +24,23 @@ public class LintResultAction extends AbstractResultAction<LintResult> {
* @param owner Build owning this action.
* @param healthDescriptor Health descriptor to use.
* @param result The Lint result for this build.
*
* @deprecated see {@link #LintResultAction(Run, HealthDescriptor, LintResult)}
*/
@Deprecated
public LintResultAction(final AbstractBuild<?, ?> owner,
final HealthDescriptor healthDescriptor, final LintResult result) {
this((Run<?, ?>) owner, new LintHealthDescriptor(healthDescriptor), result);
}

/**
* Creates a new instance of {@link LintResultAction}.
*
* @param owner Build owning this action.
* @param healthDescriptor Health descriptor to use.
* @param result The Lint result for this build.
*/
public LintResultAction(final Run<?, ?> owner, final HealthDescriptor healthDescriptor, final LintResult result) {
super(owner, new LintHealthDescriptor(healthDescriptor), result);
}

Expand Down
@@ -1,11 +1,11 @@
package org.jenkinsci.plugins.android_lint.parser;
package org.jenkinsci.plugins.android_lint;

import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.plugins.analysis.core.FilesParser;
import hudson.plugins.analysis.core.ParserResult;
import hudson.plugins.analysis.util.model.Priority;
import org.jenkinsci.plugins.android_lint.LintResult;
import org.jenkinsci.plugins.android_lint.parser.LintParser;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.ExtractResourceSCM;
Expand Down

0 comments on commit ec7b381

Please sign in to comment.