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

Commit

Permalink
[JENKINS-10319] When computing the build history correctly select the
Browse files Browse the repository at this point in the history
results that use the same parser. If there is no such result then try to
use the action of the 3.x parsers.
  • Loading branch information
uhafner committed Mar 28, 2012
1 parent 495511c commit 12b6571
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/main/java/hudson/plugins/warnings/WarningsBuildHistory.java
@@ -0,0 +1,45 @@
package hudson.plugins.warnings;

import hudson.model.AbstractBuild;
import hudson.plugins.analysis.core.BuildHistory;

import java.util.List;

/**
* A build history for warnings results. Picks the right action using the parser group.
*
* @author Ulli Hafner
*/
public class WarningsBuildHistory extends BuildHistory {
private final String group;

/**
* Creates a new instance of {@link WarningsBuildHistory}.
*
* @param lastFinishedBuild
* the last finished build
* @param group
* the parser group
*/
public WarningsBuildHistory(final AbstractBuild<?, ?> lastFinishedBuild, final String group) {
super(lastFinishedBuild, WarningsResultAction.class);

this.group = group;
}

/** {@inheritDoc} */
@Override
public WarningsResultAction getResultAction(final AbstractBuild<?, ?> build) {
List<WarningsResultAction> actions = build.getActions(WarningsResultAction.class);
for (WarningsResultAction action : actions) {
if (group.equals(action.getParser())) {
return action;
}
}
if (!actions.isEmpty() && actions.get(0).getParser() == null) { // fallback 3.x
return actions.get(0);
}
return null;
}
}

29 changes: 29 additions & 0 deletions src/main/java/hudson/plugins/warnings/WarningsProjectAction.java
@@ -1,6 +1,9 @@
package hudson.plugins.warnings;

import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.plugins.analysis.core.BuildHistory;
import hudson.plugins.analysis.core.NullBuildHistory;
import hudson.plugins.analysis.core.AbstractProjectAction;
import hudson.plugins.warnings.parser.ParserRegistry;

Expand Down Expand Up @@ -30,5 +33,31 @@ public WarningsProjectAction(final AbstractProject<?, ?> project, final String g
WarningsDescriptor.getResultUrl(group));
this.group = group;
}

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

/**
* Creates the build history.
*
* @return build history
*/
@Override
protected BuildHistory createBuildHistory() {
AbstractBuild<?, ?> lastFinishedBuild = getLastFinishedBuild();
if (lastFinishedBuild == null) {
return new NullBuildHistory();
}
else {
return createHistory(lastFinishedBuild);
}
}

private WarningsBuildHistory createHistory(final AbstractBuild<?, ?> build) {
return new WarningsBuildHistory(build, group);
}
}

0 comments on commit 12b6571

Please sign in to comment.