maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From schu...@apache.org
Subject maven git commit: [MNG-2199] Support version ranges in parent elements
Date Sun, 13 Dec 2015 15:16:13 GMT
Repository: maven
Updated Branches:
  refs/heads/master 20b741691 -> 893efe3a9


[MNG-2199] Support version ranges in parent elements

o Updated to make local and remote parent model resolution consistent.
  'MavenProject.getParentArtifact()' now returns the same artifact
  no matter where the parent has been read from and the 'ModelBuilder'
  will disallow empty versions and version expressions in local child
  modules when using parent version ranges the same way as is done
  for remote parent models.
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/893efe3a
Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/893efe3a
Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/893efe3a

Branch: refs/heads/master
Commit: 893efe3a9c49952d916b0eac66973581cd2702cd
Parents: 20b7416
Author: Christian Schulte <schulte@apache.org>
Authored: Sun Dec 13 15:55:21 2015 +0100
Committer: Christian Schulte <schulte@apache.org>
Committed: Sun Dec 13 16:04:58 2015 +0100

----------------------------------------------------------------------
 .../maven/project/DefaultProjectBuilder.java    |  30 ++++-
 .../project/DefaultProjectBuildingRequest.java  |   2 -
 .../maven/project/ProjectBuildingRequest.java   |   2 -
 .../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     |  28 +++-
 18 files changed, 411 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven/blob/893efe3a/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 5c8e707..e29efa4 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;
@@ -613,11 +612,32 @@ public class DefaultProjectBuilder
         project.setModel( model );
         project.setOriginalModel( result.getRawModel() );
         project.setFile( model.getPomFile() );
-        Parent p = model.getParent();
-        if ( p != null )
+
+        Model parentModel = null;
+        if ( !result.getModelIds().get( 1 ).isEmpty() )
+        {
+            // Note: The parent model already got resolved by the ModelBuilder based on model.getParent().
+            parentModel = result.getRawModel( result.getModelIds().get( 1 ) );
+        }
+
+        if ( parentModel != null )
         {
-            project.setParentArtifact( repositorySystem.createProjectArtifact( p.getGroupId(),
p.getArtifactId(),
-                                                                               p.getVersion()
) );
+            String parentGroupId = parentModel.getGroupId();
+            if ( parentGroupId == null && parentModel.getParent() != null )
+            {
+                parentGroupId = parentModel.getParent().getGroupId();
+            }
+
+            String parentVersion = parentModel.getVersion();
+            if ( parentVersion == null && parentModel.getParent() != null )
+            {
+                parentVersion = parentModel.getParent().getVersion();
+            }
+
+            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();

http://git-wip-us.apache.org/repos/asf/maven/blob/893efe3a/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 5a22afe..97eb276 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
@@ -226,7 +226,6 @@ public class DefaultProjectBuildingRequest
      * @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.
-     * Commit 8c863b01af76d990b7650add5cb98efda4c83533 moved parent version range resolution
to the 'ModelBuilder'.
      */
     @Deprecated
     public ProjectBuildingRequest setResolveVersionRanges( boolean value )
@@ -239,7 +238,6 @@ public class DefaultProjectBuildingRequest
      * @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.
-     * Commit 8c863b01af76d990b7650add5cb98efda4c83533 moved parent version range resolution
to the 'ModelBuilder'.
      */
     @Deprecated
     public boolean isResolveVersionRanges()

http://git-wip-us.apache.org/repos/asf/maven/blob/893efe3a/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 ff639cc..17a53b1 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
@@ -172,7 +172,6 @@ public interface ProjectBuildingRequest
      * @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.
-     * Commit 8c863b01af76d990b7650add5cb98efda4c83533 moved parent version range resolution
to the 'ModelBuilder'.
      */
     @Deprecated
     boolean isResolveVersionRanges();
@@ -181,7 +180,6 @@ public interface ProjectBuildingRequest
      * @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.
-     * Commit 8c863b01af76d990b7650add5cb98efda4c83533 moved parent version range resolution
to the 'ModelBuilder'.
      */
     @Deprecated
     ProjectBuildingRequest setResolveVersionRanges( boolean value );

http://git-wip-us.apache.org/repos/asf/maven/blob/893efe3a/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/893efe3a/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 d61fc6e..3959cdd 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/893efe3a/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/893efe3a/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-subscribe@apache.org</subscribe>
+      <unsubscribe>announce-unsubscribe@apache.org</unsubscribe>
+      <post>announce@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/893efe3a/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/893efe3a/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/893efe3a/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/893efe3a/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/893efe3a/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/893efe3a/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/893efe3a/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/893efe3a/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/893efe3a/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/893efe3a/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/893efe3a/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 6e4d24f..49a1f3c 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,26 @@ 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 )
+                {
+                    problems.add( new ModelProblemCollectorRequest( Severity.FATAL, Version.V31
)
+                        .setMessage( "Version must be a constant" ).setLocation( childModel.getLocation(
"" ) ) );
+
+                }
+                else
+                {
+                    if ( childModel.getVersion().contains( "${" ) )
+                    {
+                        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 )
             {
@@ -983,8 +1003,7 @@ public class DefaultModelBuilder
     {
         problems.setSource( childModel );
 
-        // Note: The 'ModelResolver' will update the version property for any parent version
ranges.
-        Parent parent = childModel.getParent();
+        Parent parent = childModel.getParent().clone();
 
         String groupId = parent.getGroupId();
         String artifactId = parent.getArtifactId();
@@ -1055,8 +1074,7 @@ public class DefaultModelBuilder
             }
             else
             {
-                if ( childModel.getVersion()
-                               .contains( "${" ) )
+                if ( childModel.getVersion().contains( "${" ) )
                 {
                     problems.add( new ModelProblemCollectorRequest( Severity.FATAL, Version.V31
)
                         .setMessage( "Version must be a constant" )


Mime
View raw message