Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Merge branch 'JENKINS-31202' of https://github.com/benjaminfuchs/warn…
…ings-plugin into benjaminfuchs-JENKINS-31202
  • Loading branch information
uhafner committed Oct 23, 2016
2 parents e064b74 + 016030d commit 87b33c6d768d3fda06045a48579e0826bf8af3e0
56 pom.xml
@@ -44,24 +44,68 @@
<dependency>
<groupId>org.jvnet.hudson.plugins</groupId>
<artifactId>analysis-core</artifactId>
<version>1.77</version>
<version>1.80-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>violations</artifactId>
<version>0.7.11</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-digester3</artifactId>
<version>3.2</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>script-security</artifactId>
<version>1.17</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-scm-step</artifactId>
<version>2.2</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>git</artifactId>
<version>2.5.2</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>subversion</artifactId>
<version>2.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>git</artifactId>
<version>2.5.2</version>
<classifier>tests</classifier>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-multibranch</artifactId>
<version>1.14</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jvnet.hudson.plugins</groupId>
<artifactId>analysis-test</artifactId>
@@ -6,8 +6,7 @@
import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.StaplerRequest;

import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Job;
import hudson.model.Run;
import hudson.plugins.analysis.core.AbstractProjectAction;
import hudson.plugins.analysis.core.BuildHistory;
@@ -19,7 +18,7 @@
import hudson.plugins.warnings.parser.ParserRegistry;

/**
* Entry point to visualize the warnings trend graph in the project screen.
* Entry point to visualize the warnings trend graph in the job screen.
* Drawing of the graph is delegated to the associated
* {@link WarningsResultAction}.
*
@@ -40,13 +39,13 @@ public static List<BuildResultGraph> getAllGraphs() {
/**
* Creates a new instance of {@link WarningsProjectAction}.
*
* @param project
* the project that owns this action
* @param job
* the job that owns this action
* @param group
* the group of the parsers that share this action
*/
public WarningsProjectAction(final AbstractProject<?, ?> project, final String group) {
super(project, WarningsResultAction.class,
public WarningsProjectAction(final Job<?, ?> job, final String group) {
super(job, WarningsResultAction.class,
ParserRegistry.getParser(group).getLinkName(), ParserRegistry.getParser(group).getTrendName(),
WarningsDescriptor.getProjectUrl(group),
ParserRegistry.getParser(group).getSmallImage(),
@@ -70,15 +69,15 @@ protected GraphConfigurationView createUserConfiguration(final StaplerRequest re

private UserGraphConfigurationView createUserConfiguration(final StaplerRequest request, final String urlName) {
return new UserGraphConfigurationView(
createConfiguration(getAvailableGraphs()), getProject(),
createConfiguration(getAvailableGraphs()), getOwner(),
urlName, WarningsDescriptor.getProjectUrl(null),
request.getCookies(), createBuildHistory());
}

@Override
protected GraphConfigurationView createDefaultConfiguration() {
return new DefaultGraphConfigurationView(
createConfiguration(getAvailableGraphs()), getProject(),
createConfiguration(getAvailableGraphs()), getOwner(),
WarningsDescriptor.getProjectUrl(parser),
createBuildHistory(), WarningsDescriptor.getProjectUrl(null));
}
@@ -96,7 +95,7 @@ public boolean isInGroup(@CheckForNull final String group) {
}

@Override
protected WarningsResultAction getResultAction(final AbstractBuild<?, ?> lastBuild) {
protected WarningsResultAction getResultAction(final Run<?, ?> lastBuild) {
return createHistory(lastBuild).getResultAction((Run<?, ?>) lastBuild);
}

@@ -107,7 +106,7 @@ protected WarningsResultAction getResultAction(final AbstractBuild<?, ?> lastBui
*/
@Override
protected BuildHistory createBuildHistory() {
AbstractBuild<?, ?> lastFinishedBuild = getLastFinishedBuild();
Run<?, ?> lastFinishedBuild = getLastFinishedRun();
if (lastFinishedBuild == null) {
return new NullBuildHistory();
}
@@ -116,7 +115,7 @@ protected BuildHistory createBuildHistory() {
}
}

private WarningsBuildHistory createHistory(final AbstractBuild<?, ?> build) {
private WarningsBuildHistory createHistory(final Run<?, ?> build) {
return new WarningsBuildHistory(build, parser, false, false);
}
}
@@ -14,14 +14,19 @@

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import java.util.Collection;
import java.util.Collections;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import jenkins.tasks.SimpleBuildStep;

import hudson.FilePath;
import hudson.Launcher;
import hudson.matrix.MatrixAggregator;
import hudson.matrix.MatrixBuild;
import hudson.model.AbstractProject;
import hudson.model.AbstractBuild;
import hudson.model.Action;
import hudson.model.BuildListener;
import hudson.model.Run;
@@ -48,7 +53,7 @@
* @author Ulli Hafner
*/
// CHECKSTYLE:COUPLING-OFF
public class WarningsPublisher extends HealthAwarePublisher {
public class WarningsPublisher extends HealthAwarePublisher implements SimpleBuildStep {
private static final long serialVersionUID = -5936973521277401764L;

private static final String PLUGIN_NAME = "WARNINGS";
@@ -268,12 +273,7 @@ public Action getProjectAction(final AbstractProject<?, ?> project) {

@Override
public Collection<? extends Action> getProjectActions(final AbstractProject<?, ?> project) {
List<Action> actions = Lists.newArrayList();
for (String parserName : getParsers()) {
actions.add(new WarningsProjectAction(project, parserName));
}
actions.add(new AggregatedWarningsProjectAction(project));
return actions;
return Collections.emptyList();
}

private List<String> getParsers() {
@@ -287,40 +287,41 @@ private List<String> getParsers() {
return parsers;
}


@Override
protected BuildResult perform(final Run<?, ?> build, final FilePath workspace, final PluginLogger logger)
protected BuildResult perform(final Run<?, ?> run, final FilePath workspace, final PluginLogger logger)
throws InterruptedException, IOException {
try {
if (!hasConsoleParsers() && !hasFileParsers()) {
throw new IOException("Error: No warning parsers defined in the job configuration.");
}

List<ParserResult> fileResults = parseFiles(build, workspace, logger);
List<ParserResult> consoleResults = parseConsoleLog(build, workspace, logger);
List<ParserResult> fileResults = parseFiles(run, workspace, logger);
List<ParserResult> consoleResults = parseConsoleLog(run, workspace, logger);

ParserResult totals = new ParserResult();
add(totals, consoleResults);
add(totals, fileResults);

BuildHistory history = new BuildHistory(build, AggregatedWarningsResultAction.class,
BuildHistory history = new BuildHistory(run, AggregatedWarningsResultAction.class,
usePreviousBuildAsReference(), useOnlyStableBuildsAsReference());
AggregatedWarningsResult result = new AggregatedWarningsResult(build, history, totals, getDefaultEncoding());
build.addAction(new AggregatedWarningsResultAction(build, result));
AggregatedWarningsResult result = new AggregatedWarningsResult(run, history, totals, getDefaultEncoding());
run.addAction(new AggregatedWarningsResultAction(run, result));

return result;
}
catch (ParsingCanceledException exception) {
return emptyBuildResult(build, logger, exception);
return emptyBuildResult(run, logger, exception);
}
catch (InterruptedException exception) {
return emptyBuildResult(build, logger, exception);
return emptyBuildResult(run, logger, exception);
}
}

private BuildResult emptyBuildResult(final Run<?, ?> build, final PluginLogger logger, final Exception exception) {
private BuildResult emptyBuildResult(final Run<?, ?> run, final PluginLogger logger, final Exception exception) {
logger.log(exception.getMessage());

return new AggregatedWarningsResult(build, new NullBuildHistory(), new ParserResult(), getDefaultEncoding());
return new AggregatedWarningsResult(run, new NullBuildHistory(), new ParserResult(), getDefaultEncoding());
}

private boolean hasFileParsers() {
@@ -347,22 +348,22 @@ private void returnIfCanceled() throws InterruptedException {
}
}

private List<ParserResult> parseConsoleLog(final Run<?, ?> build, final FilePath workspace, final PluginLogger logger)
private List<ParserResult> parseConsoleLog(final Run<?, ?> run, final FilePath workspace, final PluginLogger logger)
throws IOException, InterruptedException {
List<ParserResult> results = Lists.newArrayList();
for (ConsoleParser parser : getConsoleParsers()) {
String parserName = parser.getParserName();
logger.log("Parsing warnings in console log with parser " + parserName);

Collection<FileAnnotation> warnings = new ParserRegistry(ParserRegistry.getParsers(parserName),
getDefaultEncoding()).parse(build.getLogFile());
getDefaultEncoding()).parse(run.getLogFile());
if (!workspace.isRemote()) {
guessModuleNames(workspace, warnings);
}
ParserResult project = new ParserResult(workspace, canResolveRelativePaths());
project.addAnnotations(warnings);

results.add(annotate(build, workspace, filterWarnings(project, logger), parserName));
results.add(annotate(run, workspace, filterWarnings(project, logger), parserName));
}
return results;
}
@@ -385,37 +386,37 @@ private void guessModuleNames(final FilePath workspace, final Collection<FileAnn
}
}

private List<ParserResult> parseFiles(final Run<?, ?> build, final FilePath workspace, final PluginLogger logger)
private List<ParserResult> parseFiles(final Run<?, ?> run, final FilePath workspace, final PluginLogger logger)
throws IOException, InterruptedException {
List<ParserResult> results = Lists.newArrayList();
for (ParserConfiguration configuration : getParserConfigurations()) {
String filePattern = expandFilePattern(configuration.getPattern(), build.getEnvironment(TaskListener.NULL));
String filePattern = expandFilePattern(configuration.getPattern(), run.getEnvironment(TaskListener.NULL));
String parserName = configuration.getParserName();

logger.log("Parsing warnings in files '" + filePattern + "' with parser " + parserName);

FilesParser parser = new FilesParser(PLUGIN_NAME, filePattern,
new FileWarningsParser(ParserRegistry.getParsers(parserName), getDefaultEncoding()),
shouldDetectModules(), isMavenBuild(build), canResolveRelativePaths());
shouldDetectModules(), isMavenBuild(run), canResolveRelativePaths());
ParserResult project = workspace.act(parser);
logger.logLines(project.getLogMessages());

returnIfCanceled();
results.add(annotate(build, workspace, filterWarnings(project, logger), configuration.getParserName()));
results.add(annotate(run, workspace, filterWarnings(project, logger), configuration.getParserName()));
}
return results;
}

private ParserResult annotate(final Run<?, ?> build, final FilePath workspace, final ParserResult input, final String parserName)
private ParserResult annotate(final Run<?, ?> run, final FilePath workspace, final ParserResult input, final String parserName)
throws IOException, InterruptedException {
ParserResult output = workspace.act(new AnnotationsClassifier(input, getDefaultEncoding()));
for (FileAnnotation annotation : output.getAnnotations()) {
annotation.setPathName(workspace.getRemote());
}
WarningsBuildHistory history = new WarningsBuildHistory(build, parserName,
WarningsBuildHistory history = new WarningsBuildHistory(run, parserName,
usePreviousBuildAsReference(), useOnlyStableBuildsAsReference());
WarningsResult result = new WarningsResult(build, history, output, getDefaultEncoding(), parserName);
build.addAction(new WarningsResultAction(build, this, result, parserName));
WarningsResult result = new WarningsResult(run, history, output, getDefaultEncoding(), parserName);
run.addAction(new WarningsResultAction(run, this, result, parserName));

return output;
}
@@ -435,8 +436,8 @@ public WarningsDescriptor getDescriptor() {
}

@Override
public MatrixAggregator createAggregator(final MatrixBuild build, final Launcher launcher, final BuildListener listener) {
return new WarningsAnnotationsAggregator(build, launcher, listener, this, getDefaultEncoding(),
public MatrixAggregator createAggregator(final MatrixBuild run, final Launcher launcher, final BuildListener listener) {
return new WarningsAnnotationsAggregator(run, launcher, listener, this, getDefaultEncoding(),
usePreviousBuildAsReference(), useOnlyStableBuildsAsReference());
}

@@ -5,6 +5,9 @@

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import java.util.Collection;
import java.util.Collections;
import hudson.model.Action;
import hudson.model.Run;
import hudson.plugins.analysis.core.AbstractResultAction;
import hudson.plugins.analysis.core.HealthDescriptor;
@@ -41,6 +44,16 @@ public WarningsResultAction(final Run<?, ?> owner, final HealthDescriptor health

this.parserName = parserName;
}

/**
* Returns the project actions if this action is used in a pipeline.
*
* @return default implementation returns empty collection, plug-in must override if they want to contribute to the UI
*/
@Override
public Collection<? extends Action> getProjectActions() {
return Collections.<Action>singleton(new WarningsProjectAction(this.getOwner().getParent(), parserName));
}

@Override @Exported
public String getUrlName() {

0 comments on commit 87b33c6

Please sign in to comment.