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
Changes from 1 commit
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
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
}

/*
* sortBuildMap - sorts a build Map by rank property values
*/
def sortBuildMap(HashMap<String, String> buildMap, String rankPropertyName) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we call this sortBuildListMap ?

Build Map is a reserved term, and might be confusing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, did the changes accordingly.

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