Author: rafale
Date: Mon Jun 23 11:30:18 2008
New Revision: 670702

URL: http://svn.apache.org/viewvc?rev=670702&view=rev
Log:
When the archetypeCatalog property is defined with catalogURL starting with 
file:// of http://, the archetype repository for an archetype selected in such 
a catalog is the one defined in the archetype or the archetype's location.
It is first the one defined in the catalog or central for the other options.

Modified:
    
maven/archetype/trunk/archetype-plugin/src/main/java/org/apache/maven/archetype/ui/DefaultArchetypeSelector.java

Modified: 
maven/archetype/trunk/archetype-plugin/src/main/java/org/apache/maven/archetype/ui/DefaultArchetypeSelector.java
URL: 
http://svn.apache.org/viewvc/maven/archetype/trunk/archetype-plugin/src/main/java/org/apache/maven/archetype/ui/DefaultArchetypeSelector.java?rev=670702&r1=670701&r2=670702&view=diff
==============================================================================
--- 
maven/archetype/trunk/archetype-plugin/src/main/java/org/apache/maven/archetype/ui/DefaultArchetypeSelector.java
 (original)
+++ 
maven/archetype/trunk/archetype-plugin/src/main/java/org/apache/maven/archetype/ui/DefaultArchetypeSelector.java
 Mon Jun 23 11:30:18 2008
@@ -90,6 +90,7 @@
                 while ( !found && ca.hasNext () )
                 {
                     String catalogKey = (String) ca.next ();
+                    String[] keySplitted = catalogKey.split("-", 2);
                     List catalog = (List) archetypes.get ( catalogKey );
                     Archetype example = new Archetype ();
                     example.setGroupId ( request.getArchetypeGroupId () );
@@ -101,7 +102,17 @@
                         Archetype foundArchetype =
                             (Archetype) catalog.get ( catalog.indexOf ( 
example ) );
                         definition.setName ( foundArchetype.getArtifactId () );
-                        definition.setRepository ( 
foundArchetype.getRepository () );
+                        if ( StringUtils.isNotEmpty( 
foundArchetype.getRepository () ) )
+                        {
+                            definition.setRepository ( 
foundArchetype.getRepository () );
+                        }
+                        else if ( keySplitted.length > 1 )
+                        {
+                            int lastIndex = catalogKey.lastIndexOf("/");
+                            String catalogBase = catalogKey.substring(0, 
+                                    (lastIndex > 7 ? lastIndex : 
catalogKey.length()));
+                            definition.setRepository ( catalogBase );
+                        }
 
                         getLogger ().info (
                             "Archetype repository missing. Using the one from 
" + foundArchetype
@@ -125,6 +136,7 @@
                 {
                     String catalogKey = (String) ca.next ();
                     List catalog = (List) archetypes.get ( catalogKey );
+                    String[] keySplitted = catalogKey.split(":", 2);
                     Archetype example = new Archetype ();
                     example.setGroupId ( request.getArchetypeGroupId () );
                     example.setArtifactId ( request.getArchetypeArtifactId () 
);
@@ -138,7 +150,17 @@
                         definition.setArtifactId ( 
foundArchetype.getArtifactId () );
                         definition.setVersion ( foundArchetype.getVersion () );
                         definition.setName ( foundArchetype.getArtifactId () );
-                        definition.setRepository ( 
foundArchetype.getRepository () );
+                        if ( StringUtils.isNotEmpty( 
foundArchetype.getRepository () ) )
+                        {
+                            definition.setRepository ( 
foundArchetype.getRepository () );
+                        }
+                        else if ( keySplitted.length > 1 )
+                        {
+                            int lastIndex = catalogKey.lastIndexOf("/");
+                            String catalogBase = catalogKey.substring(0, 
+                                    (lastIndex > 7 ? lastIndex : 
catalogKey.length()));
+                            definition.setRepository ( catalogBase );
+                        }
 
                         String goals =
                             StringUtils.join ( foundArchetype.getGoals 
().iterator (), "," );
@@ -194,7 +216,19 @@
                     definition.setArtifactId( 
selectedArchetype.getArtifactId() );
                     definition.setVersion( selectedArchetype.getVersion() );
                     definition.setName( selectedArchetype.getArtifactId() );
-                    definition.setRepository( 
selectedArchetype.getRepository() );
+                    String catalogKey = getCatalogKey ( archetypes, 
selectedArchetype );
+                    String[] keySplitted = catalogKey.split(":", 2);
+                    if ( StringUtils.isNotEmpty( 
selectedArchetype.getRepository () ) )
+                    {
+                        definition.setRepository ( 
selectedArchetype.getRepository () );
+                    }
+                    else if ( keySplitted.length > 1 )
+                    {
+                        int lastIndex = catalogKey.lastIndexOf("/");
+                        String catalogBase = catalogKey.substring(0, 
+                                (lastIndex > 7 ? lastIndex : 
catalogKey.length()));
+                        definition.setRepository ( catalogBase );
+                    }
                     String goals = StringUtils.join( 
selectedArchetype.getGoals().iterator(), "," );
                     definition.setGoals( goals );
                 }
@@ -244,9 +278,9 @@
                 archetypes.put("remote", 
archetype.getRemoteCatalog().getArchetypes());
             } else if (catalog.startsWith("file://")) {
                 String path = catalog.substring(7);
-                archetypes.put("local", 
archetype.getLocalCatalog(path).getArchetypes());
+                archetypes.put(catalog, 
archetype.getLocalCatalog(path).getArchetypes());
             } else if (catalog.startsWith("http://";)) {
-                archetypes.put("remote", 
archetype.getRemoteCatalog(catalog).getArchetypes());
+                archetypes.put(catalog, 
archetype.getRemoteCatalog(catalog).getArchetypes());
             }
         }
 
@@ -282,4 +316,20 @@
     {
         this.archetypeSelectionQueryer = archetypeSelectionQueryer;
     }
+
+    private String getCatalogKey(Map archetypes, Archetype selectedArchetype) {
+        String key = "";
+        Iterator keys = archetypes.keySet().iterator();
+        boolean found = false;
+        while ( keys.hasNext() && !found)
+        {
+            key = (String) keys.next();
+            List catalog = (List) archetypes.get( key );
+            if ( catalog.contains( selectedArchetype ) )
+            {
+                found = true;
+            }
+        }
+        return key;
+    }
 }


Reply via email to