-
Notifications
You must be signed in to change notification settings - Fork 8
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
Detect duplicate artifacts and block deployment #32
base: main
Are you sure you want to change the base?
Conversation
@@ -106,6 +109,12 @@ private void doExecute() throws MojoFailureException, MojoExecutionException { | |||
catch (MojoExecutionException e) { | |||
throw e; | |||
} | |||
catch (dv ex) { | |||
Optional<String> message = ex.b(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea why this needs to be obfuscated but an error message like this is very poor:
[ERROR] Failed to execute goal org.sonatype.plugins:nxrm3-maven-plugin:1.0.3:staging-deploy (default-cli) on project XYZ: Upload component was unsuccessful (400 response from server): Bad Request -> [Help 1]
Only executing Maven with --debug
unveiled the real error:
[DEBUG] http-outgoing-3 << "[ {[\n]"
[DEBUG] http-outgoing-3 << " "id" : "*",[\n]"
[DEBUG] http-outgoing-3 << " "message" : "The assets 3 and 4 have identical coordinates"[\n]"
[DEBUG] http-outgoing-3 << "} ]"
Note, I think it would be better if the plug-in would not fail but just ignore duplicate artifacts, which can happen. In our case it worked fine with Nexus 2 for all those years. 🤷♂️ |
if(message.isPresent()) | ||
throw new MojoFailureException(ex.getMessage() + ": " + message.get(), ex); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please surround with curly braces
private Optional<String> findJsonErrorMessage(Throwable e) { | ||
if(e == null) | ||
return Optional.empty(); | ||
|
||
if(e instanceof HttpResponseException) { | ||
Method[] declaredMethods = e.getClass().getDeclaredMethods(); | ||
for (Method method : declaredMethods) { | ||
if(method.getParameterCount() == 0 && isPublic(method.getModifiers()) && Optional.class.isAssignableFrom(method.getReturnType())) { | ||
try { | ||
Optional<?> result = (Optional<?>) method.invoke(e); | ||
if(result.isPresent()) { | ||
Object potentialMessage = result.get(); | ||
// filter out the raw json message | ||
if(potentialMessage instanceof String && !((String)potentialMessage).contains("\"message\"")) { | ||
return Optional.of((String)potentialMessage); | ||
} | ||
} | ||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e1) { | ||
// ignore and continue | ||
} | ||
} | ||
} | ||
// nothing found | ||
return Optional.empty(); | ||
} | ||
|
||
return findJsonErrorMessage(e.getCause()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add tests to exercise the recursive flow in this new method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bobotimi I think it would be better if the team introduces a proper API to make the error response from Nexus part of the Nexus client API. For some reason the code is obfuscated, which doesn't make a lot of sense.
The reflection shouldn't be used as a long term solution.
https://stackoverflow.com/questions/4251488/maven-release-plugin-fails-source-artifacts-getting-deployed-twice