[MNG-2919] Add fix for depMan scope overwriting to the trunk.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@552182 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Patrick Schneider 2007-06-30 17:31:45 +00:00
parent f3f3c70321
commit 5da9d28906
4 changed files with 127 additions and 11 deletions
maven-artifact/src/main/java/org/apache/maven/artifact/resolver
maven-project/src/test
java/org/apache/maven/project/inheritance/t11
resources/inheritance-repo/t11/p0

View File

@ -127,19 +127,14 @@ public class DefaultArtifactCollector
Artifact managedOriginatingArtifact = (Artifact) versionMap.get( originatingArtifact.getDependencyConflictId() );
if ( managedOriginatingArtifact != null )
{
String managedVersion = managedOriginatingArtifact.getVersion();
String version = originatingArtifact.getVersion();
if ( !managedVersion.equals( version ) )
// TODO we probably want to warn the user that he is building an artifact with
// different values than in dependencyManagement
if ( managedVersions instanceof ManagedVersionMap )
{
// TODO we probably want to warn the user that he is building and artifact with a
// different version than in dependencyManagement
if ( managedVersions instanceof ManagedVersionMap )
{
/* avoid modifying the managedVersions parameter creating a new map */
versionMap = new ManagedVersionMap( managedVersions );
}
versionMap.remove( originatingArtifact.getDependencyConflictId() );
/* avoid modifying the managedVersions parameter creating a new map */
versionMap = new ManagedVersionMap( managedVersions );
}
versionMap.remove( originatingArtifact.getDependencyConflictId() );
}
return versionMap;

View File

@ -0,0 +1,78 @@
package org.apache.maven.project.inheritance.t11;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.io.File;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Iterator;
import org.apache.maven.model.Build;
import org.apache.maven.model.MailingList;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginExecution;
import org.apache.maven.model.Dependency;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase;
import org.apache.maven.artifact.Artifact;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.codehaus.plexus.logging.LoggerManager;
import org.codehaus.plexus.logging.Logger;
/**
* Verifies scope of root project is preserved regardless of parent depenedency management.
*
* @author <a href="mailto:pschneider@gmail.com">Patrick Schneider</a>
* @version $Id$
* @see <a href="http://jira.codehaus.org/browse/MNG-2919">MNG-2919</a>
*/
public class ProjectInheritanceTest
extends AbstractProjectInheritanceTestCase
{
// ----------------------------------------------------------------------
//
// p1 inherits from p0
// p0 inhertis from super model
//
// or we can show it graphically as:
//
// p1 ---> p0 --> super model
//
// ----------------------------------------------------------------------
public void testDependencyManagementDoesNotOverrideScopeOfCurrentArtifact()
throws Exception
{
File localRepo = getLocalRepositoryPath();
File pom0 = new File( localRepo, "p0/pom.xml" );
File pom0Basedir = pom0.getParentFile();
File pom1 = new File( pom0Basedir, "p1/pom.xml" );
// load the child project, which inherits from p0...
MavenProject project0 = getProjectWithDependencies( pom0 );
MavenProject project1 = getProjectWithDependencies( pom1 );
assertEquals( pom0Basedir, project1.getParent().getBasedir() );
assertNull( "dependencyManagement has overwritten the scope of the currently building child project",
project1.getArtifact().getScope() );
}
}

View File

@ -0,0 +1,16 @@
<project>
<parent>
<artifactId>p0</artifactId>
<groupId>maven</groupId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>maven</groupId>
<artifactId>p1</artifactId>
<packaging>jar</packaging>
<name>p1</name>
<version>1.0</version>
<scm>
<url>scm-url</url>
</scm>
</project>

View File

@ -0,0 +1,27 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>maven</groupId>
<artifactId>p0</artifactId>
<packaging>pom</packaging>
<name>p0</name>
<version>1.0</version>
<organization>
<name>Codehaus</name>
</organization>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>maven</groupId>
<artifactId>p1</artifactId>
<version>1.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>