Repository: maven
Updated Branches:
  refs/heads/MNG-6182 [created] ab800b0cf


[MNG-6182] ModelResolver interface enhancements.


Project: http://git-wip-us.apache.org/repos/asf/maven/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/ab800b0c
Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/ab800b0c
Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/ab800b0c

Branch: refs/heads/MNG-6182
Commit: ab800b0cfae4e3ca9453304e3b9727ba4a4b712b
Parents: 114ef6c
Author: Christian Schulte <schu...@apache.org>
Authored: Sat Jan 30 19:17:34 2016 +0100
Committer: Christian Schulte <schu...@apache.org>
Committed: Wed Mar 8 18:24:18 2017 +0100

----------------------------------------------------------------------
 .../maven/project/ProjectModelResolver.java     | 84 +++++++++++++++----
 .../maven/model/resolution/ModelResolver.java   | 32 ++++++++
 .../internal/DefaultModelResolver.java          | 85 ++++++++++++++++----
 3 files changed, 167 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven/blob/ab800b0c/maven-core/src/main/java/org/apache/maven/project/ProjectModelResolver.java
----------------------------------------------------------------------
diff --git 
a/maven-core/src/main/java/org/apache/maven/project/ProjectModelResolver.java 
b/maven-core/src/main/java/org/apache/maven/project/ProjectModelResolver.java
index 7b93217..3a31d33 100644
--- 
a/maven-core/src/main/java/org/apache/maven/project/ProjectModelResolver.java
+++ 
b/maven-core/src/main/java/org/apache/maven/project/ProjectModelResolver.java
@@ -28,7 +28,7 @@ import java.util.Set;
 
 import com.google.common.base.Predicate;
 import com.google.common.collect.Iterables;
-
+import org.apache.maven.model.Dependency;
 import org.apache.maven.model.Parent;
 import org.apache.maven.model.Repository;
 import org.apache.maven.model.building.FileModelSource;
@@ -203,24 +203,26 @@ public class ProjectModelResolver
         return new FileModelSource( pomFile );
     }
 
-    public ModelSource resolveModel( Parent parent )
+    @Override
+    public ModelSource resolveModel( final Parent parent )
         throws UnresolvableModelException
     {
-        Artifact artifact = new DefaultArtifact( parent.getGroupId(), 
parent.getArtifactId(), "", "pom",
-                                                 parent.getVersion() );
-
-        VersionRangeRequest versionRangeRequest = new VersionRangeRequest( 
artifact, repositories, context );
-        versionRangeRequest.setTrace( trace );
-
         try
         {
-            VersionRangeResult versionRangeResult = 
resolver.resolveVersionRange( session, versionRangeRequest );
+            final Artifact artifact = new DefaultArtifact( 
parent.getGroupId(), parent.getArtifactId(), "", "pom",
+                                                           parent.getVersion() 
);
+
+            final VersionRangeRequest versionRangeRequest = new 
VersionRangeRequest( artifact, repositories, context );
+            versionRangeRequest.setTrace( trace );
+
+            final VersionRangeResult versionRangeResult = 
resolver.resolveVersionRange( session, versionRangeRequest );
 
             if ( versionRangeResult.getHighestVersion() == null )
             {
-                throw new UnresolvableModelException( "No versions matched the 
requested range '" + parent.getVersion()
-                                                          + "'", 
parent.getGroupId(), parent.getArtifactId(),
-                                                      parent.getVersion() );
+                throw new UnresolvableModelException(
+                    String.format( "No versions matched the requested parent 
version range '%s'",
+                                   parent.getVersion() ),
+                    parent.getGroupId(), parent.getArtifactId(), 
parent.getVersion() );
 
             }
 
@@ -229,21 +231,69 @@ public class ProjectModelResolver
                      && 
versionRangeResult.getVersionConstraint().getRange().getUpperBound() == null )
             {
                 // Message below is checked for in the MNG-2199 core IT.
-                throw new UnresolvableModelException( "The requested version 
range '" + parent.getVersion()
-                                                          + "' does not 
specify an upper bound", parent.getGroupId(),
-                                                      parent.getArtifactId(), 
parent.getVersion() );
+                throw new UnresolvableModelException(
+                    String.format( "The requested parent version range '%s' 
does not specify an upper bound",
+                                   parent.getVersion() ),
+                    parent.getGroupId(), parent.getArtifactId(), 
parent.getVersion() );
 
             }
 
             parent.setVersion( 
versionRangeResult.getHighestVersion().toString() );
+
+            return resolveModel( parent.getGroupId(), parent.getArtifactId(), 
parent.getVersion() );
         }
-        catch ( VersionRangeResolutionException e )
+        catch ( final VersionRangeResolutionException e )
         {
             throw new UnresolvableModelException( e.getMessage(), 
parent.getGroupId(), parent.getArtifactId(),
                                                   parent.getVersion(), e );
 
         }
+    }
 
-        return resolveModel( parent.getGroupId(), parent.getArtifactId(), 
parent.getVersion() );
+    @Override
+    public ModelSource resolveModel( final Dependency dependency )
+        throws UnresolvableModelException
+    {
+        try
+        {
+            final Artifact artifact = new DefaultArtifact( 
dependency.getGroupId(), dependency.getArtifactId(), "",
+                                                           "pom", 
dependency.getVersion() );
+
+            final VersionRangeRequest versionRangeRequest = new 
VersionRangeRequest( artifact, repositories, context );
+            versionRangeRequest.setTrace( trace );
+
+            final VersionRangeResult versionRangeResult = 
resolver.resolveVersionRange( session, versionRangeRequest );
+
+            if ( versionRangeResult.getHighestVersion() == null )
+            {
+                throw new UnresolvableModelException(
+                    String.format( "No versions matched the requested 
dependency version range '%s'",
+                                   dependency.getVersion() ),
+                    dependency.getGroupId(), dependency.getArtifactId(), 
dependency.getVersion() );
+
+            }
+
+            if ( versionRangeResult.getVersionConstraint() != null
+                     && versionRangeResult.getVersionConstraint().getRange() 
!= null
+                     && 
versionRangeResult.getVersionConstraint().getRange().getUpperBound() == null )
+            {
+                // Message below is checked for in the MNG-4463 core IT.
+                throw new UnresolvableModelException(
+                    String.format( "The requested dependency version range 
'%s' does not specify an upper bound",
+                                   dependency.getVersion() ),
+                    dependency.getGroupId(), dependency.getArtifactId(), 
dependency.getVersion() );
+
+            }
+
+            dependency.setVersion( 
versionRangeResult.getHighestVersion().toString() );
+
+            return resolveModel( dependency.getGroupId(), 
dependency.getArtifactId(), dependency.getVersion() );
+        }
+        catch ( VersionRangeResolutionException e )
+        {
+            throw new UnresolvableModelException( e.getMessage(), 
dependency.getGroupId(), dependency.getArtifactId(),
+                                                  dependency.getVersion(), e );
+
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/maven/blob/ab800b0c/maven-model-builder/src/main/java/org/apache/maven/model/resolution/ModelResolver.java
----------------------------------------------------------------------
diff --git 
a/maven-model-builder/src/main/java/org/apache/maven/model/resolution/ModelResolver.java
 
b/maven-model-builder/src/main/java/org/apache/maven/model/resolution/ModelResolver.java
index c81a536..39695f7 100644
--- 
a/maven-model-builder/src/main/java/org/apache/maven/model/resolution/ModelResolver.java
+++ 
b/maven-model-builder/src/main/java/org/apache/maven/model/resolution/ModelResolver.java
@@ -19,6 +19,7 @@ package org.apache.maven.model.resolution;
  * under the License.
  */
 
+import org.apache.maven.model.Dependency;
 import org.apache.maven.model.Parent;
 import org.apache.maven.model.Repository;
 import org.apache.maven.model.building.ModelSource;
@@ -47,16 +48,47 @@ public interface ModelResolver
 
     /**
      * Tries to resolve the POM for the specified parent coordinates possibly 
updating {@code parent}.
+     * <p>
+     * Unlike the {@link #resolveModel(java.lang.String, java.lang.String, 
java.lang.String)} method, this method
+     * supports version ranges and updates the given {@code parent} instance 
to match the returned {@code ModelSource}.
+     * If {@code parent} declares a version range, the version corresponding 
to the returned {@code ModelSource} will
+     * be set on the given {@code parent}.
+     * </p>
      *
      * @param parent The parent coordinates to resolve, must not be {@code 
null}.
+     *
      * @return The source of the requested POM, never {@code null}.
+     *
      * @throws UnresolvableModelException If the POM could not be resolved 
from any configured repository.
      * @since 3.2.2
+     *
+     * @see Parent#clone()
      */
     ModelSource resolveModel( Parent parent )
         throws UnresolvableModelException;
 
     /**
+     * Tries to resolve the POM for the specified dependency coordinates 
possibly updating {@code dependency}.
+     * <p>
+     * Unlike the {@link #resolveModel(java.lang.String, java.lang.String, 
java.lang.String)} method, this method
+     * supports version ranges and updates the given {@code dependency} 
instance to match the returned
+     * {@code ModelSource}. If {@code dependency} declares a version range, 
the version corresponding to the returned
+     * {@code ModelSource} will be set on the given {@code dependency}.
+     * </p>
+     *
+     * @param dependency The dependency coordinates to resolve, must not be 
{@code null}.
+     *
+     * @return The source of the requested POM, never {@code null}.
+     *
+     * @throws UnresolvableModelException If the POM could not be resolved 
from any configured repository.
+     * @since 3.5.0-alpha-2
+     *
+     * @see Dependency#clone()
+     */
+    ModelSource resolveModel( Dependency dependency )
+        throws UnresolvableModelException;
+
+    /**
      * Adds a repository to use for subsequent resolution requests. The order 
in which repositories are added matters,
      * repositories that were added first should also be searched first. When 
multiple repositories with the same
      * identifier are added, only the first repository being added will be 
used.

http://git-wip-us.apache.org/repos/asf/maven/blob/ab800b0c/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultModelResolver.java
----------------------------------------------------------------------
diff --git 
a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultModelResolver.java
 
b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultModelResolver.java
index 9ea91ff..3e82eb9 100644
--- 
a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultModelResolver.java
+++ 
b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultModelResolver.java
@@ -28,6 +28,7 @@ import java.util.Set;
 
 import com.google.common.base.Predicate;
 import com.google.common.collect.Iterables;
+import org.apache.maven.model.Dependency;
 import org.apache.maven.model.Parent;
 import org.apache.maven.model.Repository;
 import org.apache.maven.model.building.FileModelSource;
@@ -182,25 +183,27 @@ class DefaultModelResolver
         return new FileModelSource( pomFile );
     }
 
-    public ModelSource resolveModel( Parent parent )
+    @Override
+    public ModelSource resolveModel( final Parent parent )
         throws UnresolvableModelException
     {
-        Artifact artifact = new DefaultArtifact( parent.getGroupId(), 
parent.getArtifactId(), "", "pom",
-                                                 parent.getVersion() );
-
-        VersionRangeRequest versionRangeRequest = new VersionRangeRequest( 
artifact, repositories, context );
-        versionRangeRequest.setTrace( trace );
-
         try
         {
-            VersionRangeResult versionRangeResult =
+            final Artifact artifact = new DefaultArtifact( 
parent.getGroupId(), parent.getArtifactId(), "", "pom",
+                                                           parent.getVersion() 
);
+
+            final VersionRangeRequest versionRangeRequest = new 
VersionRangeRequest( artifact, repositories, context );
+            versionRangeRequest.setTrace( trace );
+
+            final VersionRangeResult versionRangeResult =
                 versionRangeResolver.resolveVersionRange( session, 
versionRangeRequest );
 
             if ( versionRangeResult.getHighestVersion() == null )
             {
-                throw new UnresolvableModelException( "No versions matched the 
requested range '" + parent.getVersion()
-                                                          + "'", 
parent.getGroupId(), parent.getArtifactId(),
-                                                      parent.getVersion() );
+                throw new UnresolvableModelException(
+                    String.format( "No versions matched the requested parent 
version range '%s'",
+                                   parent.getVersion() ),
+                    parent.getGroupId(), parent.getArtifactId(), 
parent.getVersion() );
 
             }
 
@@ -209,22 +212,70 @@ class DefaultModelResolver
                      && 
versionRangeResult.getVersionConstraint().getRange().getUpperBound() == null )
             {
                 // Message below is checked for in the MNG-2199 core IT.
-                throw new UnresolvableModelException( "The requested version 
range '" + parent.getVersion()
-                                                          + "' does not 
specify an upper bound", parent.getGroupId(),
-                                                      parent.getArtifactId(), 
parent.getVersion() );
+                throw new UnresolvableModelException(
+                    String.format( "The requested parent version range '%s' 
does not specify an upper bound",
+                                   parent.getVersion() ),
+                    parent.getGroupId(), parent.getArtifactId(), 
parent.getVersion() );
 
             }
 
             parent.setVersion( 
versionRangeResult.getHighestVersion().toString() );
+
+            return resolveModel( parent.getGroupId(), parent.getArtifactId(), 
parent.getVersion() );
         }
-        catch ( VersionRangeResolutionException e )
+        catch ( final VersionRangeResolutionException e )
         {
             throw new UnresolvableModelException( e.getMessage(), 
parent.getGroupId(), parent.getArtifactId(),
                                                   parent.getVersion(), e );
 
         }
-
-        return resolveModel( parent.getGroupId(), parent.getArtifactId(), 
parent.getVersion() );
     }
 
+    @Override
+    public ModelSource resolveModel( final Dependency dependency )
+        throws UnresolvableModelException
+    {
+        try
+        {
+            final Artifact artifact = new DefaultArtifact( 
dependency.getGroupId(), dependency.getArtifactId(), "",
+                                                           "pom", 
dependency.getVersion() );
+
+            final VersionRangeRequest versionRangeRequest = new 
VersionRangeRequest( artifact, repositories, context );
+            versionRangeRequest.setTrace( trace );
+
+            final VersionRangeResult versionRangeResult =
+                versionRangeResolver.resolveVersionRange( session, 
versionRangeRequest );
+
+            if ( versionRangeResult.getHighestVersion() == null )
+            {
+                throw new UnresolvableModelException(
+                    String.format( "No versions matched the requested 
dependency version range '%s'",
+                                   dependency.getVersion() ),
+                    dependency.getGroupId(), dependency.getArtifactId(), 
dependency.getVersion() );
+
+            }
+
+            if ( versionRangeResult.getVersionConstraint() != null
+                     && versionRangeResult.getVersionConstraint().getRange() 
!= null
+                     && 
versionRangeResult.getVersionConstraint().getRange().getUpperBound() == null )
+            {
+                // Message below is checked for in the MNG-4463 core IT.
+                throw new UnresolvableModelException(
+                    String.format( "The requested dependency version range 
'%s' does not specify an upper bound",
+                                   dependency.getVersion() ),
+                    dependency.getGroupId(), dependency.getArtifactId(), 
dependency.getVersion() );
+
+            }
+
+            dependency.setVersion( 
versionRangeResult.getHighestVersion().toString() );
+
+            return resolveModel( dependency.getGroupId(), 
dependency.getArtifactId(), dependency.getVersion() );
+        }
+        catch ( VersionRangeResolutionException e )
+        {
+            throw new UnresolvableModelException( e.getMessage(), 
dependency.getGroupId(), dependency.getArtifactId(),
+                                                  dependency.getVersion(), e );
+
+        }
+    }
 }

Reply via email to