Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/mavenBuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,12 @@ func runMavenBuild(config *mavenBuildOptions, _ *telemetry.CustomData, utils mav
mavenOptions.ProjectSettingsFile = projectSettingsFilePath
}

deployFlags := []string{}
var deployFlags []string
if len(config.DeployFlags) > 0 {
deployFlags = append(deployFlags, config.DeployFlags...)
}
if (len(config.AltDeploymentRepositoryID) > 0) && (len(config.AltDeploymentRepositoryURL) > 0) {
deployFlags = append(deployFlags, "-DaltDeploymentRepository="+config.AltDeploymentRepositoryID+"::default::"+config.AltDeploymentRepositoryURL)
deployFlags = append(deployFlags, "-DaltDeploymentRepository="+config.AltDeploymentRepositoryID+"::"+config.AltDeploymentRepositoryURL)
}

downloadClient := &piperhttp.Client{}
Expand Down
2 changes: 1 addition & 1 deletion cmd/mavenBuild_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 40 additions & 1 deletion cmd/mavenBuild_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,46 @@ func TestMavenBuild(t *testing.T) {

assert.Nil(t, err)
if assert.Equal(t, 2, len(mockedUtils.Calls), "Expected two Maven invocations (main and deploy)") {
assert.Contains(t, mockedUtils.Calls[1].Params, "-DaltDeploymentRepository=ID::default::http://sampleRepo.com")
assert.Contains(t, mockedUtils.Calls[1].Params, "-DaltDeploymentRepository=ID::http://sampleRepo.com")
Comment thread
fskhiri marked this conversation as resolved.
Comment thread
fskhiri marked this conversation as resolved.
}
})

t.Run("mavenBuild with deploy must not set altDeploymentRepository when URL is missing", func(t *testing.T) {
mockedUtils := newMavenMockUtils()

options := mavenBuildOptions{Publish: true, Verify: false, AltDeploymentRepositoryID: "ID"}

err := runMavenBuild(&options, nil, &mockedUtils, &cpe)

assert.Nil(t, err)
if assert.Equal(t, 2, len(mockedUtils.Calls), "Expected two Maven invocations (main and deploy)") {
assert.NotContains(t, mockedUtils.Calls[1].Params, "-DaltDeploymentRepository=ID::")
}
})

t.Run("mavenBuild with deploy must not set altDeploymentRepository when ID is missing", func(t *testing.T) {
mockedUtils := newMavenMockUtils()

options := mavenBuildOptions{Publish: true, Verify: false, AltDeploymentRepositoryURL: "http://sampleRepo.com"}

err := runMavenBuild(&options, nil, &mockedUtils, &cpe)

assert.Nil(t, err)
if assert.Equal(t, 2, len(mockedUtils.Calls), "Expected two Maven invocations (main and deploy)") {
assert.NotContains(t, mockedUtils.Calls[1].Params, "-DaltDeploymentRepository=::http://sampleRepo.com")
}
})

t.Run("mavenBuild must not set altDeploymentRepository when Publish is false", func(t *testing.T) {
mockedUtils := newMavenMockUtils()

options := mavenBuildOptions{Publish: false, AltDeploymentRepositoryID: "ID", AltDeploymentRepositoryURL: "http://sampleRepo.com"}

err := runMavenBuild(&options, nil, &mockedUtils, &cpe)

assert.Nil(t, err)
if assert.Equal(t, 1, len(mockedUtils.Calls), "Expected one Maven invocation (no deploy when Publish is false)") {
assert.NotContains(t, mockedUtils.Calls[0].Params, "-DaltDeploymentRepository=ID::http://sampleRepo.com")
}
})

Expand Down
2 changes: 1 addition & 1 deletion resources/metadata/mavenBuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ spec:
param: custom/repositoryUrl
- name: altDeploymentRepositoryID
type: string
description: Id for the alternative deployment repository to which the project artifacts should be deployed ( other than those specified in <distributionManagement> ). This id will be updated in settings.xml and will be used as a flag with DaltDeploymentRepository along with mavenAltDeploymentRepositoryUrl during maven deploy . When no settings.xml is provided a new one is created corresponding with <servers> tag
description: "Id for the alternative deployment repository to which the project artifacts should be deployed ( other than those specified in <distributionManagement> ). This id will be updated in settings.xml and will be used as a flag with DaltDeploymentRepository along with mavenAltDeploymentRepositoryUrl during maven deploy . When no settings.xml is provided a new one is created corresponding with <servers> tag. Note: Piper emits the flag in Maven 3.x format (-DaltDeploymentRepository=id::url); maven-deploy-plugin 3.0.0 or newer is required. The legacy three-token id::layout::url form is no longer used."
scope:
- GENERAL
- PARAMETERS
Expand Down
Loading