1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00
sap-jenkins-library/cmd/mavenBuild.go
Marcus Holl 4f2ba73314
[refactoring] move the shell/command related interfaces into pkg/command (#1737)
* [refactoring] move the shell/command related interfaces into pkg/command

otherwise we are not able to use the corresponding mocks for the items contained in pkg since
these interfaces are not visible from the pkg folder

Co-authored-by: Daniel Kurzynski <daniel.kurzynski@sap.com>
2020-07-01 11:28:16 +02:00

63 lines
1.8 KiB
Go

package cmd
import (
"github.com/SAP/jenkins-library/pkg/command"
"github.com/SAP/jenkins-library/pkg/log"
"github.com/SAP/jenkins-library/pkg/maven"
"github.com/SAP/jenkins-library/pkg/piperutils"
"github.com/SAP/jenkins-library/pkg/telemetry"
)
func mavenBuild(config mavenBuildOptions, telemetryData *telemetry.CustomData) {
c := command.Command{}
c.Stdout(log.Writer())
c.Stderr(log.Writer())
utils := piperutils.Files{}
err := runMavenBuild(&config, telemetryData, &c, &utils)
if err != nil {
log.Entry().WithError(err).Fatal("step execution failed")
}
}
func runMavenBuild(config *mavenBuildOptions, telemetryData *telemetry.CustomData, command command.ExecRunner, utils piperutils.FileUtils) error {
var flags = []string{"-update-snapshots", "--batch-mode"}
exists, _ := utils.FileExists("integration-tests/pom.xml")
if exists {
flags = append(flags, "-pl", "!integration-tests")
}
var defines []string
var goals []string
goals = append(goals, "org.jacoco:jacoco-maven-plugin:prepare-agent")
if config.Flatten {
goals = append(goals, "flatten:flatten")
defines = append(defines, "-Dflatten.mode=resolveCiFriendliesOnly", "-DupdatePomFile=true")
}
if config.Verify {
goals = append(goals, "verify")
} else {
goals = append(goals, "install")
}
mavenOptions := maven.ExecuteOptions{
Flags: flags,
Goals: goals,
Defines: defines,
PomPath: config.PomPath,
ProjectSettingsFile: config.ProjectSettingsFile,
GlobalSettingsFile: config.GlobalSettingsFile,
M2Path: config.M2Path,
LogSuccessfulMavenTransfers: config.LogSuccessfulMavenTransfers,
}
_, err := maven.Execute(&mavenOptions, command)
return err
}