mirror of https://github.com/apache/maven.git
Fix MNG-508: make mboot use dependencyManagement.
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@227079 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5a99a71bcb
commit
6da771ab70
|
@ -66,6 +66,8 @@ public class ModelReader
|
|||
|
||||
private List testResources = new ArrayList();
|
||||
|
||||
private Map managedDependencies = new HashMap();
|
||||
|
||||
private Dependency currentDependency;
|
||||
|
||||
private Resource currentResource;
|
||||
|
@ -119,6 +121,13 @@ public class ModelReader
|
|||
return m.values();
|
||||
}
|
||||
|
||||
public Collection getManagedDependencies()
|
||||
{
|
||||
Map m = new HashMap();
|
||||
m.putAll( managedDependencies );
|
||||
return m.values();
|
||||
}
|
||||
|
||||
public List getResources()
|
||||
{
|
||||
return resources;
|
||||
|
@ -137,14 +146,11 @@ public class ModelReader
|
|||
insideRepository = true;
|
||||
}
|
||||
else if ( rawName.equals( "dependency" ) )
|
||||
{
|
||||
if ( !insideDependencyManagement )
|
||||
{
|
||||
currentDependency = new Dependency();
|
||||
|
||||
insideDependency = true;
|
||||
}
|
||||
}
|
||||
else if ( rawName.equals( "dependencyManagement" ) )
|
||||
{
|
||||
insideDependencyManagement = true;
|
||||
|
@ -218,6 +224,8 @@ public class ModelReader
|
|||
|
||||
addDependencies( p.getDependencies(), parentDependencies, null );
|
||||
|
||||
addDependencies( p.getManagedDependencies(), managedDependencies, null );
|
||||
|
||||
resources.addAll( p.getResources() );
|
||||
|
||||
insideParent = false;
|
||||
|
@ -226,19 +234,15 @@ public class ModelReader
|
|||
{
|
||||
insideDependency = false;
|
||||
|
||||
if ( !hasDependency( currentDependency, dependencies ) )
|
||||
if ( insideDependencyManagement )
|
||||
{
|
||||
if ( resolveTransitiveDependencies )
|
||||
managedDependencies.put( currentDependency.getConflictId(), currentDependency );
|
||||
}
|
||||
else
|
||||
{
|
||||
ModelReader p = retrievePom( currentDependency.getGroupId(), currentDependency.getArtifactId(),
|
||||
currentDependency.getVersion(), currentDependency.getType(),
|
||||
resolveTransitiveDependencies );
|
||||
|
||||
addDependencies( p.getDependencies(), transitiveDependencies, currentDependency.getScope() );
|
||||
}
|
||||
}
|
||||
dependencies.put( currentDependency.getConflictId(), currentDependency );
|
||||
}
|
||||
}
|
||||
else if ( rawName.equals( "dependencyManagement" ) )
|
||||
{
|
||||
insideDependencyManagement = false;
|
||||
|
@ -375,12 +379,45 @@ public class ModelReader
|
|||
packaging = getBodyText();
|
||||
}
|
||||
}
|
||||
else if ( depth == 1 ) // model / project
|
||||
{
|
||||
resolveDependencies();
|
||||
}
|
||||
|
||||
bodyText = new StringBuffer();
|
||||
|
||||
depth--;
|
||||
}
|
||||
|
||||
private void resolveDependencies()
|
||||
throws SAXException
|
||||
{
|
||||
for ( Iterator it = dependencies.values().iterator(); it.hasNext(); )
|
||||
{
|
||||
Dependency dependency = (Dependency) it.next();
|
||||
|
||||
if ( dependency.getVersion() == null )
|
||||
{
|
||||
Dependency managedDependency = (Dependency) managedDependencies.get( dependency.getConflictId() );
|
||||
if ( managedDependency == null )
|
||||
{
|
||||
throw new NullPointerException( "[" + groupId + ":" + artifactId +":" + packaging + ":" + version + "] " +
|
||||
"Dependency " + dependency.getConflictId() + " is missing a version, and nothing is found in dependencyManagement. ");
|
||||
}
|
||||
dependency.setVersion( managedDependency.getVersion() );
|
||||
}
|
||||
|
||||
if ( resolveTransitiveDependencies )
|
||||
{
|
||||
ModelReader p = retrievePom( dependency.getGroupId(), dependency.getArtifactId(),
|
||||
dependency.getVersion(), dependency.getType(),
|
||||
resolveTransitiveDependencies );
|
||||
|
||||
addDependencies( p.getDependencies(), transitiveDependencies, dependency.getScope() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addDependencies( Collection dependencies, Map target, String inheritedScope )
|
||||
{
|
||||
for ( Iterator i = dependencies.iterator(); i.hasNext(); )
|
||||
|
|
Loading…
Reference in New Issue