All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.danielsomerfield.cvecheck.gradle.handlers.buildRules.CVEBuildRuleBuilder.groovy Maven / Gradle / Ivy

There is a newer version: 0.6.2-100
Show newest version
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 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)
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy