Skip to content
This repository has been archived by the owner on Jun 13, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-6446] Added global configurations for all the six type…
…s of unittest changes (increase or descrease of passed, failed and skipped tests). The configuration is available under 'Continuous integration game - Unit Tests' section in advanced mode. Default values are set to 1 for increasing passing tests, -1 for increasing failed tests and 0 for all other 4 scenarios
  • Loading branch information
lkamal committed Oct 24, 2013
1 parent e796a32 commit 626af1c
Show file tree
Hide file tree
Showing 19 changed files with 303 additions and 91 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.498</version>
<version>1.499</version>
</parent>

<artifactId>ci-game</artifactId>
Expand Down
74 changes: 73 additions & 1 deletion src/main/java/hudson/plugins/cigame/GameDescriptor.java
Expand Up @@ -19,6 +19,7 @@
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.Publisher;

// Config page for the application (descriptor of the game plugin)
@Extension
public class GameDescriptor extends BuildStepDescriptor<Publisher> {

Expand All @@ -27,6 +28,13 @@ public class GameDescriptor extends BuildStepDescriptor<Publisher> {

private transient RuleBook rulebook;
private boolean namesAreCaseSensitive = true;

private int passedTestIncreasingPoints = 1;
private int passedTestDecreasingPoints = 0;
private int failedTestIncreasingPoints = -1;
private int failedTestDecreasingPoints = 0;
private int skippedTestIncreasingPoints = 0;
private int skippedTestDecreasingPoints = 0;

public GameDescriptor() {
super(GamePublisher.class);
Expand Down Expand Up @@ -60,24 +68,27 @@ private void addRuleSetIfAvailable(RuleBook book, RuleSet ruleSet) {
}
}

// config page heading
@Override
public String getDisplayName() {
return Messages.Plugin_Title();
}

// creates a instance with form data; but this only creates empty new object
@Override
public GamePublisher newInstance(StaplerRequest req, JSONObject formData)
throws hudson.model.Descriptor.FormException {
return new GamePublisher();
}

// invoked when even properties are updated (global properties configured with global.jelly
@Override
public boolean configure(StaplerRequest req, JSONObject json) throws FormException {
req.bindJSON(this, json);
save();
return true;
}

public boolean getNamesAreCaseSensitive() {
return namesAreCaseSensitive;
}
Expand All @@ -90,4 +101,65 @@ public void setNamesAreCaseSensitive(boolean namesAreCaseSensitive) {
public boolean isApplicable(Class<? extends AbstractProject> arg0) {
return true;
}


public int getPassedTestIncreasingPoints() {
return passedTestIncreasingPoints;
}


public void setPassedTestIncreasingPoints(int passedTestIncreasingPoints) {
this.passedTestIncreasingPoints = passedTestIncreasingPoints;
}


public int getPassedTestDecreasingPoints() {
return passedTestDecreasingPoints;
}


public void setPassedTestDecreasingPoints(int passedTestDecreasingPoints) {
this.passedTestDecreasingPoints = passedTestDecreasingPoints;
}


public int getFailedTestIncreasingPoints() {
return failedTestIncreasingPoints;
}


public void setFailedTestIncreasingPoints(int failedTestIncreasingPoints) {
this.failedTestIncreasingPoints = failedTestIncreasingPoints;
}


public int getFailedTestDecreasingPoints() {
return failedTestDecreasingPoints;
}


public void setFailedTestDecreasingPoints(int failedTestDecreasingPoints) {
this.failedTestDecreasingPoints = failedTestDecreasingPoints;
}


public int getSkippedTestIncreasingPoints() {
return skippedTestIncreasingPoints;
}


public void setSkippedTestIncreasingPoints(int skippedTestIncreasingPoints) {
this.skippedTestIncreasingPoints = skippedTestIncreasingPoints;
}


public int getSkippedTestDecreasingPoints() {
return skippedTestDecreasingPoints;
}


public void setSkippedTestDecreasingPoints(int skippedTestDecreasingPoints) {
this.skippedTestDecreasingPoints = skippedTestDecreasingPoints;
}

}
@@ -1,23 +1,22 @@
package hudson.plugins.cigame.rules.unittesting;

import jenkins.model.Jenkins;
import hudson.plugins.cigame.GameDescriptor;
import hudson.plugins.cigame.model.RuleResult;

/**
* Rule that gives points for decreasing the number of failed tests. By default 1 mark given.
* Rule that gives points for decreasing the number of failed tests. By default 0 mark given.
*
* @author <a href="www.digizol.com">Kamal Mettananda</a>
* @since 1.20
*/
public class DecreasingFailedTestsRule extends AbstractFailedTestsRule {

private int pointsForDecreasingOneFailedTest;
private static final int DEFAULT_POINTS = 0;

public DecreasingFailedTestsRule() {
this(1);
}

public DecreasingFailedTestsRule(int points) {
pointsForDecreasingOneFailedTest = points;
private int getPoints() {
GameDescriptor gameDescriptor = Jenkins.getInstance().getDescriptorByType(GameDescriptor.class);
return gameDescriptor!=null?gameDescriptor.getFailedTestDecreasingPoints():DEFAULT_POINTS;
}

public String getName() {
Expand All @@ -33,7 +32,7 @@ protected String getResultDescription(Integer testDiff) {
protected RuleResult<Integer> evaluate(int failedTestDiff) {
if (failedTestDiff < 0) {
failedTestDiff = -failedTestDiff;
return new RuleResult<Integer>(failedTestDiff * pointsForDecreasingOneFailedTest,
return new RuleResult<Integer>(failedTestDiff * getPoints(),
Messages.UnitTestingRuleSet_DecreasingFailedRule_Count(failedTestDiff),
failedTestDiff);
}
Expand Down
@@ -1,5 +1,7 @@
package hudson.plugins.cigame.rules.unittesting;

import jenkins.model.Jenkins;
import hudson.plugins.cigame.GameDescriptor;
import hudson.plugins.cigame.model.RuleResult;

/**
Expand All @@ -10,16 +12,13 @@
*/
public class DecreasingPassedTestsRule extends AbstractPassedTestsRule {

private int pointsForDecreasingOnePassingTest;
private static final int DEFAULT_POINTS = 1;

public DecreasingPassedTestsRule() {
this(-1);
private int getPoints() {
GameDescriptor gameDescriptor = Jenkins.getInstance().getDescriptorByType(GameDescriptor.class);
return gameDescriptor!=null?gameDescriptor.getPassedTestDecreasingPoints():DEFAULT_POINTS;
}

public DecreasingPassedTestsRule(int points) {
pointsForDecreasingOnePassingTest = points;
}


public String getName() {
return Messages.UnitTestingRuleSet_DecreasingPassedRule_Name();
}
Expand All @@ -33,7 +32,7 @@ protected String getResultDescription(Integer testDiff) {
protected RuleResult<Integer> evaluate(int passedTestDiff) {
if (passedTestDiff < 0) {
passedTestDiff = -passedTestDiff;
return new RuleResult<Integer>(passedTestDiff * pointsForDecreasingOnePassingTest,
return new RuleResult<Integer>(passedTestDiff * getPoints(),
Messages.UnitTestingRuleSet_DecreasingPassedRule_Count(passedTestDiff),
passedTestDiff);
}
Expand Down
@@ -1,5 +1,7 @@
package hudson.plugins.cigame.rules.unittesting;

import jenkins.model.Jenkins;
import hudson.plugins.cigame.GameDescriptor;
import hudson.plugins.cigame.model.RuleResult;

/**
Expand All @@ -10,16 +12,13 @@
*/
public class DecreasingSkippedTestsRule extends AbstractSkippedTestsRule {

private int pointsForDecreasingOneSkippedTest;
private static final int DEFAULT_POINTS = 0;

public DecreasingSkippedTestsRule() {
this(0);
private int getPoints() {
GameDescriptor gameDescriptor = Jenkins.getInstance().getDescriptorByType(GameDescriptor.class);
return gameDescriptor!=null?gameDescriptor.getSkippedTestDecreasingPoints():DEFAULT_POINTS;
}

public DecreasingSkippedTestsRule(int points) {
pointsForDecreasingOneSkippedTest = points;
}


public String getName() {
return Messages.UnitTestingRuleSet_DecreasingSkippedRule_Name();
}
Expand All @@ -33,7 +32,7 @@ protected String getResultDescription(Integer testDiff) {
protected RuleResult<Integer> evaluate(int skippedTestDiff) {
if (skippedTestDiff < 0) {
skippedTestDiff = -skippedTestDiff;
return new RuleResult<Integer>(skippedTestDiff * pointsForDecreasingOneSkippedTest,
return new RuleResult<Integer>(skippedTestDiff * getPoints(),
Messages.UnitTestingRuleSet_DecreasingSkippedRule_Count(skippedTestDiff),
skippedTestDiff);
}
Expand Down
@@ -1,5 +1,7 @@
package hudson.plugins.cigame.rules.unittesting;

import jenkins.model.Jenkins;
import hudson.plugins.cigame.GameDescriptor;
import hudson.plugins.cigame.model.RuleResult;

/**
Expand All @@ -11,16 +13,13 @@
*/
public class IncreasingFailedTestsRule extends AbstractFailedTestsRule {

private int pointsForIncreasingOneFailedTest;
private static final int DEFAULT_POINTS = -1;

public IncreasingFailedTestsRule() {
this(-1);
private int getPoints() {
GameDescriptor gameDescriptor = Jenkins.getInstance().getDescriptorByType(GameDescriptor.class);
return gameDescriptor!=null?gameDescriptor.getFailedTestIncreasingPoints():DEFAULT_POINTS;
}

public IncreasingFailedTestsRule(int points) {
pointsForIncreasingOneFailedTest = points;
}


public String getName() {
return Messages.UnitTestingRuleSet_IncreasingFailedRule_Name();
}
Expand All @@ -33,7 +32,7 @@ protected String getResultDescription(Integer testDiff) {
@Override
protected RuleResult<Integer> evaluate(int failingTestDiff) {
if (failingTestDiff > 0) {
return new RuleResult<Integer>(failingTestDiff * pointsForIncreasingOneFailedTest,
return new RuleResult<Integer>(failingTestDiff * getPoints(),
Messages.UnitTestingRuleSet_IncreasingFailedRule_Count(failingTestDiff),
failingTestDiff);
}
Expand Down
@@ -1,6 +1,8 @@
package hudson.plugins.cigame.rules.unittesting;

import hudson.plugins.cigame.GameDescriptor;
import hudson.plugins.cigame.model.RuleResult;
import jenkins.model.Jenkins;

/**
* Rule that gives points for increasing the number of passed tests. By default 1 mark given.
Expand All @@ -11,16 +13,13 @@
*/
public class IncreasingPassedTestsRule extends AbstractPassedTestsRule {

private int pointsForIncreasingOnePassingTest;
private static final int DEFAULT_POINTS = 1;

public IncreasingPassedTestsRule() {
this(1);
private int getPoints() {
GameDescriptor gameDescriptor = Jenkins.getInstance().getDescriptorByType(GameDescriptor.class);
return gameDescriptor!=null?gameDescriptor.getPassedTestIncreasingPoints():DEFAULT_POINTS;
}

public IncreasingPassedTestsRule(int points) {
pointsForIncreasingOnePassingTest = points;
}


public String getName() {
return Messages.UnitTestingRuleSet_IncreasingPassedRule_Name();
}
Expand All @@ -33,7 +32,7 @@ protected String getResultDescription(Integer testDiff) {
@Override
protected RuleResult<Integer> evaluate(int passedTestDiff) {
if (passedTestDiff > 0) {
return new RuleResult<Integer>(passedTestDiff * pointsForIncreasingOnePassingTest,
return new RuleResult<Integer>(passedTestDiff * getPoints(),
Messages.UnitTestingRuleSet_IncreasingPassedRule_Count(passedTestDiff),
passedTestDiff);
}
Expand Down
@@ -1,5 +1,7 @@
package hudson.plugins.cigame.rules.unittesting;

import jenkins.model.Jenkins;
import hudson.plugins.cigame.GameDescriptor;
import hudson.plugins.cigame.model.RuleResult;

/**
Expand All @@ -10,16 +12,13 @@
*/
public class IncreasingSkippedTestsRule extends AbstractSkippedTestsRule {

private int pointsForIncreasingOneSkippedTest;
private static final int DEFAULT_POINTS = 0;

public IncreasingSkippedTestsRule() {
this(0);
private int getPoints() {
GameDescriptor gameDescriptor = Jenkins.getInstance().getDescriptorByType(GameDescriptor.class);
return gameDescriptor!=null?gameDescriptor.getSkippedTestIncreasingPoints():DEFAULT_POINTS;
}

public IncreasingSkippedTestsRule(int points) {
pointsForIncreasingOneSkippedTest = points;
}


public String getName() {
return Messages.UnitTestingRuleSet_IncreasingSkippedRule_Name();
}
Expand All @@ -32,7 +31,7 @@ protected String getResultDescription(Integer testDiff) {
@Override
protected RuleResult<Integer> evaluate(int passedTestDiff) {
if (passedTestDiff > 0) {
return new RuleResult<Integer>(passedTestDiff * pointsForIncreasingOneSkippedTest,
return new RuleResult<Integer>(passedTestDiff * getPoints(),
Messages.UnitTestingRuleSet_IncreasingSkippedRule_Count(passedTestDiff),
passedTestDiff);
}
Expand Down
Expand Up @@ -5,4 +5,26 @@
<f:checkbox field="namesAreCaseSensitive"/>
</f:entry>
</f:section>
<f:section title="${%cigame.title} - ${%cigame.unittests.subtitle}">
<f:advanced>
<f:entry title="${%cigame.unittests.marksForIncreasingPassedTestsByOne}" field="passedTestIncreasingPoints">
<f:textbox/>
</f:entry>
<f:entry title="${%cigame.unittests.marksForDecreasingPassedTestsByOne}" field="passedTestDecreasingPoints">
<f:textbox/>
</f:entry>
<f:entry title="${%cigame.unittests.marksForIncreasingFailedTestsByOne}" field="failedTestIncreasingPoints">
<f:textbox/>
</f:entry>
<f:entry title="${%cigame.unittests.marksForDecreasingFailedTestsByOne}" field="failedTestDecreasingPoints">
<f:textbox/>
</f:entry>
<f:entry title="${%cigame.unittests.marksForIncreasingSkippedTestsByOne}" field="skippedTestIncreasingPoints">
<f:textbox/>
</f:entry>
<f:entry title="${%cigame.unittests.marksForDecreasingSkippedTestsByOne}" field="skippedTestDecreasingPoints">
<f:textbox/>
</f:entry>
</f:advanced>
</f:section>
</j:jelly>

0 comments on commit 626af1c

Please sign in to comment.