2018-03-13 10:31:01 +02:00
|
|
|
package com.sap.piper
|
|
|
|
|
|
|
|
import java.util.Map
|
|
|
|
|
|
|
|
import hudson.AbortException
|
|
|
|
|
|
|
|
class MtaUtils {
|
|
|
|
|
|
|
|
final protected script
|
|
|
|
|
|
|
|
protected MtaUtils(script) {
|
|
|
|
this.script = script
|
|
|
|
}
|
|
|
|
|
|
|
|
def generateMtaDescriptorFromPackageJson (String srcPackageJson, String targetMtaDescriptor, String applicationName) throws Exception{
|
|
|
|
if (!srcPackageJson) throw new IllegalArgumentException("The parameter 'srcPackageJson' can not be null or empty.")
|
|
|
|
if (!targetMtaDescriptor) throw new IllegalArgumentException("The parameter 'targetMtaDescriptor' can not be null or empty.")
|
|
|
|
if (!applicationName) throw new IllegalArgumentException("The parameter 'applicationName' can not be null or empty.")
|
|
|
|
|
|
|
|
if (!script.fileExists(srcPackageJson)) throw new AbortException("'${srcPackageJson}' does not exist.")
|
|
|
|
|
|
|
|
def dataFromJson = script.readJSON file: srcPackageJson
|
|
|
|
|
2020-02-20 15:57:50 +02:00
|
|
|
def mtaData = script.readYaml text: script.libraryResource('template_mta.yaml')
|
2018-03-13 10:31:01 +02:00
|
|
|
|
|
|
|
if(!dataFromJson.name) throw new AbortException("'name' not set in the given package.json.")
|
|
|
|
mtaData['ID'] = dataFromJson.name
|
|
|
|
|
|
|
|
if(!dataFromJson.version) throw new AbortException("'version' not set in the given package.json.")
|
|
|
|
mtaData['version'] = dataFromJson.version
|
|
|
|
mtaData['modules'][0]['parameters']['version'] = "${dataFromJson.version}-\${timestamp}"
|
2020-02-20 15:57:50 +02:00
|
|
|
mtaData['modules'][0]['parameters']['name'] = applicationName
|
2018-03-13 10:31:01 +02:00
|
|
|
|
|
|
|
mtaData['modules'][0]['name'] = applicationName
|
|
|
|
|
|
|
|
script.writeYaml file: targetMtaDescriptor, data: mtaData
|
|
|
|
|
|
|
|
if (!script.fileExists(targetMtaDescriptor)) throw new AbortException("'${targetMtaDescriptor}' has not been generated.")
|
|
|
|
}
|
|
|
|
}
|