diff --git a/src/main/java/io/jenkins/plugins/util/QualityGate.java b/src/main/java/io/jenkins/plugins/util/QualityGate.java index 4efbef4..80aca7a 100644 --- a/src/main/java/io/jenkins/plugins/util/QualityGate.java +++ b/src/main/java/io/jenkins/plugins/util/QualityGate.java @@ -16,9 +16,13 @@ import jenkins.model.Jenkins; /** - * Defines a quality gate based on a specific threshold of code coverage in the current build. After a build has been - * finished, a set of {@link QualityGate quality gates} will be evaluated and the overall quality gate status will be - * reported in Jenkins UI. + * Defines a quality gate based on a specific threshold of a selected property in the current build. After a build has + * been finished, a set of {@link QualityGate quality gates} will be evaluated and the overall quality gate status will + * be reported in Jenkins UI. The criticality of the quality gate is determined by the + * {@link QualityGateCriticality criticality}. Subclasses must implement the {@link #getName()} method to provide a + * human-readable name of the quality gate. Additionally, subclasses must provide a {@link Descriptor} to describe the + * quality gate in the UI. Subclasses may add additional properties to configure the quality gate, these must be annotated with the + * {@link DataBoundSetter} annotation. * * @author Johannes Walter */ @@ -41,15 +45,19 @@ protected QualityGate(final double threshold) { } /** - * Sets the criticality of this quality gate. When a quality gate has been missed, this property determines whether - * the result of the associated coverage stage will be marked as unstable or failure. + * Creates a new instance of {@link QualityGate}. * - * @param criticality - * the criticality for this quality gate + * @param threshold + * minimum or maximum value that triggers this quality gate */ - @DataBoundSetter - public final void setCriticality(final QualityGateCriticality criticality) { - this.criticality = criticality; + protected QualityGate(final int threshold) { + super(); + + this.threshold = threshold; + } + + public final double getThreshold() { + return threshold; } /** @@ -59,8 +67,24 @@ public final void setCriticality(final QualityGateCriticality criticality) { */ public abstract String getName(); - protected void setThreshold(final double threshold) { - this.threshold = threshold; + private int asInt(final double value) { + return Double.valueOf(value).intValue(); + } + + /** + * Sets the threshold of the quality gate. This integer-based setter is required to bind a UI number element to this + * model object. + * + * @param integerThreshold + * the threshold of the quality gate + */ + @DataBoundSetter + public final void setIntegerThreshold(final int integerThreshold) { + this.threshold = asInt(integerThreshold); + } + + public final int getIntegerThreshold() { + return asInt(threshold); } @Override @@ -68,8 +92,16 @@ public String toString() { return getName() + String.format(" - %s: %f", getCriticality(), getThreshold()); } - public final double getThreshold() { - return threshold; + /** + * Sets the criticality of this quality gate. When a quality gate has been missed, this property determines whether + * the result of the associated coverage stage will be marked as unstable or failure. + * + * @param criticality + * the criticality for this quality gate + */ + @DataBoundSetter + public final void setCriticality(final QualityGateCriticality criticality) { + this.criticality = criticality; } public final QualityGateCriticality getCriticality() {