mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-28 05:47:08 +02:00
Pass settings file also to install-file (#2279)
This commit is contained in:
parent
546bc7b692
commit
1015371efd
@ -53,7 +53,7 @@ func runMavenExecuteIntegration(config *mavenExecuteIntegrationOptions, utils ma
|
||||
}
|
||||
|
||||
if config.InstallArtifacts {
|
||||
err := maven.InstallMavenArtifacts(utils, maven.EvaluateOptions{
|
||||
err := maven.InstallMavenArtifacts(utils, &maven.EvaluateOptions{
|
||||
M2Path: config.M2Path,
|
||||
ProjectSettingsFile: config.ProjectSettingsFile,
|
||||
GlobalSettingsFile: config.GlobalSettingsFile,
|
||||
|
@ -51,7 +51,7 @@ func runMavenStaticCodeChecks(config *mavenExecuteStaticCodeChecksOptions, telem
|
||||
}
|
||||
|
||||
if config.InstallArtifacts {
|
||||
err := maven.InstallMavenArtifacts(utils, maven.EvaluateOptions{
|
||||
err := maven.InstallMavenArtifacts(utils, &maven.EvaluateOptions{
|
||||
M2Path: config.M2Path,
|
||||
ProjectSettingsFile: config.ProjectSettingsFile,
|
||||
GlobalSettingsFile: config.GlobalSettingsFile,
|
||||
|
@ -224,7 +224,7 @@ func installMavenArtifacts(e command.ExecRunner, config mtaBuildOptions) error {
|
||||
return err
|
||||
}
|
||||
if pomXMLExists {
|
||||
err = maven.InstallMavenArtifacts(e, maven.EvaluateOptions{M2Path: config.M2Path})
|
||||
err = maven.InstallMavenArtifacts(e, &maven.EvaluateOptions{M2Path: config.M2Path})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ func Evaluate(options *EvaluateOptions, expression string, command mavenExecRunn
|
||||
|
||||
// InstallFile installs a maven artifact and its pom into the local maven repository.
|
||||
// If "file" is empty, only the pom is installed. "pomFile" must not be empty.
|
||||
func InstallFile(file, pomFile, m2Path string, command mavenExecRunner) error {
|
||||
func InstallFile(file, pomFile string, options *EvaluateOptions, command mavenExecRunner) error {
|
||||
if len(pomFile) == 0 {
|
||||
return fmt.Errorf("pomFile can't be empty")
|
||||
}
|
||||
@ -133,9 +133,11 @@ func InstallFile(file, pomFile, m2Path string, command mavenExecRunner) error {
|
||||
}
|
||||
defines = append(defines, "-DpomFile="+pomFile)
|
||||
mavenOptionsInstall := ExecuteOptions{
|
||||
Goals: []string{"install:install-file"},
|
||||
Defines: defines,
|
||||
M2Path: m2Path,
|
||||
Goals: []string{"install:install-file"},
|
||||
Defines: defines,
|
||||
M2Path: options.M2Path,
|
||||
ProjectSettingsFile: options.ProjectSettingsFile,
|
||||
GlobalSettingsFile: options.GlobalSettingsFile,
|
||||
}
|
||||
_, err := Execute(&mavenOptionsInstall, command)
|
||||
if err != nil {
|
||||
@ -145,11 +147,11 @@ func InstallFile(file, pomFile, m2Path string, command mavenExecRunner) error {
|
||||
}
|
||||
|
||||
// InstallMavenArtifacts finds maven modules (identified by pom.xml files) and installs the artifacts into the local maven repository.
|
||||
func InstallMavenArtifacts(command mavenExecRunner, options EvaluateOptions) error {
|
||||
func InstallMavenArtifacts(command mavenExecRunner, options *EvaluateOptions) error {
|
||||
return doInstallMavenArtifacts(command, options, newUtils())
|
||||
}
|
||||
|
||||
func doInstallMavenArtifacts(command mavenExecRunner, options EvaluateOptions, utils mavenUtils) error {
|
||||
func doInstallMavenArtifacts(command mavenExecRunner, options *EvaluateOptions, utils mavenUtils) error {
|
||||
err := flattenPom(command, options)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -174,7 +176,7 @@ func doInstallMavenArtifacts(command mavenExecRunner, options EvaluateOptions, u
|
||||
|
||||
// Set this module's pom file as the pom file for evaluating the packaging,
|
||||
// otherwise we would evaluate the root pom in all iterations.
|
||||
evaluateProjectPackagingOptions := options
|
||||
evaluateProjectPackagingOptions := *options
|
||||
evaluateProjectPackagingOptions.PomPath = pomFile
|
||||
packaging, err := Evaluate(&evaluateProjectPackagingOptions, "project.packaging", command)
|
||||
if err != nil {
|
||||
@ -191,7 +193,7 @@ func doInstallMavenArtifacts(command mavenExecRunner, options EvaluateOptions, u
|
||||
}
|
||||
|
||||
if packaging == "pom" {
|
||||
err = InstallFile("", pathToPomFile, options.M2Path, command)
|
||||
err = InstallFile("", pathToPomFile, options, command)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -206,15 +208,15 @@ func doInstallMavenArtifacts(command mavenExecRunner, options EvaluateOptions, u
|
||||
return err
|
||||
}
|
||||
|
||||
func installJarWarArtifacts(pomFile, dir string, command mavenExecRunner, utils mavenUtils, options EvaluateOptions) error {
|
||||
func installJarWarArtifacts(pomFile, dir string, command mavenExecRunner, utils mavenUtils, options *EvaluateOptions) error {
|
||||
options.PomPath = filepath.Join(dir, "pom.xml")
|
||||
finalName, err := Evaluate(&options, "project.build.finalName", command)
|
||||
finalName, err := Evaluate(options, "project.build.finalName", command)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if finalName == "" {
|
||||
log.Entry().Warn("project.build.finalName is empty, skipping install of artifact. Installing only the pom file.")
|
||||
err = InstallFile("", pomFile, options.M2Path, command)
|
||||
err = InstallFile("", pomFile, options, command)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -233,26 +235,26 @@ func installJarWarArtifacts(pomFile, dir string, command mavenExecRunner, utils
|
||||
|
||||
// Due to spring's jar repackaging we need to check for an "original" jar file because the repackaged one is no suitable source for dependent maven modules
|
||||
if originalJarExists {
|
||||
err = InstallFile(originalJarFile(dir, finalName), pomFile, options.M2Path, command)
|
||||
err = InstallFile(originalJarFile(dir, finalName), pomFile, options, command)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else if jarExists {
|
||||
err = InstallFile(jarFile(dir, finalName), pomFile, options.M2Path, command)
|
||||
err = InstallFile(jarFile(dir, finalName), pomFile, options, command)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if warExists {
|
||||
err = InstallFile(warFile(dir, finalName), pomFile, options.M2Path, command)
|
||||
err = InstallFile(warFile(dir, finalName), pomFile, options, command)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if classesJarExists {
|
||||
err = InstallFile(classesJarFile(dir, finalName), pomFile, options.M2Path, command)
|
||||
err = InstallFile(classesJarFile(dir, finalName), pomFile, options, command)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -276,7 +278,7 @@ func warFile(dir, finalName string) string {
|
||||
return filepath.Join(dir, "target", finalName+".war")
|
||||
}
|
||||
|
||||
func flattenPom(command mavenExecRunner, o EvaluateOptions) error {
|
||||
func flattenPom(command mavenExecRunner, o *EvaluateOptions) error {
|
||||
mavenOptionsFlatten := ExecuteOptions{
|
||||
Goals: []string{"flatten:flatten"},
|
||||
Defines: []string{"-Dflatten.mode=resolveCiFriendliesOnly"},
|
||||
|
@ -182,7 +182,7 @@ func TestMavenInstall(t *testing.T) {
|
||||
execMockRunner := mock.ExecMockRunner{}
|
||||
expectedParameters := []string{"-Dfile=app.jar", "-Dpackaging=jar", "-DpomFile=pom.xml", "-Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn", "--batch-mode", "install:install-file"}
|
||||
|
||||
err := InstallFile("app.jar", "pom.xml", "", &execMockRunner)
|
||||
err := InstallFile("app.jar", "pom.xml", &EvaluateOptions{}, &execMockRunner)
|
||||
|
||||
assert.NoError(t, err)
|
||||
if assert.Equal(t, len(expectedParameters), len(execMockRunner.Calls[0].Params)) {
|
||||
@ -202,15 +202,15 @@ func TestMavenInstall(t *testing.T) {
|
||||
|
||||
execMockRunner := mock.ExecMockRunner{}
|
||||
execMockRunner.StdoutReturn = map[string]string{"mvn --settings settings.xml --file pom.xml -Dexpression=project.build.finalName -DforceStdout -q -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn --batch-mode org.apache.maven.plugins:maven-help-plugin:3.1.0:evaluate": "foo"}
|
||||
err := doInstallMavenArtifacts(&execMockRunner, options, &utils)
|
||||
err := doInstallMavenArtifacts(&execMockRunner, &options, &utils)
|
||||
|
||||
assert.NoError(t, err)
|
||||
if assert.Equal(t, 5, len(execMockRunner.Calls)) {
|
||||
assert.Equal(t, mock.ExecCall{Exec: "mvn", Params: []string{"--settings", "settings.xml", "--file", "pom.xml", "-Dflatten.mode=resolveCiFriendliesOnly", "-Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn", "--batch-mode", "flatten:flatten"}}, execMockRunner.Calls[0])
|
||||
assert.Equal(t, mock.ExecCall{Exec: "mvn", Params: []string{"--settings", "settings.xml", "--file", "pom.xml", "-Dexpression=project.packaging", "-DforceStdout", "-q", "-Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn", "--batch-mode", "org.apache.maven.plugins:maven-help-plugin:3.1.0:evaluate"}}, execMockRunner.Calls[1])
|
||||
assert.Equal(t, mock.ExecCall{Exec: "mvn", Params: []string{"--settings", "settings.xml", "--file", "pom.xml", "-Dexpression=project.build.finalName", "-DforceStdout", "-q", "-Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn", "--batch-mode", "org.apache.maven.plugins:maven-help-plugin:3.1.0:evaluate"}}, execMockRunner.Calls[2])
|
||||
assert.Equal(t, mock.ExecCall{Exec: "mvn", Params: []string{"-Dfile=" + filepath.Join(".", "target", "foo.jar"), "-Dpackaging=jar", "-DpomFile=pom.xml", "-Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn", "--batch-mode", "install:install-file"}}, execMockRunner.Calls[3])
|
||||
assert.Equal(t, mock.ExecCall{Exec: "mvn", Params: []string{"-Dfile=" + filepath.Join(".", "target", "foo.war"), "-DpomFile=pom.xml", "-Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn", "--batch-mode", "install:install-file"}}, execMockRunner.Calls[4])
|
||||
assert.Equal(t, mock.ExecCall{Exec: "mvn", Params: []string{"--settings", "settings.xml", "-Dfile=" + filepath.Join(".", "target", "foo.jar"), "-Dpackaging=jar", "-DpomFile=pom.xml", "-Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn", "--batch-mode", "install:install-file"}}, execMockRunner.Calls[3])
|
||||
assert.Equal(t, mock.ExecCall{Exec: "mvn", Params: []string{"--settings", "settings.xml", "-Dfile=" + filepath.Join(".", "target", "foo.war"), "-DpomFile=pom.xml", "-Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn", "--batch-mode", "install:install-file"}}, execMockRunner.Calls[4])
|
||||
}
|
||||
})
|
||||
|
||||
@ -223,7 +223,7 @@ func TestMavenInstall(t *testing.T) {
|
||||
options := EvaluateOptions{}
|
||||
execMockRunner := mock.ExecMockRunner{}
|
||||
execMockRunner.StdoutReturn = map[string]string{"mvn --file pom.xml -Dexpression=project.build.finalName -DforceStdout -q -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn --batch-mode org.apache.maven.plugins:maven-help-plugin:3.1.0:evaluate": "foo"}
|
||||
err := doInstallMavenArtifacts(&execMockRunner, options, &utils)
|
||||
err := doInstallMavenArtifacts(&execMockRunner, &options, &utils)
|
||||
|
||||
assert.NoError(t, err)
|
||||
if assert.Equal(t, 4, len(execMockRunner.Calls)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user