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

Commit

Permalink
[JENKINS-31202] Replacing occurences of AbstractProject with Job and …
Browse files Browse the repository at this point in the history
…AbstractBuild.
  • Loading branch information
benjaminfuchs committed Jul 17, 2016
1 parent 2cc7bf1 commit 34d169c
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 34 deletions.
19 changes: 9 additions & 10 deletions src/main/java/hudson/plugins/warnings/WarningsProjectAction.java
Expand Up @@ -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;
Expand All @@ -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}.
*
Expand All @@ -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(),
Expand Down Expand Up @@ -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);
}

Expand All @@ -107,7 +106,7 @@ protected WarningsResultAction getResultAction(final AbstractBuild<?, ?> lastBui
*/
@Override
protected BuildHistory createBuildHistory() {
AbstractBuild<?, ?> lastFinishedBuild = getLastFinishedBuild();
Run<?, ?> lastFinishedBuild = getLastFinishedBuild();
if (lastFinishedBuild == null) {
return new NullBuildHistory();
}
Expand All @@ -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);
}
}
Expand Down
52 changes: 28 additions & 24 deletions src/main/java/hudson/plugins/warnings/WarningsPublisher.java
Expand Up @@ -17,11 +17,14 @@

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;
Expand All @@ -48,7 +51,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";
Expand Down Expand Up @@ -287,40 +290,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() {
Expand All @@ -347,22 +351,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;
}
Expand All @@ -385,37 +389,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;
}
Expand All @@ -435,8 +439,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());
}

Expand Down
16 changes: 16 additions & 0 deletions src/main/java/hudson/plugins/warnings/WarningsResultAction.java
@@ -1,10 +1,15 @@
package hudson.plugins.warnings;

import org.jvnet.localizer.Localizable;

import org.kohsuke.stapler.export.Exported;

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;
Expand Down Expand Up @@ -41,6 +46,17 @@ 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
*/
// FIXME: See JENKINS-31202. Currently the whole graphing is based around AbstractBuild (large refactoring required)
@Override
public Collection<? extends Action> getProjectActions() {
return Collections.<Action>singleton(new WarningsProjectAction(this.getOwner().getParent(), parserName));
}

@Override @Exported
public String getUrlName() {
Expand Down

0 comments on commit 34d169c

Please sign in to comment.