gnodet commented on code in PR #12680:
URL: https://github.com/apache/maven/pull/12680#discussion_r3951609543
##########
impl/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java:
##########
@@ -130,29 +129,35 @@ private void collectDependencyRequirements(
}
}
- private Collection<String> toScopes(String classpath) {
- Collection<String> scopes = Collections.emptyList();
-
- if (classpath != null && !classpath.isEmpty()) {
- if (Artifact.SCOPE_COMPILE.equals(classpath)) {
- scopes = Arrays.asList(Artifact.SCOPE_COMPILE,
Artifact.SCOPE_SYSTEM, Artifact.SCOPE_PROVIDED);
- } else if (Artifact.SCOPE_RUNTIME.equals(classpath)) {
- scopes = Arrays.asList(Artifact.SCOPE_COMPILE,
Artifact.SCOPE_RUNTIME);
- } else if (Artifact.SCOPE_COMPILE_PLUS_RUNTIME.equals(classpath)) {
- scopes = Arrays.asList(
- Artifact.SCOPE_COMPILE, Artifact.SCOPE_SYSTEM,
Artifact.SCOPE_PROVIDED, Artifact.SCOPE_RUNTIME);
- } else if (Artifact.SCOPE_RUNTIME_PLUS_SYSTEM.equals(classpath)) {
- scopes = Arrays.asList(Artifact.SCOPE_COMPILE,
Artifact.SCOPE_SYSTEM, Artifact.SCOPE_RUNTIME);
- } else if (Artifact.SCOPE_TEST.equals(classpath)) {
- scopes = Arrays.asList(
+ /**
+ * Expands a dependency scope identifier to the set of artifact scopes
included
+ * in dependency resolution for that scope.
+ *
+ * @param classpath the scope identifier (e.g. "compile", "runtime",
"test"), may be {@code null}
+ * @return an unmodifiable set of matching artifact scopes, empty if
{@code classpath} is null/empty/unknown
Review Comment:
**Low — Javadoc `@return` is inaccurate for the `default` case.** The doc
says *"empty if {@code classpath} is null/empty/unknown"* but the
implementation returns `Set.of(classpath)` for unknown values (the `default`
branch). This matters for `filterByScope()` callers: a plugin-declared
lifecycle dependency with an unrecognized scope string (e.g. `"provided"`
passed directly as a scope identifier) will now produce a singleton
`{"provided"}` set instead of empty — a behavior change from the old code. The
behavior is probably correct (pass the scope through and let the filter match),
but the doc actively misleads.
```suggestion
* @return an unmodifiable set of matching artifact scopes; for
unknown/unrecognized scope identifiers,
* returns a singleton set containing the scope itself; empty
only if {@code classpath} is null or empty
```
--
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]