diff --git a/Setup.sh b/Setup.sh index 37eb90b..dcb0551 100755 --- a/Setup.sh +++ b/Setup.sh @@ -39,8 +39,7 @@ DBB_MODELER_HOME=$(cd "$(dirname "$0")" && pwd) export MigrationModelerRelease=`cat $DBB_MODELER_HOME/release.properties | awk -F '=' '{printf $2}'` Prolog -if [ "$DBB_HOME" = "" ] -then +if [ "$DBB_HOME" = "" ]; then echo "[ERROR] Environment variable DBB_HOME is not set. Exiting." exit 1 fi @@ -52,7 +51,7 @@ echo "[SETUP] Configuring DBB Git Migration Modeler environment variables" DBB_MODELER_WORK="${DBB_MODELER_HOME}-work" read -p "Specify the DBB Git Migration Modeler work directory [default: $DBB_MODELER_WORK]: " variable if [ "$variable" ]; then - DBB_MODELER_WORK="${variable}" + DBB_MODELER_WORK="${variable}" fi # Default environment variables @@ -114,6 +113,9 @@ ARTIFACT_REPOSITORY_USER=user # Password to connect to the Artifact Repository Server # e.q.: ARTIFACT_REPOSITORY_PASSWORD=xxxxx ARTIFACT_REPOSITORY_PASSWORD=password +# Artifact repository naming suffix +# e.q.: +ARTIFACT_REPOSITORY_SUFFIX=zos-local # User ID of the pipeline user PIPELINE_USER=ADO @@ -121,13 +123,13 @@ PIPELINE_USER=ADO PIPELINE_USER_GROUP=JENKINSG # Pipeline technology used # Either '1' for 'AzureDevOps', '2' for 'GitlabCI', '3' for 'Jenkins' or '4' for 'GitHubActions' -# The parameter will then be translated later in the process to its final value +# The parameter will then be translated later in the process to its final value # as defined in the Templates folder of the DBB Community repo (without the 'Pipeline' suffix) PIPELINE_CI=1 # Arrays for configuration parameters, that will the Setup script will prompt the user for path_config_array=(DBB_MODELER_APPCONFIG_DIR DBB_MODELER_APPLICATION_DIR DBB_MODELER_LOGS DBB_MODELER_DEFAULT_GIT_CONFIG) -input_array=(DBB_MODELER_APPMAPPINGS_DIR REPOSITORY_PATH_MAPPING_FILE APPLICATION_MEMBER_TYPE_MAPPING TYPE_CONFIGURATIONS_FILE APPLICATION_ARTIFACTS_HLQ SCAN_DATASET_MEMBERS SCAN_DATASET_MEMBERS_ENCODING DBB_ZAPPBUILD DBB_COMMUNITY_REPO APPLICATION_DEFAULT_BRANCH INTERACTIVE_RUN PUBLISH_ARTIFACTS ARTIFACT_REPOSITORY_SERVER_URL ARTIFACT_REPOSITORY_USER ARTIFACT_REPOSITORY_PASSWORD PIPELINE_USER PIPELINE_USER_GROUP) +input_array=(DBB_MODELER_APPMAPPINGS_DIR REPOSITORY_PATH_MAPPING_FILE APPLICATION_MEMBER_TYPE_MAPPING TYPE_CONFIGURATIONS_FILE APPLICATION_ARTIFACTS_HLQ SCAN_DATASET_MEMBERS SCAN_DATASET_MEMBERS_ENCODING DBB_ZAPPBUILD DBB_COMMUNITY_REPO APPLICATION_DEFAULT_BRANCH INTERACTIVE_RUN PUBLISH_ARTIFACTS ARTIFACT_REPOSITORY_SERVER_URL ARTIFACT_REPOSITORY_USER ARTIFACT_REPOSITORY_PASSWORD ARTIFACT_REPOSITORY_SUFFIX PIPELINE_USER PIPELINE_USER_GROUP) # Create work dir echo @@ -142,16 +144,6 @@ if [[ -z "$variable" || $variable =~ ^[Yy]$ ]]; then else mkdir -p $DBB_MODELER_WORK rc=$? - - if [ $rc -eq 0 ]; then - if [ ! -d "${DBB_MODELER_DEFAULT_GIT_CONFIG}" ]; then - mkdir -p $DBB_MODELER_DEFAULT_GIT_CONFIG - fi - - cp $DBB_MODELER_HOME/samples/git-config/* $DBB_MODELER_DEFAULT_GIT_CONFIG/ - cp $DBB_MODELER_HOME/samples/git-config/.* $DBB_MODELER_DEFAULT_GIT_CONFIG/ - rc=$? - fi fi fi @@ -163,7 +155,7 @@ if [ $rc -eq 0 ]; then if [ "$variable" ]; then declare DBB_MODELER_METADATASTORE_TYPE="${variable}" fi - + if [ "$DBB_MODELER_METADATASTORE_TYPE" = "file" ]; then read -p "Specify the location of the DBB File Metadatastore [default: ${DBB_MODELER_FILE_METADATA_STORE_DIR}]: " variable if [ "$variable" ]; then @@ -192,8 +184,8 @@ if [ $rc -eq 0 ]; then echo "[ERROR] Either the Db2 JDBC User Password or the Db2 JDBC Password File must be specified. Exiting." rm -rf $DBB_MODELER_WORK exit 1 - fi - fi + fi + fi fi if [ $rc -eq 0 ]; then @@ -226,10 +218,10 @@ if [ $rc -eq 0 ]; then "4") PIPELINE_CI="GitHubActions" ;; - esac + esac echo - echo "[SETUP] Copying DBB Git Migration Modeler configuration files to '$DBB_MODELER_WORK'" + echo "[SETUP] Copying DBB Git Migration Modeler sample configuration files to '$DBB_MODELER_WORK'" if [ ! -d "${DBB_MODELER_APPMAPPINGS_DIR}" ]; then mkdir -p $DBB_MODELER_APPMAPPINGS_DIR rc=$? @@ -247,7 +239,16 @@ if [ $rc -eq 0 ]; then rc=$? fi if [ $rc -eq 0 ]; then - cp $DBB_MODELER_HOME/samples/typesConfigurations.yaml $TYPE_CONFIGURATIONS_FILE + cp $DBB_MODELER_HOME/samples/typesConfigurations.yaml $TYPE_CONFIGURATIONS_FILE + rc=$? + fi + if [ $rc -eq 0 ]; then + if [ ! -d "${DBB_MODELER_DEFAULT_GIT_CONFIG}" ]; then + mkdir -p $DBB_MODELER_DEFAULT_GIT_CONFIG + fi + + cp $DBB_MODELER_HOME/samples/git-config/* $DBB_MODELER_DEFAULT_GIT_CONFIG/ + cp $DBB_MODELER_HOME/samples/git-config/.* $DBB_MODELER_DEFAULT_GIT_CONFIG/ rc=$? fi fi @@ -267,7 +268,7 @@ fi if [ $rc -eq 0 ]; then DBB_GIT_MIGRATION_MODELER_CONFIG_FILE="${CONFIG_DIR}/DBB_GIT_MIGRATION_MODELER.config" touch $DBB_GIT_MIGRATION_MODELER_CONFIG_FILE - chtag -tc IBM-1047 $DBB_GIT_MIGRATION_MODELER_CONFIG_FILE + chtag -tc IBM-1047 $DBB_GIT_MIGRATION_MODELER_CONFIG_FILE echo "# DBB Git Migration Modeler configuration settings" > $DBB_GIT_MIGRATION_MODELER_CONFIG_FILE echo "# Generated at $(date)" >> $DBB_GIT_MIGRATION_MODELER_CONFIG_FILE @@ -303,15 +304,15 @@ if [ $rc -eq 0 ]; then echo "This DBB Git Migration Modeler configuration file will be imported by the DBB Git Migration Modeler process." echo if [ "$DBB_MODELER_METADATASTORE_TYPE" = "db2" ]; then - ## Checking DBB Toolkit version + ## Checking DBB Toolkit version CURRENT_DBB_TOOLKIT_VERSION=`$DBB_MODELER_HOME/src/scripts/utils/0-environment.sh -c $DBB_GIT_MIGRATION_MODELER_CONFIG_FILE -v 3.0.1` - rc=$? + rc=$? if [ $rc -ne 0 ]; then rc=8 echo "[ERROR] The DBB Toolkit's version is $CURRENT_DBB_TOOLKIT_VERSION. To use the Db2-based MetadataStore, the minimal recommended version for the DBB Toolkit is 3.0.1." fi else - ## Checking DBB Toolkit version + ## Checking DBB Toolkit version CURRENT_DBB_TOOLKIT_VERSION=`$DBB_MODELER_HOME/src/scripts/utils/0-environment.sh -c $DBB_GIT_MIGRATION_MODELER_CONFIG_FILE -v 2.0.2` rc=$? if [ $rc -ne 0 ]; then @@ -325,7 +326,7 @@ if [ $rc -eq 0 ]; then echo "********************************************* SUGGESTED ACTION *********************************************" echo "Check the successful configuration and access to the Db2-based MetadataStore with the following command:" echo "'$DBB_MODELER_HOME/src/scripts/CheckDb2MetadataStore.sh -c $DBB_GIT_MIGRATION_MODELER_CONFIG_FILE'" - fi + fi echo echo "********************************************* SUGGESTED ACTION *********************************************" echo "Tailor the following input files prior to using the DBB Git Migration Modeler:" diff --git a/schema/application-descriptor-schema.json b/schema/application-descriptor-schema.json index 09b80bb..d21d461 100644 --- a/schema/application-descriptor-schema.json +++ b/schema/application-descriptor-schema.json @@ -124,9 +124,26 @@ "type": "string", "description": "Branch name for which the baseline is set" }, - "baseline": { + "type": { + "type": "string", + "title": "The type of build of the baseline archive.", + "description": "Type of build of the baseline archive.", + "default": "release", + "enum": [ + "release", + "build" + ] + }, + "reference": { "type": "string", - "description": "Baseline reference for the given branch" + "title": "The reference of the baseline archive.", + "description": "In case of a release build, the release identifier reference like rel-2.1.0. Or a preliminary build reference by indicating the branch name from where the archive is derived." + } + , + "buildid": { + "type": "string", + "title": "The build identifier of the baseline archive.", + "description": "The unique identifier of the archive." } } } @@ -145,23 +162,31 @@ }, "type": { "type": "string", - "title": "The location of the dependency.", - "description": "Location from where the dependency is fetched.", - "default": "artifactrepository", + "title": "The type of build of the dependent archive.", + "description": "Type of build of the dependent archive.", + "default": "release", "enum": [ - "artifactrepository" + "release", + "build" ] }, - "version": { + "reference": { + "type": "string", + "title": "The reference of the dependency.", + "description": "In case of a release build, the release identifier reference like rel-2.1.0. Or a preliminary build reference by indicating the branch name from where the archive is derived." + } + , + "buildid": { "type": "string", - "title": "The version of the dependency.", - "description": "Can either be a release version including the unique identifier of the build or a preliminary package." + "title": "The build identifier of the dependent application archive.", + "description": "The unique identifier of the archive." } }, "required": [ "name", "type", - "version" + "reference", + "buildid" ] } }, diff --git a/src/groovy/assessUsage.groovy b/src/groovy/assessUsage.groovy index e284591..8f5a4f3 100644 --- a/src/groovy/assessUsage.groovy +++ b/src/groovy/assessUsage.groovy @@ -387,6 +387,13 @@ def parseArgs(String[] args) { logger.logMessage("*! [ERROR] The type of MetadataStore (file or db2) must be specified in the DBB Git Migration Modeler Configuration file. Exiting.") System.exit(1) } + + if (configuration.APPLICATION_DEFAULT_BRANCH) { + props.APPLICATION_DEFAULT_BRANCH = configuration.APPLICATION_DEFAULT_BRANCH + } else { + logger.logMessage("*! [ERROR] The default branch name setting APPLICATION_DEFAULT_BRANCH must be specified in the DBB Git Migration Modeler Configuration file. Exiting.") + System.exit(1) + } if (props.DBB_MODELER_METADATASTORE_TYPE.equals("file")) { if (configuration.DBB_MODELER_FILE_METADATA_STORE_DIR) { @@ -457,8 +464,11 @@ def updateConsumerApplicationDescriptor(consumer, dependencyType, providerApplic } } // Consumer's Application Descriptor file has been found and can be updated - if (consumerApplicationDescriptor) { - applicationDescriptorUtils.addApplicationDependency(consumerApplicationDescriptor, providerApplicationDescriptor.application, "latest", dependencyType) + if (consumerApplicationDescriptor) { // fetch the internal baseline that is added + providerInternalBaseline=providerApplicationDescriptor.baselines.find() { baselineDefinition -> + baselineDefinition.branch.equals(props.APPLICATION_DEFAULT_BRANCH) + } + applicationDescriptorUtils.addApplicationDependency(consumerApplicationDescriptor, providerApplicationDescriptor.application, providerInternalBaseline.reference , providerInternalBaseline.buildid ) applicationDescriptorUtils.writeApplicationDescriptor(consumerApplicationDescriptorFile, consumerApplicationDescriptor) } // update provider's Application Descriptor diff --git a/src/groovy/extractApplications.groovy b/src/groovy/extractApplications.groovy index e5a84e0..086f4df 100644 --- a/src/groovy/extractApplications.groovy +++ b/src/groovy/extractApplications.groovy @@ -337,14 +337,14 @@ def generateApplicationFiles(String application) { applicationDescriptor.description = foundApplication.description applicationDescriptor.owner = foundApplication.owner // Adding baseline to ApplicationDescriptor - applicationDescriptorUtils.addBaseline(applicationDescriptor, "main" as String, foundApplication.baseline) - applicationDescriptorUtils.addBaseline(applicationDescriptor, "release/${foundApplication.baseline}" as String, foundApplication.baseline) + applicationDescriptorUtils.addBaseline(applicationDescriptor, "main", "release", foundApplication.baseline) + applicationDescriptorUtils.addBaseline(applicationDescriptor, "release/${foundApplication.baseline}", "release", foundApplication.baseline) } else { applicationDescriptor.application = "UNASSIGNED" applicationDescriptor.description = "Unassigned components" applicationDescriptor.owner = "None" - applicationDescriptorUtils.addBaseline(applicationDescriptor, "main" as String, "rel-1.0.0" as String) - applicationDescriptorUtils.addBaseline(applicationDescriptor, "release/rel-1.0.0" as String, "rel-1.0.0" as String) + applicationDescriptorUtils.addBaseline(applicationDescriptor, "main", "release", "rel-1.0.0") + applicationDescriptorUtils.addBaseline(applicationDescriptor, "release/rel-1.0.0", "release", "rel-1.0.0") } // Main loop, iterating through the dataset members assigned to the current application diff --git a/src/groovy/utils/applicationDescriptorUtils.groovy b/src/groovy/utils/applicationDescriptorUtils.groovy index 5594ec4..30ce6e4 100644 --- a/src/groovy/utils/applicationDescriptorUtils.groovy +++ b/src/groovy/utils/applicationDescriptorUtils.groovy @@ -12,165 +12,170 @@ import groovy.util.* import java.nio.file.* /** - * Utilities to read, update or export existing ApplicationDescriptor from/to YAML + * Utilities to read, update or export existing ApplicationDescriptor from/to YAML */ class ApplicationDescriptor { - String application - String schemaVersion = "applicationDescriptor/0.11.0" - String description - String owner - ArrayList sources - ArrayList baselines - ArrayList dependencies - ArrayList consumers + String application + String schemaVersion = "applicationDescriptor/0.11.0" + String description + String owner + ArrayList sources + ArrayList baselines + ArrayList dependencies + ArrayList consumers } class Source { - String name - String repositoryPath - String language - String languageProcessor - String fileExtension - String artifactsType - ArrayList files + String name + String repositoryPath + String language + String languageProcessor + String fileExtension + String artifactsType + ArrayList files } class FileDef { - String name - String type - String usage + String name + String type + String usage } class Baseline { - String branch - String baseline + String branch + String type + String reference + String buildid } class DependencyDescriptor { - String name - String version - String type + String name + String type + String reference + String buildid } class Consumer { - String name + String name } /** - * + * * Reads an existing application descriptor YAML * returns an ApplicationDescriptor Object - * + * */ def readApplicationDescriptor(File yamlFile) { - // Internal objects - def yamlSlurper = new groovy.yaml.YamlSlurper() - ApplicationDescriptor applicationDescriptor = yamlSlurper.parse(yamlFile) - return applicationDescriptor + // Internal objects + def yamlSlurper = new groovy.yaml.YamlSlurper() + ApplicationDescriptor applicationDescriptor = yamlSlurper.parse(yamlFile) + return applicationDescriptor } /** * Write an ApplicationDescriptor Object into a YAML file */ def writeApplicationDescriptor(File yamlFile, ApplicationDescriptor applicationDescriptor) { - // Sort source groups and files by name before writing to YAML file - if (applicationDescriptor.sources) { - applicationDescriptor.sources.sort { - it.name - } - applicationDescriptor.sources.each() { source -> - source.files.sort { - it.name - } - } - } - - def yamlBuilder = new YamlBuilder() - // build updated application descriptor - - yamlBuilder { - application applicationDescriptor.application - schemaVersion applicationDescriptor.schemaVersion - description applicationDescriptor.description - owner applicationDescriptor.owner - sources (applicationDescriptor.sources) - baselines (applicationDescriptor.baselines) - if (applicationDescriptor.dependencies) { - dependencies applicationDescriptor.dependencies - } - if (applicationDescriptor.consumers) { - consumers applicationDescriptor.consumers - } - } - - // write file - yamlFile.withWriter("IBM-1047") { writer -> - writer.write(yamlBuilder.toString()) - } - + // Sort source groups and files by name before writing to YAML file + if (applicationDescriptor.sources) { + applicationDescriptor.sources.sort { + it.name + } + applicationDescriptor.sources.each() { source -> + source.files.sort { + it.name + } + } + } + + def yamlBuilder = new YamlBuilder() + // build updated application descriptor + + yamlBuilder { + application applicationDescriptor.application + schemaVersion applicationDescriptor.schemaVersion + description applicationDescriptor.description + owner applicationDescriptor.owner + sources (applicationDescriptor.sources) + baselines (applicationDescriptor.baselines) + if (applicationDescriptor.dependencies) { + dependencies applicationDescriptor.dependencies + } + if (applicationDescriptor.consumers) { + consumers applicationDescriptor.consumers + } + } + + // write file + yamlFile.withWriter("IBM-1047") { writer -> + writer.write(yamlBuilder.toString()) + } Process process = "chtag -tc IBM-1047 ${yamlFile.getAbsolutePath()}".execute() - process.waitFor() + process.waitFor() } /** * Method to update the Application Descriptor - * + * * Appends to an existing source sourceGroupName, if it exists. * If the sourceGroupName cannot be found, it creates a new sourceGroup - * + * */ def appendFileDefinition(ApplicationDescriptor applicationDescriptor, String sourceGroupName, - String language, String languageProcessor, String artifactsType, - String fileExtension, String repositoryPath, String name, - String type, String usage) { - - def sourceGroupRecord - - def fileRecord = new FileDef() - fileRecord.name = name - fileRecord.type = type - fileRecord.usage = usage - - if (!applicationDescriptor.sources) { - applicationDescriptor.sources = new ArrayList() - } - - existingSourceGroup = applicationDescriptor.sources.find(){ source -> - source.name == sourceGroupName - } - - if (existingSourceGroup) { // append file record definition to existing sourceGroup - sourceGroupRecord = existingSourceGroup - - // check if the fileRecord already exists, and this is an update - - existingFileRecord = sourceGroupRecord.files.find(){ file -> - file.name == fileRecord.name - } - - if (existingFileRecord) { // update existing file record - existingFileRecord.type = type - existingFileRecord.usage = usage - } else { // add a new record - sourceGroupRecord.files.add(fileRecord) - } + String language, String languageProcessor, String artifactsType, + String fileExtension, String repositoryPath, String name, + String type, String usage) { + + def sourceGroupRecord + + def fileRecord = new FileDef() + fileRecord.name = name + fileRecord.type = type + fileRecord.usage = usage + + if (!applicationDescriptor.sources) { + applicationDescriptor.sources = new ArrayList() + } + + existingSourceGroup = applicationDescriptor.sources.find(){ source -> + source.name == sourceGroupName + } + + if (existingSourceGroup) { + // append file record definition to existing sourceGroup + sourceGroupRecord = existingSourceGroup + + // check if the fileRecord already exists, and this is an update + + existingFileRecord = sourceGroupRecord.files.find(){ file -> + file.name == fileRecord.name + } + + if (existingFileRecord) { + // update existing file record + existingFileRecord.type = type + existingFileRecord.usage = usage + } else { + // add a new record + sourceGroupRecord.files.add(fileRecord) + } } else { - // create a new source group entry - sourceGroupRecord = new Source() - sourceGroupRecord.name = sourceGroupName - sourceGroupRecord.language = language - sourceGroupRecord.languageProcessor = languageProcessor - sourceGroupRecord.fileExtension = fileExtension - sourceGroupRecord.artifactsType = artifactsType - sourceGroupRecord.repositoryPath = repositoryPath - - sourceGroupRecord.files = new ArrayList() - // append file record - sourceGroupRecord.files.add(fileRecord) - applicationDescriptor.sources.add(sourceGroupRecord) - } + // create a new source group entry + sourceGroupRecord = new Source() + sourceGroupRecord.name = sourceGroupName + sourceGroupRecord.language = language + sourceGroupRecord.languageProcessor = languageProcessor + sourceGroupRecord.fileExtension = fileExtension + sourceGroupRecord.artifactsType = artifactsType + sourceGroupRecord.repositoryPath = repositoryPath + + sourceGroupRecord.files = new ArrayList() + // append file record + sourceGroupRecord.files.add(fileRecord) + applicationDescriptor.sources.add(sourceGroupRecord) + } } @@ -180,43 +185,46 @@ def appendFileDefinition(ApplicationDescriptor applicationDescriptor, String sou def removeFileDefinition(ApplicationDescriptor applicationDescriptor, String sourceGroupName, String name) { - if (applicationDescriptor.sources) { - def existingSourceGroup = applicationDescriptor.sources.find() { source -> - source.name == sourceGroupName - } - if (existingSourceGroup) { // Found an existing Source Group that matches - def existingFileDef = existingSourceGroup.files.find { file -> - file.name.equals(name) - } - if (existingFileDef) { -// println "Found matching file ${existingFileDef.name}" - existingSourceGroup.files.remove(existingFileDef) - } - } - } + if (applicationDescriptor.sources) { + def existingSourceGroup = applicationDescriptor.sources.find() { source -> + source.name == sourceGroupName + } + if (existingSourceGroup) { + // Found an existing Source Group that matches + def existingFileDef = existingSourceGroup.files.find { file -> + file.name.equals(name) + } + if (existingFileDef) { + // println "Found matching file ${existingFileDef.name}" + existingSourceGroup.files.remove(existingFileDef) + } + } + } } /** - * Method to add an application dependency + * Method to add an application dependency */ -def addApplicationDependency(ApplicationDescriptor applicationDescriptor, String applicationDependency, String version, String type) { - if (!applicationDescriptor.dependencies) { - applicationDescriptor.dependencies = new ArrayList() - } - def existingDependencies = applicationDescriptor.dependencies.findAll() { - it.name.equals(applicationDependency) & it.type.equals(type) - } - if (!existingDependencies) { - def dependency = new DependencyDescriptor() - dependency.name = applicationDependency - dependency.version = version - dependency.type = type - applicationDescriptor.dependencies.add(dependency) - applicationDescriptor.dependencies.sort { - it.name - } - } +def addApplicationDependency(ApplicationDescriptor applicationDescriptor, String applicationDependency, String reference, String buildid) { + if (!applicationDescriptor.dependencies) { + applicationDescriptor.dependencies = new ArrayList() + } + // skip readding same/similar entries + def existingDependencies = applicationDescriptor.dependencies.findAll() { + it.name.equals(applicationDependency) + } + if (!existingDependencies) { + def dependency = new DependencyDescriptor() + dependency.name = applicationDependency + dependency.type = "release" // hard-coded + dependency.reference = reference + dependency.buildid = buildid + applicationDescriptor.dependencies.add(dependency) + applicationDescriptor.dependencies.sort { + it.name + } + } } /** @@ -224,22 +232,22 @@ def addApplicationDependency(ApplicationDescriptor applicationDescriptor, String */ def addApplicationConsumer(ApplicationDescriptor applicationDescriptor, String consumingApplication) { - - if (!applicationDescriptor.consumers) { - applicationDescriptor.consumers = new ArrayList() - } - // don't add the "owning" application - if (applicationDescriptor.application != consumingApplication) { - def existingConsumers = applicationDescriptor.consumers.findAll() { - it.name.equals(consumingApplication) - } - if (!existingConsumers) { - Consumer consumer = new Consumer() - consumer.name = consumingApplication - applicationDescriptor.consumers.add(consumer) - applicationDescriptor.consumers.sort() - } - } + + if (!applicationDescriptor.consumers) { + applicationDescriptor.consumers = new ArrayList() + } + // don't add the "owning" application + if (applicationDescriptor.application != consumingApplication) { + def existingConsumers = applicationDescriptor.consumers.findAll() { + it.name.equals(consumingApplication) + } + if (!existingConsumers) { + Consumer consumer = new Consumer() + consumer.name = consumingApplication + applicationDescriptor.consumers.add(consumer) + applicationDescriptor.consumers.sort() + } + } } /** @@ -247,7 +255,7 @@ def addApplicationConsumer(ApplicationDescriptor applicationDescriptor, String c */ def resetAllSourceGroups(ApplicationDescriptor applicationDescriptor) { - applicationDescriptor.sources = new ArrayList() + applicationDescriptor.sources = new ArrayList() } /** @@ -255,18 +263,18 @@ def resetAllSourceGroups(ApplicationDescriptor applicationDescriptor) { */ def resetConsumersAndDependencies(ApplicationDescriptor applicationDescriptor) { - applicationDescriptor.consumers = new ArrayList() - applicationDescriptor.dependencies = new ArrayList() + applicationDescriptor.consumers = new ArrayList() + applicationDescriptor.dependencies = new ArrayList() } /** - * Method to create an empty application descriptor object + * Method to create an empty application descriptor object */ def createEmptyApplicationDescriptor() { - ApplicationDescriptor applicationDescriptor = new ApplicationDescriptor() - applicationDescriptor.sources = new ArrayList() - applicationDescriptor.baselines = new ArrayList() - return applicationDescriptor + ApplicationDescriptor applicationDescriptor = new ApplicationDescriptor() + applicationDescriptor.sources = new ArrayList() + applicationDescriptor.baselines = new ArrayList() + return applicationDescriptor } /** @@ -288,8 +296,11 @@ def getFileUsage(ApplicationDescriptor applicationDescriptor, String sourceGroup if (matchingFiles) { if (matchingFiles.size() == 1) { return matchingFiles[0].usage + } else if (matchingFiles.size() > 1) { + println("*! [WARNING] Multiple files found matching '${name}'. Skipping search.") + return null } else { - println("*! [WARNING] Multiple Files found matching '${name}'. Skipping search.") + println("*! [WARNING] No file found matching '${name}'. Skipping search.") return null } } else { @@ -308,7 +319,44 @@ def getFileUsage(ApplicationDescriptor applicationDescriptor, String sourceGroup } /** - * Method to return an ArraList that contains relative Paths + * Method to return a FileDef that matches what we are looking for + * Return null if nothing is found + * Return null if multiple entries are found (for artifactsType or files) with a warning message + */ + +def getFileUsageByType(ApplicationDescriptor applicationDescriptor, String artifactsType, String name) { + if (applicationDescriptor) { + def matchingSourceGroups = applicationDescriptor.sources.findAll() { matchingSourceGroup -> + matchingSourceGroup.artifactsType.equals(artifactsType) + } + if (matchingSourceGroups) { + def allMatchingFiles = new ArrayList() + matchingSourceGroups.each { matchingSourceGroup -> + def matchingFiles = matchingSourceGroup.files.findAll() { matchingFile -> + matchingFile.name.equalsIgnoreCase(name) + } + allMatchingFiles.addAll(matchingFiles) + } + if (allMatchingFiles.size() == 1) { + return allMatchingFiles[0].usage + } else if (allMatchingFiles.size() > 1) { + println("*! [WARNING] Multiple files found matching '${name}'. Skipping search.") + return null + } else { + println("*! [WARNING] No file found matching '${name}'. Skipping search.") + return null + } + } else { + return null + } + } else { + return null + } +} + + +/** + * Method to return an ArrayList that contains relative Paths * to public & shared include files */ @@ -338,24 +386,26 @@ def getFilesByTypeAndUsage(ApplicationDescriptor applicationDescriptor, String a } /** - * Method to add a baseline + * Method to add a baseline * If an existing baseline for a given branch already exists, the method replaces it */ -def addBaseline(ApplicationDescriptor applicationDescriptor, String branch, String baseline) { +def addBaseline(ApplicationDescriptor applicationDescriptor, String branch, String type, String reference) { if (applicationDescriptor.baselines) { def existingBaselines = applicationDescriptor.baselines.findAll() { baselineDefinition -> baselineDefinition.branch.equals(branch) } existingBaselines.forEach() { existingBaseline -> applicationDescriptor.baselines.remove(existingBaseline) - } + } } else { applicationDescriptor.baselines = new ArrayList() } Baseline newBaseline = new Baseline() newBaseline.branch = branch - newBaseline.baseline = baseline + newBaseline.type = type + newBaseline.reference = reference + newBaseline.buildid = "baseline" // hard-coded default identifier applicationDescriptor.baselines.add(newBaseline) -} +} \ No newline at end of file diff --git a/src/scripts/utils/5-initApplicationRepositories.sh b/src/scripts/utils/5-initApplicationRepositories.sh index 1ecbe8c..49bd2e6 100755 --- a/src/scripts/utils/5-initApplicationRepositories.sh +++ b/src/scripts/utils/5-initApplicationRepositories.sh @@ -275,7 +275,7 @@ if [ $rc -eq 0 ]; then # mkdir application log directory mkdir -p $DBB_MODELER_LOGS/$applicationDir - version=`cat $DBB_MODELER_APPLICATION_DIR/$applicationDir/applicationDescriptor.yml | grep -A 1 "branch: \"${APPLICATION_DEFAULT_BRANCH}\"" | tail -1 | awk -F ':' {'printf $2'} | sed "s/[\" ]//g"` + version=`cat $DBB_MODELER_APPLICATION_DIR/$applicationDir/applicationDescriptor.yml | grep -A 2 "branch: \"${APPLICATION_DEFAULT_BRANCH}\"" | tail -1 | awk -F ':' {'printf $2'} | sed "s/[\" ]//g"` if [ -z ${version} ]; then version="rel-1.0.0" fi @@ -285,14 +285,15 @@ if [ $rc -eq 0 ]; then --addExtension \ --branch $APPLICATION_DEFAULT_BRANCH \ --version $version \ - --tarFileName $applicationDir-$version.tar \ + --tarFileName $applicationDir-$version-baseline.tar \ --applicationFolderPath $DBB_MODELER_APPLICATION_DIR/$applicationDir \ --owner $PIPELINE_USER:$PIPELINE_USER_GROUP" if [ "$PUBLISH_ARTIFACTS" == "true" ]; then CMD="${CMD} -p --artifactRepositoryUrl $ARTIFACT_REPOSITORY_SERVER_URL \ --artifactRepositoryUser $ARTIFACT_REPOSITORY_USER \ --artifactRepositoryPassword $ARTIFACT_REPOSITORY_PASSWORD \ - --artifactRepositoryName $applicationDir" + --artifactRepositoryDirectory release \ + --artifactRepositoryName $applicationDir-$ARTIFACT_REPOSITORY_SUFFIX" fi echo "** $CMD" >> $DBB_MODELER_LOGS/5-$applicationDir-initApplicationRepository.log $CMD > $DBB_MODELER_LOGS/$applicationDir/packaging-preview-$applicationDir.log