Skip to content
Permalink
Browse files

Merge pull request #20 from piomis/JENKINS-34439_no_trend_graph_on_ma…

…in_job_page

[JENKINS-34439] Clover plugin still has problems with pipeline builds
  • Loading branch information...
marek-parfianowicz committed Jun 28, 2017
2 parents 53acf8b + 02b1838 commit 8f4be30f572caa7a5b3fca1fe94e83702ac4829e
@@ -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().
@@ -129,10 +134,21 @@ static CloverBuildAction getPreviousResult(Run<?, ?> start) {
}
}

private List<CloverProjectAction> getActions()
{
if( this.projectActions == null )
{
this.projectActions = new ArrayList<CloverProjectAction>();
}
return this.projectActions;
}

CloverBuildAction(String workspacePath, ProjectCoverage r, CoverageTarget healthyTarget, CoverageTarget unhealthyTarget) {
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 +165,13 @@ static CloverBuildAction getPreviousResult(Run<?, ?> start) {
if (c != null) {
c.setOwner(build);
}

getActions().add(new CloverProjectAction(build.getParent()));
}

@Override public void onLoad(Run<?,?> r) {
owner = r;
getActions().add(new CloverProjectAction(r.getParent()));
}

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

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

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.
@@ -63,6 +63,9 @@ private void checkCloverReports(Run<?, ?> build, Job<?, ?> project) throws Excep
CloverBuildAction cloverBuildAction = build.getAction(CloverBuildAction.class);
assertNotNull("CloverBuildAction should be not Null", cloverBuildAction);

CloverProjectAction cloverProjectAction = project.getAction(CloverProjectAction.class);
assertNotNull("CloverProjectAction should be not Null", cloverProjectAction);

//Access clover reports
JenkinsRule.WebClient wc = j.createWebClient();
wc.getPage(project); // project page

0 comments on commit 8f4be30

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