class lifecycleValidator extends Object
Validates the contents of a lifecycle file and provides quick access to supported languages.
To run this example, clone Jervis and execute ./gradlew console to bring up a Groovy Console with the classpath set up.
Please note, if you are writing Job DSL plugin groovy scripts you should not use the relative file paths to access files in the repository where your DSL scripts reside. Instead, use the readFileFromWorkspace method provided by the Job DSL plugin in Jenkins.
import net.gleske.jervis.lang.lifecycleValidator def lifecycles = new lifecycleValidator() lifecycles.load_JSON('resources/lifecycles-ubuntu1604-stable.json') println 'Does the file validate? ' + lifecycles.validate() print 'Supported languages include:\n ' println lifecycles.languages.collect { lifecycles.lifecycles[it]['friendlyName'] }.sort().join('\n ')
Type | Name and description |
---|---|
String[] |
languages A String Array which contains a list of supported languages in the lifecycles file. |
Map |
lifecycles A Map of the parsed lifecycles file. |
Type Params | Return Type | Name and description |
---|---|---|
|
void |
load_JSON(String file) Load the JSON of a lifecycles file and parse it. |
|
void |
load_JSONString(String json) Parse the JSON which is the contents of a lifecycles file. |
|
Boolean |
supportedLanguage(String lang) Checks to see if a language is a supported language based on the lifecycles file. |
|
Boolean |
validate() Validates the lifecycles file. |
|
Boolean |
validate_asBool() Executes the validate() function but always returns a Boolean instead of throwing an exception upon failed validation. |
A String Array which contains a list of supported languages in the lifecycles file. This is just a list of the keys in lifecycles.
Load the JSON of a lifecycles file and parse it. This should be the first function called after class instantiation. Alternately, load_JSONString() can be called instead. It populates lifecycles and languages.
file
- A String which is a path to a lifecycles file.Parse the JSON which is the contents of a lifecycles file. It populates lifecycles and languages. This is required in order to use the readFileFromWorkspace method from the Jenkins Job DSL Plugin.
json
- A String containing the contents of a lifecycles file.Checks to see if a language is a supported language based on the lifecycles file.
lang
- A String which is a language to look up based on the keys in the lifecycles file.Validates the lifecycles file.
Executes the validate() function but always returns a Boolean instead of throwing an exception upon failed validation.