IBM / dbb-zappbuild

zAppBuild is a generic build solution for building z/OS applications using Apache Groovy build scripts and IBM Dependency Based Build (DBB) APIs.
Apache License 2.0
40 stars 124 forks source link

Enhancement - Limit site impacts on the getLangPrefix function of the BuildUtilities.groovy script #396

Closed FALLAI-Denis closed 10 months ago

FALLAI-Denis commented 11 months ago

Hi,

The BuildUtilities.groovy script declares the getLangPrefix(String scriptName) function which is used by various functions. This function tries to determine the language from the name of the language script.

/*
 * returns languagePrefix for language script name or null if not defined.
 */
def getLangPrefix(String scriptName){
    def langPrefix = null
    switch(scriptName) {
        case "Cobol.groovy":
            langPrefix = 'cobol'
            break;
        case "LinkEdit.groovy" :
            langPrefix = 'linkedit'
            break;
        case "PLI.groovy":
            langPrefix = 'pli'
            break;
        case "Assembler.groovy":
            langPrefix = 'assembler'
            break;
        case "BMS.groovy":
            langPrefix = 'bms'
            break;
        case "DBDgen.groovy":
            langPrefix = 'dbdgen'
            break;
        case "MFS.groovy":
            langPrefix = 'mfs'
            break;
        case "PSBgen.groovy":
            langPrefix = 'psbgen'
            break;
        default:
            if (props.verbose) println ("*** ! No language prefix defined for $scriptName.")
            break;
    }
    return langPrefix
}

We made the choice not to modify the zAppbuild language scripts, but each time to duplicate them when we want to make a specific version to our context. This has an impact on the getLangPrefix function and as it stands forces us to modify the BuildUtilities.groovy script, which we would like to avoid...

We have chosen to suffix the name of the standard language script to create a new script. Example: CobolXXXX.groovy to replace Cobol.groovy. Maybe we should have named them <language>_XXXX.groovy...

To avoid having to modify the getLangPrefix function, it should not test the full name of the language script, but only part of it.

In a naming plan of the form <language>XXXX.groovy, you should test with the startWith() function:

if scriptName.startsWith('Cobol')...
if scriptName.startsWith('LinkEditCobol')...
...

In a naming scheme of the form <language>_XXXX.groovy, the script name should be cut on the separator character, then test the part bearing the name of the language:

language = scriptName.takeWhile{it != '.' && it != '_'}
switch (language) {
   case 'Cobol':
     langPrefix = 'cobol'
   case 'LinkEdit':
     langPrefix = 'linkedit'

Or in an even simpler way, because langPrefix is always the suffix used by scritp language:

langPrefix = scriptName.takeWhile{it != '.' && it != '_'}.toLowerCase()

In short, it would seem useful to us to define a standard for naming custom language scripts and to modify the zAppbuild functions to take this standard into account and not to have to modify them on site.

Thanks.

dennis-behm commented 11 months ago

@FALLAI-Denis, as you know we also accept a pull request from zAppBuild users :-)

Yes, fetching the prefix from the language script name might be the most flexible one to implement.

dennis-behm commented 10 months ago

Delivered via zAppBuild Release 3.4.0 (#392). Feedback welcome via #410