Skip to content

Commit 7bbdaf7

Browse files
authored
Dont dedup mvn flags (#1479)
1 parent 60e06a8 commit 7bbdaf7

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed

cmd/mavenExecute.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ func runMavenExecute(config mavenExecuteOptions, runner execRunner) error {
2424
ProjectSettingsFile: config.ProjectSettingsFile,
2525
GlobalSettingsFile: config.GlobalSettingsFile,
2626
M2Path: config.M2Path,
27-
Goals: splitTrimAndDeDupParams(config.Goals),
28-
Defines: splitTrimAndDeDupParams(config.Defines),
29-
Flags: splitTrimAndDeDupParams(config.Flags),
27+
Goals: splitAndTrimParams(config.Goals),
28+
Defines: splitAndTrimParams(config.Defines),
29+
Flags: splitAndTrimParams(config.Flags),
3030
LogSuccessfulMavenTransfers: config.LogSuccessfulMavenTransfers,
3131
ReturnStdout: config.ReturnStdout,
3232
}
@@ -38,6 +38,8 @@ func runMavenExecute(config mavenExecuteOptions, runner execRunner) error {
3838
return err
3939
}
4040

41-
func splitTrimAndDeDupParams(params []string) []string {
42-
return sliceUtils.SplitTrimAndDeDup(params, " ")
41+
// We *must not* deduplicate the parameters here as this will break commands such as `mvn -pl a -pl b`,
42+
// which would become `mvn -pl a b` which is invalid
43+
func splitAndTrimParams(params []string) []string {
44+
return sliceUtils.SplitAndTrim(params, " ")
4345
}

pkg/piperutils/slices.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,17 @@ func Trim(in []string) (out []string) {
5454
return
5555
}
5656

57-
// SplitTrimAndDeDup iterates over the strings in the given slice and splits each on the provided separator.
58-
// Each resulting sub-string is then a separate entry in the returned array. Duplicate and empty entries are eliminated.
59-
func SplitTrimAndDeDup(in []string, separator string) (out []string) {
57+
// SplitAndTrim iterates over the strings in the given slice and splits each on the provided separator.
58+
// Each resulting sub-string is then a separate entry in the returned array.
59+
func SplitAndTrim(in []string, separator string) (out []string) {
6060
if len(in) == 0 {
6161
return in
6262
}
6363
for _, entry := range in {
6464
entryParts := strings.Split(entry, separator)
6565
for _, part := range entryParts {
6666
part = strings.TrimSpace(part)
67-
if part != "" && !ContainsString(out, part) {
67+
if part != "" {
6868
out = append(out, part)
6969
}
7070
}

pkg/piperutils/slices_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -69,33 +69,33 @@ func TestSplitTrimAndDeDup(t *testing.T) {
6969
// init
7070
s := []string{" a", "", "-a-b --c ", "d-e", "f", " f", ""}
7171
// test
72-
s = SplitTrimAndDeDup(s, "-")
72+
s = SplitAndTrim(s, "-")
7373
// assert
74-
assert.Equal(t, []string{"a", "b", "c", "d", "e", "f"}, s)
74+
assert.Equal(t, []string{"a", "a", "b", "c", "d", "e", "f", "f"}, s)
7575
})
7676
t.Run("Separator is space", func(t *testing.T) {
7777
// init
7878
s := []string{" a", " a b c ", "d e", "f", "f ", ""}
7979
// test
80-
s = SplitTrimAndDeDup(s, " ")
80+
s = SplitAndTrim(s, " ")
8181
// assert
82-
assert.Equal(t, []string{"a", "b", "c", "d", "e", "f"}, s)
82+
assert.Equal(t, []string{"a", "a", "b", "c", "d", "e", "f", "f"}, s)
8383
})
8484
t.Run("Separator is multi-char", func(t *testing.T) {
8585
// init
8686
s := []string{" a", " a** b**c ", "**d **e", "f**", "f ", ""}
8787
// test
88-
s = SplitTrimAndDeDup(s, "**")
88+
s = SplitAndTrim(s, "**")
8989
// assert
90-
assert.Equal(t, []string{"a", "b", "c", "d", "e", "f"}, s)
90+
assert.Equal(t, []string{"a", "a", "b", "c", "d", "e", "f", "f"}, s)
9191
})
9292
t.Run("Separator is empty string", func(t *testing.T) {
9393
// init
9494
s := []string{" a", " a bc ", "d e", "f", "f ", ""}
9595
// test
96-
s = SplitTrimAndDeDup(s, "")
96+
s = SplitAndTrim(s, "")
9797
// assert
9898
// If "sep" is empty, underlying strings.Split() splits after each UTF-8 char sequence.
99-
assert.Equal(t, []string{"a", "b", "c", "d", "e", "f"}, s)
99+
assert.Equal(t, []string{"a", "a", "b", "c", "d", "e", "f", "f"}, s)
100100
})
101101
}

0 commit comments

Comments
 (0)