Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gradle - fix command properties recognition #222

Merged
merged 10 commits into from
Dec 27, 2023
14 changes: 9 additions & 5 deletions build/gradle.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,16 +265,20 @@ func (config *gradleRunConfig) GetCmd() *exec.Cmd {
func handleGradleCommandProperties(tasks []string) []string {
var cmdArgs []string
for _, task := range tasks {
if !strings.HasPrefix(task, systemPropertiesFlag) && !strings.HasPrefix(task, projectPropertiesFlag) {
cmdArgs = append(cmdArgs, task)
continue
if isGradleSystemOrProjectProperty(task) {
propertyParts := strings.SplitN(task, "=", 2)
task = fmt.Sprintf(`%s="%s"`, propertyParts[0], propertyParts[1])
}
propertyParts := strings.SplitN(task, "=", 2)
cmdArgs = append(cmdArgs, fmt.Sprintf(`%s="%s"`, propertyParts[0], propertyParts[1]))
cmdArgs = append(cmdArgs, task)
}
return cmdArgs
}

func isGradleSystemOrProjectProperty(task string) bool {
hasPropertiesFlag := strings.HasPrefix(task, systemPropertiesFlag) || strings.HasPrefix(task, projectPropertiesFlag)
return hasPropertiesFlag && strings.Contains(task, "=")
}

func (config *gradleRunConfig) runCmd(stdout, stderr io.Writer) error {
command := config.GetCmd()
command.Env = os.Environ()
Expand Down
4 changes: 4 additions & 0 deletions build/gradle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ func TestHandleGradleCommandProperties(t *testing.T) {
input: []string{"-Dparam1=value1", "run", "-Pkey2=value2", "-Dparam2=value2"},
expected: []string{`-Dparam1="value1"`, "run", `-Pkey2="value2"`, `-Dparam2="value2"`},
},
{
input: []string{"-Dparam1=value1", "run", "-Psign"},
expected: []string{`-Dparam1="value1"`, "run", "-Psign"},
},
}

for _, test := range tests {
Expand Down
Loading