gnodet commented on code in PR #450: URL: https://github.com/apache/maven-resolver/pull/450#discussion_r1549385293
########## maven-resolver-util/src/main/java/org/eclipse/aether/util/graph/transformer/ConfigurableVersionSelector.java: ########## @@ -0,0 +1,350 @@ +/* + * 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.eclipse.aether.util.graph.transformer; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; + +import org.eclipse.aether.RepositoryException; +import org.eclipse.aether.collection.UnsolvableVersionConflictException; +import org.eclipse.aether.graph.DependencyFilter; +import org.eclipse.aether.graph.DependencyNode; +import org.eclipse.aether.util.graph.transformer.ConflictResolver.ConflictContext; +import org.eclipse.aether.util.graph.transformer.ConflictResolver.ConflictItem; +import org.eclipse.aether.util.graph.transformer.ConflictResolver.VersionSelector; +import org.eclipse.aether.util.graph.visitor.PathRecordingDependencyVisitor; +import org.eclipse.aether.util.graph.visitor.TreeDependencyVisitor; +import org.eclipse.aether.version.Version; +import org.eclipse.aether.version.VersionConstraint; + +import static java.util.Objects.requireNonNull; + +/** + * A configurable version selector for use with {@link ConflictResolver} that resolves version conflicts using a + * specified strategy. If there is no single node that satisfies all encountered version ranges, the selector will fail. + * Based on configuration, this selector may fail for other reasons as well. + * + * @since 2.0.0 + */ +public class ConfigurableVersionSelector extends VersionSelector { + /** + * The strategy how "winner" is being selected. + */ + public enum SelectionStrategy { + /** + * This is how Maven3 works, chooses "nearer" dependency for winner. + */ + NEARER, + /** + * This is new mode, chooses "higher version" dependency for winner. + */ + HIGHER_VERSION; + } + /** + * The compatibility check strategy. + */ + public interface CompatibilityStrategy { + /** + * This method should determine are versions of two items "compatible" or not. This method is invoked whenever + * {@code candidate} is "considered" (does not have to be selected as "winner"). + */ + boolean isIncompatibleVersion(ConflictItem candidate, ConflictItem winner) + throws UnsolvableVersionConflictException; + } + /** + * If true, this version selector will fail if detects "dependency version divergence" in graph. + */ + protected final boolean enforceVersionConvergence; Review Comment: Should that be a specific selection strategy instead ? We can't really enforce a single version and select the higher (or nearer) at the same time, right ? -- 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: issues-unsubscr...@maven.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org