2020-05-27 18:20:10 +02:00
import com.sap.piper.BuildTool
2020-04-24 10:41:49 +02:00
import com.sap.piper.DownloadCacheUtils
2020-05-06 17:43:32 +02:00
import com.sap.piper.BashUtils
2018-08-15 11:53:28 +02:00
import groovy.transform.Field
2020-04-24 10:41:49 +02:00
import static com . sap . piper . Prerequisites . checkScript
2019-04-24 12:47:37 +02:00
2018-11-29 10:54:05 +02:00
@Field def STEP_NAME = getClass ( ) . getName ( )
2020-04-24 10:41:49 +02:00
@Field String METADATA_FILE = 'metadata/mavenExecute.yaml'
2018-08-15 11:53:28 +02:00
2020-01-23 10:31:01 +02:00
def call ( Map parameters = [ : ] ) {
final script = checkScript ( this , parameters ) ? : this
2020-05-27 18:20:10 +02:00
parameters = DownloadCacheUtils . injectDownloadCacheInParameters ( script , parameters , BuildTool . MAVEN )
2020-01-23 10:31:01 +02:00
2020-05-06 17:43:32 +02:00
validateParameter ( parameters . defines , 'defines' )
validateParameter ( parameters . flags , 'flags' )
validateParameter ( parameters . goals , 'goals' )
validateStringParameter ( parameters . pomPath )
validateStringParameter ( parameters . projectSettingsFile )
validateStringParameter ( parameters . globalSettingsFile )
validateStringParameter ( parameters . m2Path )
List credentials = [ ]
2020-04-24 10:41:49 +02:00
piperExecuteBin ( parameters , STEP_NAME , METADATA_FILE , credentials )
2018-08-15 11:53:28 +02:00
2020-04-24 10:41:49 +02:00
String output = ''
if ( parameters . returnStdout ) {
String outputFile = '.pipeline/maven_output.txt'
if ( ! fileExists ( outputFile ) ) {
error "[$STEP_NAME] Internal error. A text file with the contents of the maven output was expected " +
"but does not exist at '$outputFile'. " +
"Please file a ticket at https://github.com/SAP/jenkins-library/issues/new/choose"
2017-12-06 13:03:06 +02:00
}
2020-04-24 10:41:49 +02:00
output = readFile ( outputFile )
2020-01-23 10:31:01 +02:00
}
2020-04-24 10:41:49 +02:00
return output
2017-12-06 13:03:06 +02:00
}
2020-05-06 17:43:32 +02:00
private void validateParameter ( parameter , name ) {
if ( ! parameter ) {
return
}
String errorMessage = "Expected parameter ${name} with value ${parameter} to be of type List, but it is ${parameter.class}. "
// Specifically check for string-like types as the old step (v1.23.0 and before) allowed that as input
if ( parameter in CharSequence ) {
errorMessage + = "This is a breaking change for mavenExecute in library version v1.24.0 which allowed strings as input for defines, flags and goals before. " +
"To fix that, please update the interface to pass in lists, or use v1.23.0 which is the last version with the old interface. "
if ( parameter . contains ( BashUtils . ESCAPED_SINGLE_QUOTE ) ) {
errorMessage + = "It looks like your input contains shell escaped quotes. "
}
error errorMessage + "Note that *no* shell escaping is allowed."
}
if ( ! parameter in List ) {
error errorMessage + "Note that *no* shell escaping is allowed."
}
for ( int i = 0 ; i < parameter . size ( ) ; i + + ) {
String element = parameter [ i ]
validateStringParameter ( element )
}
}
private void validateStringParameter ( String element ) {
if ( ! element ) {
return
}
if ( element = ~ /-D.*='.*'/ ) {
echo "[$STEP_NAME WARNING] It looks like you passed a define in the form -Dmy.key='this is my value' in $element. Please note that the quotes might cause issues. Correct form: -Dmy.key=this is my value"
}
if ( element . length ( ) > = 2 & & element . startsWith ( "'" ) & & element . endsWith ( "'" ) ) {
echo "[$STEP_NAME WARNING] It looks like $element is quoted but it should not be quoted."
}
}