This is an automated email from the ASF dual-hosted git repository. khmarbaise pushed a commit to branch MDEP-896 in repository https://gitbox.apache.org/repos/asf/maven-dependency-plugin.git
commit 90311eaffcdd5497a7b0e313dacc41e5c913e5c0 Author: Karl Heinz Marbaise <khmarba...@apache.org> AuthorDate: Fri Nov 10 02:58:09 2023 +0100 [MDEP-896] - Removing unused code --- .../maven/plugins/dependency/tree/TreeMojo.java | 29 +------------ .../tree/TestTreeMojo_ContainsVersion.java | 49 ---------------------- 2 files changed, 2 insertions(+), 76 deletions(-) diff --git a/src/main/java/org/apache/maven/plugins/dependency/tree/TreeMojo.java b/src/main/java/org/apache/maven/plugins/dependency/tree/TreeMojo.java index 960f101b..f40cfcf9 100644 --- a/src/main/java/org/apache/maven/plugins/dependency/tree/TreeMojo.java +++ b/src/main/java/org/apache/maven/plugins/dependency/tree/TreeMojo.java @@ -64,6 +64,8 @@ import org.eclipse.aether.RepositorySystem; import org.eclipse.aether.RepositorySystemSession; import org.eclipse.aether.repository.RemoteRepository; +import static java.util.Objects.nonNull; + /** * Displays the dependency tree for this project. Multiple formats are supported: text (by default), but also * <a href="https://en.wikipedia.org/wiki/DOT_language">DOT</a>, @@ -442,31 +444,4 @@ public class TreeMojo extends AbstractMojo { // following is required because the version handling in maven code // doesn't work properly. I ripped it out of the enforcer rules. - - /** - * Copied from Artifact.VersionRange. This is tweaked to handle singular ranges properly. Currently the default - * containsVersion method assumes a singular version means allow everything. This method assumes that "2.0.4" == - * "[2.0.4,)" - * - * @param allowedRange range of allowed versions. - * @param theVersion the version to be checked. - * @return true if the version is contained by the range. - * @deprecated This method is unused in this project and will be removed in the future. - */ - @Deprecated - public static boolean containsVersion(VersionRange allowedRange, ArtifactVersion theVersion) { - ArtifactVersion recommendedVersion = allowedRange.getRecommendedVersion(); - if (recommendedVersion == null) { - List<Restriction> restrictions = allowedRange.getRestrictions(); - for (Restriction restriction : restrictions) { - if (restriction.containsVersion(theVersion)) { - return true; - } - } - return false; - } else { - // only singular versions ever have a recommendedVersion - return recommendedVersion.compareTo(theVersion) <= 0; - } - } } diff --git a/src/test/java/org/apache/maven/plugins/dependency/tree/TestTreeMojo_ContainsVersion.java b/src/test/java/org/apache/maven/plugins/dependency/tree/TestTreeMojo_ContainsVersion.java deleted file mode 100644 index 95badb0b..00000000 --- a/src/test/java/org/apache/maven/plugins/dependency/tree/TestTreeMojo_ContainsVersion.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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.Collections; - -import junit.framework.TestCase; -import org.apache.maven.artifact.versioning.ArtifactVersion; -import org.apache.maven.artifact.versioning.Restriction; -import org.apache.maven.artifact.versioning.VersionRange; - -import static org.apache.maven.plugins.dependency.tree.TreeMojo.containsVersion; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -/** - * Tests <code>TreeMojo.containsVersion</code>. - */ -public class TestTreeMojo_ContainsVersion extends TestCase { - private VersionRange range = mock(VersionRange.class); - - private ArtifactVersion version = mock(ArtifactVersion.class); - - public void testWhenRecommendedVersionIsNullAndNoRestrictions() { - when(range.getRecommendedVersion()).thenReturn(null); - when(range.getRestrictions()).thenReturn(Collections.<Restriction>emptyList()); - - @SuppressWarnings("deprecation") - boolean doesItContain = containsVersion(range, version); - - assertFalse(doesItContain); - } -}