forked from IBM/dbb-zappbuild
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDatasetValidationUtilities.groovy
66 lines (52 loc) · 1.92 KB
/
DatasetValidationUtilities.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
@groovy.transform.BaseScript com.ibm.dbb.groovy.ScriptLoader baseScript
import com.ibm.dbb.build.*
import groovy.transform.*
import groovy.cli.commons.*
import java.util.Properties
import com.ibm.jzos.ZFile
// define script properties
@Field BuildProperties props = BuildProperties.getInstance()
validateDatasets(args)
def validateSystemDatasets(String propertyFiles, String verbose) {
propertyFiles.split(",").each { propertyFile ->
// load property file using java.util.Properties
def properties = new Properties()
// convert to absolute path based on zAppBuild conventions and structure
if (props && !propertyFile.startsWith('/')) propertyFile = "${props.zAppBuildDir}/build-conf/$propertyFile"
File propFile = new File(propertyFile)
if (propFile.exists()) {
propFile.withInputStream { properties.load(it) }
properties.each { key,dataset ->
if (dataset) {
if (ZFile.dsExists("'$dataset'")) {
if (verbose.toBoolean()) println "** The dataset $dataset referenced for property $key was found."
} else {
println "*! The dataset $dataset referenced for property $key was not found. Process exits."
System.exit(1)
}
} else {
if (verbose.toBoolean()) println "*! No dataset defined for property $key specified in $propertyFile."
}
}
} else {
println "*!* The specified $propertyFile (in the list [$propertyFiles]) does not exist."
}
}
}
def validateDatasets(String[] cliArgs)
{
def cli = new CliBuilder(usage: "DatasetValidationUtilites.groovy [options]", header: '', stopAtNonOption: false)
cli.d(longOpt:'systemDatasetDefinition', args:1, required:true, 'List of property files containing system dataset definitions.')
cli.h(longOpt:'help', 'Flag to print the Help message.')
def opts = cli.parse(cliArgs)
// if opt parse fail exit.
if (! opts) {
System.exit(1)
}
if (opts.help)
{
cli.usage()
System.exit(0)
}
validateSystemDatasets(opts.d, "true")
}