Skip to content
Permalink
Browse files

[JENKINS-34439] Clover plugin still has problems with pipeline builds

Clover action not displayed on workflow job main page.

CloverBuildAction.java
- Added SimpleBuildStep.LastBuildAction interface
- changed AbstractBuild to Run<?,?>

CloverProjectAction.java
- changed Project to Job
- changed Build to Run

CloverPublisher.java
- removed not needed imports
- removed getProjectAction (moved to BuildAction)
  • Loading branch information...
piomis committed Jun 24, 2017
1 parent 53acf8b commit a58061c681f24c6262fd7c07088f002b48fe5b49
@@ -3,7 +3,7 @@
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import hudson.model.AbstractBuild;
import hudson.model.Action;
import hudson.model.HealthReport;
import hudson.model.HealthReportingAction;
import hudson.model.Result;
@@ -19,23 +19,28 @@

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import jenkins.model.RunAction2;
import jenkins.tasks.SimpleBuildStep;
import org.jvnet.localizer.Localizable;


/**
* A health reporter for the individual build page.
*/
public class CloverBuildAction extends AbstractPackageAggregatedMetrics implements HealthReportingAction, StaplerProxy, RunAction2 {
public class CloverBuildAction extends AbstractPackageAggregatedMetrics implements HealthReportingAction, StaplerProxy, RunAction2, SimpleBuildStep.LastBuildAction {
public transient Run<?, ?> owner;
private String buildBaseDir;
private CoverageTarget healthyTarget;
private CoverageTarget unhealthyTarget;
private transient List<CloverProjectAction> projectActions;

private static final LoadingCache<CloverBuildAction,ProjectCoverage> reports = CacheBuilder.newBuilder().
weakKeys().
@@ -133,6 +138,8 @@ static CloverBuildAction getPreviousResult(Run<?, ?> start) {
if (r != null) {
reports.put(this, r);
}
this.projectActions = new ArrayList<CloverProjectAction>();

this.buildBaseDir = workspacePath;
if (this.buildBaseDir == null) {
this.buildBaseDir = File.separator;
@@ -149,10 +156,20 @@ static CloverBuildAction getPreviousResult(Run<?, ?> start) {
if (c != null) {
c.setOwner(build);
}
if( this.projectActions == null )
{
this.projectActions = new ArrayList<CloverProjectAction>();
}
this.projectActions.add(new CloverProjectAction(build.getParent()));
}

@Override public void onLoad(Run<?,?> r) {
owner = r;
if( this.projectActions == null )
{
this.projectActions = new ArrayList<CloverProjectAction>();
}
this.projectActions.add(new CloverProjectAction(r.getParent()));
}

/**
@@ -276,6 +293,11 @@ public int getPackages() {
@Override public int getElements() {
return getResult().getElements();
}

@Override
public Collection<? extends Action> getProjectActions() {
return this.projectActions;
}

private static final Logger logger = Logger.getLogger(CloverBuildAction.class.getName());

@@ -1,9 +1,9 @@
package hudson.plugins.clover;

import hudson.FilePath;
import hudson.model.Project;
import hudson.model.Job;
import hudson.model.ProminentProjectAction;
import hudson.model.Build;
import hudson.model.Run;
import hudson.model.Result;
import hudson.model.DirectoryBrowserSupport;
import hudson.model.Actionable;
@@ -26,9 +26,9 @@

static final String ICON = "/plugin/clover/clover_48x48.png";

private final Project<?, ?> project;
private transient final Job<?, ?> project;

public CloverProjectAction(Project project) {
public CloverProjectAction(Job<?,?> project) {
this.project = project;
}

@@ -77,7 +77,7 @@ public String getUrlName() {
* @return the last successful build result
*/
public CloverBuildAction getLastSuccessfulResult() {
for (Build<?, ?> b = project.getLastBuild(); b != null; b = b.getPreviousBuild()) {
for (Run<?, ?> b = project.getLastBuild(); b != null; b = b.getPreviousBuild()) {
if (b.getResult() == Result.FAILURE)
continue;
CloverBuildAction r = b.getAction(CloverBuildAction.class);
@@ -5,11 +5,8 @@
import hudson.FilePath;
import hudson.Launcher;
import hudson.Util;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Action;
import hudson.model.BuildListener;
import hudson.model.Project;
import hudson.model.Job;
import hudson.model.Result;
import hudson.model.Run;
import hudson.model.TaskListener;
@@ -144,12 +141,6 @@ static File getCloverXmlReport(Run<?, ?> build) {
return new File(build.getRootDir(), "clover.xml");
}

@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener)
throws InterruptedException, IOException {
return performImpl(build, build.getWorkspace(), listener);
}

@Override
public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath workspace, @Nonnull Launcher launcher,
@Nonnull TaskListener listener) throws InterruptedException, IOException {
@@ -319,11 +310,6 @@ private void flagMissingCloverXml(TaskListener listener, Run<?, ?> build) {
+ "'. Did you generate the XML report for Clover?");
}

@Override
public Action getProjectAction(AbstractProject<?,?> project) {
return project instanceof Project ? new CloverProjectAction((Project)project) : null;
}

@Override
public BuildStepDescriptor<Publisher> getDescriptor() {
// see Descriptor javadoc for more about what a descriptor is.

0 comments on commit a58061c

Please sign in to comment.
You can’t perform that action at this time.