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
Merge pull request #11 from lkamal/master
[FIXED JENKINS-6446] added global configurations for all the six types of unittest changes (increase or descrease of passed, failed and skipped tests)
  • Loading branch information
simschla committed Nov 3, 2013
2 parents 321ce5b + 57b4377 commit c662016
Show file tree
Hide file tree
Showing 27 changed files with 597 additions and 310 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;
}

}
@@ -0,0 +1,24 @@
package hudson.plugins.cigame.rules.unittesting;

import hudson.plugins.cigame.model.RuleResult;
import hudson.tasks.test.AbstractTestResultAction;

/**
* Rule that gives points for increasing or decreasing the number of failed
* tests. This is done by comparing the current with the previous build.
*
* @author <a href="www.digizol.com">Kamal Mettananda</a>
* @since 1.20
*/
public abstract class AbstractFailedTestsRule extends AbstractUnitTestsRule {

protected abstract RuleResult<Integer> evaluate(int failedTestDiff);

@Override
protected RuleResult<Integer> evaluate(AbstractTestResultAction<?> testResult,
AbstractTestResultAction<?> previousTestResult) {

return evaluate(testResult.getFailCount() - previousTestResult.getFailCount());
}

}
@@ -0,0 +1,25 @@
package hudson.plugins.cigame.rules.unittesting;

import hudson.plugins.cigame.model.RuleResult;
import hudson.tasks.test.AbstractTestResultAction;

/**
* Rule that gives points for increasing or decreasing the number of passed
* tests. This is done by comparing the current with the previous build.
*
* @author <a href="www.digizol.com">Kamal Mettananda</a>
* @since 1.20
*/
public abstract class AbstractPassedTestsRule extends AbstractUnitTestsRule {

protected abstract RuleResult<Integer> evaluate(int passedTestDiff);

@Override
protected RuleResult<Integer> evaluate(AbstractTestResultAction<?> testResult,
AbstractTestResultAction<?> previousTestResult) {

return evaluate((testResult.getTotalCount() - testResult.getFailCount() - testResult.getSkipCount())
- (previousTestResult.getTotalCount() - previousTestResult.getFailCount() - previousTestResult.getSkipCount()));
}

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

import hudson.plugins.cigame.model.RuleResult;
import hudson.tasks.test.AbstractTestResultAction;

/**
* Rule that gives points for increasing or decreasing the number of skipped
* tests. This is done by comparing the current with the previous build.
*
* @author <a href="www.digizol.com">Kamal Mettananda</a>
* @since 1.20
*/
public abstract class AbstractSkippedTestsRule extends AbstractUnitTestsRule {

protected abstract RuleResult<Integer> evaluate(int skippedTestDiff);

@Override
protected RuleResult<Integer> evaluate(AbstractTestResultAction<?> testResult,
AbstractTestResultAction<?> previousTestResult) {
return evaluate(testResult.getSkipCount() - previousTestResult.getSkipCount());
}

}
Expand Up @@ -100,6 +100,9 @@ public final RuleResult<Integer> evaluate(AbstractBuild<?, ?> previousBuild,
prevResult = prevResult != null ? prevResult : Result.ABORTED;
result = result != null ? result : Result.ABORTED;

// if the current action is null, let's assume as a ZERO result
action = action != null ? action : ZERO_RESULT;

if ((prevResult.isBetterThan(Result.FAILURE))
&& (result.isBetterThan(Result.FAILURE))) {
return evaluate(action, prevAction);
Expand Down
@@ -0,0 +1,42 @@
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 0 mark given.
*
* @author <a href="www.digizol.com">Kamal Mettananda</a>
* @since 1.20
*/
public class DecreasingFailedTestsRule extends AbstractFailedTestsRule {

private static final int DEFAULT_POINTS = 0;

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

public String getName() {
return Messages.UnitTestingRuleSet_DecreasingFailedRule_Name();
}

@Override
protected String getResultDescription(Integer testDiff) {
return Messages.UnitTestingRuleSet_DecreasingFailedRule_Count(testDiff);
}

@Override
protected RuleResult<Integer> evaluate(int failedTestDiff) {
if (failedTestDiff < 0) {
failedTestDiff = -failedTestDiff;
return new RuleResult<Integer>(failedTestDiff * getPoints(),
Messages.UnitTestingRuleSet_DecreasingFailedRule_Count(failedTestDiff),
failedTestDiff);
}
return null;
}

}
@@ -0,0 +1,42 @@
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 passed tests. By default -1 mark given.
*
* @author <a href="www.digizol.com">Kamal Mettananda</a>
* @since 1.20
*/
public class DecreasingPassedTestsRule extends AbstractPassedTestsRule {

private static final int DEFAULT_POINTS = 1;

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

public String getName() {
return Messages.UnitTestingRuleSet_DecreasingPassedRule_Name();
}

@Override
protected String getResultDescription(Integer testDiff) {
return Messages.UnitTestingRuleSet_DecreasingPassedRule_Count(testDiff);
}

@Override
protected RuleResult<Integer> evaluate(int passedTestDiff) {
if (passedTestDiff < 0) {
passedTestDiff = -passedTestDiff;
return new RuleResult<Integer>(passedTestDiff * getPoints(),
Messages.UnitTestingRuleSet_DecreasingPassedRule_Count(passedTestDiff),
passedTestDiff);
}
return null;
}

}
@@ -0,0 +1,42 @@
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 skipped tests. By default 0 marks given.
*
* @author <a href="www.digizol.com">Kamal Mettananda</a>
* @since 1.20
*/
public class DecreasingSkippedTestsRule extends AbstractSkippedTestsRule {

private static final int DEFAULT_POINTS = 0;

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

public String getName() {
return Messages.UnitTestingRuleSet_DecreasingSkippedRule_Name();
}

@Override
protected String getResultDescription(Integer testDiff) {
return Messages.UnitTestingRuleSet_DecreasingSkippedRule_Count(testDiff);
}

@Override
protected RuleResult<Integer> evaluate(int skippedTestDiff) {
if (skippedTestDiff < 0) {
skippedTestDiff = -skippedTestDiff;
return new RuleResult<Integer>(skippedTestDiff * getPoints(),
Messages.UnitTestingRuleSet_DecreasingSkippedRule_Count(skippedTestDiff),
skippedTestDiff);
}
return null;
}

}

0 comments on commit c662016

Please sign in to comment.