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

Maven dependency update - improve non-existing version error #605

Merged
merged 12 commits into from
Dec 18, 2023
6 changes: 5 additions & 1 deletion packagehandlers/mavenpackagehandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,11 @@ func (mph *MavenPackageHandler) updatePackageVersion(impactedPackage, fixedVersi
fmt.Sprintf("-DprocessDependencyManagement=%t", foundInDependencyManagement)}
updateVersionCmd := fmt.Sprintf("mvn %s", strings.Join(updateVersionArgs, " "))
log.Debug(fmt.Sprintf("Running '%s'", updateVersionCmd))
_, err := mph.RunMvnCmd(updateVersionArgs)
output, err := mph.RunMvnCmd(updateVersionArgs)
if err != nil && strings.Contains(string(output), fmt.Sprintf("Version %s is not available for artifact", fixedVersion)) {
sverdlov93 marked this conversation as resolved.
Show resolved Hide resolved
// Replace Maven's 'version not available' error with more readable error message
err = fmt.Errorf("couldn't update '%s' to suggested fix version: Version '%s' is not available", impactedPackage, fixedVersion)
}
return err
}

Expand Down
5 changes: 5 additions & 0 deletions packagehandlers/packagehandlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,11 @@ func TestUpdatePackageVersion(t *testing.T) {
for _, test := range testCases {
assert.Contains(t, fmt.Sprintf("<version>%s</version>", string(modifiedPom)), test.fixedVersion)
}

// Test non-existing version error
assert.ErrorContains(t,
mvnHandler.updatePackageVersion("org.apache.httpcomponents:httpcore", "non.existing.version", true),
"is not available")
}

func TestUpdatePropertiesVersion(t *testing.T) {
Expand Down
Loading