com.danielsomerfield.cvecheck.gradle.handlers.buildRules.CVEBuildRuleBuilder.groovy Maven / Gradle / Ivy
package com.danielsomerfield.cvecheck.gradle.handlers.buildRules
import com.danielsomerfield.util.Maybe
import java.lang.reflect.Constructor
import static com.danielsomerfield.util.Maybe.nothing
import static com.danielsomerfield.util.Maybe.some
class CVEBuildRuleBuilder implements BuildRuleBuilder {
private String buildFailureStrategy;
private Maybe threshold = nothing();
private Map> buildRuleTypes;
CVEBuildRuleBuilder(final Map> buildRuleTypes) {
this.buildRuleTypes = buildRuleTypes
}
@Override
Maybe create() {
some(buildRuleTypes.get(buildFailureStrategy)).map {
Class extends BuildRule> clazz ->
def constructor = clazz.getConstructor(BuildRuleConfiguration.class)
constructor.newInstance(getConfiguration()) as BuildRule
}
}
@Override
CVEBuildRuleBuilder setBuildFailureStrategy(final String buildFailureStrategy) {
this.buildFailureStrategy = buildFailureStrategy;
this
}
@Override
CVEBuildRuleBuilder setThreshold(final int threshold) {
this.threshold = some(threshold)
this
}
public BuildRuleConfiguration getConfiguration() {
return new BuildRuleConfiguration(threshold)
}
}