2021-12-22 16:34:36 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2022-03-21 11:17:03 +02:00
|
|
|
"os"
|
|
|
|
|
2021-12-22 16:34:36 +02:00
|
|
|
"github.com/SAP/jenkins-library/pkg/command"
|
|
|
|
"github.com/SAP/jenkins-library/pkg/gradle"
|
|
|
|
"github.com/SAP/jenkins-library/pkg/log"
|
|
|
|
"github.com/SAP/jenkins-library/pkg/piperutils"
|
|
|
|
"github.com/SAP/jenkins-library/pkg/telemetry"
|
|
|
|
)
|
|
|
|
|
|
|
|
type gradleExecuteBuildUtils interface {
|
|
|
|
command.ExecRunner
|
|
|
|
FileExists(filename string) (bool, error)
|
2022-03-21 11:17:03 +02:00
|
|
|
FileWrite(path string, content []byte, perm os.FileMode) error
|
|
|
|
FileRemove(path string) error
|
2021-12-22 16:34:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type gradleExecuteBuildUtilsBundle struct {
|
|
|
|
*command.Command
|
|
|
|
*piperutils.Files
|
|
|
|
}
|
|
|
|
|
|
|
|
func newGradleExecuteBuildUtils() gradleExecuteBuildUtils {
|
|
|
|
utils := gradleExecuteBuildUtilsBundle{
|
|
|
|
Command: &command.Command{},
|
|
|
|
Files: &piperutils.Files{},
|
|
|
|
}
|
|
|
|
utils.Stdout(log.Writer())
|
|
|
|
utils.Stderr(log.Writer())
|
|
|
|
return &utils
|
|
|
|
}
|
|
|
|
|
|
|
|
func gradleExecuteBuild(config gradleExecuteBuildOptions, telemetryData *telemetry.CustomData) {
|
|
|
|
utils := newGradleExecuteBuildUtils()
|
2022-03-21 11:17:03 +02:00
|
|
|
err := runGradleExecuteBuild(&config, telemetryData, utils)
|
2021-12-22 16:34:36 +02:00
|
|
|
if err != nil {
|
|
|
|
log.Entry().WithError(err).Fatal("step execution failed: %w", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-21 11:17:03 +02:00
|
|
|
func runGradleExecuteBuild(config *gradleExecuteBuildOptions, telemetryData *telemetry.CustomData, utils gradleExecuteBuildUtils) error {
|
|
|
|
opt := &gradle.ExecuteOptions{
|
|
|
|
BuildGradlePath: config.Path,
|
|
|
|
Task: config.Task,
|
|
|
|
CreateBOM: config.CreateBOM,
|
|
|
|
}
|
2021-12-22 16:34:36 +02:00
|
|
|
|
2022-03-21 11:17:03 +02:00
|
|
|
if err := gradle.Execute(opt, utils); err != nil {
|
2021-12-22 16:34:36 +02:00
|
|
|
log.Entry().WithError(err).Errorln("build.gradle execution was failed: %w", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|