
com.stanfy.helium.gradle.HeliumExtension.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gradle-plugin Show documentation
Show all versions of gradle-plugin Show documentation
DSL and Java API for REST API specification
The newest version!
package com.stanfy.helium.gradle
import com.stanfy.helium.gradle.tasks.BaseHeliumTask
import com.stanfy.helium.utils.ConfigurableStringMap
import com.stanfy.helium.utils.DslUtils
import groovy.transform.PackageScope
import org.gradle.api.GradleException
import static com.stanfy.helium.gradle.UserConfig.specName
/**
* Helium extension.
*/
class HeliumExtension {
public static final String VERSION = "0.6.0"
/** Tasks group. */
public static final String GROUP = "Helium"
private static final String HELIUM_ARTIFACT_NAME = "helium"
public static final String HELIUM_DEP = "com.stanfy.helium:$HELIUM_ARTIFACT_NAME"
/** Specifications collection. */
private final ArrayList specifications = new ArrayList<>()
/** Ignore test failures. */
boolean ignoreFailures
/** Source generation tasks for each specification. */
private final Map> sourceGenTasks = new HashMap<>()
private UserConfig config
@PackageScope
void attach(final UserConfig config) {
this.config = config
}
Collection getSpecifications() {
return specifications
}
final void specification(def spec) {
specification(spec, null)
}
void specification(def spec, Closure config) {
File specFile = this.config.project.file(spec)
String name = specName(specFile)
if (!this.config.contains(specFile)) {
sourceGenTasks[name] = new HashMap<>()
specifications.add specFile
}
if (config) {
SpecificationDslDelegate delegate = new SpecificationDslDelegate(specFile, this.config)
DslUtils.runWithProxy(delegate, config)
}
}
void sourceGen(Closure> config) {
if (!this.config.defaultSourceGeneration) {
this.config.defaultSourceGeneration = new SourceGenDslDelegate(config.owner)
}
DslUtils.runWithProxy(this.config.defaultSourceGeneration, config)
}
void variables(Closure> config) {
DslUtils.runWithProxy(new ConfigurableStringMap(this.config.variables, "Variables"), config)
}
Map getSourceGen() {
if (sourceGenTasks.empty) {
return null
}
if (sourceGenTasks.size() == 1) {
return sourceGenTasks.values().iterator().next()
} else {
throw new GradleException("Default sourceGen property cannot be accessed when "
+ "multiple specifications are declared. Use sourceGen('') instead.")
}
}
Map sourceGen(final String name) {
if (!name) {
throw new IllegalArgumentException("Specification name is not provided")
}
return sourceGenTasks[name]
}
Map sourceGen(final File spec) {
if (!spec) {
throw new IllegalArgumentException("Specification is not provided")
}
return sourceGenTasks[specName(spec)]
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy