Skip to content

Commit c05f9e3

Browse files
authored
zCEE2 language script (#434)
* zCEE2 language script Signed-off-by: Mathieu Dalbin <mathieu.dalbin@fr.ibm.com>
1 parent b5d0038 commit c05f9e3

File tree

6 files changed

+317
-39
lines changed

6 files changed

+317
-39
lines changed

build-conf/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,16 @@ zcee3_shellEnvironment | Shell environment used to run the gradle command
301301
zcee3_gradlePath | Path to gradle executable
302302
zcee3_gradle_JAVA_OPTS | JAVA Options used with gradle
303303

304+
### zCEE2.properties
305+
Application properties used by zAppBuild/language/zCEE2.groovy
306+
307+
Property | Description
308+
--- | ---
309+
zcee2_zconbtPath | Absolute path to zconbt executable on z/OS UNIX System Services
310+
zcee2_JAVA_HOME | Java installation used by the zconbt utility
311+
zcee2_inputType | Mapping of input files with types of files
312+
zcee2_ARA_PackageArtifacts | Flag to indicate if artifacts produced for the ARA processing should be packaged
313+
304314
### CRB.properties
305315
Application properties used by zAppBuild/language/CRB.groovy
306316

build-conf/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
buildPropFiles=datasets.properties,dependencyReport.properties,Assembler.properties,BMS.properties,\
2020
MFS.properties,PSBgen.properties,DBDgen.properties,ACBgen.properties,Cobol.properties,\
2121
LinkEdit.properties,PLI.properties,REXX.properties,ZunitConfig.properties,Transfer.properties,\
22-
CRB.properties,zCEE3.properties
22+
CRB.properties,zCEE3.properties,zCEE2.properties
2323

2424
#
2525
# Comma separated list of default application configuration property files to load

build-conf/zCEE2.properties

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Releng properties used by language/zCEE2.groovy
2+
3+
#
4+
# Comma separated list of required build properties for zCEE3.groovy
5+
zcee2_requiredBuildProperties=zcee2_zconbtPath,zcee2_JAVA_HOME
6+
7+
#
8+
# Absolute path to zconbt executable on z/OS UNIX System Services
9+
# for instance: /var/zosconnect/v359/bin/zconbt.zos
10+
zcee2_zconbtPath=
11+
12+
#
13+
# Java installation used by the zconbt utility
14+
# for instance: /usr/lpp/java/J8.0_64
15+
zcee2_JAVA_HOME=
16+
17+
#
18+
# Mapping of input files with types of files
19+
# PROJECT can be used for SAR and AAR projects
20+
# SAR and ARA can be used for SAR Properties files and ARA properties files
21+
# Can be overridden by file-level properties
22+
zcee2_inputType=PROJECT
23+
24+
#
25+
# Flag to indicate if artifacts produced for the ARA processing should be packaged (generated copybooks, API information copybook and logs)
26+
# When set to true, the artifacts are located based on the dataStructuresLocation, apiInfoFileLocation and logFileDirectory properties of the ARA properties files
27+
# When not defined, the default value is false and artifacts are packaged
28+
zcee2_ARA_PackageArtifacts=true

languages/zCEE2.groovy

Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
@groovy.transform.BaseScript com.ibm.dbb.groovy.ScriptLoader baseScript
2+
import com.ibm.dbb.dependency.*
3+
import com.ibm.dbb.build.*
4+
import groovy.transform.*
5+
import com.ibm.dbb.build.report.*
6+
import com.ibm.dbb.build.report.records.*
7+
import java.nio.file.*;
8+
9+
10+
// define script properties
11+
@Field BuildProperties props = BuildProperties.getInstance()
12+
@Field def buildUtils= loadScript(new File("${props.zAppBuildDir}/utilities/BuildUtilities.groovy"))
13+
14+
// verify required build properties
15+
buildUtils.assertBuildProperties(props.zcee2_requiredBuildProperties)
16+
17+
// create updated build map, removing duplicates in case of PROJECT input Type
18+
HashMap<String, String> updatedBuildMap = new HashMap<String, String>()
19+
20+
println("** Streamlining the build list to remove duplicates")
21+
argMap.buildList.each { buildFile ->
22+
PropertyMappings inputTypeMappings = new PropertyMappings("zcee2_inputType")
23+
inputType = inputTypeMappings.getValue(buildFile)
24+
25+
if (inputType) {
26+
if (inputType == "PROJECT") {
27+
File changedBuildFile = new File(buildFile);
28+
File projectDir = changedBuildFile.getParentFile()
29+
boolean projectDirFound = false
30+
while (projectDir != null && !projectDirFound) {
31+
File projectFile = new File(projectDir.getPath() + '/.project')
32+
if (projectFile.exists()) {
33+
projectDirFound = true
34+
} else {
35+
projectDir = projectDir.getParentFile()
36+
}
37+
}
38+
if (projectDirFound) {
39+
updatedBuildMap.put(projectDir.getPath(), "PROJECT")
40+
} else {
41+
if (props.verbose) println("!* No project directory found for file '${buildFile}'. Skipping...")
42+
}
43+
} else {
44+
updatedBuildMap.put(buildFile, inputType);
45+
}
46+
} else {
47+
println("!* No Input Type mapping for file ${buildFile}, skipping it...")
48+
}
49+
}
50+
51+
println("** Building ${updatedBuildMap.size()} API ${updatedBuildMap.size() == 1 ? 'definition' : 'definitions'} mapped to ${this.class.getName()}.groovy script")
52+
// sort the build list based on build file rank if provided
53+
HashMap<String, String> sortedMap = buildUtils.sortBuildMap(updatedBuildMap, 'zcee2_fileBuildRank')
54+
55+
int currentBuildFileNumber = 1
56+
57+
// iterate through build list
58+
sortedMap.each { buildFile, inputType ->
59+
println "*** (${currentBuildFileNumber++}/${sortedMap.size()}) Building ${inputType == "PROJECT" ? 'project' : 'properties file'} $buildFile"
60+
61+
String parameters = ""
62+
String outputDir = ""
63+
String outputFile = ""
64+
if (inputType == "PROJECT") {
65+
outputDir = "${props.buildOutDir}/zCEE2/$buildFile"
66+
parameters = "-od $outputDir -pd $buildFile"
67+
} else {
68+
File changedBuildFile = new File(buildFile);
69+
String outputFileName = changedBuildFile.getName().split("\\.")[0] + "." + inputType.toLowerCase()
70+
File projectDir = changedBuildFile.getParentFile()
71+
outputFile = "${props.buildOutDir}/zCEE2/${projectDir.getPath()}/${outputFileName}"
72+
outputDir = "${props.buildOutDir}/zCEE2/${projectDir.getPath()}"
73+
parameters = "-f $outputFile -p $buildFile"
74+
}
75+
File outputDirectory = new File(outputDir)
76+
outputDirectory.mkdirs()
77+
78+
79+
Properties ARAproperties = new Properties()
80+
File dataStructuresLocation
81+
File apiInfoFileLocation
82+
File logFileDirectory
83+
if (inputType == "ARA") {
84+
File ARApropertiesFile = new File(buildFile)
85+
ARApropertiesFile.withInputStream {
86+
ARAproperties.load(it)
87+
}
88+
println("*** dataStructuresLocation: ${ARAproperties.dataStructuresLocation}")
89+
println("*** apiInfoFileLocation: ${ARAproperties.apiInfoFileLocation}")
90+
println("*** logFileDirectory: ${ARAproperties.logFileDirectory}")
91+
dataStructuresLocation = new File(ARAproperties.dataStructuresLocation)
92+
dataStructuresLocation.mkdirs()
93+
apiInfoFileLocation = new File(ARAproperties.apiInfoFileLocation)
94+
apiInfoFileLocation.mkdirs()
95+
logFileDirectory = new File(ARAproperties.logFileDirectory)
96+
logFileDirectory.mkdirs()
97+
}
98+
99+
100+
// log file - Changing slashes with dots to avoid conflicts
101+
String logFilePath = buildFile.replace("/", ".")
102+
File logFile = new File("${props.buildOutDir}/${logFilePath}.zCEE2.log")
103+
if (logFile.exists())
104+
logFile.delete()
105+
106+
String zconbtPath = props.getFileProperty('zcee2_zconbtPath', buildFile)
107+
108+
File zconbt = new File(zconbtPath)
109+
if (!zconbt.exists()) {
110+
def errorMsg = "*! zconbt wasn't find at location '$zconbtPath'"
111+
println(errorMsg)
112+
props.error = "true"
113+
buildUtils.updateBuildResult(errorMsg:errorMsg)
114+
} else {
115+
String[] command;
116+
117+
command = [zconbtPath, parameters]
118+
String commandString = command.join(" ")
119+
if (props.verbose)
120+
println("** Executing command '${commandString}'...")
121+
122+
StringBuffer shellOutput = new StringBuffer()
123+
StringBuffer shellError = new StringBuffer()
124+
125+
String JAVA_HOME = props.getFileProperty('zcee2_JAVA_HOME', buildFile)
126+
127+
ProcessBuilder cmd = new ProcessBuilder(zconbtPath, parameters);
128+
Map<String, String> env = cmd.environment();
129+
env.put("JAVA_HOME", JAVA_HOME);
130+
env.put("PATH", JAVA_HOME + "/bin" + ";" + env.get("PATH"))
131+
Process process = cmd.start()
132+
process.consumeProcessOutput(shellOutput, shellError)
133+
process.waitFor()
134+
if (props.verbose)
135+
println("** Exit value for the zconbt process: ${process.exitValue()}");
136+
137+
// write outputs to log file
138+
String enc = props.logEncoding ?: 'IBM-1047'
139+
logFile.withWriter(enc) { writer ->
140+
writer.append(shellOutput)
141+
writer.append(shellError)
142+
}
143+
144+
if (process.exitValue() != 0) {
145+
def errorMsg = "*! Error during the zconbt process"
146+
println(errorMsg)
147+
if (props.verbose)
148+
println("*! zconbt error message:\n${shellError}")
149+
props.error = "true"
150+
buildUtils.updateBuildResult(errorMsg:errorMsg)
151+
} else {
152+
if (props.verbose)
153+
println("** zconbt output:\n${shellOutput}")
154+
155+
ArrayList<String> outputProperty = []
156+
Path outputDirectoryPath = Paths.get(props.buildOutDir)
157+
if (inputType == "PROJECT") {
158+
String[] outputFiles = outputDirectory.list()
159+
for (int i=0; i<outputFiles.length; i++) {
160+
Path outputFilePath = Paths.get(outputDir + "/" + outputFiles[i])
161+
Path relativeOutputFilePath = outputDirectoryPath.relativize(outputFilePath)
162+
outputProperty.add("[${props.buildOutDir}, ${relativeOutputFilePath.toString()}, zCEE2]")
163+
}
164+
} else {
165+
Path outputFilePath = Paths.get(outputFile)
166+
Path relativeOutputFilePath = outputDirectoryPath.relativize(outputFilePath)
167+
outputProperty.add("[${props.buildOutDir}, ${relativeOutputFilePath.toString()}, zCEE2]")
168+
169+
if (inputType == "ARA") {
170+
def ARA_PackageArtifacts = props.getFileProperty('zcee2_ARA_PackageArtifacts', buildFile)
171+
if (ARA_PackageArtifacts && ARA_PackageArtifacts.toBoolean()) {
172+
173+
String[] outputFiles
174+
Path finalOutputFilePath
175+
176+
outputFiles = dataStructuresLocation.list()
177+
File dataStructuresLocationDir = new File("${props.buildOutDir}/zCEE2/dataStructures")
178+
dataStructuresLocationDir.mkdirs()
179+
for (int i=0; i<outputFiles.length; i++) {
180+
outputFilePath = Paths.get(dataStructuresLocation.getPath() + "/" + outputFiles[i])
181+
finalOutputFilePath = Paths.get(dataStructuresLocationDir.getPath() + "/" + outputFiles[i])
182+
Files.copy(outputFilePath, finalOutputFilePath, StandardCopyOption.COPY_ATTRIBUTES);
183+
relativeOutputFilePath = outputDirectoryPath.relativize(finalOutputFilePath)
184+
outputProperty.add("[${props.buildOutDir}, ${relativeOutputFilePath.toString()}, zCEE2-Copy]")
185+
}
186+
outputFiles = apiInfoFileLocation.list()
187+
File apiInfoFileLocationDir = new File("${props.buildOutDir}/zCEE2/apiInfoFiles")
188+
apiInfoFileLocationDir.mkdirs()
189+
for (int i=0; i<outputFiles.length; i++) {
190+
outputFilePath = Paths.get(apiInfoFileLocation.getPath() + "/" + outputFiles[i])
191+
finalOutputFilePath = Paths.get(apiInfoFileLocationDir.getPath() + "/" + outputFiles[i])
192+
Files.copy(outputFilePath, finalOutputFilePath, StandardCopyOption.COPY_ATTRIBUTES);
193+
relativeOutputFilePath = outputDirectoryPath.relativize(finalOutputFilePath)
194+
outputProperty.add("[${props.buildOutDir}, ${relativeOutputFilePath.toString()}, zCEE2-Info]")
195+
}
196+
outputFiles = logFileDirectory.list()
197+
File logFileDirectoryDir = new File("${props.buildOutDir}/zCEE2/logs")
198+
logFileDirectoryDir.mkdirs()
199+
for (int i=0; i<outputFiles.length; i++) {
200+
if (outputFiles[i].endsWith(".log")) {
201+
outputFilePath = Paths.get(logFileDirectory.getPath() + "/" + outputFiles[i])
202+
finalOutputFilePath = Paths.get(logFileDirectoryDir.getPath() + "/" + outputFiles[i])
203+
Files.copy(outputFilePath, finalOutputFilePath, StandardCopyOption.COPY_ATTRIBUTES);
204+
relativeOutputFilePath = outputDirectoryPath.relativize(finalOutputFilePath)
205+
outputProperty.add("[${props.buildOutDir}, ${relativeOutputFilePath.toString()}, zCEE2-Log]")
206+
}
207+
}
208+
}
209+
}
210+
}
211+
AnyTypeRecord zCEEWARRecord = new AnyTypeRecord("USS_RECORD")
212+
zCEEWARRecord.setAttribute("file", buildFile)
213+
zCEEWARRecord.setAttribute("label", "z/OS Connect EE OpenAPI 2 definition")
214+
zCEEWARRecord.setAttribute("outputs", outputProperty.join(";"))
215+
zCEEWARRecord.setAttribute("command", commandString);
216+
BuildReportFactory.getBuildReport().addRecord(zCEEWARRecord)
217+
}
218+
}
219+
}

0 commit comments

Comments
 (0)