Skip to content
Permalink
Browse files

Fixed bug:

JENKINS-14589

Added Features:
JENKINS-11025
JENKINS-8326
  • Loading branch information...
podarsmarty committed Jul 26, 2012
1 parent 704338b commit 1cef2b6890bf3388e7e80f12bbe8588035049403
@@ -49,6 +49,10 @@
private final AbstractBuild<?, ?> owner;
private CoverageTarget healthyTarget;
private CoverageTarget unhealthyTarget;
private boolean failUnhealthy;
private boolean failUnstable;
private boolean autoUpdateHealth;
private boolean autoUpdateStability;
/**
* Overall coverage result.
*/
@@ -180,12 +184,16 @@ private boolean includeOnlyStable() {
}

CoberturaBuildAction(AbstractBuild<?, ?> owner, CoverageResult r, CoverageTarget healthyTarget,
CoverageTarget unhealthyTarget, boolean onlyStable) {
CoverageTarget unhealthyTarget, boolean onlyStable, boolean failUnhealthy, boolean failUnstable, boolean autoUpdateHealth, boolean autoUpdateStability) {
this.owner = owner;
this.report = new WeakReference<CoverageResult>(r);
this.healthyTarget = healthyTarget;
this.unhealthyTarget = unhealthyTarget;
this.onlyStable = onlyStable;
this.failUnhealthy = failUnhealthy;
this.failUnstable = failUnstable;
this.autoUpdateHealth = autoUpdateHealth;
this.autoUpdateStability = autoUpdateStability;
r.setOwner(owner);
if (result == null) {
result = new EnumMap<CoverageMetric,Ratio>(CoverageMetric.class);
@@ -224,8 +232,8 @@ public synchronized CoverageResult getResult() {
private static final Logger logger = Logger.getLogger(CoberturaBuildAction.class.getName());

public static CoberturaBuildAction load(AbstractBuild<?, ?> build, CoverageResult result, CoverageTarget healthyTarget,
CoverageTarget unhealthyTarget, boolean onlyStable) {
return new CoberturaBuildAction(build, result, healthyTarget, unhealthyTarget, onlyStable);
CoverageTarget unhealthyTarget, boolean onlyStable, boolean failUnhealthy, boolean failUnstable, boolean autoUpdateHealth, boolean autoUpdateStability) {
return new CoberturaBuildAction(build, result, healthyTarget, unhealthyTarget, onlyStable, failUnhealthy, failUnstable, autoUpdateHealth, autoUpdateStability);
}

/**
@@ -49,6 +49,10 @@

private final String coberturaReportFile;
private final boolean onlyStable;
private final boolean failUnhealthy;
private final boolean failUnstable;
private final boolean autoUpdateHealth;
private final boolean autoUpdateStability;

private CoverageTarget healthyTarget;
private CoverageTarget unhealthyTarget;
@@ -61,9 +65,13 @@
* @stapler-constructor
*/
@DataBoundConstructor
public CoberturaPublisher(String coberturaReportFile, boolean onlyStable, SourceEncoding sourceEncoding) {
public CoberturaPublisher(String coberturaReportFile, boolean onlyStable, boolean failUnhealthy, boolean failUnstable, boolean autoUpdateHealth, boolean autoUpdateStability, SourceEncoding sourceEncoding) {
this.coberturaReportFile = coberturaReportFile;
this.onlyStable = onlyStable;
this.failUnhealthy = failUnhealthy;
this.failUnstable = failUnstable;
this.autoUpdateHealth = autoUpdateHealth;
this.autoUpdateStability = autoUpdateStability;
this.sourceEncoding = sourceEncoding;
this.healthyTarget = new CoverageTarget();
this.unhealthyTarget = new CoverageTarget();
@@ -146,6 +154,42 @@ public String getCoberturaReportFile() {
public boolean getOnlyStable() {
return onlyStable;
}

/**
* Getter for property 'failUnhealthy'.
*
* @return Value for property 'failUnhealthy'.
*/
public boolean getFailUnhealthy() {
return failUnhealthy;
}

/**
* Getter for property 'failUnstable'.
*
* @return Value for property 'failUnstable'.
*/
public boolean getFailUnstable() {
return failUnstable;
}

/**
* Getter for property 'autoUpdateHealth'.
*
* @return Value for property 'autoUpdateHealth'.
*/
public boolean getAutoUpdateHealth() {
return autoUpdateHealth;
}

/**
* Getter for property 'autoUpdateStability'.
*
* @return Value for property 'autoUpdateStability'.
*/
public boolean getAutoUpdateStability() {
return autoUpdateStability;
}

/**
* Getter for property 'healthyTarget'.
@@ -301,6 +345,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
}
}
if (result != null) {
listener.getLogger().println("Cobertura coverage report found.");
result.setOwner(build);
final FilePath paintedSourcesPath = new FilePath(new File(build.getProject().getRootDir(), "cobertura"));
paintedSourcesPath.mkdirs();
@@ -310,7 +355,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
moduleRoot.act(painter);

final CoberturaBuildAction action = CoberturaBuildAction.load(build, result, healthyTarget,
unhealthyTarget, getOnlyStable());
unhealthyTarget, getOnlyStable(), getFailUnhealthy(), getFailUnstable(), getAutoUpdateHealth(), getAutoUpdateStability());

build.getActions().add(action);
Set<CoverageMetric> failingMetrics = failingTarget.getFailingMetrics(result);
@@ -319,8 +364,40 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
for (CoverageMetric metric : failingMetrics) {
listener.getLogger().println(" " + metric.getName());
}
listener.getLogger().println("Setting Build to unstable.");
build.setResult(Result.UNSTABLE);
if(!getFailUnstable())
{
listener.getLogger().println("Setting Build to unstable.");
build.setResult(Result.UNSTABLE);
}
else
{
listener.getLogger().println("Failing build due to unstability.");
build.setResult(Result.FAILURE);
}
}
if(getFailUnhealthy())
{
Set<CoverageMetric> unhealthyMetrics = unhealthyTarget.getFailingMetrics(result);
if (!unhealthyMetrics.isEmpty()) {
listener.getLogger().println("Unhealthy for the following metrics:");
for (CoverageMetric metric : unhealthyMetrics) {
listener.getLogger().println(" " + metric.getName());
}
listener.getLogger().println("Failing build because it is unhealthy.");
build.setResult(Result.FAILURE);
}
}
if(build.getResult() == Result.SUCCESS)
{
if(getAutoUpdateHealth())
{
setNewPercentages(result, true, listener);
}

if(getAutoUpdateStability())
{
setNewPercentages(result, false, listener);
}
}
} else {
listener.getLogger().println("No coverage results were successfully parsed. Did you generate " +
@@ -330,7 +407,45 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen

return true;
}


/**
* Changes unhealthy or unstable percentage fields for ratcheting.
*/
public void setNewPercentages(CoverageResult result, boolean select, BuildListener listener)
{
Set<CoverageMetric> healthyMetrics = healthyTarget.getAllMetrics(result);
int newPercent;
int oldPercent;
if(!healthyMetrics.isEmpty())
{
for (CoverageMetric metric : healthyMetrics)
{
newPercent = healthyTarget.getObservedPercent(result, metric);
if(select)
{
oldPercent = unhealthyTarget.getSetPercent(result, metric);
}
else
{
oldPercent = failingTarget.getSetPercent(result, metric);
}
if(newPercent > oldPercent)
{
if(select)
{
unhealthyTarget.setTarget(metric, newPercent);
listener.getLogger().println(" " + metric.getName() + "'s new health minimum is: " + newPercent);
}
else
{
failingTarget.setTarget(metric, newPercent);
listener.getLogger().println(" " + metric.getName() + "'s new stability minimum is: " + newPercent);
}
}
}
}
}

/**
* {@inheritDoc}
*/
@@ -22,8 +22,8 @@
@SuppressWarnings("unused")
private static final Logger LOGGER = Logger.getLogger(MavenCoberturaBuildAction.class.getName());

MavenCoberturaBuildAction(MavenBuild build, CoverageResult r, CoverageTarget healthyTarget, CoverageTarget unhealthyTarget, boolean onlyStable) {
super(build, r, healthyTarget, unhealthyTarget, onlyStable);
MavenCoberturaBuildAction(MavenBuild build, CoverageResult r, CoverageTarget healthyTarget, CoverageTarget unhealthyTarget, boolean onlyStable, boolean failUnhealthy, boolean failUnstable, boolean autoUpdateHealth, boolean autoUpdateStability) {
super(build, r, healthyTarget, unhealthyTarget, onlyStable, failUnhealthy, failUnstable, autoUpdateHealth, autoUpdateStability);
}

public MavenAggregatedReport createAggregatedAction(MavenModuleSetBuild build, Map<MavenModule, List<MavenBuild>> moduleBuilds) {
@@ -281,7 +281,7 @@ public Boolean call(MavenBuild build) throws IOException {
CoverageResult result = CoberturaCoverageParser.parse(cvgxml, null, new HashSet<String>());
result.setOwner(build);

CoberturaBuildAction o = CoberturaBuildAction.load(build, result, null, null, false);
CoberturaBuildAction o = CoberturaBuildAction.load(build, result, null, null, false, false, false, false, false);
build.getActions().add(o);
} else {
return false;

0 comments on commit 1cef2b6

Please sign in to comment.
You can’t perform that action at this time.