Author: carlos
Date: Fri Jun  2 15:38:03 2006
New Revision: 411320

URL: http://svn.apache.org/viewvc?rev=411320&view=rev
Log:
[MNG-2335] Use maven-model-converter instead of bundled class

Modified:
    maven/sandbox/plugins/maven-maven1-plugin/pom.xml
    
maven/sandbox/plugins/maven-maven1-plugin/src/main/java/org/apache/maven/maven1converter/PomV3ConvertMojo.java
    
maven/sandbox/plugins/maven-maven1-plugin/src/main/java/org/apache/maven/maven1converter/PomV3ToV4Converter.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=411320&r1=411319&r2=411320&view=diff
==============================================================================
--- maven/sandbox/plugins/maven-maven1-plugin/pom.xml (original)
+++ maven/sandbox/plugins/maven-maven1-plugin/pom.xml Fri Jun  2 15:38:03 2006
@@ -58,12 +58,17 @@
     <dependency>
       <groupId>org.apache.maven</groupId>
       <artifactId>maven-model</artifactId>
-      <version>2.0</version>
+      <version>2.0.4</version>
     </dependency>
     <dependency>
       <groupId>org.apache.maven</groupId>
       <artifactId>maven-model-v3</artifactId>
       <version>2.0</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-model-converter</artifactId>
+      <version>2.0.4</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=411320&r1=411319&r2=411320&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
 Fri Jun  2 15:38:03 2006
@@ -18,6 +18,7 @@
 
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.FileReader;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.InputStream;
@@ -30,17 +31,23 @@
 import org.apache.maven.maven1converter.plugins.PCCWar;
 import org.apache.maven.maven1converter.plugins.PluginConfigurationConverter;
 import org.apache.maven.model.Model;
+import org.apache.maven.model.v3_0_0.io.xpp3.MavenXpp3Reader;
+import org.apache.maven.model.converter.PomV3ToV4Translator;
 import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
 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;
 
 /**
  * Converts a Maven 1 project.xml (v3 pom) to a Maven 2 pom.xml (v4 pom).
  * @goal convert
  * @requiresProject false
  * @author Fabrizio Giustina
+ * @author Dennis Lundberg
  * @version $Id$
  */
 public class PomV3ConvertMojo
@@ -77,12 +84,12 @@
             throw new MojoFailureException( "Missing project.xml in " + 
basedir.getAbsolutePath() );
         }
 
-        PomV3ToV4Converter converter = new PomV3ToV4Converter();
+        PomV3ToV4Translator translator = new PomV3ToV4Translator();
 
         org.apache.maven.model.v3_0_0.Model v3Model;
         try
         {
-            v3Model = converter.loadV3Pom( projectxml );
+            v3Model = loadV3Pom( projectxml );
         }
         catch ( Exception e )
         {
@@ -92,7 +99,8 @@
         Model v4Model;
         try
         {
-            v4Model = converter.convertModel( projectxml, v3Model );
+            v4Model = translator.translate( v3Model );
+            removeDistributionManagementStatus( v4Model );
         }
         catch ( Exception e )
         {
@@ -117,6 +125,11 @@
         writeV4Pom( v4Model );
     }
 
+    private boolean isEmpty( String value )
+    {
+        return value == null || value.trim().length() == 0;
+    }
+
     private void loadProperties( Properties properties, File propertiesFile )
     {
         if ( propertiesFile.exists() )
@@ -135,6 +148,90 @@
             {
                 IOUtil.close( is );
             }
+        }
+    }
+
+    private org.apache.maven.model.v3_0_0.Model loadV3Pom( File inputFile )
+        throws Exception
+    {
+        MavenXpp3Reader v3Reader = new MavenXpp3Reader();
+
+        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 ( "converted".equals( 
v4Model.getDistributionManagement().getStatus() ) )
+        {
+            v4Model.getDistributionManagement().setStatus( null );
         }
     }
 

Modified: 
maven/sandbox/plugins/maven-maven1-plugin/src/main/java/org/apache/maven/maven1converter/PomV3ToV4Converter.java
URL: 
http://svn.apache.org/viewvc/maven/sandbox/plugins/maven-maven1-plugin/src/main/java/org/apache/maven/maven1converter/PomV3ToV4Converter.java?rev=411320&r1=411319&r2=411320&view=diff
==============================================================================
--- 
maven/sandbox/plugins/maven-maven1-plugin/src/main/java/org/apache/maven/maven1converter/PomV3ToV4Converter.java
 (original)
+++ 
maven/sandbox/plugins/maven-maven1-plugin/src/main/java/org/apache/maven/maven1converter/PomV3ToV4Converter.java
 Fri Jun  2 15:38:03 2006
@@ -1,796 +0,0 @@
-package org.apache.maven.maven1converter;
-
-/*
- * Copyright 2001-2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Properties;
-
-import org.apache.maven.model.Build;
-import org.apache.maven.model.CiManagement;
-import org.apache.maven.model.Contributor;
-import org.apache.maven.model.Dependency;
-import org.apache.maven.model.DeploymentRepository;
-import org.apache.maven.model.Developer;
-import org.apache.maven.model.DistributionManagement;
-import org.apache.maven.model.IssueManagement;
-import org.apache.maven.model.License;
-import org.apache.maven.model.MailingList;
-import org.apache.maven.model.Model;
-import org.apache.maven.model.Notifier;
-import org.apache.maven.model.Organization;
-import org.apache.maven.model.Parent;
-import org.apache.maven.model.Resource;
-import org.apache.maven.model.Scm;
-import org.apache.maven.model.Site;
-import org.apache.maven.model.v3_0_0.SourceModification;
-import org.apache.maven.model.v3_0_0.io.xpp3.MavenXpp3Reader;
-import org.dom4j.Document;
-import org.dom4j.Element;
-import org.dom4j.io.SAXReader;
-
-/**
- * PomV3ToV4Converter originally developed in maven-repository-tools
- * @author <a href="mailto:[EMAIL PROTECTED]">Trygve Laugst&oslash;l</a>
- * @author Fabrizio Giustina
- * @version $Id$
- */
-public class PomV3ToV4Converter
-{
-    private org.apache.maven.model.v3_0_0.Model v3ParentModel;
-
-    public Model convertFile( File input )
-        throws Exception
-    {
-        org.apache.maven.model.v3_0_0.Model v3Model = loadV3Pom( input );
-        return convertModel( input, v3Model );
-    }
-
-    public Model convertModel( File file, org.apache.maven.model.v3_0_0.Model 
v3Model )
-        throws Exception
-    {
-        Model v4Model = populateModel( file, v3Model );
-        return v4Model;
-    }
-
-    private Model populateModel( File file, 
org.apache.maven.model.v3_0_0.Model v3Model )
-        throws Exception
-    {
-        Model v4Model = new Model();
-
-        v4Model.setModelVersion( "4.0.0" );
-        v4Model.setParent( getParent( file, v3Model ) );
-
-        // Group id
-        String groupId = v3Model.getGroupId();
-        String parentGroupId = null;
-
-        if ( v3ParentModel != null )
-        {
-            parentGroupId = v3ParentModel.getGroupId();
-        }
-
-        if ( isEmpty( groupId ) && isEmpty( parentGroupId ) )
-        {
-            throw new Exception( "Missing 'groupId' from both pom and the 
extended pom." );
-        }
-
-        v4Model.setGroupId( groupId );
-
-        // Artifact id
-        String artifactId = v3Model.getArtifactId();
-
-        if ( isEmpty( artifactId ) )
-        {
-            v4Model.setArtifactId( groupId );
-        }
-        else
-        {
-            v4Model.setArtifactId( artifactId );
-        }
-
-        // Version
-        String version = v3Model.getCurrentVersion();
-
-        if ( isEmpty( version ) && ( v3ParentModel == null || isEmpty( 
v3ParentModel.getCurrentVersion() ) ) )
-        {
-            throw new Exception( "Missing 'currentVersion' from both pom and 
the extended pom." );
-        }
-
-        v4Model.setVersion( version );
-        v4Model.setName( v3Model.getName() );
-        v4Model.setDescription( v3Model.getDescription() );
-        v4Model.setUrl( v3Model.getUrl() );
-        v4Model.setOrganization( getOrganization( v3Model ) );
-
-        // @todo write in site.xml
-        // v4Model.setLogo( v3Model.getLogo() );
-
-        v4Model.setIssueManagement( getIssueManagement( v3Model ) );
-        v4Model.setCiManagement( getCiManagement( v3Model ) );
-        v4Model.setInceptionYear( v3Model.getInceptionYear() );
-
-        if ( !isEmpty( v3Model.getGumpRepositoryId() ) )
-        {
-            warn( "The 'gumpRepositoryId' is removed from the version 4 pom." 
);
-        }
-
-        v4Model.setRepositories( getRepositories( v3Model ) );
-        v4Model.setDevelopers( getDevelopers( v3Model ) );
-        v4Model.setContributors( getContributors( v3Model ) );
-        v4Model.setDependencies( getDependencies( v3Model ) );
-        v4Model.setLicenses( getLicenses( v3Model ) );
-
-        List versions = v3Model.getVersions();
-        if ( versions != null )
-        {
-            warn( "The <versions> list is removed in the version 4 of the 
pom." );
-        }
-
-        List branches = v3Model.getBranches();
-        if ( branches != null )
-        {
-            warn( "The <branches> list is removed in the version 4 of the 
pom." );
-        }
-
-        // @todo reports in v4 are an Xpp3Dom
-        // v4Model.setReports( returnList( v3Model.getReports() ) );
-
-        v4Model.setScm( getScm( v3Model ) );
-        v4Model.setBuild( getBuild( v3Model ) );
-        v4Model.setDistributionManagement( getDistributionManagement( v3Model 
) );
-
-        return v4Model;
-    }
-
-    private Parent getParent( File file, org.apache.maven.model.v3_0_0.Model 
v3Model )
-        throws Exception
-    {
-        Parent parent = new Parent();
-        String extend = v3Model.getExtend();
-
-        if ( isEmpty( extend ) )
-        {
-            return null;
-        }
-
-        final String basedir = "${basedir}";
-
-        int i = extend.indexOf( basedir );
-
-        if ( i >= 0 )
-        {
-            extend = extend.substring( 0, i ) + file.getParentFile() + 
File.separator
-                + extend.substring( i + basedir.length() + 1 );
-        }
-
-        File extendFile = new File( extend );
-
-        if ( !extendFile.isAbsolute() )
-        {
-            extendFile = new File( file.getParentFile(), extend );
-        }
-
-        if ( !extendFile.isFile() )
-        {
-            throw new FileNotFoundException( "Could not find the file the pom 
extends: '"
-                + extendFile.getAbsolutePath() + "' is not a file." );
-        }
-
-        // try to find the parent pom.
-        v3ParentModel = loadV3Pom( extendFile );
-
-        String groupId = v3ParentModel.getGroupId();
-
-        if ( isEmpty( groupId ) )
-        {
-            throw new Exception( "Missing groupId from the extended pom." );
-        }
-
-        parent.setGroupId( groupId );
-
-        String artifactId = v3ParentModel.getArtifactId();
-
-        if ( isEmpty( artifactId ) )
-        {
-            throw new Exception( "Missing 'artifactId' from the extended pom." 
);
-        }
-
-        parent.setArtifactId( artifactId );
-
-        String version = v3ParentModel.getCurrentVersion();
-
-        if ( isEmpty( version ) )
-        {
-            throw new Exception( "Missing 'currentVersion' from the extended 
pom." );
-        }
-
-        parent.setVersion( version );
-
-        return parent;
-    }
-
-    private Organization getOrganization( org.apache.maven.model.v3_0_0.Model 
v3Model )
-    {
-        Organization organization = new Organization();
-
-        if ( v3Model.getOrganization() == null )
-        {
-            return null;
-        }
-
-        organization.setName( v3Model.getOrganization().getName() );
-
-        organization.setUrl( v3Model.getOrganization().getUrl() );
-
-        // @todo write in site.xml
-        // organization.setLogo( v3Model.getOrganization().getLogo() );
-
-        return organization;
-    }
-
-    private IssueManagement getIssueManagement( 
org.apache.maven.model.v3_0_0.Model v3Model )
-    {
-        String issueTrackingUrl = v3Model.getIssueTrackingUrl();
-
-        if ( isEmpty( issueTrackingUrl ) )
-        {
-            return null;
-        }
-
-        IssueManagement issueManagement = new IssueManagement();
-        issueManagement.setUrl( issueTrackingUrl );
-
-        return issueManagement;
-    }
-
-    private CiManagement getCiManagement( org.apache.maven.model.v3_0_0.Model 
v3Model )
-    {
-        if ( v3Model.getBuild() == null )
-        {
-            return null;
-        }
-
-        String nagEmailAddress = v3Model.getBuild().getNagEmailAddress();
-
-        if ( isEmpty( nagEmailAddress ) )
-        {
-            return null;
-        }
-
-        CiManagement ciManagement = new CiManagement();
-
-        Notifier notifier = new Notifier();
-        notifier.setAddress( nagEmailAddress );
-        notifier.setType( "mail" );
-
-        ciManagement.addNotifier( notifier );
-
-        return ciManagement;
-    }
-
-    // @TODO:
-    // note: these are not SCM repositories but rather artifact repositories
-    private List getRepositories( org.apache.maven.model.v3_0_0.Model v3Model )
-    {
-        List repositories = new ArrayList( 1 );
-
-        //        warn( "" );
-
-        return returnList( repositories );
-    }
-
-    private List getMailingLists( org.apache.maven.model.v3_0_0.Model v3Model )
-    {
-        List mailingLists = new ArrayList();
-
-        List v3MailingLists = v3Model.getMailingLists();
-
-        if ( isEmpty( v3MailingLists ) )
-        {
-            return null;
-        }
-
-        for ( Iterator it = v3MailingLists.iterator(); it.hasNext(); )
-        {
-            org.apache.maven.model.v3_0_0.MailingList v3MailingList = 
(org.apache.maven.model.v3_0_0.MailingList) it
-                .next();
-
-            MailingList mailingList = new MailingList();
-            mailingList.setName( v3MailingList.getName() );
-            mailingList.setSubscribe( v3MailingList.getSubscribe() );
-            mailingList.setUnsubscribe( v3MailingList.getUnsubscribe() );
-            mailingList.setArchive( v3MailingList.getArchive() );
-            mailingLists.add( mailingList );
-        }
-
-        return mailingLists;
-    }
-
-    private List getDevelopers( org.apache.maven.model.v3_0_0.Model v3Model )
-    {
-        List developers = new ArrayList();
-
-        List v3Developers = v3Model.getDevelopers();
-
-        if ( isEmpty( v3Developers ) )
-        {
-            return null;
-        }
-
-        for ( Iterator it = v3Developers.iterator(); it.hasNext(); )
-        {
-            org.apache.maven.model.v3_0_0.Developer v3Developer = 
(org.apache.maven.model.v3_0_0.Developer) it.next();
-
-            Developer developer = new Developer();
-            developer.setId( nullIfEmpty( v3Developer.getId() ) );
-            developer.setName( nullIfEmpty( v3Developer.getName() ) );
-            developer.setEmail( nullIfEmpty( v3Developer.getEmail() ) );
-            developer.setOrganization( nullIfEmpty( 
v3Developer.getOrganization() ) );
-            developer.setTimezone( nullIfEmpty( v3Developer.getTimezone() ) );
-            developer.setUrl( nullIfEmpty( v3Developer.getUrl() ) );
-            developer.setRoles( returnList( v3Developer.getRoles() ) );
-            developers.add( developer );
-        }
-
-        return developers;
-    }
-
-    private List getContributors( org.apache.maven.model.v3_0_0.Model v3Model )
-    {
-        List contributors = new ArrayList();
-
-        List v3Contributors = v3Model.getContributors();
-
-        if ( isEmpty( v3Contributors ) )
-        {
-            return null;
-        }
-
-        for ( Iterator it = v3Contributors.iterator(); it.hasNext(); )
-        {
-            org.apache.maven.model.v3_0_0.Contributor v3Contributor = 
(org.apache.maven.model.v3_0_0.Contributor) it
-                .next();
-
-            Contributor contributor = new Contributor();
-            contributor.setName( nullIfEmpty( v3Contributor.getName() ) );
-            contributor.setEmail( nullIfEmpty( v3Contributor.getEmail() ) );
-            contributor.setOrganization( nullIfEmpty( 
v3Contributor.getOrganization() ) );
-            contributor.setTimezone( nullIfEmpty( v3Contributor.getTimezone() 
) );
-            contributor.setUrl( nullIfEmpty( v3Contributor.getUrl() ) );
-            contributor.setRoles( returnList( v3Contributor.getRoles() ) );
-            contributors.add( contributor );
-        }
-
-        return contributors;
-    }
-
-    private List getDependencies( org.apache.maven.model.v3_0_0.Model v3Model )
-        throws Exception
-    {
-        List dependencies = new ArrayList();
-
-        List v3Dependencies = v3Model.getDependencies();
-
-        if ( isEmpty( v3Dependencies ) )
-        {
-            return null;
-        }
-
-        for ( Iterator it = v3Dependencies.iterator(); it.hasNext(); )
-        {
-            org.apache.maven.model.v3_0_0.Dependency v3Dependency = 
(org.apache.maven.model.v3_0_0.Dependency) it
-                .next();
-
-            String artifacttype = v3Dependency.getType();
-            String id = nullIfEmpty( v3Dependency.getId() );
-            String groupId = nullIfEmpty( v3Dependency.getGroupId() );
-            String artifactId = nullIfEmpty( v3Dependency.getArtifactId() );
-
-            if ( isEmpty( groupId ) )
-            {
-                groupId = id;
-            }
-            if ( isEmpty( artifactId ) )
-            {
-                artifactId = id;
-            }
-
-            if ( isEmpty( groupId ) )
-            {
-                fatal( "Missing dependency.groupId." );
-            }
-
-            if ( isEmpty( artifactId ) )
-            {
-                fatal( "Missing dependency.artifactId." );
-            }
-
-            if ( "plugin".equalsIgnoreCase( artifacttype ) )
-            {
-                warn( "Plugin dependency " + artifactId + " not copied to v4 
pom" );
-                continue;
-            }
-
-            Dependency dependency = new Dependency();
-
-            dependency.setGroupId( groupId );
-            dependency.setArtifactId( artifactId );
-
-            dependency.setType( nullIfEmpty( v3Dependency.getType() ) );
-            dependency.setVersion( nullIfEmpty( v3Dependency.getVersion() ) );
-
-            Properties v3Properties = v3Dependency.getProperties();
-
-            for ( Iterator iter = v3Properties.keySet().iterator(); 
iter.hasNext(); )
-            {
-                String key = (String) iter.next();
-                if ( ( "scope" ).equals( key ) )
-                {
-                    dependency.setScope( v3Properties.getProperty( key ) );
-                }
-                else if ( ( "optional" ).equals( key ) )
-                {
-                    dependency.setOptional( true );
-                }
-
-            }
-
-            dependencies.add( dependency );
-        }
-
-        return dependencies;
-    }
-
-    private List getLicenses( org.apache.maven.model.v3_0_0.Model v3Model )
-    {
-        List licenses = new ArrayList();
-
-        List v3Licenses = v3Model.getLicenses();
-
-        if ( isEmpty( v3Licenses ) )
-        {
-            return null;
-        }
-
-        for ( Iterator it = v3Licenses.iterator(); it.hasNext(); )
-        {
-            org.apache.maven.model.v3_0_0.License v3License = 
(org.apache.maven.model.v3_0_0.License) it.next();
-
-            License license = new License();
-            license.setName( nullIfEmpty( v3License.getName() ) );
-            license.setUrl( nullIfEmpty( v3License.getUrl() ) );
-            license.setComments( nullIfEmpty( v3License.getComments() ) );
-            licenses.add( license );
-        }
-
-        return licenses;
-    }
-
-    private Scm getScm( org.apache.maven.model.v3_0_0.Model v3Model )
-    {
-        if ( v3Model.getRepository() == null )
-        {
-            return null;
-        }
-
-        Scm scm = new Scm();
-
-        scm.setConnection( v3Model.getRepository().getConnection() );
-        scm.setDeveloperConnection( 
v3Model.getRepository().getDeveloperConnection() );
-        scm.setUrl( v3Model.getRepository().getUrl() );
-
-        return scm;
-    }
-
-    private Build getBuild( org.apache.maven.model.v3_0_0.Model v3Model )
-    {
-        org.apache.maven.model.v3_0_0.Build v3Build = v3Model.getBuild();
-
-        if ( v3Build == null )
-        {
-            return null;
-        }
-
-        Build build = new Build();
-
-        build.setSourceDirectory( v3Build.getSourceDirectory() );
-
-        List v3SourceModifications = v3Build.getSourceModifications();
-
-        if ( v3SourceModifications != null && v3SourceModifications.size() > 0 
)
-        {
-            List sourceModifications = new ArrayList();
-
-            for ( Iterator it = v3SourceModifications.iterator(); 
it.hasNext(); )
-            {
-                org.apache.maven.model.v3_0_0.SourceModification 
v3SourceModification = (org.apache.maven.model.v3_0_0.SourceModification) it
-                    .next();
-
-                SourceModification sourceModification = new 
SourceModification();
-                sourceModification.setClassName( 
v3SourceModification.getClassName() );
-                sourceModification.setIncludes( getIncludes( 
v3SourceModification.getIncludes() ) );
-                sourceModification.setExcludes( getExcludes( 
v3SourceModification.getExcludes() ) );
-                sourceModifications.add( sourceModification );
-            }
-
-            // @todo SourceModifications
-            // build.setSourceModifications( sourceModifications );
-        }
-
-        build.setTestSourceDirectory( v3Build.getUnitTestSourceDirectory() );
-
-        // @todo getAspectSourceDirectory
-        // build.setAspectSourceDirectory( v3Build.getAspectSourceDirectory() 
);
-
-        org.apache.maven.model.v3_0_0.UnitTest v3UnitTest = 
v3Build.getUnitTest();
-
-        if ( v3UnitTest != null )
-        {
-            build.setTestResources( convertResources( 
v3UnitTest.getResources() ) );
-        }
-
-        build.setResources( convertResources( v3Build.getResources() ) );
-
-        return build;
-    }
-
-    private DistributionManagement getDistributionManagement( 
org.apache.maven.model.v3_0_0.Model v3Model )
-        throws Exception
-    {
-        DistributionManagement distributionManagement = new 
DistributionManagement();
-
-        Site site = null;
-
-        String siteAddress = v3Model.getSiteAddress();
-
-        String siteDirectory = v3Model.getSiteDirectory();
-
-        if ( isEmpty( siteAddress ) )
-        {
-            if ( !isEmpty( siteDirectory ) )
-            {
-                site = new Site();
-
-                site.setId( "default" );
-                site.setName( "Default Site" );
-                site.setUrl( "file://" + siteDirectory );
-            }
-        }
-        else
-        {
-            if ( isEmpty( siteDirectory ) )
-            {
-                throw new Exception(
-                                     "Missing 'siteDirectory': Both 
siteAddress and siteDirectory must be set at the same time." );
-            }
-
-            site = new Site();
-
-            site.setId( "default" );
-            site.setName( "Default Site" );
-            site.setUrl( "scp://" + siteAddress + "/" + siteDirectory );
-        }
-
-        distributionManagement.setSite( site );
-
-        String distributionSite = v3Model.getDistributionSite();
-        String distributionDirectory = v3Model.getDistributionDirectory();
-
-        DeploymentRepository deploymentRepository = null;
-
-        if ( isEmpty( distributionSite ) )
-        {
-            if ( !isEmpty( distributionDirectory ) )
-            {
-                deploymentRepository = new DeploymentRepository();
-                deploymentRepository.setId( "default" );
-                deploymentRepository.setName( "Default Repository" );
-                deploymentRepository.setUrl( "file://" + distributionDirectory 
);
-            }
-        }
-        else
-        {
-            if ( isEmpty( distributionDirectory ) )
-            {
-                throw new Exception( "Missing 'distributionDirectory': must be 
set is 'distributionSite' is set." );
-            }
-
-            deploymentRepository = new DeploymentRepository();
-            deploymentRepository.setId( "default" );
-            deploymentRepository.setName( "Default Repository" );
-            deploymentRepository.setUrl( distributionSite + "/" + 
distributionDirectory );
-        }
-
-        distributionManagement.setRepository( deploymentRepository );
-
-        if ( site == null && deploymentRepository == null )
-        {
-            return null;
-        }
-
-        return distributionManagement;
-    }
-
-    public org.apache.maven.model.v3_0_0.Model loadV3Pom( File inputFile )
-        throws Exception
-    {
-        MavenXpp3Reader v3Reader = new MavenXpp3Reader();
-
-        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 ) )
-            {
-                warn( "Both <id> and <groupId> is set, using <groupId>." );
-
-                model.setGroupId( groupId );
-            }
-
-            if ( !isEmpty( artifactId ) )
-            {
-                warn( "Both <id> and <artifactId> is set, using <artifactId>." 
);
-
-                model.setArtifactId( artifactId );
-            }
-        }
-
-        return model;
-    }
-
-    private List getIncludes( List includes )
-    {
-        if ( includes == null || includes.size() == 0 )
-        {
-            return null;
-        }
-
-        return includes;
-    }
-
-    private List getExcludes( List excludes )
-    {
-        if ( excludes == null || excludes.size() == 0 )
-        {
-            return null;
-        }
-
-        return excludes;
-    }
-
-    private List convertResources( List v3Resources )
-    {
-        List resources = new ArrayList();
-
-        if ( v3Resources == null || v3Resources.size() == 0 )
-        {
-            return null;
-        }
-
-        for ( Iterator it = v3Resources.iterator(); it.hasNext(); )
-        {
-            org.apache.maven.model.v3_0_0.Resource v3Resource = 
(org.apache.maven.model.v3_0_0.Resource) it.next();
-
-            Resource resource = new Resource();
-            resource.setDirectory( v3Resource.getDirectory() );
-            resource.setTargetPath( v3Resource.getTargetPath() );
-            resource.setIncludes( getIncludes( v3Resource.getIncludes() ) );
-            resource.setExcludes( getExcludes( v3Resource.getExcludes() ) );
-
-            resources.add( resource );
-        }
-
-        return resources;
-    }
-
-    private List returnList( List list )
-    {
-        if ( list == null || list.size() == 0 )
-            return null;
-
-        return list;
-    }
-
-    private boolean isEmpty( String value )
-    {
-        return value == null || value.trim().length() == 0;
-    }
-
-    private boolean isEmpty( List list )
-    {
-        return list == null || list.size() == 0;
-    }
-
-    private String nullIfEmpty( String string )
-    {
-        if ( string == null || string.trim().length() == 0 )
-        {
-            return null;
-        }
-
-        return string;
-    }
-
-    private void fatal( String msg )
-        throws Exception
-    {
-        System.err.println( "[FATAL] " + msg );
-        throw new Exception( msg );
-    }
-
-    private void warn( String msg )
-    {
-        System.err.println( "[WARN] " + msg );
-        System.err.flush();
-    }
-
-    private void info( String msg )
-    {
-        System.err.println( msg );
-        System.err.flush();
-    }
-}


Reply via email to