Skip to content

Commit

Permalink
BUGZID: 94318, 94319 - healthReports Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
TimSVector committed Aug 27, 2021
1 parent 8f5fc56 commit 3820181
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 48 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ None

## Change Log

### Version 0.19 (26 Aug 2021)
- Fixed snippet generator
- Fixed health reports for pipeline

### Version 0.18 (10 Aug 2021)
- Use HTTPS URLs in pom.xml
- Bump dashboard-view from 2.1 to 2.16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@

import jenkins.tasks.SimpleBuildStep;
import hudson.model.Job;
import java.util.logging.Logger;
import java.util.logging.Level;
import org.kohsuke.stapler.DataBoundSetter;

/**
* {@link Publisher} that captures VectorCAST coverage reports.
Expand All @@ -49,44 +52,66 @@ public class VectorCASTPublisher extends Recorder implements SimpleBuildStep {
* Relative path to the VectorCAST XML file inside the workspace.
*/
public String includes;
public boolean useThreshold;
public VectorCASTHealthReportThresholds healthyTarget;
public VectorCASTHealthReportThresholds unhealthyTarget;

public Boolean useThreshold;

/**
/**
* Rule to be enforced. Can be null.
*
* TODO: define a configuration mechanism.
*/
public Rule rule;


/**
* {@link hudson.model.HealthReport} thresholds to apply.
*/
public VectorCASTHealthReportThresholds healthReports = new VectorCASTHealthReportThresholds(0, 100, 0, 70, 0, 80, 0, 80, 0, 80, 0, 80 );

public VectorCASTPublisher() {

this.includes = "xml_data/coverage_results*.xml";
this.useThreshold = false;
this.healthyTarget = new VectorCASTHealthReportThresholds();
this.unhealthyTarget = new VectorCASTHealthReportThresholds();
}

public VectorCASTPublisher(String includes, Boolean useThreshold) {

@DataBoundConstructor
public VectorCASTPublisher(String includes, Boolean useThreshold, VectorCASTHealthReportThresholds healthyTarget){
this.includes = includes;
this.useThreshold = useThreshold;
this.healthyTarget = new VectorCASTHealthReportThresholds();
this.unhealthyTarget = new VectorCASTHealthReportThresholds();
this.healthReports = healthyTarget;
}

@Deprecated
public VectorCASTPublisher(String includes, Boolean useThreshold, VectorCASTHealthReportThresholds healthyTarget, VectorCASTHealthReportThresholds unhealthyTarget){
this(includes, useThreshold, healthyTarget);
}

@DataBoundConstructor
public VectorCASTPublisher(String includes, Boolean useThreshold, VectorCASTHealthReportThresholds healthyTarget, VectorCASTHealthReportThresholds unhealthyTarget) {
@Nonnull
public final String getIncludes() {
return includes;
}

@Nonnull
public final Boolean getUseThreshold() {
return useThreshold;
}

@Nonnull
public final VectorCASTHealthReportThresholds getHealthReports() {
return healthReports;
}

@DataBoundSetter public final void setIncludes(String includes) {
this.includes = includes;
}

@DataBoundSetter public final void setUseThreshold(Boolean useThreshold) {
this.useThreshold = useThreshold;
this.healthyTarget = healthyTarget;
this.unhealthyTarget = unhealthyTarget;
}
/**
* {@link hudson.model.HealthReport} thresholds to apply.
*/
public VectorCASTHealthReportThresholds healthReports = new VectorCASTHealthReportThresholds();


@DataBoundSetter public final void setHealthReports(VectorCASTHealthReportThresholds healthReports) {
this.healthReports = healthReports;
}
/**
* look for VectorCAST reports based in the configured parameter includes. 'includes' is - an Ant-style pattern - a list
* of files and folders separated by the characters ;:,
Expand Down Expand Up @@ -229,8 +254,12 @@ public boolean performImpl(Run<?, ?> run, FilePath workspace, TaskListener liste
}

final VectorCASTBuildAction action = VectorCASTBuildAction.load(run, rule, healthReports, streams); //reports);

logger.println("**[VectorCASTCoverage] [INFO]: " + action.getBuildHealth().getDescription());

if (action.getBuildHealth() != null) {
logger.println("**[VectorCASTCoverage] [INFO]: " + action.getBuildHealth().getDescription());
} else {
logger.println("**[VectorCASTCoverage] [INFO]: No thresholds set");
}

run.getActions().add(action);

Expand Down Expand Up @@ -396,35 +425,44 @@ public boolean configure(StaplerRequest req, JSONObject formData) throws FormExc

@Override
public Publisher newInstance(StaplerRequest req, JSONObject json) throws FormException {
VectorCASTPublisher pub = new VectorCASTPublisher();

/*
* Setup for snippet generator
*/
String loc_includes;
Boolean loc_useThreshold;
int maxStatement,maxBranch,maxBasisPath,maxMCDC,maxFunction,maxFunctionCall;
int minStatement,minBranch,minBasisPath,minMCDC,minFunction,minFunctionCall;

/* Get the input from the JSON object */
loc_includes = json.optString("includes", "xml_data/coverage_results*.xml");
if (loc_includes.isEmpty()) {
loc_includes = "xml_data/coverage_results*.xml";
}
loc_useThreshold = json.optBoolean("useThreshold", false);

maxStatement = json.optInt("maxStatement", 100);
maxBranch = json.optInt("maxBranch", 70);
maxBasisPath = json.optInt("maxBasisPath", 80);
maxMCDC = json.optInt("maxMCDC", 80);
maxFunction = json.optInt("maxFunction", 80);
maxFunctionCall = json.optInt("maxFunctionCall", 80);

minStatement = json.optInt("minStatement",0);
minBranch = json.optInt("minBranch",0);
minBasisPath = json.optInt("minBasisPath",0);
minMCDC = json.optInt("minMCDC",0);
minFunction = json.optInt("minFunction",0);
minFunctionCall = json.optInt("minFunctionCall",0);

/* Setup the healthReport */
VectorCASTHealthReportThresholds loc_healthReports = new VectorCASTHealthReportThresholds( minStatement, maxStatement, minBranch, maxBranch, minBasisPath, maxBasisPath, minMCDC, maxMCDC, minFunction, maxFunction, minFunctionCall, maxFunctionCall);

VectorCASTPublisher pub = new VectorCASTPublisher(loc_includes,loc_useThreshold,loc_healthReports);

req.bindParameters(pub, "vectorcastcoverage.");
req.bindParameters(pub.healthReports, "vectorCASTHealthReports.");
// start ugly hack
//@TODO remove ugly hack
// the default converter for integer values used by req.bindParameters
// defaults an empty value to 0. This happens even if the type is Integer
// and not int. We want to change the default values, so we use this hack.
//
// If you know a better way, please fix.
if ("".equals(req.getParameter("vectorCASTHealthReports.maxStatement"))) {
pub.healthReports.setMaxStatement(100);
}
if ("".equals(req.getParameter("vectorCASTHealthReports.maxBranch"))) {
pub.healthReports.setMaxBranch(70);
}
if ("".equals(req.getParameter("vectorCASTHealthReports.maxBasisPath"))) {
pub.healthReports.setMaxBasisPath(80);
}
if ("".equals(req.getParameter("vectorCASTHealthReports.maxMCDC"))) {
pub.healthReports.setMaxMCDC(80);
}
if ("".equals(req.getParameter("vectorCASTHealthReports.maxFunction"))) {
pub.healthReports.setMaxFunction(80);
}
if ("".equals(req.getParameter("vectorCASTHealthReports.maxFunctionCall"))) {
pub.healthReports.setMaxFunctionCall(80);
}

// end ugly hack
return pub;
}
Expand Down

0 comments on commit 3820181

Please sign in to comment.