Skip to content
Permalink
Browse files

JENKINS-36536: Trend graph on pipeline project page

  • Loading branch information...
mheinzerling committed Jul 11, 2016
1 parent c6bf58a commit 4f5fbd90cfde8cec56104868a034ab1a143fa6ab
@@ -5,19 +5,22 @@
import java.io.Serializable;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import hudson.model.Action;
import hudson.model.Run;
import hudson.model.TaskListener;
import jenkins.model.RunAction2;
import jenkins.tasks.SimpleBuildStep.LastBuildAction;
import org.jacoco.core.analysis.IBundleCoverage;
import org.jvnet.localizer.Localizable;
import org.kohsuke.stapler.StaplerProxy;

import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import hudson.model.HealthReport;
import hudson.model.HealthReportingAction;
import hudson.model.Result;
@@ -36,9 +39,9 @@
* @author Jonathan Fuerth
* @author Ognjen Bubalo
*/
public final class JacocoBuildAction extends CoverageObject<JacocoBuildAction> implements HealthReportingAction, StaplerProxy, Serializable, RunAction2 {
public final class JacocoBuildAction extends CoverageObject<JacocoBuildAction> implements HealthReportingAction, StaplerProxy, Serializable, RunAction2, LastBuildAction {

public transient Run<?,?> owner;
private transient Run<?,?> owner;

@Deprecated public transient AbstractBuild<?,?> build;

@@ -53,6 +56,7 @@
* TODO: add ability to trend thresholds on the graph
*/
private final JacocoHealthReportThresholds thresholds;
private transient List<JacocoProjectAction> jacocoProjectActions=Collections.emptyList();

/**
*
@@ -355,13 +359,27 @@ public final PrintStream getLogger() {
return System.out;
}

public Run<?, ?> getOwner() {
return owner;
}

private void setOwner(Run<?, ?> owner) {
jacocoProjectActions = Collections.singletonList(new JacocoProjectAction(owner.getParent()));
this.owner = owner;
}

@Override
public void onAttached(Run<?, ?> run) {
this.owner = run;
setOwner(run);
}

@Override
public void onLoad(Run<?, ?> run) {
this.owner = run;
setOwner(run);
}

@Override
public Collection<? extends Action> getProjectActions() {
return jacocoProjectActions;
}
}
@@ -1,9 +1,11 @@
package hudson.plugins.jacoco;

import hudson.model.Action;
import hudson.model.Job;
import hudson.model.Result;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Run;

import java.io.IOException;

@@ -16,9 +18,9 @@
* @author Kohsuke Kawaguchi
*/
public final class JacocoProjectAction implements Action {
public final AbstractProject<?,?> project;
public final Job<?,?> project;

public JacocoProjectAction(AbstractProject<?,?> project) {
public JacocoProjectAction(Job<?,?> project) {
this.project = project;
}

@@ -38,7 +40,7 @@ public String getUrlName() {
* Gets the most recent {@link JacocoBuildAction} object.
*/
public JacocoBuildAction getLastResult() {
for (AbstractBuild<?, ?> b = project.getLastBuild(); b != null; b = b.getPreviousBuild()) {
for (Run<?, ?> b = project.getLastBuild(); b != null; b = b.getPreviousBuild()) {
if (b.isBuilding() || b.getResult() == Result.FAILURE || b.getResult() == Result.ABORTED)
continue;
JacocoBuildAction r = b.getAction(JacocoBuildAction.class);
@@ -519,11 +519,6 @@ public static Result checkResult(JacocoBuildAction action) {
return Result.SUCCESS;
}

@Override
public Action getProjectAction(AbstractProject<?, ?> project) {
return new JacocoProjectAction(project);
}

public BuildStepMonitor getRequiredMonitorService() {
return BuildStepMonitor.NONE;
}
@@ -533,7 +528,6 @@ public BuildStepMonitor getRequiredMonitorService() {
return DESCRIPTOR;
}


@Extension
public static final BuildStepDescriptor<Publisher> DESCRIPTOR = new DescriptorImpl();

@@ -220,7 +220,7 @@ public CoverageReport getPreviousResult() {

@Override
public Run<?,?> getBuild() {
return action.owner;
return action.getOwner();
}

/**
@@ -7,15 +7,23 @@
import hudson.model.Result;
import hudson.model.Run;
import hudson.model.TaskListener;
import org.easymock.IAnswer;
import org.junit.Before;
import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicReference;

import static org.easymock.EasyMock.*;
import org.easymock.IAnswer;
import org.junit.Before;
import org.junit.Test;

import static org.easymock.EasyMock.anyObject;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.expectLastCall;
import static org.easymock.EasyMock.getCurrentArguments;
import static org.easymock.EasyMock.mock;
import static org.easymock.EasyMock.niceMock;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -89,6 +97,7 @@ public void testPerformWithDefaultSettings() throws IOException, InterruptedExce
final Run run = mock(Run.class);
expect(run.getResult()).andReturn(Result.SUCCESS).anyTimes();
expect(run.getEnvironment(taskListener)).andReturn(new EnvVars()).anyTimes();
expect(run.getParent()).andReturn(null).anyTimes();
Action action = anyObject();
run.addAction(action);
final AtomicReference<JacocoBuildAction> buildAction = new AtomicReference<JacocoBuildAction>();

0 comments on commit 4f5fbd9

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