Author: carlos
Date: Fri Jun  2 15:34:35 2006
New Revision: 411318

URL: http://svn.apache.org/viewvc?rev=411318&view=rev
Log:
[MNG-2338] Allow configuration conversion for reporting plugins

Modified:
    
maven/sandbox/plugins/maven-maven1-plugin/src/main/java/org/apache/maven/maven1converter/plugins/AbstractPluginConfigurationConverter.java
    
maven/sandbox/plugins/maven-maven1-plugin/src/main/java/org/apache/maven/maven1converter/plugins/PCCCompiler.java
    
maven/sandbox/plugins/maven-maven1-plugin/src/main/java/org/apache/maven/maven1converter/plugins/PCCSurefire.java
    
maven/sandbox/plugins/maven-maven1-plugin/src/main/java/org/apache/maven/maven1converter/plugins/PCCWar.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=411318&r1=411317&r2=411318&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
 Fri Jun  2 15:34:35 2006
@@ -16,24 +16,29 @@
  * limitations under the License.
  */
 
-import java.io.StringReader;
-import java.util.Iterator;
-import java.util.Properties;
-
+import org.apache.maven.model.Build;
 import org.apache.maven.model.Model;
 import org.apache.maven.model.Plugin;
+import org.apache.maven.model.ReportPlugin;
+import org.apache.maven.model.Reporting;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.codehaus.plexus.util.xml.Xpp3Dom;
 import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
 
+import java.io.StringReader;
+import java.util.Iterator;
+import java.util.Properties;
+
 /**
  * @author Fabrizio Giustina
  * @author Dennis Lundberg
  * @version $Id$
  */
-public abstract class AbstractPluginConfigurationConverter
-    implements PluginConfigurationConverter
+public abstract class AbstractPluginConfigurationConverter implements 
PluginConfigurationConverter
 {
+    public static final String TYPE_BUILD_PLUGIN = "build plugin";
+    public static final String TYPE_REPORT_PLUGIN = "report plugin";
+
     public abstract String getArtifactId();
 
     public String getGroupId()
@@ -41,6 +46,8 @@
         return "org.apache.maven.plugins";
     }
 
+    public abstract String getType();
+
     /**
      * Add a child element to the configuration.
      *
@@ -61,9 +68,9 @@
     /**
      * Add a child element to the configuration.
      *
-     * @param configuration     The configuration to add the element to
-     * @param mavenTwoElement   The name of the Maven 2 configuration element
-     * @param value             Set the value of the element to this
+     * @param configuration   The configuration to add the element to
+     * @param mavenTwoElement The name of the Maven 2 configuration element
+     * @param value           Set the value of the element to this
      * @throws MojoExecutionException if an element can't be created
      */
     protected void addConfigurationChild( Xpp3Dom configuration, String 
mavenTwoElement, String value )
@@ -76,7 +83,7 @@
     }
 
     public void convertConfiguration( Model v4Model, 
org.apache.maven.model.v3_0_0.Model v3Model,
-                                     Properties projectProperties )
+                                      Properties projectProperties )
         throws MojoExecutionException
     {
         boolean addPlugin = false;
@@ -87,34 +94,67 @@
 
         if ( configuration.getChildCount() > 0 )
         {
-            Plugin plugin = findPlugin( v4Model, getGroupId(), getArtifactId() 
);
-            if ( plugin == null )
+            if ( TYPE_BUILD_PLUGIN.equals( getType() ) )
             {
-                addPlugin = true;
-                plugin = new Plugin();
-                plugin.setGroupId( getGroupId() );
-                plugin.setArtifactId( getArtifactId() );
+                Plugin plugin = findBuildPlugin( v4Model, getGroupId(), 
getArtifactId() );
+                if ( plugin == null )
+                {
+                    addPlugin = true;
+                    plugin = new Plugin();
+                    plugin.setGroupId( getGroupId() );
+                    plugin.setArtifactId( getArtifactId() );
+                }
+
+                plugin.setConfiguration( configuration );
+
+                if ( addPlugin )
+                {
+                    if ( v4Model.getBuild() == null )
+                    {
+                        v4Model.setBuild( new Build() );
+                    }
+                    v4Model.getBuild().addPlugin( plugin );
+                }
             }
-
-            plugin.setConfiguration( configuration );
-
-            if ( addPlugin )
+            else if ( TYPE_REPORT_PLUGIN.equals( getType() ) )
             {
-            v4Model.getBuild().addPlugin( plugin );
-        }
+                ReportPlugin plugin = findReportPlugin( v4Model, getGroupId(), 
getArtifactId() );
+                if ( plugin == null )
+                {
+                    addPlugin = true;
+                    plugin = new ReportPlugin();
+                    plugin.setGroupId( getGroupId() );
+                    plugin.setArtifactId( getArtifactId() );
+                }
+
+                plugin.setConfiguration( configuration );
+
+                if ( addPlugin )
+                {
+                    if ( v4Model.getReporting() == null )
+                    {
+                        v4Model.setReporting( new Reporting() );
+                    }
+                    v4Model.getReporting().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
+     * @param model      Look for the build plugin in this model
+     * @param groupId    The groupId for the build plugin to look for
+     * @param artifactId The artifactId for the build plugin to look for
+     * @return The requested build plugin if it exists, otherwise null
      */
-    private Plugin findPlugin( Model model, String groupId, String artifactId )
+    private Plugin findBuildPlugin( Model model, String groupId, String 
artifactId )
     {
+        if ( model.getBuild() == null || model.getBuild().getPlugins() == null 
)
+        {
+            return null;
+        }
         Iterator iterator = model.getBuild().getPlugins().iterator();
         while ( iterator.hasNext() )
         {
@@ -122,13 +162,39 @@
             if ( plugin.getGroupId().equals( groupId ) && 
plugin.getArtifactId().equals( artifactId ) )
             {
                 return plugin;
+            }
+        }
+        return null;
     }
+
+    /**
+     * Try to find a report plugin in a model.
+     *
+     * @param model      Look for the report plugin in this model
+     * @param groupId    The groupId for the report plugin to look for
+     * @param artifactId The artifactId for the report plugin to look for
+     * @return The requested report plugin if it exists, otherwise null
+     */
+    private ReportPlugin findReportPlugin( Model model, String groupId, String 
artifactId )
+    {
+        if ( model.getReporting() == null || model.getReporting().getPlugins() 
== null )
+        {
+            return null;
+        }
+        Iterator iterator = model.getReporting().getPlugins().iterator();
+        while ( iterator.hasNext() )
+        {
+            ReportPlugin plugin = (ReportPlugin) 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,
-                                               Properties projectProperties )
+                                                Properties projectProperties )
         throws MojoExecutionException;
 
     protected Xpp3Dom newXpp3Dom( String input )

Modified: 
maven/sandbox/plugins/maven-maven1-plugin/src/main/java/org/apache/maven/maven1converter/plugins/PCCCompiler.java
URL: 
http://svn.apache.org/viewvc/maven/sandbox/plugins/maven-maven1-plugin/src/main/java/org/apache/maven/maven1converter/plugins/PCCCompiler.java?rev=411318&r1=411317&r2=411318&view=diff
==============================================================================
--- 
maven/sandbox/plugins/maven-maven1-plugin/src/main/java/org/apache/maven/maven1converter/plugins/PCCCompiler.java
 (original)
+++ 
maven/sandbox/plugins/maven-maven1-plugin/src/main/java/org/apache/maven/maven1converter/plugins/PCCCompiler.java
 Fri Jun  2 15:34:35 2006
@@ -37,6 +37,11 @@
         return "maven-compiler-plugin";
     }
 
+    public String getType()
+    {
+        return TYPE_BUILD_PLUGIN;
+    }
+
     protected void addOnOffConfigurationChild( Xpp3Dom configuration, 
Properties projectProperties,
                                                String mavenOneProperty, String 
mavenTwoElement )
         throws MojoExecutionException

Modified: 
maven/sandbox/plugins/maven-maven1-plugin/src/main/java/org/apache/maven/maven1converter/plugins/PCCSurefire.java
URL: 
http://svn.apache.org/viewvc/maven/sandbox/plugins/maven-maven1-plugin/src/main/java/org/apache/maven/maven1converter/plugins/PCCSurefire.java?rev=411318&r1=411317&r2=411318&view=diff
==============================================================================
--- 
maven/sandbox/plugins/maven-maven1-plugin/src/main/java/org/apache/maven/maven1converter/plugins/PCCSurefire.java
 (original)
+++ 
maven/sandbox/plugins/maven-maven1-plugin/src/main/java/org/apache/maven/maven1converter/plugins/PCCSurefire.java
 Fri Jun  2 15:34:35 2006
@@ -40,6 +40,11 @@
         return "maven-surefire-plugin";
     }
 
+    public String getType()
+    {
+        return TYPE_BUILD_PLUGIN;
+    }
+
     protected void buildConfiguration( Xpp3Dom configuration, 
org.apache.maven.model.v3_0_0.Model v3Model,
                                        Properties projectProperties )
         throws MojoExecutionException

Modified: 
maven/sandbox/plugins/maven-maven1-plugin/src/main/java/org/apache/maven/maven1converter/plugins/PCCWar.java
URL: 
http://svn.apache.org/viewvc/maven/sandbox/plugins/maven-maven1-plugin/src/main/java/org/apache/maven/maven1converter/plugins/PCCWar.java?rev=411318&r1=411317&r2=411318&view=diff
==============================================================================
--- 
maven/sandbox/plugins/maven-maven1-plugin/src/main/java/org/apache/maven/maven1converter/plugins/PCCWar.java
 (original)
+++ 
maven/sandbox/plugins/maven-maven1-plugin/src/main/java/org/apache/maven/maven1converter/plugins/PCCWar.java
 Fri Jun  2 15:34:35 2006
@@ -38,6 +38,11 @@
         return "maven-war-plugin";
     }
 
+    public String getType()
+    {
+        return TYPE_BUILD_PLUGIN;
+    }
+
     protected void buildConfiguration( Xpp3Dom configuration, 
org.apache.maven.model.v3_0_0.Model v3Model,
                                       Properties projectProperties )
         throws MojoExecutionException


Reply via email to