class platformValidator extends Object
Validates the contents of a platforms file and provides quick access to supported platforms.
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.platformValidator def platforms = new platformValidator() platforms.load_JSON('resources/platforms.json') println 'Does the file validate? ' + platforms.validate() //List supported platforms and operating systems platforms.platforms['supported_platforms'].sort { k, v -> k }.each { platform, os -> println "Platform '${platform}' includes operating systems:" os.sort { k, v -> k }.each { o, s -> println " ${o} (Supported languages: ${s['language'].sort().join(', ')})" } } null
Type Params | Return Type | Name and description |
---|---|---|
|
void |
load_JSON(String file) Load the JSON of a platforms file and parse it. |
|
void |
load_JSONString(String json) Parse the JSON which is the contents of a platforms file. |
|
Boolean |
validate() Validates the platforms file. |
|
Boolean |
validate_asBool() Executes the validate() function but always returns a Boolean instead of throwing an exception upon failed validation. |
Load the JSON of a platforms file and parse it. This should be the first function called after class instantiation. Alternately, load_JSONString() can be called instead. It populates platforms.
file
- A String which is a path to a platforms file.Parse the JSON which is the contents of a platforms file. It populates platforms. This is required in order to use the readFileFromWorkspace method from the Jenkins Job DSL Plugin.
json
- A String containing the contents of a platforms file.Validates the platforms file.
Executes the validate() function but always returns a Boolean instead of throwing an exception upon failed validation.