Skip to content

Commit

Permalink
JENKINS-30700 / jenkinsci#50 Jenkins pipeline support
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarrien committed Jun 9, 2016
1 parent 270872b commit bdef7de
Show file tree
Hide file tree
Showing 15 changed files with 142 additions and 142 deletions.
33 changes: 20 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.480.3</version>
<version>1.609.2</version>
</parent>

<artifactId>cobertura</artifactId>
Expand All @@ -15,6 +15,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<workflow-jenkins-plugin.version>1.11</workflow-jenkins-plugin.version>
</properties>

<scm>
Expand Down Expand Up @@ -43,18 +44,6 @@
</developers>

<dependencies>
<dependency>
<groupId>org.jenkins-ci.main</groupId>
<artifactId>maven-plugin</artifactId>
<scope>compile</scope>
<!-- Exclude a dependency that conflicts with easymock dependencies -->
<exclusions>
<exclusion>
<groupId>org.sonatype.sisu.inject</groupId>
<artifactId>cglib</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymockclassextension</artifactId>
Expand Down Expand Up @@ -85,6 +74,24 @@
<version>4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-job</artifactId>
<version>${workflow-jenkins-plugin.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-cps</artifactId>
<version>${workflow-jenkins-plugin.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-basic-steps</artifactId>
<version>${workflow-jenkins-plugin.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/hudson/plugins/cobertura/BuildUtils.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package hudson.plugins.cobertura;

import hudson.model.AbstractBuild;
import hudson.model.Run;

public class BuildUtils {
public static AbstractBuild<?, ?> getPreviousNotFailedCompletedBuild(AbstractBuild<?, ?> b) {
public static Run<?, ?> getPreviousNotFailedCompletedBuild(Run<?, ?> b) {
while (true) {
b = b.getPreviousNotFailedBuild();
if (b == null) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/hudson/plugins/cobertura/Chartable.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package hudson.plugins.cobertura;

import hudson.model.AbstractBuild;
import hudson.model.Run;
import hudson.plugins.cobertura.targets.CoverageMetric;

import java.util.Map;
Expand All @@ -12,6 +12,6 @@ public interface Chartable

Map<CoverageMetric, Ratio> getResults();

AbstractBuild< ? , ? > getOwner();
Run<?, ?> getOwner();

}
71 changes: 47 additions & 24 deletions src/main/java/hudson/plugins/cobertura/CoberturaBuildAction.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
package hudson.plugins.cobertura;

import hudson.model.Action;
import hudson.model.HealthReport;
import hudson.model.HealthReportingAction;
import hudson.model.Result;
import hudson.model.AbstractBuild;
import hudson.model.Run;
import hudson.plugins.cobertura.targets.CoverageMetric;
import hudson.plugins.cobertura.targets.CoverageTarget;
import hudson.plugins.cobertura.targets.CoverageResult;
import hudson.util.ChartUtil;
import hudson.util.DescribableList;
import jenkins.model.RunAction2;
import jenkins.tasks.SimpleBuildStep;

import java.io.File;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumMap;
import java.util.Map;
import java.util.logging.Level;
Expand All @@ -31,15 +36,17 @@
* @author connollys
* @since 03-Jul-2007 08:43:08
*/
public class CoberturaBuildAction implements HealthReportingAction, StaplerProxy, Chartable {
public class CoberturaBuildAction implements HealthReportingAction, StaplerProxy, Chartable, SimpleBuildStep.LastBuildAction, RunAction2 {

private final AbstractBuild<?, ?> owner;
private Run<?, ?> owner;
private CoverageTarget healthyTarget;
private CoverageTarget unhealthyTarget;
private boolean failUnhealthy;
private boolean failUnstable;
private boolean autoUpdateHealth;
private boolean autoUpdateStability;
private boolean zoomCoverageChart;
private int maxNumberOfBuilds;
/**
* Overall coverage result.
*/
Expand All @@ -56,17 +63,6 @@ public HealthReport getBuildHealth() {
if (health != null) {
return health;
}
//try to get targets from root project (for maven modules targets are null)
DescribableList rootpublishers = owner.getProject().getRootProject().getPublishersList();

if (rootpublishers != null) {
CoberturaPublisher publisher = (CoberturaPublisher) rootpublishers.get(CoberturaPublisher.class);
if (publisher != null) {
healthyTarget = publisher.getHealthyTarget();
unhealthyTarget = publisher.getUnhealthyTarget();
}
}

if (healthyTarget == null || unhealthyTarget == null) {
return null;
}
Expand Down Expand Up @@ -135,7 +131,7 @@ public Object getTarget() {
return getResult(); //To change body of implemented methods use File | Settings | File Templates.
}

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

Expand All @@ -156,8 +152,8 @@ public CoberturaBuildAction getPreviousResult() {
* Gets the previous {@link CoberturaBuildAction} of the given build.
*/
/*package*/
static CoberturaBuildAction getPreviousResult(AbstractBuild<?, ?> start) {
AbstractBuild<?, ?> b = start;
static CoberturaBuildAction getPreviousResult(Run<?, ?> start) {
Run<?, ?> b = start;
while (true) {
b = BuildUtils.getPreviousNotFailedCompletedBuild(b);
if (b == null) {
Expand All @@ -178,9 +174,10 @@ private boolean includeOnlyStable() {
return onlyStable;
}

CoberturaBuildAction(AbstractBuild<?, ?> owner, CoverageResult r, CoverageTarget healthyTarget,
CoverageTarget unhealthyTarget, boolean onlyStable, boolean failUnhealthy, boolean failUnstable, boolean autoUpdateHealth, boolean autoUpdateStability) {
this.owner = owner;
CoberturaBuildAction(CoverageResult r, CoverageTarget healthyTarget,
CoverageTarget unhealthyTarget, boolean onlyStable, boolean failUnhealthy,
boolean failUnstable, boolean autoUpdateHealth, boolean autoUpdateStability,
boolean zoomCoverageChart, int maxNumberOfBuilds) {
this.report = new WeakReference<CoverageResult>(r);
this.healthyTarget = healthyTarget;
this.unhealthyTarget = unhealthyTarget;
Expand All @@ -189,7 +186,8 @@ private boolean includeOnlyStable() {
this.failUnstable = failUnstable;
this.autoUpdateHealth = autoUpdateHealth;
this.autoUpdateStability = autoUpdateStability;
r.setOwner(owner);
this.zoomCoverageChart = zoomCoverageChart;
this.maxNumberOfBuilds = maxNumberOfBuilds;
if (result == null) {
result = new EnumMap<CoverageMetric, Ratio>(CoverageMetric.class);
result.putAll(r.getResults());
Expand Down Expand Up @@ -227,9 +225,11 @@ public synchronized CoverageResult getResult() {
}
private static final Logger logger = Logger.getLogger(CoberturaBuildAction.class.getName());

public static CoberturaBuildAction load(AbstractBuild<?, ?> build, CoverageResult result, CoverageTarget healthyTarget,
CoverageTarget unhealthyTarget, boolean onlyStable, boolean failUnhealthy, boolean failUnstable, boolean autoUpdateHealth, boolean autoUpdateStability) {
return new CoberturaBuildAction(build, result, healthyTarget, unhealthyTarget, onlyStable, failUnhealthy, failUnstable, autoUpdateHealth, autoUpdateStability);
public static CoberturaBuildAction load(CoverageResult result, CoverageTarget healthyTarget,
CoverageTarget unhealthyTarget, boolean onlyStable, boolean failUnhealthy, boolean failUnstable,
boolean autoUpdateHealth, boolean autoUpdateStability, boolean zoomCoverageChart, int maxNumberOfBuilds) {
return new CoberturaBuildAction(result, healthyTarget, unhealthyTarget, onlyStable,
failUnhealthy, failUnstable, autoUpdateHealth, autoUpdateStability, zoomCoverageChart, maxNumberOfBuilds);
}

/**
Expand All @@ -250,4 +250,27 @@ public void doGraph(StaplerRequest req, StaplerResponse rsp) throws IOException
JFreeChart chart = new CoverageChart(this).createChart();
ChartUtil.generateGraph(req, rsp, chart, 500, 200);
}

public boolean getZoomCoverageChart() {
return zoomCoverageChart;
}

public int getMaxNumberOfBuilds() {
return maxNumberOfBuilds;
}

@Override
public Collection<? extends Action> getProjectActions() {
return Collections.singleton(new CoberturaProjectAction(owner, onlyStable));
}

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

@Override
public void onLoad(Run<?,?> r) {
this.owner = r;
}
}
33 changes: 14 additions & 19 deletions src/main/java/hudson/plugins/cobertura/CoberturaProjectAction.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package hudson.plugins.cobertura;

import hudson.model.*;
import hudson.model.Actionable;
import hudson.model.Job;
import hudson.model.ProminentProjectAction;
import hudson.model.Result;
import hudson.model.Run;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;

Expand All @@ -13,25 +17,16 @@
*/
public class CoberturaProjectAction extends Actionable implements ProminentProjectAction {

private final AbstractProject<?, ?> project;
private final Run<?, ?> run;
private boolean onlyStable;

public CoberturaProjectAction(AbstractProject<?, ?> project, boolean onlyStable) {
this.project = project;
public CoberturaProjectAction(Run<?, ?> run, boolean onlyStable) {
this.run = run;
this.onlyStable = onlyStable;
}

public CoberturaProjectAction(AbstractProject<?, ?> project) {
this.project = project;

CoberturaPublisher cp = (CoberturaPublisher) project.getPublishersList().get(CoberturaPublisher.DESCRIPTOR);
if (cp != null) {
onlyStable = cp.getOnlyStable();
}
}

public AbstractProject<?, ?> getProject() {
return project;
public CoberturaProjectAction(Run<?, ?> run) {
this(run, false);
}

/**
Expand Down Expand Up @@ -61,7 +56,7 @@ public String getUrlName() {
* @return Value for property 'lastResult'.
*/
public CoberturaBuildAction getLastResult() {
for (AbstractBuild<?, ?> b = getLastBuildToBeConsidered(); b != null; b = BuildUtils.getPreviousNotFailedCompletedBuild(b)) {
for (Run<?, ?> b = getLastBuildToBeConsidered(); b != null; b = BuildUtils.getPreviousNotFailedCompletedBuild(b)) {
if (b.getResult() == Result.FAILURE || (b.getResult() != Result.SUCCESS && onlyStable))
continue;
CoberturaBuildAction r = b.getAction(CoberturaBuildAction.class);
Expand All @@ -70,16 +65,16 @@ public CoberturaBuildAction getLastResult() {
}
return null;
}
private AbstractBuild<?, ?> getLastBuildToBeConsidered(){
return onlyStable ? project.getLastStableBuild() : project.getLastSuccessfulBuild();
private Run<?, ?> getLastBuildToBeConsidered(){
return onlyStable ? run.getParent().getLastStableBuild() : run.getParent().getLastSuccessfulBuild();
}
/**
* Getter for property 'lastResult'.
*
* @return Value for property 'lastResult'.
*/
public Integer getLastResultBuild() {
for (AbstractBuild<?, ?> b = getLastBuildToBeConsidered(); b != null; b = BuildUtils.getPreviousNotFailedCompletedBuild(b)) {
for (Run<?, ?> b = getLastBuildToBeConsidered(); b != null; b = BuildUtils.getPreviousNotFailedCompletedBuild(b)) {
if (b.getResult() == Result.FAILURE || (b.getResult() != Result.SUCCESS && onlyStable))
continue;
CoberturaBuildAction r = b.getAction(CoberturaBuildAction.class);
Expand Down
Loading

0 comments on commit bdef7de

Please sign in to comment.