Skip to content

Commit

Permalink
add advanced settings to plugin:
Browse files Browse the repository at this point in the history
- tests not mandatory (for ratio calculation)
- data item mapping for coverage.xml elements
  • Loading branch information
brandt authored and brandt committed Oct 21, 2015
1 parent 32eb6e5 commit cbbd509
Show file tree
Hide file tree
Showing 22 changed files with 501 additions and 66 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
<configuration>
<source>1.6</source>
<target>1.6</target>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
Expand Down
83 changes: 83 additions & 0 deletions src/main/java/hudson/plugins/emma/AbstractReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,87 @@ public SELF getPreviousResult() {
public AbstractBuild<?,?> getBuild() {
return parent.getBuild();
}

////////////////////////////////////////////////////////////////////////////////
//[KB] default interface implementation for the advanced setup support

// @Override
public boolean getTestNotMandatory(){
boolean ret_val = false;
PARENT p = getParent();

if(p != null){
ret_val = p.getTestNotMandatory();
}

return ret_val;
}

@Override
public String getFirstDataColumnDescriptor()
{
String ret_val = "";
PARENT p = getParent();

if(p != null){
ret_val = p.getFirstDataColumnDescriptor();
}

return ret_val;
}

@Override
public String getSecondDataColumnDescriptor()
{
String ret_val = "";
PARENT p = getParent();

if(p != null){
ret_val = p.getSecondDataColumnDescriptor();
}

return ret_val;
}

@Override
public String getThirdDataColumnDescriptor()
{
String ret_val = "";
PARENT p = getParent();

if(p != null){
ret_val = p.getThirdDataColumnDescriptor();
}

return ret_val;
}

@Override
public String getFourthDataColumnDescriptor()
{
String ret_val = "";
PARENT p = getParent();

if(p != null){
ret_val = p.getFourthDataColumnDescriptor();
}

return ret_val;
}

@Override
public String getFifthDataColumnDescriptor()
{
String ret_val = "";
PARENT p = getParent();

if(p != null){
ret_val = p.getFifthDataColumnDescriptor();
}

return ret_val;
}
//
////////////////////////////////////////////////////////////////////////////////

}
102 changes: 102 additions & 0 deletions src/main/java/hudson/plugins/emma/AdvancedSettings.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@

package hudson.plugins.emma;

import java.io.Serializable;

////////////////////////////////////////////////////////////////////////////////
//[KB] implementation for the advanced setup support
public class AdvancedSettings implements Serializable {

private boolean testNotMandatory = false;

private String firstDataColumnDescriptor = "";
private String secondDataColumnDescriptor = "";
private String thirdDataColumnDescriptor = "";
private String fourthDataColumnDescriptor = "";
private String fifthDataColumnDescriptor = "";


private String getValue(String value, String defaultValue){

if ((value == null)||("".equals(value)))
{
value = defaultValue;
}
return value;
}


public void setTestNotMandatory(boolean state){

testNotMandatory = state;
}

public boolean getTestNotMandatory(){

return testNotMandatory;
}

public String getFirstDataColumnDescriptor() {

return getValue(firstDataColumnDescriptor, Messages.CoverageObject_Legend_Class());
}

public void setFirstDataColumnDescriptor(String name) {

firstDataColumnDescriptor = name;
}

public String getSecondDataColumnDescriptor() {

return getValue(secondDataColumnDescriptor, Messages.CoverageObject_Legend_Block());
}

public void setSecondDataColumnDescriptor(String name) {

secondDataColumnDescriptor = name;
}

public String getThirdDataColumnDescriptor() {

return getValue(thirdDataColumnDescriptor, Messages.CoverageObject_Legend_Method());
}

public void setThirdDataColumnDescriptor(String name) {

thirdDataColumnDescriptor = name;
}

public String getFourthDataColumnDescriptor() {

return getValue(fourthDataColumnDescriptor, Messages.CoverageObject_Legend_Line());
}

public void setFourthDataColumnDescriptor(String name) {

fourthDataColumnDescriptor = name;
}

public String getFifthDataColumnDescriptor() {

return getValue(fifthDataColumnDescriptor, Messages.CoverageObject_Legend_Condition());
}

public void setFifthDataColumnDescriptor(String name) {

fifthDataColumnDescriptor = name;
}

public void applySettings(AdvancedSettings settings){

if(settings != null){
setTestNotMandatory(settings.getTestNotMandatory());
setFirstDataColumnDescriptor(settings.getFirstDataColumnDescriptor());
setSecondDataColumnDescriptor(settings.getSecondDataColumnDescriptor());
setThirdDataColumnDescriptor(settings.getThirdDataColumnDescriptor());
setFourthDataColumnDescriptor(settings.getFourthDataColumnDescriptor());
setFifthDataColumnDescriptor(settings.getFifthDataColumnDescriptor());
}
}
}
//
////////////////////////////////////////////////////////////////////////////////
42 changes: 23 additions & 19 deletions src/main/java/hudson/plugins/emma/CoverageObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* @author Kohsuke Kawaguchi
*/
@ExportedBean
public abstract class CoverageObject<SELF extends CoverageObject<SELF>> {
public abstract class CoverageObject<SELF extends CoverageObject<SELF>> extends AdvancedSettings {

Ratio clazz = new Ratio();
Ratio method = new Ratio();
Expand Down Expand Up @@ -113,11 +113,11 @@ public Ratio getConditionCoverage() {
*/
public String printFourCoverageColumns() {
StringBuilder buf = new StringBuilder();
printRatioCell(isFailed(), clazz, buf);
printRatioCell(isFailed(), method, buf);
printRatioCell(isFailed(), block, buf);
printRatioCell(isFailed(), line, buf);
printRatioCell(isFailed(), condition, buf);
printRatioCell(isFailed(), clazz, buf, getTestNotMandatory());
printRatioCell(isFailed(), method, buf, getTestNotMandatory());
printRatioCell(isFailed(), block, buf, getTestNotMandatory());
printRatioCell(isFailed(), line, buf, getTestNotMandatory());
printRatioCell(isFailed(), condition, buf, getTestNotMandatory());
return buf.toString();
}

Expand All @@ -138,26 +138,26 @@ public boolean hasClassCoverage() {
static NumberFormat percentFormat = new DecimalFormat("0.0");
static NumberFormat intFormat = new DecimalFormat("0");

protected static void printRatioCell(boolean failed, Ratio ratio, StringBuilder buf) {
if (ratio != null && ratio.isInitialized()) {
protected static void printRatioCell(boolean failed, Ratio ratio, StringBuilder buf, boolean no_tests_required) {
if (ratio != null && ratio.isInitialized()) {
String className = "nowrap" + (failed ? " red" : "");
buf.append("<td class='").append(className).append("'");
buf.append(" data='").append(dataFormat.format(ratio.getPercentageFloat()));
buf.append(" data='").append(dataFormat.format(ratio.getPercentageFloat(no_tests_required)));
buf.append("'>\n");
printRatioTable(ratio, buf);
printRatioTable(ratio, buf, no_tests_required);
buf.append("</td>\n");
}
}

protected static void printRatioTable(Ratio ratio, StringBuilder buf){
String data = dataFormat.format(ratio.getPercentageFloat());
String percent = percentFormat.format(ratio.getPercentageFloat());
protected static void printRatioTable(Ratio ratio, StringBuilder buf, boolean no_tests_required){
String data = dataFormat.format(ratio.getPercentageFloat(no_tests_required));
String percent = percentFormat.format(ratio.getPercentageFloat(no_tests_required));
String numerator = intFormat.format(ratio.getNumerator());
String denominator = intFormat.format(ratio.getDenominator());
buf.append("<table class='percentgraph' cellpadding='0px' cellspacing='0px'><tr class='percentgraph'>")
.append("<td width='64px' class='data'>").append(percent).append("%</td>")
.append("<td class='percentgraph'>")
.append("<div class='percentgraph'><div class='greenbar' style='width: ").append(ratio.getPercentageFloat()).append("px;'>")
.append("<div class='percentgraph'><div class='greenbar' style='width: ").append(ratio.getPercentageFloat(no_tests_required)).append("px;'>")
.append("<span class='text'>").append(numerator).append("/").append(denominator)
.append("</span></div></div></td></tr></table>") ;
}
Expand Down Expand Up @@ -188,14 +188,18 @@ protected DataSetBuilder<String, NumberOnlyBuildLabel> createDataSet(CoverageObj

for (CoverageObject<SELF> a = obj; a != null; a = a.getPreviousResult()) {
NumberOnlyBuildLabel label = new NumberOnlyBuildLabel(a.getBuild());
dsb.add(a.clazz.getPercentageFloat(), Messages.CoverageObject_Legend_Class(), label);
dsb.add(a.block.getPercentageFloat(), Messages.CoverageObject_Legend_Block(), label);
dsb.add(a.method.getPercentageFloat(), Messages.CoverageObject_Legend_Method(), label);
dsb.add(a.clazz.getPercentageFloat(getTestNotMandatory()), a.getFirstDataColumnDescriptor(), label);
dsb.add(a.method.getPercentageFloat(getTestNotMandatory()), a.getSecondDataColumnDescriptor(), label);
dsb.add(a.block.getPercentageFloat(getTestNotMandatory()), a.getThirdDataColumnDescriptor(), label);
if (a.line != null) {
dsb.add(a.line.getPercentageFloat(), Messages.CoverageObject_Legend_Line(), label);
if (a.hasLineCoverage()){
dsb.add(a.line.getPercentageFloat(getTestNotMandatory()), a.getFourthDataColumnDescriptor(), label);
}
}
if (a.condition != null) {
dsb.add(a.condition.getPercentageFloat(), Messages.CoverageObject_Legend_Condition(), label);
if (a.hasConditionCoverage()){
dsb.add(a.condition.getPercentageFloat(getTestNotMandatory()), a.getFifthDataColumnDescriptor(), label);
}
}
}

Expand Down
50 changes: 50 additions & 0 deletions src/main/java/hudson/plugins/emma/CoverageReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,54 @@ private Digester createDigester() {
//digester.addBeanPropertySetter("*/status","statusMessage");
return digester;
}

////////////////////////////////////////////////////////////////////////////////
//[KB] overridden interface implementation for the advanced setup support
//
// root object for reporting
// -> get config data from action object
// -> read from build.xml???

// @Override
public boolean getTestNotMandatory(){
return action.getTestNotMandatory();
}

// @Override
public String getFirstDataColumnDescriptor()
{
//return getLastAction().getFirstDataColumnDescriptor();
return action.getFirstDataColumnDescriptor();
}

// @Override
public String getSecondDataColumnDescriptor()
{
//return getLastAction().getFirstDataColumnDescriptor();
return action.getSecondDataColumnDescriptor();
}

// @Override
public String getThirdDataColumnDescriptor()
{
//return getLastAction().getFirstDataColumnDescriptor();
return action.getThirdDataColumnDescriptor();
}

// @Override
public String getFourthDataColumnDescriptor()
{
//return getLastAction().getFirstDataColumnDescriptor();
return action.getFourthDataColumnDescriptor();
}

// @Override
public String getFifthDataColumnDescriptor()
{
//return getLastAction().getFirstDataColumnDescriptor();
return action.getFifthDataColumnDescriptor();
}
//
////////////////////////////////////////////////////////////////////////////////

}
10 changes: 5 additions & 5 deletions src/main/java/hudson/plugins/emma/EmmaBuildAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,39 +85,39 @@ public HealthReport getBuildHealth() {
int score = 100, percent;
ArrayList<Localizable> reports = new ArrayList<Localizable>(5);
if (clazz != null && thresholds.getMaxClass() > 0) {
percent = clazz.getPercentage();
percent = clazz.getPercentage(getTestNotMandatory());
if (percent < thresholds.getMaxClass()) {
reports.add(Messages._BuildAction_Classes(clazz, percent));
}
score = updateHealthScore(score, thresholds.getMinClass(),
percent, thresholds.getMaxClass());
}
if (method != null && thresholds.getMaxMethod() > 0) {
percent = method.getPercentage();
percent = method.getPercentage(getTestNotMandatory());
if (percent < thresholds.getMaxMethod()) {
reports.add(Messages._BuildAction_Methods(method, percent));
}
score = updateHealthScore(score, thresholds.getMinMethod(),
percent, thresholds.getMaxMethod());
}
if (block != null && thresholds.getMaxBlock() > 0) {
percent = block.getPercentage();
percent = block.getPercentage(getTestNotMandatory());
if (percent < thresholds.getMaxBlock()) {
reports.add(Messages._BuildAction_Blocks(block, percent));
}
score = updateHealthScore(score, thresholds.getMinBlock(),
percent, thresholds.getMaxBlock());
}
if (line != null && thresholds.getMaxLine() > 0) {
percent = line.getPercentage();
percent = line.getPercentage(getTestNotMandatory());
if (percent < thresholds.getMaxLine()) {
reports.add(Messages._BuildAction_Lines(line, percent));
}
score = updateHealthScore(score, thresholds.getMinLine(),
percent, thresholds.getMaxLine());
}
if (condition != null && thresholds.getMaxCondition() > 0) {
percent = condition.getPercentage();
percent = condition.getPercentage(getTestNotMandatory());
if (percent < thresholds.getMaxCondition()) {
reports.add(Messages._BuildAction_Conditions(condition, percent));
}
Expand Down
Loading

0 comments on commit cbbd509

Please sign in to comment.