[ https://issues.apache.org/jira/browse/MDEP-650?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17888991#comment-17888991 ]
ASF GitHub Bot commented on MDEP-650: ------------------------------------- elharo commented on code in PR #12: URL: https://github.com/apache/maven-dependency-plugin/pull/12#discussion_r1798284616 ########## src/test/java/org/apache/maven/plugins/dependency/fromConfiguration/TestUnpackMojo.java: ########## @@ -80,8 +93,25 @@ protected void setUp() DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) session.getRepositorySession(); repoSession.setLocalRepositoryManager( new SimpleLocalRepositoryManager( stubFactory.getWorkingDir() ) ); + + artifactHandlerManager = new DefaultArtifactHandlerManager(); + + Map<String, ArtifactHandler> handlerMap = new HashMap<>(); + handlerMap.put("", new DefaultArtifactHandler("")); + handlerMap.put("jar", new DefaultArtifactHandler("jar")); + artifactHandlerManager.addHandlers(handlerMap); + } + + @Override + protected void tearDown() + { + super.tearDown(); Review Comment: this comes last, not first ########## src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/AbstractFromConfigurationMojo.java: ########## @@ -189,6 +202,105 @@ protected List<ArtifactItem> getProcessedArtifactItems( ProcessArtifactItemsRequ return artifactItems; } + /** + * If the artifact item has a version range, rather than a version, this + * method attempts to resolve this range by inspecting the list of resolved dependencies + * in the project for a match, before using the maven dependency resolver to resolve + * the range. + * + * If the dependency can be found and the version fits the artifact item's range + * then the artifact item is updated with the found version. + * + * If the dependency is not found or the range does not match, then the version + * is not changed. + * + * @param artifactItem The artifact item to update, if required. Review Comment: nit: the artifact item to update, if required per oracle javadoc conventions ########## src/test/java/org/apache/maven/plugins/dependency/testUtils/stubs/DependencyResolverStub.java: ########## @@ -0,0 +1,98 @@ +package org.apache.maven.plugins.dependency.testUtils.stubs; + +/* + * 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. + */ + +import java.io.IOException; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Model; +import org.apache.maven.project.ProjectBuildingRequest; +import org.apache.maven.shared.artifact.filter.resolve.TransformableFilter; +import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResult; +import org.apache.maven.shared.transfer.dependencies.DependableCoordinate; +import org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolver; +import org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolverException; + +/** + * A very simple stub to use for whiteboxing the a Maven DependencyResolver + * class. + */ +public class DependencyResolverStub implements DependencyResolver { + + private Map<String, Artifact> coordCache = new HashMap<>(); + + public void addDependableCoordinateLookup( + final DependableCoordinate coord, + final Artifact artifact ) + { + coordCache.put( coord.toString(), artifact ); + } + + @Override + public Iterable<ArtifactResult> resolveDependencies( + final ProjectBuildingRequest buildingRequest, + final DependableCoordinate coordinate, + final TransformableFilter filter ) throws DependencyResolverException + { + + + if ( coordCache.get( coordinate.toString() ) != null ) { + ArtifactResult result = new ArtifactResult() + { + + @Override + public Artifact getArtifact() + { + // TODO Auto-generated method stub Review Comment: remove comment ########## pom.xml: ########## @@ -30,7 +30,7 @@ under the License. </parent> <artifactId>maven-dependency-plugin</artifactId> - <version>3.1.2-SNAPSHOT</version> + <version>3.1.1.alehane-SNAPSHOT</version> Review Comment: nope ########## src/test/java/org/apache/maven/plugins/dependency/testUtils/stubs/DependencyResolverStub.java: ########## @@ -0,0 +1,98 @@ +package org.apache.maven.plugins.dependency.testUtils.stubs; + Review Comment: above package > dependency:unpack doesn't seem to handle version ranges > ------------------------------------------------------- > > Key: MDEP-650 > URL: https://issues.apache.org/jira/browse/MDEP-650 > Project: Maven Dependency Plugin > Issue Type: Bug > Components: unpack > Affects Versions: 3.1.1 > Reporter: Andy Lehane > Priority: Minor > Time Spent: 0.5h > Remaining Estimate: 0h > > This call is a reopened version of MDEP-50. > > I have a maven-dependency-plugin configuration of: > {code:java} > <plugin> > <groupId>org.apache.maven.plugins</groupId> > <artifactId>maven-dependency-plugin</artifactId> > <executions> > <execution> > <id>unpack commons-lang example</id> > <phase>process-resources</phase> > <goals> > <goal>unpack</goal> > </goals> > <configuration> > <artifactItems> > <artifactItem> > <groupId>commons-lang</groupId> > <artifactId>commons-lang</artifactId> > <version>[0,)</version> > <type>jar</type> > <overWrite>true</overWrite> > <outputDirectory>${project.build.directory}/test</outputDirectory> > </artifactItem> > </artifactItems> > </configuration> > </execution> > </executions> > </plugin> > {code} > When this is run using maven 3.6.0 and the maven-dependency-plugin version > 3.1.1, the following error is produced: > > {code:java} > [INFO] --- maven-dependency-plugin:3.1.1:unpack (unpack commons-lang example) > @ MavenDependencyPluginTestBed --- > [INFO] Configured Artifact: common-lang:commons-lang:[0,):jar > Downloading from central-proxy: > http://internal-repo/repository/central/commons-lang/commons-lang/%5B0,)/commons-lang-%5B0,).pom > [INFO] > ------------------------------------------------------------------------ > [INFO] BUILD FAILURE > [INFO] --------------------------------------------------------------- > {code} -- This message was sent by Atlassian Jira (v8.20.10#820010)