forked from SAP/jenkins-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmavenExecuteIntegration.go
90 lines (78 loc) · 2.5 KB
/
mavenExecuteIntegration.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package cmd
import (
"fmt"
"github.com/SAP/jenkins-library/pkg/log"
"github.com/SAP/jenkins-library/pkg/maven"
"github.com/SAP/jenkins-library/pkg/telemetry"
"path/filepath"
"strconv"
"strings"
"unicode"
)
func mavenExecuteIntegration(config mavenExecuteIntegrationOptions, _ *telemetry.CustomData) {
err := runMavenExecuteIntegration(&config, maven.NewUtilsBundle())
if err != nil {
log.Entry().WithError(err).Fatal("step execution failed")
}
}
func runMavenExecuteIntegration(config *mavenExecuteIntegrationOptions, utils maven.Utils) error {
pomPath := filepath.Join("integration-tests", "pom.xml")
hasIntegrationTestsModule, _ := utils.FileExists(pomPath)
if !hasIntegrationTestsModule {
return fmt.Errorf("maven module 'integration-tests' does not exist in project structure")
}
if config.InstallArtifacts {
err := maven.InstallMavenArtifacts(&maven.EvaluateOptions{
M2Path: config.M2Path,
ProjectSettingsFile: config.ProjectSettingsFile,
GlobalSettingsFile: config.GlobalSettingsFile,
}, utils)
if err != nil {
return err
}
}
if err := validateForkCount(config.ForkCount); err != nil {
return err
}
retryDefine := fmt.Sprintf("-Dsurefire.rerunFailingTestsCount=%v", config.Retry)
forkCountDefine := fmt.Sprintf("-Dsurefire.forkCount=%v", config.ForkCount)
mavenOptions := maven.ExecuteOptions{
PomPath: pomPath,
M2Path: config.M2Path,
ProjectSettingsFile: config.ProjectSettingsFile,
GlobalSettingsFile: config.GlobalSettingsFile,
Goals: []string{"org.jacoco:jacoco-maven-plugin:prepare-agent", config.Goal},
Defines: []string{retryDefine, forkCountDefine},
}
_, err := maven.Execute(&mavenOptions, utils)
return err
}
func validateForkCount(value string) error {
var err error
if strings.HasSuffix(value, "C") {
value := strings.TrimSuffix(value, "C")
for _, c := range value {
if !unicode.IsDigit(c) && c != '.' {
err = fmt.Errorf("only integers or floats allowed with 'C' suffix")
break
}
}
if err == nil {
_, err = strconv.ParseFloat(value, 64)
}
} else {
for _, c := range value {
if !unicode.IsDigit(c) {
err = fmt.Errorf("only integers allowed without 'C' suffix")
break
}
}
if err == nil {
_, err = strconv.ParseInt(value, 10, 64)
}
}
if err != nil {
return fmt.Errorf("invalid forkCount parameter '%v': %w, please see https://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html#forkCount for details", value, err)
}
return nil
}