Skip to content

Commit

Permalink
Add integer based threshold.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Jan 4, 2024
1 parent 80b65e3 commit 384b719
Showing 1 changed file with 46 additions and 14 deletions.
60 changes: 46 additions & 14 deletions src/main/java/io/jenkins/plugins/util/QualityGate.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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();

Check warning on line 54 in src/main/java/io/jenkins/plugins/util/QualityGate.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/jenkins/plugins/util/QualityGate.java#L54

Added line #L54 was not covered by tests

this.threshold = threshold;
}

Check warning on line 57 in src/main/java/io/jenkins/plugins/util/QualityGate.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/jenkins/plugins/util/QualityGate.java#L56-L57

Added lines #L56 - L57 were not covered by tests

public final double getThreshold() {
return threshold;

Check warning on line 60 in src/main/java/io/jenkins/plugins/util/QualityGate.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/jenkins/plugins/util/QualityGate.java#L60

Added line #L60 was not covered by tests
}

/**
Expand All @@ -59,17 +67,41 @@ 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();

Check warning on line 71 in src/main/java/io/jenkins/plugins/util/QualityGate.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/jenkins/plugins/util/QualityGate.java#L71

Added line #L71 was not covered by tests
}

/**
* 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);
}

Check warning on line 84 in src/main/java/io/jenkins/plugins/util/QualityGate.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/jenkins/plugins/util/QualityGate.java#L83-L84

Added lines #L83 - L84 were not covered by tests

public final int getIntegerThreshold() {
return asInt(threshold);

Check warning on line 87 in src/main/java/io/jenkins/plugins/util/QualityGate.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/jenkins/plugins/util/QualityGate.java#L87

Added line #L87 was not covered by tests
}

@Override
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;

Check warning on line 104 in src/main/java/io/jenkins/plugins/util/QualityGate.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/jenkins/plugins/util/QualityGate.java#L104

Added line #L104 was not covered by tests
}

public final QualityGateCriticality getCriticality() {
Expand Down

0 comments on commit 384b719

Please sign in to comment.