Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for zCEE OpenAPI 3.0 processing #375

Merged
merged 12 commits into from
Sep 1, 2023
10 changes: 9 additions & 1 deletion build-conf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,15 @@ zunit_reportDatasets | Comma separated list of 'report' type data sets
zunit_reportOptions | BPXWDYN creation options for creating 'report' type data sets
zunit_dependenciesDatasetMapping | DBB property mapping to map dependencies to different target datasets

### zCEE3.properties
Application properties used by zAppBuild/language/zCEE3.groovy

Property | Description
--- | ---
zcee3_shellEnvironment | Shell environment used to run the gradle command
zcee3_gradlePath | Path to gradle executable
zcee3_gradle_JAVA_OPTS | JAVA Options used with gradle

### CRB.properties
Application properties used by zAppBuild/language/CRB.groovy

Expand All @@ -305,7 +314,6 @@ crb_zrbLocation | Absolute path to the CICS Resource Builder utility (zrb) on z/
crb_resourceModelFile | Absolute path to the CICS Resource Builder resource model YAML file on z/OS
crb_applicationConstraintsFile | (Optional) Absolute path to the CICS Resource Builder application constraints YAML file on z/OS


### Transfer.properties
Build properties used by zAppBuild/language/Transfer.groovy

Expand Down
6 changes: 3 additions & 3 deletions build-conf/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
buildPropFiles=datasets.properties,dependencyReport.properties,Assembler.properties,BMS.properties,\
MFS.properties,PSBgen.properties,DBDgen.properties,ACBgen.properties,Cobol.properties,\
LinkEdit.properties,PLI.properties,REXX.properties,ZunitConfig.properties,Transfer.properties,\
CRB.properties
CRB.properties,zCEE3.properties

#
# Comma separated list of default application configuration property files to load
Expand Down Expand Up @@ -67,7 +67,7 @@ buildOutputTSformat=yyyyMMdd.HHmmss.mmm

#
# Minimum required DBB ToolkitVersion to run this version of zAppBuild
# Build initialization process validates the DBB Toolkit Version in use and matches that against this setting
# Build initialization process validates the DBB Toolkit Version in use and matches that against this setting
requiredDBBToolkitVersion=2.0.0

#
Expand All @@ -94,7 +94,7 @@ metadataStoreType=file
#metadataStoreDb2Url=jdbc:db2:<Db2 server location>

# Db2 connection configuration property file
# Sample is povided at $DBB_HOME/conf/db2Connection.conf
# Sample is povided at $DBB_HOME/conf/db2Connection.conf
#metadataStoreDb2ConnectionConf=


Expand Down
20 changes: 20 additions & 0 deletions build-conf/zCEE3.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Releng properties used by language/zCEE3.groovy

#
# Comma separated list of required build properties for zCEE3.groovy
M-DLB marked this conversation as resolved.
Show resolved Hide resolved
zcee3_requiredBuildProperties=zcee3_shellEnvironment, zcee3_gradlePath, zcee3_gradle_JAVA_OPTS

#
# Shell environment used to run the gradle command
zcee3_shellEnvironment=bash

#
# Absolute path to gradle executable on z/OS UNIX System Services
# for instance: /var/gradle/gradle-7.6/bin/gradle
zcee3_gradlePath=

#
# JAVA Options used with gradle
# for instance: zCEE_gradle_JAVA_OPTS=-Xmx512m -XX:MaxMetaspaceSize=256m -Dfile.encoding=UTF-8
zcee3_gradle_JAVA_OPTS=-Dfile.encoding=UTF-8

1 change: 1 addition & 0 deletions languages/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ zAppBuild comes with a number of language specific build scripts. These script
* DBDgen.groovy
* PSBgen.groovy
* MFS.groovy
* zCEE3.groovy
* ZunitConfig.groovy

All language scripts both compile and optionally link-edit programs. The language build scripts are intended to be useful out of the box but depending on the complexity of your applications' build requirements, may require modifications to meet your development team's needs. By following the examples used in the existing language build scripts of keeping all application specific references out of the build scripts and instead using configuration properties with strong default values, the zAppBuild sample can continue to be a generic build solution for all of your specific applications.
Expand Down
111 changes: 111 additions & 0 deletions languages/zCEE3.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
@groovy.transform.BaseScript com.ibm.dbb.groovy.ScriptLoader baseScript
import com.ibm.dbb.dependency.*
import com.ibm.dbb.build.*
import groovy.transform.*
import com.ibm.dbb.build.report.*
import com.ibm.dbb.build.report.records.*
import java.nio.file.*;


// define script properties
@Field BuildProperties props = BuildProperties.getInstance()
@Field def buildUtils= loadScript(new File("${props.zAppBuildDir}/utilities/BuildUtilities.groovy"))

println("** Building ${argMap.buildList.size()} ${argMap.buildList.size() == 1 ? 'file' : 'files'} mapped to ${this.class.getName()}.groovy script")

// verify required build properties
buildUtils.assertBuildProperties(props.zcee3_requiredBuildProperties)

// sort the build list based on build file rank if provided
List<String> sortedList = buildUtils.sortBuildList(argMap.buildList.sort(), 'zcee3_fileBuildRank')
int currentBuildFileNumber = 1

// iterate through build list
sortedList.each { buildFile ->
println "*** (${currentBuildFileNumber++}/${sortedList.size()}) Building file $buildFile"

String workingDir = buildFile.replace("/src/main/api/openapi.yaml", "")
String gradleBuildLocation = "build"
if (props.verbose)
println("** Path to build.gradle: ${workingDir}/${gradleBuildLocation}")
String WarLocation = "${workingDir}/build/libs/api.war"
if (props.verbose)
println("** Expected location of the 'api.war' file: ${WarLocation}")
File WarFile = new File(WarLocation)
String[] command;
String commandString;

// log file - Changing slashes with dots to avoid conflicts
String member = buildFile.replace("/", ".")
File logFile = new File("${props.buildOutDir}/${member}.zCEE3.log")
if (logFile.exists())
logFile.delete()

String JAVA_OPTS = props.getFileProperty('zcee3_gradle_JAVA_OPTS', buildFile)
String gradlePath = props.getFileProperty('zcee3_gradlePath', buildFile)

File gradleExecutable = new File(gradlePath)
if (!gradleExecutable.exists()) {
def errorMsg = "*! gradle wasn't find at location '$gradlePath'"
println(errorMsg)
props.error = "true"
buildUtils.updateBuildResult(errorMsg:errorMsg)
} else {
String shellEnvironment = props.getFileProperty('zcee3_shellEnvironment', buildFile)

command = [shellEnvironment, gradlePath, gradleBuildLocation]
commandString = command.join(" ")
if (props.verbose)
println("** Executing command '${commandString}' in working directory '${workingDir}'...")
StringBuffer shellOutput = new StringBuffer()
StringBuffer shellError = new StringBuffer()

ProcessBuilder cmd = new ProcessBuilder(shellEnvironment, gradlePath, gradleBuildLocation);
Map<String, String> env = cmd.environment();
env.put("JAVA_OPTS", JAVA_OPTS);
cmd.directory(new File(workingDir));
Process process = cmd.start()
process.consumeProcessOutput(shellOutput, shellError)
process.waitFor()
if (props.verbose)
println("** Exit value for the gradle build: ${process.exitValue()}");

// write outputs to log file
String enc = props.logEncoding ?: 'IBM-1047'
logFile.withWriter(enc) { writer ->
writer.append(shellOutput)
writer.append(shellError)
}

if (process.exitValue() != 0) {
def errorMsg = "*! Error during the gradle process"
println(errorMsg)
if (props.verbose)
println("*! gradle error message:\n${shellError}")
props.error = "true"
buildUtils.updateBuildResult(errorMsg:errorMsg)
} else {
if (props.verbose)
println("** gradle output:\n${shellOutput}")
if (WarFile.exists()) {
// Copy api.war to the buildOutDir directory
File WarFileTarget = new File(props.buildOutDir + '/zCEE3/' + WarLocation);
File WarTargetDir = WarFileTarget.getParentFile();
WarTargetDir.mkdirs();
Files.copy(WarFile.toPath(), WarFileTarget.toPath(), StandardCopyOption.COPY_ATTRIBUTES);

AnyTypeRecord zCEEWARRecord = new AnyTypeRecord("USS_RECORD")
zCEEWARRecord.setAttribute("file", buildFile)
zCEEWARRecord.setAttribute("label", "z/OS Connect EE OpenAPI 3 YAML definition")
zCEEWARRecord.setAttribute("outputs", "[${props.buildOutDir}, zCEE3/$WarLocation, zCEE3]")
zCEEWARRecord.setAttribute("command", commandString);
BuildReportFactory.getBuildReport().addRecord(zCEEWARRecord)
} else {
def errorMsg = "*! Error when searching for the 'api.war' file at location '${WarLocation}'"
println(errorMsg)
props.error = "true"
buildUtils.updateBuildResult(errorMsg:errorMsg)
}
}
}
}
19 changes: 10 additions & 9 deletions samples/application-conf/file.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ dbb.scriptMapping = LinkEdit.groovy :: **/*.lnk
dbb.scriptMapping = PLI.groovy :: **/*.pli
dbb.scriptMapping = ZunitConfig.groovy :: **/*.bzucfg
dbb.scriptMapping = Transfer.groovy :: **/*.jcl, **/*.xml
dbb.scriptMapping = zCEE3.groovy :: **/openapi.yaml
dbb.scriptMapping = CRB.groovy :: **/crb/*.yaml

#
# dbb.scannerMapping to map files extensions to DBB dependency scanner configurations
#
# to override/expand the definitions from build-conf/defaultzAppBuildConf.properties
# to override/expand the definitions from build-conf/defaultzAppBuildConf.properties
#
# this maps file extensions to scanner configuration for the DBB dependency scanners
# also see:
Expand All @@ -26,9 +27,9 @@ dbb.scriptMapping = CRB.groovy :: **/crb/*.yaml
# Schema
# "scannerClass":"ScannerImplementation" : "languageHint":"DBBScannerHint" :: comma separated list of file extensions
#
# Note - if an extension of a build file is not specified in the mapping,
# Note - if an extension of a build file is not specified in the mapping,
# zAppBuild will skip scanning the file and only record a LogicalFile without capturing dependencies.
#
#
# dbb.scannerMapping = "scannerClass":"DependencyScanner", "languageHint":"COB" :: cbl,cpy,cob
# dbb.scannerMapping = "scannerClass":"DependencyScanner", "languageHint":"C" :: c, h
# dbb.scannerMapping = "scannerClass":"DependencyScanner", "languageHint":"ASM" :: asm, mac
Expand All @@ -37,12 +38,12 @@ dbb.scriptMapping = CRB.groovy :: **/crb/*.yaml
# dbb.scannerMapping = "scannerClass":"ZUnitConfigScanner" :: bzucfg

#
# General file level overwrites through DBB Build Properties
# General file level overwrites through DBB Build Properties
# isCICS = true :: **/cobol/member.cbl
# isSQL = true :: **/cobol/member.cbl
# isMQ = true :: **/cobol/member.cbl

#
#
# Please check for available file property overwrites within samples/application-conf/README.md

#
Expand All @@ -57,15 +58,15 @@ dbb.scriptMapping = CRB.groovy :: **/crb/*.yaml

#########
# Configuration for Transfer.groovy which copies files to target datasets and report them
# in the BuildReport
# in the BuildReport
#########
#
# PropertyMapping to map files using the Transfer.groovy language script to different target datasets
# PropertyMapping to map files using the Transfer.groovy language script to different target datasets
#
# transfer_datasetMapping = transfer_jclPDS :: **/*.jcl
# transfer_datasetMapping = transfer_xmlPDS :: **/xml/*.*
#
# file mapping for overwriting the default deployType of the Transfer.groovy language script
# file mapping for overwriting the default deployType of the Transfer.groovy language script
#
# transfer_deployType = JCL :: **/*.jcl
# transfer_deployType = XML :: **/xml/*.*
# transfer_deployType = XML :: **/xml/*.*