maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From car...@apache.org
Subject svn commit: r410686 - /maven/sandbox/plugins/maven-maven1-plugin/src/main/java/org/apache/maven/maven1converter/plugins/AbstractPluginConfigurationConverter.java
Date Wed, 31 May 2006 22:15:55 GMT
Author: carlos
Date: Wed May 31 15:15:54 2006
New Revision: 410686

URL: http://svn.apache.org/viewvc?rev=410686&view=rev
Log:
[MNG-2327] Don't add plugins twice

Modified:
    maven/sandbox/plugins/maven-maven1-plugin/src/main/java/org/apache/maven/maven1converter/plugins/AbstractPluginConfigurationConverter.java

Modified: maven/sandbox/plugins/maven-maven1-plugin/src/main/java/org/apache/maven/maven1converter/plugins/AbstractPluginConfigurationConverter.java
URL: http://svn.apache.org/viewvc/maven/sandbox/plugins/maven-maven1-plugin/src/main/java/org/apache/maven/maven1converter/plugins/AbstractPluginConfigurationConverter.java?rev=410686&r1=410685&r2=410686&view=diff
==============================================================================
--- maven/sandbox/plugins/maven-maven1-plugin/src/main/java/org/apache/maven/maven1converter/plugins/AbstractPluginConfigurationConverter.java
(original)
+++ maven/sandbox/plugins/maven-maven1-plugin/src/main/java/org/apache/maven/maven1converter/plugins/AbstractPluginConfigurationConverter.java
Wed May 31 15:15:54 2006
@@ -17,6 +17,7 @@
  */
 
 import java.io.StringReader;
+import java.util.Iterator;
 import java.util.Properties;
 
 import org.apache.maven.model.Model;
@@ -27,6 +28,7 @@
 
 /**
  * @author Fabrizio Giustina
+ * @author Dennis Lundberg
  * @version $Id$
  */
 public abstract class AbstractPluginConfigurationConverter
@@ -40,13 +42,10 @@
     }
 
     public void convertConfiguration( Model v4Model, org.apache.maven.model.v3_0_0.Model
v3Model,
-                                     Properties projectProperties )
+                                      Properties projectProperties )
         throws MojoExecutionException
     {
-
-        Plugin plugin = new Plugin();
-        plugin.setGroupId( getGroupId() );
-        plugin.setArtifactId( getArtifactId() );
+        boolean addPlugin = false;
 
         Xpp3Dom configuration = newXpp3Dom( "<configuration></configuration>"
);
 
@@ -54,10 +53,44 @@
 
         if ( configuration.getChildCount() > 0 )
         {
+            Plugin plugin = findPlugin( v4Model, getGroupId(), getArtifactId() );
+            if ( plugin == null )
+            {
+                addPlugin = true;
+                plugin = new Plugin();
+                plugin.setGroupId( getGroupId() );
+                plugin.setArtifactId( getArtifactId() );
+            }
+
             plugin.setConfiguration( configuration );
-            v4Model.getBuild().addPlugin( plugin );
+
+            if ( addPlugin )
+            {
+                v4Model.getBuild().addPlugin( plugin );
+            }
         }
+    }
 
+    /**
+     * Try to find a plugin in a model.
+     *
+     * @param model      Look for the plugin in this model
+     * @param groupId    The groupId for the plugin to look for
+     * @param artifactId The artifactId for the plugin to look for
+     * @return The requested plugin if it exists, otherwise null
+     */
+    private Plugin findPlugin( Model model, String groupId, String artifactId )
+    {
+        Iterator iterator = model.getBuild().getPlugins().iterator();
+        while ( iterator.hasNext() )
+        {
+            Plugin plugin = (Plugin) iterator.next();
+            if ( plugin.getGroupId().equals( groupId ) && plugin.getArtifactId().equals(
artifactId ) )
+            {
+                return plugin;
+            }
+        }
+        return null;
     }
 
     protected abstract void buildConfiguration( Xpp3Dom configuration, org.apache.maven.model.v3_0_0.Model
v3Model,



Mime
View raw message