slawekjaranowski commented on code in PR #1712: URL: https://github.com/apache/maven-dependency-plugin/pull/1712#discussion_r4149831961
########## src/main/java/org/apache/maven/plugins/dependency/tree/VerboseJavaScopeSelector.java: ########## @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.maven.plugins.dependency.tree; + +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; + +import org.eclipse.aether.RepositoryException; +import org.eclipse.aether.util.graph.transformer.ConflictResolver.ConflictContext; +import org.eclipse.aether.util.graph.transformer.ConflictResolver.ScopeSelector; +import org.eclipse.aether.util.graph.transformer.JavaScopeSelector; + +/** + * Selects the scope like Maven does and records on the winning node a wider scope that was not applied, so the verbose + * tree can report it. + */ +class VerboseJavaScopeSelector extends ScopeSelector { + static final String REDUCED_SCOPE = "REDUCED_SCOPE"; + + private static final List<String> ORDERED_SCOPES = Arrays.asList("compile", "runtime", "provided", "test"); + + private final ScopeSelector scopeSelector = new JavaScopeSelector(); + + @Override + public void selectScope(ConflictContext context) throws RepositoryException { + scopeSelector.selectScope(context); + + context.getItems().stream() + .flatMap(i -> i.getScopes().stream()) + .distinct() + .max(Comparator.comparingInt((String s) -> ORDERED_SCOPES.indexOf(s)) + .reversed()) + .filter(s -> s != context.getScope()) Review Comment: This carries over a reference comparison on strings from `maven-dependency-tree`: ```java .filter(s -> s != context.getScope()) ``` It happens to work only because the resolver usually hands back the same `String` instance that came out of `getItems()`. The intent is `!s.equals(context.getScope())`. Now that the plugin owns the class, this seems like the right moment to fix it — the change can only remove spurious `scope not updated to …` entries, never add any. -- 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]
