2018-02-08 14:18:04 +02:00
|
|
|
import com.sap.piper.ConfigurationMerger
|
2018-03-13 10:31:01 +02:00
|
|
|
import com.sap.piper.MtaUtils
|
2018-03-19 19:29:41 +02:00
|
|
|
import com.sap.piper.tools.JavaArchiveDescriptor
|
|
|
|
import com.sap.piper.tools.ToolDescriptor
|
2017-07-11 15:12:03 +02:00
|
|
|
|
2017-11-24 16:59:34 +02:00
|
|
|
|
2017-07-11 15:12:03 +02:00
|
|
|
def call(Map parameters = [:]) {
|
|
|
|
|
2018-02-08 14:18:04 +02:00
|
|
|
def stepName = 'mtaBuild'
|
2017-07-11 15:12:03 +02:00
|
|
|
|
2018-02-19 13:53:08 +02:00
|
|
|
Set parameterKeys = [
|
2018-03-21 13:29:15 +02:00
|
|
|
'applicationName',
|
2018-02-08 14:18:04 +02:00
|
|
|
'buildTarget',
|
2018-04-17 17:35:10 +02:00
|
|
|
'extension',
|
2018-03-23 11:19:49 +02:00
|
|
|
'mtaJarLocation'
|
2018-02-08 14:18:04 +02:00
|
|
|
]
|
|
|
|
|
2018-02-19 13:53:08 +02:00
|
|
|
Set stepConfigurationKeys = [
|
2018-03-21 13:29:15 +02:00
|
|
|
'applicationName',
|
2018-02-19 20:27:53 +02:00
|
|
|
'buildTarget',
|
2018-04-17 17:35:10 +02:00
|
|
|
'extension',
|
2018-03-23 11:19:49 +02:00
|
|
|
'mtaJarLocation'
|
2018-02-08 14:18:04 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
handlePipelineStepErrors (stepName: stepName, stepParameters: parameters) {
|
|
|
|
|
|
|
|
final script = parameters?.script ?: [commonPipelineEnvironment: commonPipelineEnvironment]
|
|
|
|
|
|
|
|
prepareDefaultValues script: script
|
|
|
|
|
|
|
|
final Map configuration = ConfigurationMerger.merge(
|
2018-02-28 12:42:19 +02:00
|
|
|
script, stepName,
|
2018-02-08 14:18:04 +02:00
|
|
|
parameters, parameterKeys,
|
2018-02-28 12:42:19 +02:00
|
|
|
stepConfigurationKeys)
|
2017-07-11 15:12:03 +02:00
|
|
|
|
2018-03-19 19:29:41 +02:00
|
|
|
def java = new ToolDescriptor('Java', 'JAVA_HOME', '', '/bin/', 'java', '1.8.0', '-version 2>&1')
|
|
|
|
java.verify(this, configuration)
|
2018-02-21 13:48:14 +02:00
|
|
|
|
2018-04-17 16:53:04 +02:00
|
|
|
def mta = new JavaArchiveDescriptor('SAP Multitarget Application Archive Builder', 'MTA_JAR_LOCATION', 'mtaJarLocation', '1.0.6', '-v', java)
|
2018-03-19 19:29:41 +02:00
|
|
|
mta.verify(this, configuration)
|
2018-02-20 14:09:16 +02:00
|
|
|
|
2018-03-13 10:31:01 +02:00
|
|
|
def mtaYmlName = "${pwd()}/mta.yaml"
|
|
|
|
def applicationName = configuration.applicationName
|
|
|
|
|
2018-03-21 13:29:15 +02:00
|
|
|
if (!fileExists(mtaYmlName)) {
|
|
|
|
if (!applicationName) {
|
|
|
|
echo "'applicationName' not provided as parameter - will not try to generate mta.yml file"
|
|
|
|
} else {
|
|
|
|
MtaUtils mtaUtils = new MtaUtils(this)
|
|
|
|
mtaUtils.generateMtaDescriptorFromPackageJson("${pwd()}/package.json", mtaYmlName, applicationName)
|
|
|
|
}
|
2018-03-13 10:31:01 +02:00
|
|
|
}
|
2017-07-11 15:12:03 +02:00
|
|
|
|
2018-03-13 10:31:01 +02:00
|
|
|
def mtaYaml = readYaml file: "${pwd()}/mta.yaml"
|
2018-03-19 19:29:41 +02:00
|
|
|
|
2017-07-11 15:12:03 +02:00
|
|
|
//[Q]: Why not yaml.dump()? [A]: This reformats the whole file.
|
2017-11-13 10:26:34 +02:00
|
|
|
sh "sed -ie \"s/\\\${timestamp}/`date +%Y%m%d%H%M%S`/g\" \"${pwd()}/mta.yaml\""
|
2017-07-11 15:12:03 +02:00
|
|
|
|
|
|
|
def id = mtaYaml.ID
|
|
|
|
if (!id) {
|
|
|
|
error "Property 'ID' not found in mta.yaml file at: '${pwd()}'"
|
|
|
|
}
|
|
|
|
|
|
|
|
def mtarFileName = "${id}.mtar"
|
2018-04-17 16:53:04 +02:00
|
|
|
def mtaJar = mta.getCall(this, configuration)
|
2018-02-08 14:18:04 +02:00
|
|
|
def buildTarget = configuration.buildTarget
|
2017-07-11 15:12:03 +02:00
|
|
|
|
2018-04-17 17:35:10 +02:00
|
|
|
def mtaCall = "${mtaJar} --mtar ${mtarFileName} --build-target=${buildTarget}"
|
|
|
|
|
|
|
|
if (configuration.extension) mtaCall += " --extension=$configuration.extension"
|
|
|
|
mtaCall += ' build'
|
|
|
|
|
2017-07-11 15:12:03 +02:00
|
|
|
sh """#!/bin/bash
|
|
|
|
export PATH=./node_modules/.bin:${PATH}
|
2018-04-17 17:35:10 +02:00
|
|
|
$mtaCall
|
2017-07-11 15:12:03 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
def mtarFilePath = "${pwd()}/${mtarFileName}"
|
2018-02-08 14:18:04 +02:00
|
|
|
script?.commonPipelineEnvironment?.setMtarFilePath(mtarFilePath)
|
2017-07-11 15:12:03 +02:00
|
|
|
|
|
|
|
return mtarFilePath
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|