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