Repository: maven
Updated Branches:
  refs/heads/MNG-2199 6a243f022 -> affddb2e5 (forced update)


[MNG-2199] Support version ranges in parent elements

o Updated to fix parent version range resolution broken since 3.2.3 and to
  remove parent version range resolution logic obsolete since Maven
  3.2.3 which changed the initialization of MavenProject instances.
o Updated local parent resolution to behave the same way remote parent
  resolution behaves. When referencing a parent using version ranges,
  inheriting the version or using version expressions should not be supported.
  It has been implemented that way for remote parent resolution as it got
  introduced in Maven 3.2.2. For local parent resolution the version in parent
  declarations had been ignored completely as of Maven 3.3.0 due to commit
  be3fb200326208ca4b8c41ebf16d5ae6b8049792 removing all local parent version
  validation. Work on fixing this is tracked by MNG-5840 released with Maven
  3.3.9. This commit adds the final missing bits to make local and remote parent
  resolution behave the same way as much as possible. As an exception, remote
  parent resolution still is a bit more strict than local parent resolution due
  to a different API in use. When resolving a parent from a repository using
  version ranges, the ModelBuilder verifies the range in use to declare an upper
  bound. When resolving a parent locally using version ranges, those ranges are
  not required to declare an upper bound because the API in use does not support
  querying that. Authoring a POM relying on this difference should be considered
  a bug.
o Added test cases to maven-core testing parent version range resolution for
  local and remote parent models.


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

Branch: refs/heads/MNG-2199
Commit: affddb2e5d1dca0fc956fa61ca60a5843775f94c
Parents: 1740265
Author: Christian Schulte <schu...@apache.org>
Authored: Sat Dec 12 20:28:56 2015 +0100
Committer: Christian Schulte <schu...@apache.org>
Committed: Sun Feb 5 00:00:31 2017 +0100

----------------------------------------------------------------------
 .../maven/project/DefaultProjectBuilder.java    | 113 +++++++++-------
 .../project/DefaultProjectBuildingRequest.java  |  15 ++-
 .../maven/project/ProjectBuildingRequest.java   |  14 +-
 .../maven/project/ProjectModelResolver.java     |   1 +
 .../project/AbstractMavenProjectTestCase.java   |  11 ++
 .../project/DefaultMavenProjectBuilderTest.java | 130 +++++++++++++++++++
 .../repository/TestRepositoryConnector.java     |  38 ++++++
 .../org/apache/apache/1/apache-1.pom            |  82 ++++++++++++
 .../org/apache/apache/maven-metadata.xml        |  13 ++
 .../pom.xml                                     |  12 ++
 .../pom.xml                                     |  11 ++
 .../parent-version-range-external-valid/pom.xml |  11 ++
 .../child/pom.xml                               |  12 ++
 .../pom.xml                                     |   7 +
 .../child/pom.xml                               |  11 ++
 .../pom.xml                                     |   7 +
 .../child/pom.xml                               |  11 ++
 .../parent-version-range-local-valid/pom.xml    |   7 +
 .../model/building/DefaultModelBuilder.java     |  30 ++++-
 .../internal/DefaultModelResolver.java          |   1 +
 20 files changed, 482 insertions(+), 55 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven/blob/affddb2e/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
----------------------------------------------------------------------
diff --git 
a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java 
b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
index d064ab4..869e584 100644
--- 
a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
+++ 
b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
@@ -43,7 +43,6 @@ import org.apache.maven.model.DependencyManagement;
 import org.apache.maven.model.DeploymentRepository;
 import org.apache.maven.model.Extension;
 import org.apache.maven.model.Model;
-import org.apache.maven.model.Parent;
 import org.apache.maven.model.Plugin;
 import org.apache.maven.model.Profile;
 import org.apache.maven.model.ReportPlugin;
@@ -73,9 +72,6 @@ import org.eclipse.aether.repository.RemoteRepository;
 import org.eclipse.aether.repository.WorkspaceRepository;
 import org.eclipse.aether.resolution.ArtifactRequest;
 import org.eclipse.aether.resolution.ArtifactResult;
-import org.eclipse.aether.resolution.VersionRangeRequest;
-import org.eclipse.aether.resolution.VersionRangeResolutionException;
-import org.eclipse.aether.resolution.VersionRangeResult;
 
 /**
  */
@@ -298,44 +294,6 @@ public class DefaultProjectBuilder
 
         boolean localProject;
 
-        if ( request.isResolveVersionRanges() )
-        {
-            VersionRangeRequest versionRangeRequest = new VersionRangeRequest( 
pomArtifact, config.repositories, null );
-
-            try
-            {
-                VersionRangeResult versionRangeResult =
-                    repoSystem.resolveVersionRange( config.session, 
versionRangeRequest );
-
-                if ( versionRangeResult.getHighestVersion() == null )
-                {
-                    throw new ProjectBuildingException(
-                        artifact.getId(), "Error resolving project artifact: 
No versions matched the requested range",
-                        (Throwable) null );
-
-                }
-
-                if ( versionRangeResult.getVersionConstraint() != null
-                         && 
versionRangeResult.getVersionConstraint().getRange() != null
-                         && 
versionRangeResult.getVersionConstraint().getRange().getUpperBound() == null )
-                {
-                    throw new ProjectBuildingException(
-                        artifact.getId(),
-                        "Error resolving project artifact: The requested 
version range does not specify an upper bound",
-                        (Throwable) null );
-
-                }
-
-                pomArtifact = pomArtifact.setVersion( 
versionRangeResult.getHighestVersion().toString() );
-            }
-            catch ( VersionRangeResolutionException e )
-            {
-                throw new ProjectBuildingException(
-                    artifact.getId(), "Error resolving project artifact: " + 
e.getMessage(), e );
-
-            }
-        }
-
         try
         {
             ArtifactRequest pomRequest = new ArtifactRequest();
@@ -656,11 +614,20 @@ public class DefaultProjectBuilder
         project.setModel( model );
         project.setOriginalModel( result.getRawModel() );
         project.setFile( model.getPomFile() );
-        Parent p = model.getParent();
-        if ( p != null )
+
+        Model parentModel = result.getModelIds().size() > 1 && 
!result.getModelIds().get( 1 ).isEmpty()
+                                ? result.getRawModel( 
result.getModelIds().get( 1 ) )
+                                : null;
+
+        if ( parentModel != null )
         {
-            project.setParentArtifact( repositorySystem.createProjectArtifact( 
p.getGroupId(), p.getArtifactId(),
-                                                                               
p.getVersion() ) );
+            final String parentGroupId = inheritedGroupId( result, 1 );
+            final String parentVersion = inheritedVersion( result, 1 );
+
+            project.setParentArtifact( repositorySystem.createProjectArtifact( 
parentGroupId,
+                                                                               
parentModel.getArtifactId(),
+                                                                               
parentVersion ) );
+
             // org.apache.maven.its.mng4834:parent:0.1
             String parentModelId = result.getModelIds().get( 1 );
             File parentPomFile = result.getRawModel( parentModelId 
).getPomFile();
@@ -683,7 +650,16 @@ public class DefaultProjectBuilder
                     catch ( ProjectBuildingException e )
                     {
                         // MNG-4488 where let invalid parents slide on by
-                        logger.warn( "Failed to build parent project for " + 
project.getId() );
+                        if ( logger.isDebugEnabled() )
+                        {
+                            // Message below is checked for in the MNG-2199 
core IT.
+                            logger.warn( "Failed to build parent project for " 
+ project.getId(), e );
+                        }
+                        else
+                        {
+                            // Message below is checked for in the MNG-2199 
core IT.
+                            logger.warn( "Failed to build parent project for " 
+ project.getId() );
+                        }
                     }
                 }
                 else
@@ -696,7 +672,14 @@ public class DefaultProjectBuilder
                     catch ( ProjectBuildingException e )
                     {
                         // MNG-4488 where let invalid parents slide on by
-                        logger.warn( "Failed to build parent project for " + 
project.getId() );
+                        if ( logger.isDebugEnabled() )
+                        {
+                            logger.warn( "Failed to build parent project for " 
+ project.getId(), e );
+                        }
+                        else
+                        {
+                            logger.warn( "Failed to build parent project for " 
+ project.getId() );
+                        }
                     }
                 }
             }
@@ -878,6 +861,40 @@ public class DefaultProjectBuilder
         }
     }
 
+    private static String inheritedGroupId( final ModelBuildingResult result, 
final int modelIndex )
+    {
+        String groupId = null;
+        final String modelId = result.getModelIds().get( modelIndex );
+
+        if ( !modelId.isEmpty() )
+        {
+            final Model model = result.getRawModel( modelId );
+            groupId = model.getGroupId() != null
+                          ? model.getGroupId()
+                          : inheritedGroupId( result, modelIndex + 1 );
+
+        }
+
+        return groupId;
+    }
+
+    private static String inheritedVersion( final ModelBuildingResult result, 
final int modelIndex )
+    {
+        String version = null;
+        final String modelId = result.getModelIds().get( modelIndex );
+
+        if ( !modelId.isEmpty() )
+        {
+            final Model model = result.getRawModel( modelId );
+            version = model.getVersion() != null
+                          ? model.getVersion()
+                          : inheritedVersion( result, modelIndex + 1 );
+
+        }
+
+        return version;
+    }
+
     private String findProfilesXml( ModelBuildingResult result, Map<File, 
Boolean> profilesXmls )
     {
         for ( String modelId : result.getModelIds() )

http://git-wip-us.apache.org/repos/asf/maven/blob/affddb2e/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingRequest.java
----------------------------------------------------------------------
diff --git 
a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingRequest.java
 
b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingRequest.java
index f1b271b..dafbefd 100644
--- 
a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingRequest.java
+++ 
b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingRequest.java
@@ -63,6 +63,7 @@ public class DefaultProjectBuildingRequest
 
     private boolean resolveDependencies;
 
+    @Deprecated
     private boolean resolveVersionRanges;
 
     private RepositoryMerging repositoryMerging = 
RepositoryMerging.POM_DOMINANT;
@@ -218,14 +219,24 @@ public class DefaultProjectBuildingRequest
         return resolveDependencies;
     }
 
-    /** @since 3.2.2 */
+    /**
+     * @since 3.2.2
+     * @deprecated This got added when implementing MNG-2199 and is no longer 
used.
+     * Commit 6cf9320942c34bc68205425ab696b1712ace9ba4 updated the way 
'MavenProject' objects are initialized.
+     */
+    @Deprecated
     public ProjectBuildingRequest setResolveVersionRanges( boolean value )
     {
         this.resolveVersionRanges = value;
         return this;
     }
 
-    /** @since 3.2.2 */
+    /**
+     * @since 3.2.2
+     * @deprecated This got added when implementing MNG-2199 and is no longer 
used.
+     * Commit 6cf9320942c34bc68205425ab696b1712ace9ba4 updated the way 
'MavenProject' objects are initialized.
+     */
+    @Deprecated
     public boolean isResolveVersionRanges()
     {
         return this.resolveVersionRanges;

http://git-wip-us.apache.org/repos/asf/maven/blob/affddb2e/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingRequest.java
----------------------------------------------------------------------
diff --git 
a/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingRequest.java 
b/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingRequest.java
index d8ab195..d0e4afe 100644
--- 
a/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingRequest.java
+++ 
b/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingRequest.java
@@ -168,10 +168,20 @@ public interface ProjectBuildingRequest
      */
     RepositoryMerging getRepositoryMerging();
 
-    /** @since 3.2.2 */
+    /**
+     * @since 3.2.2
+     * @deprecated This got added when implementing MNG-2199 and is no longer 
used.
+     * Commit 6cf9320942c34bc68205425ab696b1712ace9ba4 updated the way 
'MavenProject' objects are initialized.
+     */
+    @Deprecated
     boolean isResolveVersionRanges();
 
-    /** @since 3.2.2 */
+    /**
+     * @since 3.2.2
+     * @deprecated This got added when implementing MNG-2199 and is no longer 
used.
+     * Commit 6cf9320942c34bc68205425ab696b1712ace9ba4 updated the way 
'MavenProject' objects are initialized.
+     */
+    @Deprecated
     ProjectBuildingRequest setResolveVersionRanges( boolean value );
 
     /**

http://git-wip-us.apache.org/repos/asf/maven/blob/affddb2e/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 184be70..7b93217 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
@@ -228,6 +228,7 @@ public class ProjectModelResolver
                      && versionRangeResult.getVersionConstraint().getRange() 
!= null
                      && 
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() );

http://git-wip-us.apache.org/repos/asf/maven/blob/affddb2e/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java
----------------------------------------------------------------------
diff --git 
a/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java
 
b/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java
index 73bdbca..71616fa 100644
--- 
a/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java
+++ 
b/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java
@@ -169,6 +169,17 @@ public abstract class AbstractMavenProjectTestCase
         return projectBuilder.build( pom, configuration ).getProject();
     }
 
+    protected MavenProject getProjectFromRemoteRepository( final File pom )
+        throws Exception
+    {
+        final ProjectBuildingRequest configuration = new 
DefaultProjectBuildingRequest();
+        configuration.setLocalRepository( this.getLocalRepository() );
+        configuration.setRemoteRepositories( Arrays.asList( 
this.repositorySystem.createDefaultRemoteRepository() ) );
+        initRepoSession( configuration );
+
+        return projectBuilder.build( pom, configuration ).getProject();
+    }
+
     protected ProjectBuildingRequest newBuildingRequest()
         throws Exception
     {

http://git-wip-us.apache.org/repos/asf/maven/blob/affddb2e/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java
----------------------------------------------------------------------
diff --git 
a/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java
 
b/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java
index 84fb784..73629bc 100644
--- 
a/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java
+++ 
b/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java
@@ -189,4 +189,134 @@ public class DefaultMavenProjectBuilderTest
         request.setResolveDependencies( true );
         projectBuilder.build( pomFile, request );
     }
+
+    /**
+     * Tests whether local version range parent references are build correctly.
+     *
+     * @throws Exception
+     */
+    public void testBuildValidParentVersionRangeLocally() throws Exception
+    {
+        File f1 = getTestFile( 
"src/test/resources/projects/parent-version-range-local-valid/child/pom.xml" );
+
+        final MavenProject childProject = getProject( f1 );
+
+        assertNotNull( childProject.getParentArtifact() );
+        assertEquals( childProject.getParentArtifact().getVersion(), "1" );
+        assertNotNull( childProject.getParent() );
+        assertEquals( childProject.getParent().getVersion(), "1" );
+        assertNotNull( childProject.getModel().getParent() );
+        assertEquals( childProject.getModel().getParent().getVersion(), 
"[1,10]" );
+    }
+
+    /**
+     * Tests whether local version range parent references are build correctly.
+     *
+     * @throws Exception
+     */
+    public void testBuildParentVersionRangeLocallyWithoutChildVersion() throws 
Exception
+    {
+        File f1 =
+            getTestFile( 
"src/test/resources/projects/parent-version-range-local-child-without-version/child/pom.xml"
 );
+
+        try
+        {
+            getProject( f1 );
+            fail( "Expected 'ProjectBuildingException' not thrown." );
+        }
+        catch ( final ProjectBuildingException e )
+        {
+            assertNotNull( e.getMessage() );
+            assertTrue( e.getMessage().contains( "Version must be a constant" 
) );
+        }
+    }
+
+    /**
+     * Tests whether local version range parent references are build correctly.
+     *
+     * @throws Exception
+     */
+    public void testBuildParentVersionRangeLocallyWithChildVersionExpression() 
throws Exception
+    {
+        File f1 =
+            getTestFile(
+                
"src/test/resources/projects/parent-version-range-local-child-version-expression/child/pom.xml"
 );
+
+        try
+        {
+            getProject( f1 );
+            fail( "Expected 'ProjectBuildingException' not thrown." );
+        }
+        catch ( final ProjectBuildingException e )
+        {
+            assertNotNull( e.getMessage() );
+            assertTrue( e.getMessage().contains( "Version must be a constant" 
) );
+        }
+    }
+
+    /**
+     * Tests whether external version range parent references are build 
correctly.
+     *
+     * @throws Exception
+     */
+    public void testBuildParentVersionRangeExternally() throws Exception
+    {
+        File f1 = getTestFile( 
"src/test/resources/projects/parent-version-range-external-valid/pom.xml" );
+
+        final MavenProject childProject = this.getProjectFromRemoteRepository( 
f1 );
+
+        assertNotNull( childProject.getParentArtifact() );
+        assertEquals( childProject.getParentArtifact().getVersion(), "1" );
+        assertNotNull( childProject.getParent() );
+        assertEquals( childProject.getParent().getVersion(), "1" );
+        assertNotNull( childProject.getModel().getParent() );
+        assertEquals( childProject.getModel().getParent().getVersion(), 
"[1,1]" );
+    }
+
+    /**
+     * Tests whether external version range parent references are build 
correctly.
+     *
+     * @throws Exception
+     */
+    public void testBuildParentVersionRangeExternallyWithoutChildVersion() 
throws Exception
+    {
+        File f1 =
+            getTestFile(
+                
"src/test/resources/projects/parent-version-range-external-child-without-version/pom.xml"
 );
+
+        try
+        {
+            this.getProjectFromRemoteRepository( f1 );
+            fail( "Expected 'ProjectBuildingException' not thrown." );
+        }
+        catch ( final ProjectBuildingException e )
+        {
+            assertNotNull( e.getMessage() );
+            assertTrue( e.getMessage().contains( "Version must be a constant" 
) );
+        }
+    }
+
+    /**
+     * Tests whether external version range parent references are build 
correctly.
+     *
+     * @throws Exception
+     */
+    public void 
testBuildParentVersionRangeExternallyWithChildVersionExpression() throws 
Exception
+    {
+        File f1 =
+            getTestFile(
+                
"src/test/resources/projects/parent-version-range-external-child-version-expression/pom.xml"
 );
+
+        try
+        {
+            this.getProjectFromRemoteRepository( f1 );
+            fail( "Expected 'ProjectBuildingException' not thrown." );
+        }
+        catch ( final ProjectBuildingException e )
+        {
+            assertNotNull( e.getMessage() );
+            assertTrue( e.getMessage().contains( "Version must be a constant" 
) );
+        }
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/maven/blob/affddb2e/maven-core/src/test/java/org/apache/maven/repository/TestRepositoryConnector.java
----------------------------------------------------------------------
diff --git 
a/maven-core/src/test/java/org/apache/maven/repository/TestRepositoryConnector.java
 
b/maven-core/src/test/java/org/apache/maven/repository/TestRepositoryConnector.java
index 91ace4f..cb1243c 100644
--- 
a/maven-core/src/test/java/org/apache/maven/repository/TestRepositoryConnector.java
+++ 
b/maven-core/src/test/java/org/apache/maven/repository/TestRepositoryConnector.java
@@ -27,6 +27,7 @@ import java.util.Collection;
 
 import org.codehaus.plexus.util.FileUtils;
 import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
 import org.eclipse.aether.repository.RemoteRepository;
 import org.eclipse.aether.spi.connector.ArtifactDownload;
 import org.eclipse.aether.spi.connector.ArtifactUpload;
@@ -35,6 +36,8 @@ import org.eclipse.aether.spi.connector.MetadataUpload;
 import org.eclipse.aether.spi.connector.RepositoryConnector;
 import org.eclipse.aether.transfer.ArtifactNotFoundException;
 import org.eclipse.aether.transfer.ArtifactTransferException;
+import org.eclipse.aether.transfer.MetadataNotFoundException;
+import org.eclipse.aether.transfer.MetadataTransferException;
 
 /**
  * @author Benjamin Bentmann
@@ -89,6 +92,28 @@ public class TestRepositoryConnector
                 }
             }
         }
+        if ( metadataDownloads != null )
+        {
+            for ( final MetadataDownload download : metadataDownloads )
+            {
+                File remoteFile = new File( basedir, path( 
download.getMetadata() ) );
+                try
+                {
+                    FileUtils.copyFile( remoteFile, download.getFile() );
+                }
+                catch ( IOException e )
+                {
+                    if ( !remoteFile.exists() )
+                    {
+                        download.setException( new MetadataNotFoundException( 
download.getMetadata(), repository ) );
+                    }
+                    else
+                    {
+                        download.setException( new MetadataTransferException( 
download.getMetadata(), repository, e ) );
+                    }
+                }
+            }
+        }
     }
 
     private String path( Artifact artifact )
@@ -113,6 +138,19 @@ public class TestRepositoryConnector
         return path.toString();
     }
 
+    private String path( Metadata metadata )
+    {
+        StringBuilder path = new StringBuilder( 128 );
+
+        path.append( metadata.getGroupId().replace( '.', '/' ) ).append( '/' );
+
+        path.append( metadata.getArtifactId() ).append( '/' );
+
+        path.append( "maven-metadata.xml" );
+
+        return path.toString();
+    }
+
     public void put( Collection<? extends ArtifactUpload> artifactUploads,
                      Collection<? extends MetadataUpload> metadataUploads )
     {

http://git-wip-us.apache.org/repos/asf/maven/blob/affddb2e/maven-core/src/test/remote-repo/org/apache/apache/1/apache-1.pom
----------------------------------------------------------------------
diff --git a/maven-core/src/test/remote-repo/org/apache/apache/1/apache-1.pom 
b/maven-core/src/test/remote-repo/org/apache/apache/1/apache-1.pom
new file mode 100644
index 0000000..ad6b854
--- /dev/null
+++ b/maven-core/src/test/remote-repo/org/apache/apache/1/apache-1.pom
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  ~ Copyright 2005-2006 The Apache Software Foundation.
+  ~
+  ~ Licensed 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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+
+  <!-- Shared parent. Doesn't define a lot of things about Apache like general 
mailing lists, but does
+       define the settings common to all projects at Apache -->
+  <groupId>org.apache</groupId>
+  <artifactId>apache</artifactId>
+  <version>1</version>
+  <packaging>pom</packaging>
+  <name>The Apache Software Foundation</name>
+  <description>
+    The Apache Software Foundation provides support for the Apache community 
of open-source software projects.
+    The Apache projects are characterized by a collaborative, consensus based 
development process, an open and
+    pragmatic software license, and a desire to create high quality software 
that leads the way in its field.
+    We consider ourselves not simply a group of projects sharing a server, but 
rather a community of developers
+    and users.
+  </description>
+  <licenses>
+    <license>
+      <name>The Apache Software License, Version 2.0</name>
+      <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
+      <distribution>repo</distribution>
+    </license>
+  </licenses>
+  <organization>
+    <name>Apache Software Foundation</name>
+    <url>http://www.apache.org/</url>
+  </organization>
+  <url>http://www.apache.org/</url>
+  <repositories>
+    <repository>
+      <id>apache.snapshots</id>
+      <name>Apache Snapshot Repository</name>
+      <url>http://svn.apache.org/maven-snapshot-repository</url>
+      <releases>
+        <enabled>false</enabled>
+      </releases>
+    </repository>
+  </repositories>
+  <distributionManagement>
+    <!-- Site omitted - each project must provide their own -->
+    <repository>
+      <id>apache.releases</id>
+      <name>Apache Release Distribution Repository</name>
+      
<url>scp://minotaur.apache.org/www/www.apache.org/dist/maven-repository</url>
+    </repository>
+    <snapshotRepository>
+      <id>apache.snapshots</id>
+      <name>Apache Development Snapshot Repository</name>
+      
<url>scp://minotaur.apache.org/www/cvs.apache.org/maven-snapshot-repository</url>
+    </snapshotRepository>
+  </distributionManagement>
+  <mailingLists>
+    <mailingList>
+      <name>Apache Announce List</name>
+      <subscribe>announce-subscr...@apache.org</subscribe>
+      <unsubscribe>announce-unsubscr...@apache.org</unsubscribe>
+      <post>annou...@apache.org</post>
+      <archive>http://mail-archives.apache.org/mod_mbox/www-announce/</archive>
+    </mailingList>
+  </mailingLists>
+</project>
+

http://git-wip-us.apache.org/repos/asf/maven/blob/affddb2e/maven-core/src/test/remote-repo/org/apache/apache/maven-metadata.xml
----------------------------------------------------------------------
diff --git 
a/maven-core/src/test/remote-repo/org/apache/apache/maven-metadata.xml 
b/maven-core/src/test/remote-repo/org/apache/apache/maven-metadata.xml
new file mode 100644
index 0000000..596f967
--- /dev/null
+++ b/maven-core/src/test/remote-repo/org/apache/apache/maven-metadata.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<metadata>
+  <groupId>org.apache</groupId>
+  <artifactId>apache</artifactId>
+  <versioning>
+    <latest>1</latest>
+    <release>1</release>
+    <versions>
+      <version>1</version>
+    </versions>
+    <lastUpdated>20150428055824</lastUpdated>
+  </versioning>
+</metadata>

http://git-wip-us.apache.org/repos/asf/maven/blob/affddb2e/maven-core/src/test/resources/projects/parent-version-range-external-child-version-expression/pom.xml
----------------------------------------------------------------------
diff --git 
a/maven-core/src/test/resources/projects/parent-version-range-external-child-version-expression/pom.xml
 
b/maven-core/src/test/resources/projects/parent-version-range-external-child-version-expression/pom.xml
new file mode 100644
index 0000000..d07ad6e
--- /dev/null
+++ 
b/maven-core/src/test/resources/projects/parent-version-range-external-child-version-expression/pom.xml
@@ -0,0 +1,12 @@
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache</groupId>
+    <artifactId>apache</artifactId>
+    <version>[1,1]</version>
+  </parent>
+  <artifactId>child</artifactId>
+  <!-- Must not use expressions from parent due to version range. -->
+  <version>${some.property}</version>
+  <packaging>pom</packaging>
+</project>

http://git-wip-us.apache.org/repos/asf/maven/blob/affddb2e/maven-core/src/test/resources/projects/parent-version-range-external-child-without-version/pom.xml
----------------------------------------------------------------------
diff --git 
a/maven-core/src/test/resources/projects/parent-version-range-external-child-without-version/pom.xml
 
b/maven-core/src/test/resources/projects/parent-version-range-external-child-without-version/pom.xml
new file mode 100644
index 0000000..4f5a004
--- /dev/null
+++ 
b/maven-core/src/test/resources/projects/parent-version-range-external-child-without-version/pom.xml
@@ -0,0 +1,11 @@
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache</groupId>
+    <artifactId>apache</artifactId>
+    <version>[1,1]</version>
+  </parent>
+  <artifactId>child</artifactId>
+  <!-- version>2</version Must not inherit version from parent due to version 
range. -->
+  <packaging>pom</packaging>
+</project>

http://git-wip-us.apache.org/repos/asf/maven/blob/affddb2e/maven-core/src/test/resources/projects/parent-version-range-external-valid/pom.xml
----------------------------------------------------------------------
diff --git 
a/maven-core/src/test/resources/projects/parent-version-range-external-valid/pom.xml
 
b/maven-core/src/test/resources/projects/parent-version-range-external-valid/pom.xml
new file mode 100644
index 0000000..54eea90
--- /dev/null
+++ 
b/maven-core/src/test/resources/projects/parent-version-range-external-valid/pom.xml
@@ -0,0 +1,11 @@
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache</groupId>
+    <artifactId>apache</artifactId>
+    <version>[1,1]</version>
+  </parent>
+  <artifactId>child</artifactId>
+  <version>2</version>
+  <packaging>pom</packaging>
+</project>

http://git-wip-us.apache.org/repos/asf/maven/blob/affddb2e/maven-core/src/test/resources/projects/parent-version-range-local-child-version-expression/child/pom.xml
----------------------------------------------------------------------
diff --git 
a/maven-core/src/test/resources/projects/parent-version-range-local-child-version-expression/child/pom.xml
 
b/maven-core/src/test/resources/projects/parent-version-range-local-child-version-expression/child/pom.xml
new file mode 100644
index 0000000..066a11e
--- /dev/null
+++ 
b/maven-core/src/test/resources/projects/parent-version-range-local-child-version-expression/child/pom.xml
@@ -0,0 +1,12 @@
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>parent-version-range-local</groupId>
+    <artifactId>parent</artifactId>
+    <version>[1,10]</version>
+  </parent>
+  <artifactId>child</artifactId>
+  <!-- Must not use expressions from parent due to version range. -->
+  <version>${some.property}</version>
+  <packaging>pom</packaging>
+</project>

http://git-wip-us.apache.org/repos/asf/maven/blob/affddb2e/maven-core/src/test/resources/projects/parent-version-range-local-child-version-expression/pom.xml
----------------------------------------------------------------------
diff --git 
a/maven-core/src/test/resources/projects/parent-version-range-local-child-version-expression/pom.xml
 
b/maven-core/src/test/resources/projects/parent-version-range-local-child-version-expression/pom.xml
new file mode 100644
index 0000000..a82bbf2
--- /dev/null
+++ 
b/maven-core/src/test/resources/projects/parent-version-range-local-child-version-expression/pom.xml
@@ -0,0 +1,7 @@
+<project>
+       <modelVersion>4.0.0</modelVersion>
+       <groupId>parent-version-range-local</groupId>
+       <artifactId>parent</artifactId>
+       <version>1</version>
+       <packaging>pom</packaging>
+</project>

http://git-wip-us.apache.org/repos/asf/maven/blob/affddb2e/maven-core/src/test/resources/projects/parent-version-range-local-child-without-version/child/pom.xml
----------------------------------------------------------------------
diff --git 
a/maven-core/src/test/resources/projects/parent-version-range-local-child-without-version/child/pom.xml
 
b/maven-core/src/test/resources/projects/parent-version-range-local-child-without-version/child/pom.xml
new file mode 100644
index 0000000..645a8f1
--- /dev/null
+++ 
b/maven-core/src/test/resources/projects/parent-version-range-local-child-without-version/child/pom.xml
@@ -0,0 +1,11 @@
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>parent-version-range-local</groupId>
+    <artifactId>parent</artifactId>
+    <version>[1,10]</version>
+  </parent>
+  <artifactId>child</artifactId>
+  <!-- version>1</version Must not inherit version from parent due to version 
range. -->
+  <packaging>pom</packaging>
+</project>

http://git-wip-us.apache.org/repos/asf/maven/blob/affddb2e/maven-core/src/test/resources/projects/parent-version-range-local-child-without-version/pom.xml
----------------------------------------------------------------------
diff --git 
a/maven-core/src/test/resources/projects/parent-version-range-local-child-without-version/pom.xml
 
b/maven-core/src/test/resources/projects/parent-version-range-local-child-without-version/pom.xml
new file mode 100644
index 0000000..a82bbf2
--- /dev/null
+++ 
b/maven-core/src/test/resources/projects/parent-version-range-local-child-without-version/pom.xml
@@ -0,0 +1,7 @@
+<project>
+       <modelVersion>4.0.0</modelVersion>
+       <groupId>parent-version-range-local</groupId>
+       <artifactId>parent</artifactId>
+       <version>1</version>
+       <packaging>pom</packaging>
+</project>

http://git-wip-us.apache.org/repos/asf/maven/blob/affddb2e/maven-core/src/test/resources/projects/parent-version-range-local-valid/child/pom.xml
----------------------------------------------------------------------
diff --git 
a/maven-core/src/test/resources/projects/parent-version-range-local-valid/child/pom.xml
 
b/maven-core/src/test/resources/projects/parent-version-range-local-valid/child/pom.xml
new file mode 100644
index 0000000..886bcdf
--- /dev/null
+++ 
b/maven-core/src/test/resources/projects/parent-version-range-local-valid/child/pom.xml
@@ -0,0 +1,11 @@
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>parent-version-range-local</groupId>
+    <artifactId>parent</artifactId>
+    <version>[1,10]</version>
+  </parent>
+  <artifactId>child</artifactId>
+  <version>1</version>
+  <packaging>pom</packaging>
+</project>

http://git-wip-us.apache.org/repos/asf/maven/blob/affddb2e/maven-core/src/test/resources/projects/parent-version-range-local-valid/pom.xml
----------------------------------------------------------------------
diff --git 
a/maven-core/src/test/resources/projects/parent-version-range-local-valid/pom.xml
 
b/maven-core/src/test/resources/projects/parent-version-range-local-valid/pom.xml
new file mode 100644
index 0000000..a82bbf2
--- /dev/null
+++ 
b/maven-core/src/test/resources/projects/parent-version-range-local-valid/pom.xml
@@ -0,0 +1,7 @@
+<project>
+       <modelVersion>4.0.0</modelVersion>
+       <groupId>parent-version-range-local</groupId>
+       <artifactId>parent</artifactId>
+       <version>1</version>
+       <packaging>pom</packaging>
+</project>

http://git-wip-us.apache.org/repos/asf/maven/blob/affddb2e/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
----------------------------------------------------------------------
diff --git 
a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
 
b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
index 6b38926..ac54737 100644
--- 
a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
+++ 
b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
@@ -333,7 +333,7 @@ public class DefaultModelBuilder
                 currentData = superData;
             }
             else if ( currentData == resultData )
-            { // First iteration - add initial parent id after version 
resolution.
+            { // First iteration - add initial id after version resolution.
                 currentData.setGroupId( currentData.getRawModel().getGroupId() 
== null ? parentData.getGroupId()
                                                                                
       : currentData.getRawModel()
                                                                                
           .getGroupId() );
@@ -938,6 +938,28 @@ public class DefaultModelBuilder
                     // version skew drop back to resolution from the repository
                     return null;
                 }
+
+                // Validate versions aren't inherited when using parent ranges 
the same way as when read externally.
+                if ( childModel.getVersion() == null )
+                {
+                    // Message below is checked for in the MNG-2199 core IT.
+                    problems.add( new ModelProblemCollectorRequest( 
Severity.FATAL, Version.V31 )
+                        .setMessage( "Version must be a constant" 
).setLocation( childModel.getLocation( "" ) ) );
+
+                }
+                else
+                {
+                    if ( childModel.getVersion().contains( "${" ) )
+                    {
+                        // Message below is checked for in the MNG-2199 core 
IT.
+                        problems.add( new ModelProblemCollectorRequest( 
Severity.FATAL, Version.V31 )
+                            .setMessage( "Version must be a constant" )
+                            .setLocation( childModel.getLocation( "version" ) 
) );
+
+                    }
+                }
+
+                // MNG-2199: What else to check here ?
             }
             catch ( InvalidVersionSpecificationException e )
             {
@@ -1001,6 +1023,7 @@ public class DefaultModelBuilder
         }
         catch ( UnresolvableModelException e )
         {
+            // Message below is checked for in the MNG-2199 core IT.
             StringBuilder buffer = new StringBuilder( 256 );
             buffer.append( "Non-resolvable parent POM" );
             if ( !containsCoordinates( e.getMessage(), groupId, artifactId, 
version ) )
@@ -1048,15 +1071,16 @@ public class DefaultModelBuilder
         {
             if ( childModel.getVersion() == null )
             {
+                // Message below is checked for in the MNG-2199 core IT.
                 problems.add( new ModelProblemCollectorRequest( 
Severity.FATAL, Version.V31 )
                     .setMessage( "Version must be a constant" ).setLocation( 
childModel.getLocation( "" ) ) );
 
             }
             else
             {
-                if ( childModel.getVersion()
-                               .contains( "${" ) )
+                if ( childModel.getVersion().contains( "${" ) )
                 {
+                    // Message below is checked for in the MNG-2199 core IT.
                     problems.add( new ModelProblemCollectorRequest( 
Severity.FATAL, Version.V31 )
                         .setMessage( "Version must be a constant" )
                         .setLocation( childModel.getLocation( "version" ) ) );

http://git-wip-us.apache.org/repos/asf/maven/blob/affddb2e/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 f344959..9ea91ff 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
@@ -208,6 +208,7 @@ class DefaultModelResolver
                      && versionRangeResult.getVersionConstraint().getRange() 
!= null
                      && 
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() );

Reply via email to