github.com/SAP/jenkins-library@v1.362.0/cmd/mavenExecute.go (about) 1 package cmd 2 3 import ( 4 "github.com/SAP/jenkins-library/pkg/command" 5 piperhttp "github.com/SAP/jenkins-library/pkg/http" 6 "github.com/SAP/jenkins-library/pkg/log" 7 "github.com/SAP/jenkins-library/pkg/maven" 8 "github.com/SAP/jenkins-library/pkg/piperutils" 9 "os" 10 11 "github.com/SAP/jenkins-library/pkg/telemetry" 12 ) 13 14 type mavenExecuteUtils interface { 15 maven.Utils 16 FileWrite(path string, content []byte, perm os.FileMode) error 17 } 18 19 type mavenExecuteUtilsBundle struct { 20 *command.Command 21 *piperutils.Files 22 *piperhttp.Client 23 } 24 25 func newMavenExecuteUtilsBundle() mavenExecuteUtils { 26 utils := mavenExecuteUtilsBundle{ 27 Command: &command.Command{}, 28 Files: &piperutils.Files{}, 29 Client: &piperhttp.Client{}, 30 } 31 utils.Stdout(log.Writer()) 32 utils.Stderr(log.Writer()) 33 return &utils 34 } 35 36 func mavenExecute(config mavenExecuteOptions, _ *telemetry.CustomData) { 37 err := runMavenExecute(config, newMavenExecuteUtilsBundle()) 38 if err != nil { 39 log.Entry().WithError(err).Fatal("step execution failed") 40 } 41 } 42 43 func runMavenExecute(config mavenExecuteOptions, utils mavenExecuteUtils) error { 44 options := maven.ExecuteOptions{ 45 PomPath: config.PomPath, 46 ProjectSettingsFile: config.ProjectSettingsFile, 47 GlobalSettingsFile: config.GlobalSettingsFile, 48 M2Path: config.M2Path, 49 Goals: config.Goals, 50 Defines: config.Defines, 51 Flags: config.Flags, 52 LogSuccessfulMavenTransfers: config.LogSuccessfulMavenTransfers, 53 ReturnStdout: config.ReturnStdout, 54 } 55 56 output, err := maven.Execute(&options, utils) 57 if err == nil && config.ReturnStdout { 58 err = utils.FileWrite(".pipeline/maven_output.txt", []byte(output), 0644) 59 } 60 return err 61 }