maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jvan...@apache.org
Subject svn commit: r580247 - in /maven/sandbox/trunk/archetypeng: archetypeng-common/src/main/java/org/apache/maven/archetype/common/ archetypeng-common/src/main/java/org/apache/maven/archetype/source/ archetypeng-plugin/src/main/java/org/apache/maven/archety...
Date Fri, 28 Sep 2007 08:03:53 GMT
Author: jvanzyl
Date: Fri Sep 28 01:03:53 2007
New Revision: 580247

URL: http://svn.apache.org/viewvc?rev=580247&view=rev
Log:
o the archetype sources are now all components and I left some notes about what needs to be
done next
  - separate the configuration of archeytpe from the catalog of available archetypes

You might store a configuration of where to look for catalogs, say on an URL so that you can
create new archetypes, up-date
a remote catalog (wiki, or an xml file somewhere) and have developers automatically discover
them.


Added:
    maven/sandbox/trunk/archetypeng/archetypeng-common/src/main/java/org/apache/maven/archetype/source/RemoteRegistryArchetypeDataSource.java
      - copied, changed from r580177, maven/sandbox/trunk/archetypeng/archetypeng-common/src/main/java/org/apache/maven/archetype/source/RegistryArchetypeDataSource.java
Modified:
    maven/sandbox/trunk/archetypeng/archetypeng-common/src/main/java/org/apache/maven/archetype/common/ArchetypeRegistryManager.java
    maven/sandbox/trunk/archetypeng/archetypeng-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeRegistryManager.java
    maven/sandbox/trunk/archetypeng/archetypeng-common/src/main/java/org/apache/maven/archetype/source/ArchetypeDataSource.java
    maven/sandbox/trunk/archetypeng/archetypeng-common/src/main/java/org/apache/maven/archetype/source/RegistryArchetypeDataSource.java
    maven/sandbox/trunk/archetypeng/archetypeng-common/src/main/java/org/apache/maven/archetype/source/WikiArchetypeDataSource.java
    maven/sandbox/trunk/archetypeng/archetypeng-plugin/src/main/java/org/apache/maven/archetype/ui/DefaultArchetypeSelector.java

Modified: maven/sandbox/trunk/archetypeng/archetypeng-common/src/main/java/org/apache/maven/archetype/common/ArchetypeRegistryManager.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/archetypeng/archetypeng-common/src/main/java/org/apache/maven/archetype/common/ArchetypeRegistryManager.java?rev=580247&r1=580246&r2=580247&view=diff
==============================================================================
--- maven/sandbox/trunk/archetypeng/archetypeng-common/src/main/java/org/apache/maven/archetype/common/ArchetypeRegistryManager.java
(original)
+++ maven/sandbox/trunk/archetypeng/archetypeng-common/src/main/java/org/apache/maven/archetype/common/ArchetypeRegistryManager.java
Fri Sep 28 01:03:53 2007
@@ -20,13 +20,11 @@
 package org.apache.maven.archetype.common;
 
 import org.apache.maven.archetype.registry.ArchetypeRegistry;
-
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
 import java.io.File;
-import java.io.FileNotFoundException;
 import java.io.IOException;
-
+import java.io.Reader;
 import java.util.List;
 
 public interface ArchetypeRegistryManager
@@ -43,16 +41,19 @@
         throws
         IOException;
 
+    ArchetypeRegistry readArchetypeRegistry( Reader reader )
+        throws
+        IOException,
+        XmlPullParserException;
+
     ArchetypeRegistry readArchetypeRegistry( File archetypeRegistryFile )
         throws
         IOException,
-        FileNotFoundException,
         XmlPullParserException;
 
     ArchetypeRegistry readArchetypeRegistry()
         throws
         IOException,
-        FileNotFoundException,
         XmlPullParserException;
 
     List getRepositories(

Modified: maven/sandbox/trunk/archetypeng/archetypeng-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeRegistryManager.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/archetypeng/archetypeng-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeRegistryManager.java?rev=580247&r1=580246&r2=580247&view=diff
==============================================================================
--- maven/sandbox/trunk/archetypeng/archetypeng-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeRegistryManager.java
(original)
+++ maven/sandbox/trunk/archetypeng/archetypeng-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeRegistryManager.java
Fri Sep 28 01:03:53 2007
@@ -19,7 +19,6 @@
 
 package org.apache.maven.archetype.common;
 
-import org.apache.maven.archetype.registry.Archetype;
 import org.apache.maven.archetype.registry.ArchetypeRegistry;
 import org.apache.maven.archetype.registry.io.xpp3.ArchetypeRegistryXpp3Reader;
 import org.apache.maven.archetype.registry.io.xpp3.ArchetypeRegistryXpp3Writer;
@@ -32,22 +31,14 @@
 import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
-import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileReader;
 import java.io.FileWriter;
 import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.net.URL;
+import java.io.Reader;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
 import java.util.List;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
 
 /** @plexus.component */
 public class DefaultArchetypeRegistryManager
@@ -149,8 +140,6 @@
         IOException,
         XmlPullParserException
     {
-        System.out.println( "DEFAULT_REGISTRY = " + DEFAULT_REGISTRY );
-
         return readArchetypeRegistry( DEFAULT_REGISTRY );
     }
 
@@ -161,22 +150,28 @@
     {
         if ( !archetypeRegistryFile.exists() )
         {
-            ArchetypeRegistry registry = getDefaultArchetypeRegistry();
-
-            writeArchetypeRegistry( archetypeRegistryFile, registry );            
+            return getDefaultArchetypeRegistry();
         }
+        else
+        {
+            return readArchetypeRegistry( new FileReader( archetypeRegistryFile ) );
+        }
+    }
 
-        ArchetypeRegistryXpp3Reader reader = new ArchetypeRegistryXpp3Reader();
-        
-        FileReader fileReader = new FileReader( archetypeRegistryFile );
+    public ArchetypeRegistry readArchetypeRegistry( Reader reader )
+        throws
+        IOException,
+        XmlPullParserException
+    {
+        ArchetypeRegistryXpp3Reader xpp3Reader = new ArchetypeRegistryXpp3Reader();
 
         try
         {
-            return reader.read( fileReader );
+            return xpp3Reader.read( reader );
         }
         finally
         {
-            IOUtil.close( fileReader );
+            IOUtil.close( reader );
         }
     }
 

Modified: maven/sandbox/trunk/archetypeng/archetypeng-common/src/main/java/org/apache/maven/archetype/source/ArchetypeDataSource.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/archetypeng/archetypeng-common/src/main/java/org/apache/maven/archetype/source/ArchetypeDataSource.java?rev=580247&r1=580246&r2=580247&view=diff
==============================================================================
--- maven/sandbox/trunk/archetypeng/archetypeng-common/src/main/java/org/apache/maven/archetype/source/ArchetypeDataSource.java
(original)
+++ maven/sandbox/trunk/archetypeng/archetypeng-common/src/main/java/org/apache/maven/archetype/source/ArchetypeDataSource.java
Fri Sep 28 01:03:53 2007
@@ -1,6 +1,7 @@
 package org.apache.maven.archetype.source;
 
-import java.util.Map;
+import java.util.List;
+import java.util.Properties;
 
 /**
  * Sources we can get Archetypes from. This may be the local registry, a Wiki, or,
@@ -13,6 +14,8 @@
  */
 public interface ArchetypeDataSource
 {
-    Map getArchetypes()
+    String ROLE = ArchetypeDataSource.class.getName();
+
+    List getArchetypes( Properties properties )
         throws ArchetypeDataSourceException;
 }

Modified: maven/sandbox/trunk/archetypeng/archetypeng-common/src/main/java/org/apache/maven/archetype/source/RegistryArchetypeDataSource.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/archetypeng/archetypeng-common/src/main/java/org/apache/maven/archetype/source/RegistryArchetypeDataSource.java?rev=580247&r1=580246&r2=580247&view=diff
==============================================================================
--- maven/sandbox/trunk/archetypeng/archetypeng-common/src/main/java/org/apache/maven/archetype/source/RegistryArchetypeDataSource.java
(original)
+++ maven/sandbox/trunk/archetypeng/archetypeng-common/src/main/java/org/apache/maven/archetype/source/RegistryArchetypeDataSource.java
Fri Sep 28 01:03:53 2007
@@ -2,48 +2,54 @@
 
 import org.apache.maven.archetype.common.ArchetypeRegistryManager;
 import org.apache.maven.archetype.registry.Archetype;
+import org.apache.maven.archetype.registry.ArchetypeRegistry;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
-import java.util.HashMap;
+import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
-import java.io.IOException;
+import java.util.Properties;
 
-/** @author Jason van Zyl */
+/**
+ * @plexus.component role-hint="registry"
+ * @author Jason van Zyl
+ */
 public class RegistryArchetypeDataSource
     implements ArchetypeDataSource
 {
-    private ArchetypeRegistryManager archetypeRegistryManager;
-
-    public RegistryArchetypeDataSource( ArchetypeRegistryManager archetypeRegistryManager
)
-    {
-        this.archetypeRegistryManager = archetypeRegistryManager;
-    }
+    /** @plexus.requirement */
+    protected ArchetypeRegistryManager archetypeRegistryManager;
 
-    public Map getArchetypes()
+    public List getArchetypes( Properties properties )
         throws ArchetypeDataSourceException
     {
-        Map archetypes = new HashMap();
-
-        List list;
-
         try
         {
-            list = archetypeRegistryManager.readArchetypeRegistry().getArchetypes();
+            return createArchetypeMap( archetypeRegistryManager.readArchetypeRegistry() );
         }
-        catch ( Exception e )
+        catch ( IOException e )
         {
-            throw new ArchetypeDataSourceException( "Error reading ~/.m2/archetype.xml" );
+            throw new ArchetypeDataSourceException( "Error reading archetype registry.",
e );
         }
-
-        for ( Iterator i = list.iterator(); i.hasNext(); )
+        catch ( XmlPullParserException e )
         {
-            Archetype archetype = (Archetype) i.next();
-
-            archetypes.put( archetype.getArtifactId(), archetype );
+            throw new ArchetypeDataSourceException( "Error parsing archetype registry", e
);
         }
+    }
+
+    protected List createArchetypeMap( ArchetypeRegistry registry )
+        throws ArchetypeDataSourceException
+    {
+        List archetypes = new ArrayList();
+
+         for ( Iterator i = registry.getArchetypes().iterator(); i.hasNext(); )
+         {
+             Archetype archetype = (Archetype) i.next();
+
+             archetypes.add( archetype );
+         }
 
-        return archetypes;
+         return archetypes;
     }
 }

Copied: maven/sandbox/trunk/archetypeng/archetypeng-common/src/main/java/org/apache/maven/archetype/source/RemoteRegistryArchetypeDataSource.java
(from r580177, maven/sandbox/trunk/archetypeng/archetypeng-common/src/main/java/org/apache/maven/archetype/source/RegistryArchetypeDataSource.java)
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/archetypeng/archetypeng-common/src/main/java/org/apache/maven/archetype/source/RemoteRegistryArchetypeDataSource.java?p2=maven/sandbox/trunk/archetypeng/archetypeng-common/src/main/java/org/apache/maven/archetype/source/RemoteRegistryArchetypeDataSource.java&p1=maven/sandbox/trunk/archetypeng/archetypeng-common/src/main/java/org/apache/maven/archetype/source/RegistryArchetypeDataSource.java&r1=580177&r2=580247&rev=580247&view=diff
==============================================================================
--- maven/sandbox/trunk/archetypeng/archetypeng-common/src/main/java/org/apache/maven/archetype/source/RegistryArchetypeDataSource.java
(original)
+++ maven/sandbox/trunk/archetypeng/archetypeng-common/src/main/java/org/apache/maven/archetype/source/RemoteRegistryArchetypeDataSource.java
Fri Sep 28 01:03:53 2007
@@ -1,49 +1,41 @@
 package org.apache.maven.archetype.source;
 
-import org.apache.maven.archetype.common.ArchetypeRegistryManager;
-import org.apache.maven.archetype.registry.Archetype;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
 import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.List;
+import java.util.Properties;
 
-/** @author Jason van Zyl */
-public class RegistryArchetypeDataSource
-    implements ArchetypeDataSource
-{
-    private ArchetypeRegistryManager archetypeRegistryManager;
-
-    public RegistryArchetypeDataSource( ArchetypeRegistryManager archetypeRegistryManager
)
-    {
-        this.archetypeRegistryManager = archetypeRegistryManager;
-    }
-
-    public Map getArchetypes()
+/**
+ * @plexus.component role-hint="remote-registry"
+ * @author Jason van Zyl
+ */
+public class RemoteRegistryArchetypeDataSource
+    extends RegistryArchetypeDataSource
+{        
+    public List getArchetypes( Properties properties )
         throws ArchetypeDataSourceException
     {
-        Map archetypes = new HashMap();
-
-        List list;
-
         try
         {
-            list = archetypeRegistryManager.readArchetypeRegistry().getArchetypes();
+            URL url = new URL( properties.getProperty( "url" ) );
+
+            return createArchetypeMap( archetypeRegistryManager.readArchetypeRegistry( new
InputStreamReader( url.openStream() ) ) );
         }
-        catch ( Exception e )
+        catch ( MalformedURLException e )
         {
-            throw new ArchetypeDataSourceException( "Error reading ~/.m2/archetype.xml" );
+            throw new ArchetypeDataSourceException( "Invalid URL provided for archetype registry.",
e );
         }
-
-        for ( Iterator i = list.iterator(); i.hasNext(); )
+        catch ( IOException e )
         {
-            Archetype archetype = (Archetype) i.next();
-
-            archetypes.put( archetype.getArtifactId(), archetype );
+            throw new ArchetypeDataSourceException( "Error reading archetype registry.",
e );
+        }
+        catch ( XmlPullParserException e )
+        {
+            throw new ArchetypeDataSourceException( "Error parsing archetype registry", e
);
         }
-
-        return archetypes;
     }
 }

Modified: maven/sandbox/trunk/archetypeng/archetypeng-common/src/main/java/org/apache/maven/archetype/source/WikiArchetypeDataSource.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/archetypeng/archetypeng-common/src/main/java/org/apache/maven/archetype/source/WikiArchetypeDataSource.java?rev=580247&r1=580246&r2=580247&view=diff
==============================================================================
--- maven/sandbox/trunk/archetypeng/archetypeng-common/src/main/java/org/apache/maven/archetype/source/WikiArchetypeDataSource.java
(original)
+++ maven/sandbox/trunk/archetypeng/archetypeng-common/src/main/java/org/apache/maven/archetype/source/WikiArchetypeDataSource.java
Fri Sep 28 01:03:53 2007
@@ -1,37 +1,38 @@
 package org.apache.maven.archetype.source;
 
+import org.apache.maven.archetype.registry.Archetype;
+
 import java.io.BufferedReader;
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
-import java.io.IOException;
 import java.net.URL;
-import java.util.LinkedHashMap;
-import java.util.Map;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-/** @author Jason van Zyl */
+/**
+ * @plexus.component role-hint="wiki"
+ * @author Jason van Zyl
+ */
 public class WikiArchetypeDataSource
     implements ArchetypeDataSource
 {
     private static String DEFAULT_ARCHETYPE_INVENTORY_PAGE = "http://docs.codehaus.org/pages/viewpagesrc.action?pageId=48400";
 
-    private String url;
-
-    public WikiArchetypeDataSource()
+    public List getArchetypes( Properties properties )
+        throws ArchetypeDataSourceException
     {
-        this( DEFAULT_ARCHETYPE_INVENTORY_PAGE );
-    }
+        String url = properties.getProperty( "url" );
 
-    public WikiArchetypeDataSource( String url )
-    {
-        this.url = url;
-    }
+        if ( url == null )
+        {
+            url = DEFAULT_ARCHETYPE_INVENTORY_PAGE;
+        }
 
-    public Map getArchetypes()
-        throws ArchetypeDataSourceException
-    {
-        Map archetypes = new LinkedHashMap();
+        List archetypes = new ArrayList();
 
         StringBuffer sb = new StringBuffer();
 
@@ -62,11 +63,11 @@
 
         while ( m.find() )
         {
-            org.apache.maven.archetype.registry.Archetype arch = new org.apache.maven.archetype.registry.Archetype();
+            Archetype archetype = new org.apache.maven.archetype.registry.Archetype();
 
-            arch.setArtifactId( m.group( 1 ).trim() );
+            archetype.setArtifactId( m.group( 1 ).trim() );
 
-            arch.setGroupId( m.group( 2 ).trim() );
+            archetype.setGroupId( m.group( 2 ).trim() );
 
             String version = m.group( 3 ).trim();
 
@@ -75,13 +76,13 @@
                 version = "RELEASE";
             }
 
-            arch.setVersion( version );
+            archetype.setVersion( version );
 
-            arch.setRepository( cleanupUrl( m.group( 4 ).trim() ) );
+            archetype.setRepository( cleanupUrl( m.group( 4 ).trim() ) );
 
-            arch.setDescription( cleanup( m.group( 5 ).trim() ) );
+            archetype.setDescription( cleanup( m.group( 5 ).trim() ) );
 
-            archetypes.put( arch.getArtifactId(), arch );
+            archetypes.add( archetype );
         }
 
         return archetypes;

Modified: maven/sandbox/trunk/archetypeng/archetypeng-plugin/src/main/java/org/apache/maven/archetype/ui/DefaultArchetypeSelector.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/archetypeng/archetypeng-plugin/src/main/java/org/apache/maven/archetype/ui/DefaultArchetypeSelector.java?rev=580247&r1=580246&r2=580247&view=diff
==============================================================================
--- maven/sandbox/trunk/archetypeng/archetypeng-plugin/src/main/java/org/apache/maven/archetype/ui/DefaultArchetypeSelector.java
(original)
+++ maven/sandbox/trunk/archetypeng/archetypeng-plugin/src/main/java/org/apache/maven/archetype/ui/DefaultArchetypeSelector.java
Fri Sep 28 01:03:53 2007
@@ -42,6 +42,7 @@
 import java.io.IOException;
 import java.util.Collection;
 import java.util.List;
+import java.util.Map;
 import java.util.Properties;
 
 /** @plexus.component */
@@ -64,6 +65,9 @@
     /** @plexus.requirement */
     private ArchetypeSelectionQueryer archetypeSelectionQueryer;
 
+    /** @plexus.requirement role="org.apache.maven.archetype.source.ArchetypeDataSource"
*/
+    private Map archetypeSources;
+
     public ArchetypeDefinition selectArchetype(
         String archetypeGroupId,
         String archetypeArtifactId,
@@ -120,85 +124,45 @@
 
                 try
                 {
-                    ArchetypeDataSource source = new RegistryArchetypeDataSource( archetypeRegistryManager
);
+                    // Now where would this configuration come from
+                    // - We need a list of archetypes that can be added to and changed, we
need to pull
+                    //   these from different sources
+                    //
+                    // - We then need a way to configure the sources
+                    //  - we need to separate the registry from the configuration as we need
to provide one place
+                    //    to
+
 
-                    archetypes = source.getArchetypes().values();
+                    ArchetypeDataSource source = (ArchetypeDataSource) archetypeSources.get(
"registry" );
 
-                    System.out.println( "archetypes = " + archetypes );
+                    archetypes = source.getArchetypes( null );
                 }
                 catch ( ArchetypeDataSourceException e )
                 {
-                    throw new ArchetypeSelectionFailure( "Error loading archetypes from data
source.", e );
+                    throw new ArchetypeSelectionFailure( "Error loading archetypes from data
source(s).", e );
                 }
 
-                if ( archetypes != null )
+                if ( archetypes.size() > 0 )
                 {
                     org.apache.maven.archetype.registry.Archetype archetype = archetypeSelectionQueryer.selectArchetype(
                         archetypes );
 
-                    ArchetypeDefinition ad = new ArchetypeDefinition();
-
-                    ad.setArtifactId( archetype.getArtifactId() );
+                    archetypeDefinition.setArtifactId( archetype.getArtifactId() );
 
-                    ad.setName( archetype.getArtifactId() );
+                    archetypeDefinition.setName( archetype.getArtifactId() );
 
-                    ad.setGroupId( archetype.getGroupId() );
+                    archetypeDefinition.setGroupId( archetype.getGroupId() );
 
-                    ad.setVersion( archetype.getVersion() );
+                    archetypeDefinition.setVersion( archetype.getVersion() );
 
-                    ad.setRepository( archetype.getRepository() );
+                    archetypeDefinition.setRepository( archetype.getRepository() );
 
                     String goals = StringUtils.join( archetype.getGoals().iterator(), ","
);
 
-                    ad.setGoals( goals );
-
-                    archetypePropertiesManager.writeProperties(
-                        toProperties( ad ),
-                        propertyFile
-                    );
-
-                    return ad;
+                    archetypeDefinition.setGoals( goals );
                 }
             }
         }
-        else
-        {
-            if ( !archetypeDefinition.isDefined() )
-            {
-                if ( !archetypeDefinition.isPartiallyDefined() )
-                {
-                    throw new ArchetypeNotDefined( "The archetype is not defined" );
-                }
-                else
-                {
-                    getLogger().debug( "Archetype is partially defined" );
-                    archetypeDefinition.setVersion(
-                        archetypeArtifactManager.getReleaseVersion(
-                            archetypeDefinition.getGroupId(),
-                            archetypeDefinition.getArtifactId(),
-                            localRepository,
-                            repositories
-                        )
-                    );
-                    getLogger().info(
-                        "Using default version " + archetypeDefinition.getVersion()
-                    );
-                }
-            }
-
-            if ( !archetypeDefinition.isDefined() )
-            {
-                throw new ArchetypeSelectionFailure( "The archetype must be selected here"
);
-            }
-            else
-            {
-                getLogger().info(
-                    "Archetype selected (" + archetypeDefinition.getGroupId() + ":"
-                        + archetypeDefinition.getArtifactId() + ":" + archetypeDefinition
-                        .getVersion() + ")"
-                );
-            }
-        } // end if
 
         if ( !archetypeArtifactManager.exists(
             archetypeDefinition.getGroupId(),



Mime
View raw message