Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/simplebuildstep'
Browse files Browse the repository at this point in the history
  • Loading branch information
richardmkeeble committed May 10, 2019
2 parents 49b20bd + 595fafa commit 2cee79d
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 53 deletions.
@@ -1,6 +1,6 @@
package com.vectorcast.plugins.vectorcastcoverage;

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

import java.io.IOException;
Expand Down Expand Up @@ -70,7 +70,7 @@ public SELF getPreviousResult() {
}

@Override
public AbstractBuild<?,?> getBuild() {
public Run<?,?> getBuild() {
return parent.getBuild();
}
}
@@ -1,6 +1,6 @@
package com.vectorcast.plugins.vectorcastcoverage;

import hudson.model.AbstractBuild;
import hudson.model.Run;
import hudson.util.IOException2;
import org.apache.commons.digester.Digester;
import org.xml.sax.SAXException;
Expand Down Expand Up @@ -54,7 +54,7 @@ public CoverageReport getPreviousResult() {
}

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

Expand Down
Expand Up @@ -22,6 +22,13 @@
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import jenkins.model.RunAction2;
import jenkins.tasks.SimpleBuildStep.LastBuildAction;
import java.io.Serializable;
import java.util.Collection;
import java.util.Collections;
import hudson.model.Action;
import hudson.model.Run;

/**
* Build view extension by VectorCAST plugin.
Expand All @@ -30,24 +37,24 @@
*
* @author Kohsuke Kawaguchi
*/
public final class VectorCASTBuildAction extends CoverageObject<VectorCASTBuildAction> implements HealthReportingAction, StaplerProxy {
public final class VectorCASTBuildAction extends CoverageObject<VectorCASTBuildAction> implements HealthReportingAction, StaplerProxy, Serializable, RunAction2, LastBuildAction {

public final AbstractBuild<?,?> owner;
public transient Run<?,?> owner;

private transient WeakReference<CoverageReport> report;

private transient VectorCASTProjectAction vectorcastProjectAction;

/**
* Non-null if the coverage has pass/fail rules.
*/
private final Rule rule;

/**
* The thresholds that applied when this build was built.
* @TODO add ability to trend thresholds on the graph
*/
private final VectorCASTHealthReportThresholds thresholds;

public VectorCASTBuildAction(AbstractBuild<?,?> owner, Rule rule, Ratio StatementCoverage, Ratio BranchCoverage, Ratio BasisPathCoverage, Ratio MCDCCoverage, Ratio FunctionCoverage, Ratio FunctionCallCoverage, Ratio Complexity, VectorCASTHealthReportThresholds thresholds) {
public VectorCASTBuildAction(Run<?,?> owner, Rule rule, Ratio StatementCoverage, Ratio BranchCoverage, Ratio BasisPathCoverage, Ratio MCDCCoverage, Ratio FunctionCoverage, Ratio FunctionCallCoverage, Ratio Complexity, VectorCASTHealthReportThresholds thresholds) {
this.owner = owner;
this.rule = rule;
this.Statement = StatementCoverage;
Expand Down Expand Up @@ -158,7 +165,7 @@ public Object getTarget() {
}

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

Expand Down Expand Up @@ -223,8 +230,8 @@ public VectorCASTBuildAction getPreviousResult() {
/**
* Gets the previous {@link VectorCASTBuildAction} of the given build.
*/
/*package*/ static VectorCASTBuildAction getPreviousResult(AbstractBuild<?,?> start) {
AbstractBuild<?,?> b = start;
/*package*/ static VectorCASTBuildAction getPreviousResult(Run<?,?> start) {
Run<?,?> b = start;
while(true) {
b = b.getPreviousBuild();
if(b==null)
Expand Down Expand Up @@ -268,6 +275,24 @@ public static VectorCASTBuildAction load(AbstractBuild<?,?> owner, Rule rule, Ve

return new VectorCASTBuildAction(owner,rule,ratios[0],ratios[1],ratios[2],ratios[3],ratios[4],ratios[5],ratios[6],thresholds);
}

public static VectorCASTBuildAction load(Run<?,?> owner, Rule rule, VectorCASTHealthReportThresholds thresholds, InputStream... streams) throws IOException {
Ratio ratios[] = null;
boolean[] flag = {false};
for (InputStream in: streams) {
try {
ratios = loadRatios(in, ratios, flag);
} catch (XmlPullParserException e) {
throw new IOException2("Failed to parse " + in, e);
} finally {
if (in != null) {
in.close();
}
}
}

return new VectorCASTBuildAction(owner,rule,ratios[0],ratios[1],ratios[2],ratios[3],ratios[4],ratios[5],ratios[6],thresholds);
}

public static VectorCASTBuildAction load(AbstractBuild<?,?> owner, Rule rule, VectorCASTHealthReportThresholds thresholds, InputStream... streams) throws IOException, XmlPullParserException {
Ratio ratios[] = null;
Expand Down Expand Up @@ -361,5 +386,31 @@ else if ( t.equals("complexity, %") )

}

private void setOwner(Run<?, ?> owner) {
logger.log(Level.INFO,"setOwner (create new vectorcastProjectAction)");
vectorcastProjectAction = new VectorCASTProjectAction (owner.getParent());

this.owner = owner;
}

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

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

@Override
public Collection<? extends Action> getProjectActions() {
if (vectorcastProjectAction == null)
{
vectorcastProjectAction = new VectorCASTProjectAction (owner.getParent());
}
return Collections.singletonList(vectorcastProjectAction);
}

private static final Logger logger = Logger.getLogger(VectorCASTBuildAction.class.getName());
}
@@ -1,6 +1,7 @@
package com.vectorcast.plugins.vectorcastcoverage;

import java.io.Serializable;
import org.kohsuke.stapler.DataBoundConstructor;

/**
* Holds the configuration details for {@link hudson.model.HealthReport} generation
Expand All @@ -26,6 +27,7 @@ public class VectorCASTHealthReportThresholds implements Serializable {
public VectorCASTHealthReportThresholds() {
}

@DataBoundConstructor
public VectorCASTHealthReportThresholds(int minStatement, int maxStatement, int minBranch, int maxBranch, int minBasisPath, int maxBasisPath, int minMCDC, int maxMCDC, int minFunction, int maxFunction, int minFunctionCall, int maxFunctionCall) {
this.minStatement = minStatement;
this.maxStatement = maxStatement;
Expand Down
@@ -1,23 +1,23 @@
package com.vectorcast.plugins.vectorcastcoverage;

import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Job;
import hudson.model.Run;
import hudson.model.Action;
import hudson.model.Result;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;

import java.io.IOException;

/**
* Project view extension by VectorCAST plugin.
*
* @author Kohsuke Kawaguchi
*/
public final class VectorCASTProjectAction implements Action {
public final AbstractProject<?,?> project;
public final Job<?,?> project;

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

Expand All @@ -38,7 +38,7 @@ public String getUrlName() {
* @return last build result
*/
public VectorCASTBuildAction getLastResult() {
for( AbstractBuild<?,?> b = project.getLastBuild(); b!=null; b=b.getPreviousBuild()) {
for( Run<?, ?> b = project.getLastBuild(); b!=null; b=b.getPreviousBuild()) {
if(b.getResult()== Result.FAILURE)
continue;
VectorCASTBuildAction r = b.getAction(VectorCASTBuildAction.class);
Expand All @@ -49,7 +49,7 @@ public VectorCASTBuildAction getLastResult() {
}

public void doGraph(StaplerRequest req, StaplerResponse rsp) throws IOException {
if (getLastResult() != null)
getLastResult().doGraph(req,rsp);
if (getLastResult() != null)
getLastResult().doGraph(req,rsp);
}
}

0 comments on commit 2cee79d

Please sign in to comment.