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

Missing sortBuildMap function for language script zCEE2 #465

Merged
merged 4 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion build-conf/zCEE2.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#
# Comma separated list of required build properties for zCEE3.groovy
zcee2_requiredBuildProperties=zcee2_zconbtPath,zcee2_JAVA_HOME
zcee2_requiredBuildProperties=zcee2_zconbtPath

#
# Absolute path to zconbt executable on z/OS UNIX System Services
Expand All @@ -12,6 +12,7 @@ zcee2_zconbtPath=
#
# Java installation used by the zconbt utility
# for instance: /usr/lpp/java/J8.0_64
# if not set, the value of the JAVA_HOME environment variable will be used
zcee2_JAVA_HOME=

#
Expand Down
23 changes: 13 additions & 10 deletions languages/zCEE2.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import java.nio.file.*;
buildUtils.assertBuildProperties(props.zcee2_requiredBuildProperties)

// create updated build map, removing duplicates in case of PROJECT input Type
HashMap<String, String> updatedBuildMap = new HashMap<String, String>()
HashMap<String, String> updatedBuildList = new HashMap<String, String>()

println("** Streamlining the build list to remove duplicates")
argMap.buildList.each { buildFile ->
Expand All @@ -36,27 +36,27 @@ argMap.buildList.each { buildFile ->
}
}
if (projectDirFound) {
updatedBuildMap.put(projectDir.getPath(), "PROJECT")
updatedBuildList.putIfAbsent(projectDir.getPath(), "PROJECT")
} else {
if (props.verbose) println("!* No project directory found for file '${buildFile}'. Skipping...")
}
} else {
updatedBuildMap.put(buildFile, inputType);
updatedBuildList.put(buildFile, inputType);
}
} else {
println("!* No Input Type mapping for file ${buildFile}, skipping it...")
}
}

println("** Building ${updatedBuildMap.size()} API ${updatedBuildMap.size() == 1 ? 'definition' : 'definitions'} mapped to ${this.class.getName()}.groovy script")
println("** Building ${updatedBuildList.size()} API ${updatedBuildList.size() == 1 ? 'definition' : 'definitions'} mapped to ${this.class.getName()}.groovy script")
// sort the build list based on build file rank if provided
HashMap<String, String> sortedMap = buildUtils.sortBuildMap(updatedBuildMap, 'zcee2_fileBuildRank')
HashMap<String, String> sortedList = buildUtils.sortBuildListAsMap(updatedBuildList, 'zcee2_fileBuildRank')

int currentBuildFileNumber = 1

// iterate through build list
sortedMap.each { buildFile, inputType ->
println "*** (${currentBuildFileNumber++}/${sortedMap.size()}) Building ${inputType == "PROJECT" ? 'project' : 'properties file'} $buildFile"
sortedList.each { buildFile, inputType ->
println "*** (${currentBuildFileNumber++}/${sortedList.size()}) Building ${inputType == "PROJECT" ? 'project' : 'properties file'} $buildFile"

String parameters = ""
String outputDir = ""
Expand Down Expand Up @@ -122,12 +122,15 @@ sortedMap.each { buildFile, inputType ->
StringBuffer shellOutput = new StringBuffer()
StringBuffer shellError = new StringBuffer()

String JAVA_HOME = props.getFileProperty('zcee2_JAVA_HOME', buildFile)
String javaHome = props.getFileProperty('zcee2_JAVA_HOME', buildFile)
if (!javaHome) {
javaHome = System.getenv("JAVA_HOME")
}

ProcessBuilder cmd = new ProcessBuilder(zconbtPath, parameters);
Map<String, String> env = cmd.environment();
env.put("JAVA_HOME", JAVA_HOME);
env.put("PATH", JAVA_HOME + "/bin" + ";" + env.get("PATH"))
env.put("JAVA_HOME", javaHome);
env.put("PATH", javaHome + "/bin" + ":" + env.get("PATH"))
Process process = cmd.start()
process.consumeProcessOutput(shellOutput, shellError)
process.waitFor()
Expand Down
37 changes: 37 additions & 0 deletions utilities/BuildUtilities.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,43 @@ def sortBuildList(List<String> buildList, String rankPropertyName) {
return sortedList
}

/*
* sortBuildListAsMap - sorts a build List stored as Map by rank property values
*/
def sortBuildListAsMap(HashMap<String, String> buildMap, String rankPropertyName) {
HashMap<String, String> sortedMap = [:]
TreeMap<Integer,HashMap<String, String>> rankings = new TreeMap<Integer,HashMap<String, String>>()
HashMap<String, String> unranked = new HashMap<String, String>()

// sort buildFiles by rank
buildMap.each { buildFile, inputType ->
String rank = props.getFileProperty(rankPropertyName, buildFile)
if (rank) {
Integer rankNum = rank.toInteger()
HashMap<String, String> ranking = rankings.get(rankNum)
if (!ranking) {
ranking = new HashMap<String, String>()
rankings.put(rankNum, ranking)
}
ranking.put(buildFile, inputType)
} else {
unranked.put(buildFile, inputType)
}
}

// loop through rank keys adding sub lists (TreeMap automatically sorts keySet)
rankings.keySet().each { key ->
HashMap<String, String> ranking = rankings.get(key)
if (ranking)
sortedMap.putAll(ranking)
}

// finally add unranked buildFiles
sortedMap.putAll(unranked)

return sortedMap
}

/*
* updateBuildResult - used by language scripts to update the build result after a build step
*/
Expand Down