Author: dennisl
Date: Sun Jul 23 03:17:20 2006
New Revision: 424701

URL: http://svn.apache.org/viewvc?rev=424701&view=rev
Log:
Use the Maven1Converter that has moved to maven-model-converter

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

Modified: maven/sandbox/plugins/maven-maven1-plugin/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/sandbox/plugins/maven-maven1-plugin/pom.xml?rev=424701&r1=424700&r2=424701&view=diff
==============================================================================
--- maven/sandbox/plugins/maven-maven1-plugin/pom.xml (original)
+++ maven/sandbox/plugins/maven-maven1-plugin/pom.xml Sun Jul 23 03:17:20 2006
@@ -80,7 +80,7 @@
     <dependency>
       <groupId>org.apache.maven</groupId>
       <artifactId>maven-model-converter</artifactId>
-      <version>2.0.4</version>
+      <version>2.0.5-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>dom4j</groupId>

Modified: 
maven/sandbox/plugins/maven-maven1-plugin/src/main/java/org/apache/maven/maven1converter/PomV3ConvertMojo.java
URL: 
http://svn.apache.org/viewvc/maven/sandbox/plugins/maven-maven1-plugin/src/main/java/org/apache/maven/maven1converter/PomV3ConvertMojo.java?rev=424701&r1=424700&r2=424701&view=diff
==============================================================================
--- 
maven/sandbox/plugins/maven-maven1-plugin/src/main/java/org/apache/maven/maven1converter/PomV3ConvertMojo.java
 (original)
+++ 
maven/sandbox/plugins/maven-maven1-plugin/src/main/java/org/apache/maven/maven1converter/PomV3ConvertMojo.java
 Sun Jul 23 03:17:20 2006
@@ -16,42 +16,13 @@
  * limitations under the License.
  */
 
-import org.apache.maven.maven1converter.plugins.PCCChangelog;
-import org.apache.maven.maven1converter.plugins.PCCChanges;
-import org.apache.maven.maven1converter.plugins.PCCCheckstyle;
-import org.apache.maven.maven1converter.plugins.PCCCompiler;
-import org.apache.maven.maven1converter.plugins.PCCJar;
-import org.apache.maven.maven1converter.plugins.PCCJavadoc;
-import org.apache.maven.maven1converter.plugins.PCCMultiproject;
-import org.apache.maven.maven1converter.plugins.PCCPmd;
-import org.apache.maven.maven1converter.plugins.PCCSurefire;
-import org.apache.maven.maven1converter.plugins.PCCTaglist;
-import org.apache.maven.maven1converter.plugins.PCCWar;
-import org.apache.maven.maven1converter.plugins.PluginConfigurationConverter;
-import org.apache.maven.maven1converter.relocators.PluginRelocator;
-import org.apache.maven.maven1converter.relocators.PluginRelocatorManager;
-import org.apache.maven.model.Model;
-import org.apache.maven.model.converter.PomV3ToV4Translator;
-import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
-import org.apache.maven.model.v3_0_0.io.xpp3.MavenXpp3Reader;
+import org.apache.maven.model.converter.Maven1Converter;
+import org.apache.maven.model.converter.ProjectConverterException;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
-import org.codehaus.plexus.util.IOUtil;
-import org.dom4j.Document;
-import org.dom4j.Element;
-import org.dom4j.io.SAXReader;
 
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Writer;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Properties;
 
 /**
  * Converts a Maven 1 project.xml (v3 pom) to a Maven 2 pom.xml (v4 pom).
@@ -65,7 +36,7 @@
 public class PomV3ConvertMojo extends AbstractMojo
 {
     /**
-     * Project basedir
+     * Project basedir.
      *
      * @parameter expression="${basedir}"
      * @required
@@ -74,243 +45,21 @@
     private File basedir;
 
     /**
-     * Available converters for specific plugin configurations
-     */
-    private PluginConfigurationConverter[] converters = new 
PluginConfigurationConverter[] {
-        new PCCChangelog(),
-        new PCCChanges(),
-        new PCCCheckstyle(),
-        new PCCCompiler(),
-        new PCCJar(),
-        new PCCJavadoc(),
-        new PCCMultiproject(),
-        new PCCPmd(),
-        new PCCSurefire(),
-        new PCCTaglist(),
-        new PCCWar() };
-
-    /**
-     * Plexus component that manages plugin relocators
-     *
-     * @component
-     */
-    private PluginRelocatorManager pluginRelocatorManager;
-
-    /**
      * @see org.apache.maven.plugin.Mojo#execute()
      */
     public void execute()
         throws MojoExecutionException, MojoFailureException
     {
-        File projectxml = new File( basedir, "project.xml" );
-
-        if ( !projectxml.exists() )
-        {
-            throw new MojoFailureException( "Missing project.xml in " + 
basedir.getAbsolutePath() );
-        }
-
-        PomV3ToV4Translator translator = new PomV3ToV4Translator();
-
-        org.apache.maven.model.v3_0_0.Model v3Model;
-        try
-        {
-            v3Model = loadV3Pom( projectxml );
-        }
-        catch ( Exception e )
-        {
-            throw new MojoExecutionException( "Exception caught while loading 
project.xml. " + e.getMessage(), e );
-        }
-
-        Model v4Model;
-        try
-        {
-            v4Model = translator.translate( v3Model );
-            removeDistributionManagementStatus( v4Model );
-        }
-        catch ( Exception e )
-        {
-            throw new MojoExecutionException( "Exception caught while 
converting project.xml. " + e.getMessage(), e );
-        }
-
-        Properties properties = new Properties();
-
-        if ( v3Model.getExtend() != null )
-        {
-            loadProperties( properties, new File( new File( basedir, 
v3Model.getExtend() ).getParentFile(),
-                                                  "project.properties" ) );
-        }
-
-        loadProperties( properties, new File( basedir, "project.properties" ) 
);
-
-        for ( int j = 0; j < converters.length; j++ )
-        {
-            converters[j].convertConfiguration( v4Model, v3Model, properties );
-        }
-
-        // @todo Should this be run before or after the configuration 
converters?
-        Collection pluginRelocators = 
pluginRelocatorManager.getPluginRelocators();
-        getLog().info( "There are " + pluginRelocators.size() + " plugin 
relocators available" );
-        PluginRelocator pluginRelocator;
-        Iterator iterator = pluginRelocators.iterator();
-        while ( iterator.hasNext() )
-        {
-            pluginRelocator = (PluginRelocator) iterator.next();
-            pluginRelocator.relocate( v4Model );
-        }
-
-        writeV4Pom( v4Model );
-    }
-
-    private boolean isEmpty( String value )
-    {
-        return value == null || value.trim().length() == 0;
-    }
-
-    private void loadProperties( Properties properties, File propertiesFile )
-    {
-        if ( propertiesFile.exists() )
-        {
-            InputStream is = null;
-            try
-            {
-                is = new FileInputStream( propertiesFile );
-                properties.load( is );
-            }
-            catch ( IOException e )
-            {
-                getLog().warn( "Unable to read " + 
propertiesFile.getAbsolutePath() + ", ignoring." );
-            }
-            finally
-            {
-                IOUtil.close( is );
-            }
-        }
-    }
-
-    private org.apache.maven.model.v3_0_0.Model loadV3Pom( File inputFile )
-        throws Exception
-    {
-        MavenXpp3Reader v3Reader = new MavenXpp3Reader();
+        Maven1Converter converter = new Maven1Converter();
+        converter.setBasedir( basedir );
 
-        org.apache.maven.model.v3_0_0.Model model;
-
-        model = v3Reader.read( new FileReader( inputFile ) );
-
-        SAXReader r = new SAXReader();
-
-        Document d = r.read( new FileReader( inputFile ) );
-
-        Element root = d.getRootElement();
-
-        Element idElement = root.element( "id" );
-
-        String id = null;
-
-        if ( idElement != null )
-        {
-            id = idElement.getText();
-        }
-        //        String id = model.getId();
-
-        String groupId = model.getGroupId();
-
-        String artifactId = model.getArtifactId();
-
-        if ( !isEmpty( id ) )
-        {
-            int i = id.indexOf( "+" );
-
-            int j = id.indexOf( ":" );
-
-            if ( i > 0 )
-            {
-                model.setGroupId( id.substring( 0, i ) );
-
-                model.setArtifactId( id.replace( '+', '-' ) );
-            }
-            else if ( j > 0 )
-            {
-                model.setGroupId( id.substring( 0, j ) );
-
-                model.setArtifactId( id.substring( j + 1 ) );
-            }
-            else
-            {
-                model.setGroupId( id );
-
-                model.setArtifactId( id );
-            }
-
-            if ( !isEmpty( groupId ) )
-            {
-                getLog().warn( "Both <id> and <groupId> is set, using 
<groupId>." );
-
-                model.setGroupId( groupId );
-            }
-
-            if ( !isEmpty( artifactId ) )
-            {
-                getLog().warn( "Both <id> and <artifactId> is set, using 
<artifactId>." );
-
-                model.setArtifactId( artifactId );
-            }
-        }
-
-        return model;
-    }
-
-    /**
-     * The status element of the distributionManagement section must not be
-     * set in local projects. This method removes that element from the model.
-     */
-    private void removeDistributionManagementStatus( Model v4Model )
-    {
-        if ( v4Model.getDistributionManagement() != null )
-        {
-            if ( "converted".equals( 
v4Model.getDistributionManagement().getStatus() ) )
-            {
-                v4Model.getDistributionManagement().setStatus( null );
-            }
-        }
-    }
-
-    /**
-     * Write the pom to <code>${basedir}/pom.xml</code>. If the file exists it
-     * will be overwritten.
-     *
-     * @param v4Model
-     * @throws MojoExecutionException
-     */
-    private void writeV4Pom( Model v4Model )
-        throws MojoExecutionException
-    {
-        File pomxml = new File( basedir, "pom.xml" );
-
-        if ( pomxml.exists() )
-        {
-            getLog().warn( "pom.xml in " + basedir.getAbsolutePath() + " 
already exists, overwriting" );
-        }
-
-        MavenXpp3Writer v4Writer = new MavenXpp3Writer();
-
-        // write the new pom.xml
-        getLog().info( "Writing new pom to: " + pomxml.getAbsolutePath() );
-
-        Writer output = null;
         try
         {
-            output = new FileWriter( pomxml );
-            v4Writer.write( output, v4Model );
-            output.close();
+            converter.execute();
         }
-        catch ( IOException e )
+        catch ( ProjectConverterException e )
         {
-            throw new MojoExecutionException( "Unable to write pom.xml. " + 
e.getMessage(), e );
-        }
-        finally
-        {
-            IOUtil.close( output );
+            throw new MojoExecutionException( "An exception occured while 
converting the Maven 1 project", e );
         }
     }
-
 }


Reply via email to