From fbd4214e1d359622c303e4012624247c2e73e1be Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Fri, 14 Jul 2006 22:32:29 +0000 Subject: [PATCH] [MNG-2447] fix the bootstrap by adding plugin management support for modello since the versions were rationalised Submitted by: Pete Marvin King git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@422081 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/maven/bootstrap/Bootstrap.java | 14 ++++++++++++++ .../apache/maven/bootstrap/model/Model.java | 15 +++++++++++++++ .../maven/bootstrap/model/ModelReader.java | 19 +++++++++++++++++-- .../bootstrap/model/ProjectResolver.java | 10 ++++++++++ 4 files changed, 56 insertions(+), 2 deletions(-) diff --git a/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/Bootstrap.java b/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/Bootstrap.java index 1563d9f208..70bf8a7165 100644 --- a/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/Bootstrap.java +++ b/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/Bootstrap.java @@ -322,6 +322,20 @@ public class Bootstrap System.out.println( "Model exists!" ); + // acquire the version from the parent pom pluginManagement + String version = plugin.getVersion(); + if ( ( version == null ) || ( version == "" ) ) + { + Plugin managedPlugin = (Plugin) model.getManagedPlugins().get( MODELLO_PLUGIN_ID ); + + if ( managedPlugin == null ) + { + throw new Exception( "can not determine version of " + MODELLO_PLUGIN_ID ); + } + + plugin.setVersion( managedPlugin.getVersion() ); + } + String modelVersion = (String) plugin.getConfiguration().get( "version" ); if ( modelVersion == null || modelVersion.trim().length() < 1 ) { diff --git a/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/model/Model.java b/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/model/Model.java index c430105249..4a4fc67445 100644 --- a/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/model/Model.java +++ b/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/model/Model.java @@ -65,6 +65,8 @@ public class Model private Map managedDependencies = new HashMap(); + private Map managedPlugins = new HashMap(); + private List chain; public Model() @@ -224,6 +226,19 @@ public class Model return m.values(); } + public Map getManagedPlugins() + { + return managedPlugins; + } + + public Collection getManagedPluginsCollection() + { + Map m = new HashMap(); + m.putAll( managedPlugins ); + return m.values(); + } + + public String toString() { return "Model[" + getId() + "]"; diff --git a/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/model/ModelReader.java b/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/model/ModelReader.java index 03577ee2af..93bdc1dbf0 100644 --- a/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/model/ModelReader.java +++ b/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/model/ModelReader.java @@ -64,6 +64,8 @@ public class ModelReader private boolean insideDependencyManagement; private boolean insideDistributionManagement; + + private boolean insidePluginManagement; private boolean insideReleases; @@ -141,6 +143,11 @@ public class ModelReader insidePlugin = true; } + else if ( rawName.equals( "pluginManagement" ) ) + { + insidePluginManagement = true; + } + else if ( rawName.equals( "dependencyManagement" ) ) { insideDependencyManagement = true; @@ -230,6 +237,7 @@ public class ModelReader ProjectResolver.addDependencies( p.getManagedDependenciesCollection(), model.getManagedDependencies(), inheritedScope, Collections.EMPTY_SET ); + ProjectResolver.addPluginManagement( p.getManagedPluginsCollection(), model.getManagedPlugins() ); model.getRepositories().addAll( p.getRepositories() ); model.getResources().addAll( p.getResources() ); @@ -279,8 +287,15 @@ public class ModelReader } else if ( rawName.equals( "plugin" ) ) { - model.getPlugins().put( currentPlugin.getId(), currentPlugin ); - + if (insidePluginManagement) + { + model.getManagedPlugins().put( currentPlugin.getId(), currentPlugin ); + } + else + { + model.getPlugins().put( currentPlugin.getId(), currentPlugin ); + } + insidePlugin = false; } else if ( rawName.equals( "build" ) ) diff --git a/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/model/ProjectResolver.java b/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/model/ProjectResolver.java index b6f4b9f33b..fd99b7a540 100644 --- a/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/model/ProjectResolver.java +++ b/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/model/ProjectResolver.java @@ -116,6 +116,16 @@ public final class ProjectResolver } } + public static void addPluginManagement( Collection plugins, Map target) + { + Plugin managedPlugin; + for (Iterator i = plugins.iterator(); i.hasNext(); ) + { + managedPlugin = (Plugin) i.next(); + target.put(managedPlugin.getId(),managedPlugin); + } + } + private static boolean hasDependency( Dependency d, Map dependencies ) { String conflictId = d.getConflictId();