Copilot commented on code in PR #286:
URL:
https://github.com/apache/maven-remote-resources-plugin/pull/286#discussion_r4354340588
##########
src/test/java/org/apache/maven/plugin/resources/remote/RemoteResourcesMojoTest.java:
##########
@@ -279,6 +280,19 @@ public void testFilteredBundlesWithProjectProperties()
throws Exception {
assertTrue(data.contains("rules"));
}
+ public void testValidateRejectsDescriptorWithEmptySegment() throws
Exception {
+ final MavenProjectResourcesStub project =
createTestProject("default-validate");
+ final ProcessRemoteResourcesMojo mojo =
+ lookupProcessMojoWithSettings(project, new String[]
{"org.example:dep::jar"});
+
+ try {
+ mojo.validate();
+ fail("Expected validate() to reject a resource bundle descriptor
with a missing version");
+ } catch (MojoExecutionException e) {
+ assertTrue(e.getMessage().contains("resource bundle"));
Review Comment:
The assertion `contains(\"resource bundle\")` is quite broad and could pass
for unrelated failures. To make the test resilient and clearly tied to the
intended validation failure, assert a more specific substring (e.g., the
existing 'must specify groupId:artifactId:version' text) or the full expected
validation message.
##########
src/main/java/org/apache/maven/plugin/resources/remote/AbstractProcessRemoteResourcesMojo.java:
##########
@@ -723,9 +723,11 @@ protected void validate() throws MojoExecutionException {
for (String artifactDescriptor : resourceBundles) {
// groupId:artifactId:version, groupId:artifactId:version:type
// or groupId:artifactId:version:type:classifier
- String[] s = StringUtils.split(artifactDescriptor, ":");
+ // use the same splitting as downloadBundles() so both are
consistent;
+ // also reject empty groupId/artifactId/version (e.g. a missing
segment)
+ String[] s = artifactDescriptor.split(":");
- if (s.length < 3 || s.length > 5) {
+ if (s.length < 3 || s.length > 5 || s[0].isEmpty() ||
s[1].isEmpty() || s[2].isEmpty()) {
Review Comment:
With the current condition, descriptors with empty *optional* segments (e.g.
`g:a:1.0::jar` where `type` is empty, or `g:a:1.0:jar:` where `classifier` is
empty but trailing) can still pass `validate()`. If the intent is to reject any
'missing segment' beyond the required 3, consider rejecting empty `type` when
`s.length >= 4` and empty `classifier` when `s.length == 5`. If you want to
detect trailing empty segments too, `split(\":\", -1)` is required—but then
`downloadBundles()` should be updated to match for true consistency.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]