-
Notifications
You must be signed in to change notification settings - Fork 6
Support for YAML-based Files-To-Types mapping #70
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
504a08a
6ac6a0c
ecea607
009c076
40784a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| files: | ||
| - file: "DBEHM.MIG.COBOL(LGACDB01)" | ||
| types: | ||
| - "CBLCICSDB2" | ||
| properties: | ||
| - name: "COBPARM" | ||
| value: "AMODE(31)" | ||
| - file: "DBEHM.MIG.COBOL(LGACDB02)" | ||
| types: | ||
| - "CBLDB2" | ||
| properties: | ||
| - name: "COBPARM" | ||
| value: "AMODE(31)" | ||
| - file: "DBEHM.MIG.COBOL(LGACUS01)" | ||
| types: | ||
| - "CBLCICS" | ||
| properties: | ||
| - name: "COBPARM" | ||
| value: "AMODE(31)" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,7 +61,7 @@ unassignedApplicationMappingConfiguration.application = "UNASSIGNED" | |
| @Field HashSet<String> filteredApplications = new HashSet<String>() | ||
|
|
||
| // Types Configurations | ||
| @Field HashMap<String, String> types | ||
| @Field ArrayList filesToTypesMapping | ||
| // script properties | ||
| @Field Properties props = new Properties() | ||
| @Field repositoryPathsMapping | ||
|
|
@@ -100,13 +100,9 @@ if (props.REPOSITORY_PATH_MAPPING_FILE) { | |
|
|
||
| // Read the Types from file | ||
| logger.logMessage("** Reading the Type Mapping definition.") | ||
| if (props.APPLICATION_MEMBER_TYPE_MAPPING) { | ||
| def typesFile = new File(props.APPLICATION_MEMBER_TYPE_MAPPING) | ||
| if (!typesFile.exists()) { | ||
| logger.logMessage("*! [WARNING] File ${props.APPLICATION_MEMBER_TYPE_MAPPING} not found in the current working directory. All artifacts will use the 'UNKNOWN' type.") | ||
| } else { | ||
| types = fileUtils.loadTypes(props.APPLICATION_MEMBER_TYPE_MAPPING) | ||
| } | ||
| if (props.APPLICATION_FILES_TYPES_MAPPING) { | ||
| filesToTypesMapping = fileUtils.loadFilesToTypesMapping(props.APPLICATION_FILES_TYPES_MAPPING) | ||
|
||
| println(filesToTypesMapping) | ||
| } else { | ||
| logger.logMessage("*! [WARNING] No Types File provided. The 'UNKNOWN' type will be assigned by default to all artifacts.") | ||
| } | ||
|
|
@@ -286,12 +282,12 @@ def parseArgs(String[] args) { | |
| System.exit(1) | ||
| } | ||
|
|
||
| if (configuration.APPLICATION_MEMBER_TYPE_MAPPING) { | ||
| File file = new File(configuration.APPLICATION_MEMBER_TYPE_MAPPING) | ||
| if (configuration.APPLICATION_FILES_TYPES_MAPPING) { | ||
| File file = new File(configuration.APPLICATION_FILES_TYPES_MAPPING) | ||
| if (file.exists()) { | ||
| props.APPLICATION_MEMBER_TYPE_MAPPING = configuration.APPLICATION_MEMBER_TYPE_MAPPING | ||
| props.APPLICATION_FILES_TYPES_MAPPING = configuration.APPLICATION_FILES_TYPES_MAPPING | ||
| } else { | ||
| logger.logMessage("*! [ERROR] The Types file '${configuration.APPLICATION_MEMBER_TYPE_MAPPING}' does not exist. Exiting.") | ||
| logger.logMessage("*! [ERROR] The Types file '${configuration.APPLICATION_FILES_TYPES_MAPPING}' does not exist. Exiting.") | ||
| System.exit(1) | ||
| } | ||
| } | ||
|
|
@@ -393,7 +389,7 @@ def generateApplicationFiles(ApplicationMappingConfiguration applicationConfigur | |
| (scannedLanguage, scannedFileType) = scanDatasetMember(constructDatasetForZFileOperation(dataset, member)) | ||
| } | ||
| def lastQualifier = getLastQualifier(dataset) | ||
| def memberType = fileUtils.getType(types, member.toUpperCase()) | ||
| def memberType = fileUtils.getType(filesToTypesMapping, datasetMember) | ||
|
||
| // Identifying the matching Repository Path | ||
| // based on 1) the scan result if enabled | ||
| // 2) the type if set | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,36 +15,26 @@ import groovy.cli.commons.* | |
|
|
||
|
|
||
| // Reads a HashMap from the MEMBER_TYPE_MAPPING file with comma separator (',') and returns it | ||
| def loadTypes(String APPLICATION_MEMBER_TYPE_MAPPING) { | ||
| HashMap<String, String> types = new HashMap<>(); | ||
| String line; | ||
| File applicationMemberTypeMappingFile = new File(APPLICATION_MEMBER_TYPE_MAPPING) | ||
| if (!applicationMemberTypeMappingFile.exists()) { | ||
| logger.logMessage("*! [WARNING] The Application Member Type Mapping file $APPLICATION_MEMBER_TYPE_MAPPING was not found. Exiting.") | ||
| System.exit(1) | ||
| def loadFilesToTypesMapping(String APPLICATION_FILES_TYPES_MAPPING) { | ||
| File filesToTypeMappingFile = new File(APPLICATION_FILES_TYPES_MAPPING) | ||
| if (!filesToTypeMappingFile.exists()) { | ||
| logger.logMessage("*! [WARNING] The Files to Types Mapping file '$APPLICATION_FILES_TYPES_MAPPING' was not found. Exiting.") | ||
| return null | ||
| } else { | ||
| def yamlSlurper = new groovy.yaml.YamlSlurper() | ||
| applicationMemberTypeMappingFile.withReader("UTF-8") { reader -> | ||
| while ((line = reader.readLine()) != null) { | ||
| String[] keyValuePair = line.split(",", 2); | ||
| if (keyValuePair.length > 1) { | ||
| String key = keyValuePair[0].trim().toUpperCase(); | ||
| String value = keyValuePair[1].trim().replaceAll(" ", ""); | ||
| types.put(key, value); | ||
| } | ||
| } | ||
| } | ||
| return yamlSlurper.parse(filesToTypeMappingFile).files | ||
| } | ||
| return types | ||
| } | ||
|
|
||
| def getType(HashMap<String, String> types, String member) { | ||
| if (!types) { | ||
| def getType(ArrayList filesToTypes, String file) { | ||
| if (!filesToTypes) { | ||
| return "UNKNOWN" | ||
| } else { | ||
| def type = types.get(member) | ||
| if (type) { | ||
| return type | ||
| def foundFile = filesToTypes.find { fileToTypes -> | ||
|
||
| fileToTypes.file.equalsIgnoreCase(file) | ||
| } | ||
| if (foundFile) { | ||
| return foundFile.types.toString().replaceAll("\\[", "").replaceAll("\\]", "").replaceAll(" ", "") | ||
|
||
| } else { | ||
| return "UNKNOWN" | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have the
applicationsMapping.yaml, should the default file name be probablytypesMapping.yaml. This would also fit with thetypesConfiguration.yamlfile.