Author: rafale
Date: Thu Jun 12 14:09:23 2008
New Revision: 667228

URL: http://svn.apache.org/viewvc?rev=667228&view=rev
Log:
Fix for archetype-161
When a url is given to search for a remote catalog, first it is searched by 
appending archetype-catalog.xml to the URL. if no catalog is found there, then 
the URL is assumed to be the url of the file.

Modified:
    
maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/source/RemoteCatalogArchetypeDataSource.java

Modified: 
maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/source/RemoteCatalogArchetypeDataSource.java
URL: 
http://svn.apache.org/viewvc/maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/source/RemoteCatalogArchetypeDataSource.java?rev=667228&r1=667227&r2=667228&view=diff
==============================================================================
--- 
maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/source/RemoteCatalogArchetypeDataSource.java
 (original)
+++ 
maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/source/RemoteCatalogArchetypeDataSource.java
 Thu Jun 12 14:09:23 2008
@@ -59,26 +59,42 @@
                 repository = repository.substring( 0, repository.length(  ) - 
1 );
             }
 
+            getLogger().debug("Searching for remote catalog: "+ repository 
+"/archetype-catalog.xml");
             // We use wagon to take advantage of a Proxy that has already been 
setup in a Maven environment.
-
             Repository wagonRepository = new Repository( "archetype", 
repository );
-
             Wagon wagon = wagonManager.getWagon( wagonRepository );
-
             File catalog = File.createTempFile( "archetype-catalog", ".xml" );
-
             wagon.connect( wagonRepository );
-
             wagon.get( "archetype-catalog.xml", catalog );
-
             wagon.disconnect();
-
             return readCatalog( new FileReader( catalog ) );
         }
-        catch ( Exception e )
+        catch ( ArchetypeDataSourceException e )
         {
-            getLogger().warn( "Error reading archetype catalog "+ repository, 
e );
-            return new ArchetypeCatalog();
+            throw e;
+        }
+        catch ( Exception e )
+        {// When the default archetype catalog names doesn't works, we assume 
the repository is the URL to a file 
+            try
+            {
+                String repositoryPath = repository.substring(0, 
repository.lastIndexOf("/"));
+                String fileName = 
repository.substring(repository.lastIndexOf("/") + 1);
+                
+                getLogger().debug("Searching for remote catalog: "+ 
repositoryPath +"/"+fileName);
+                // We use wagon to take advantage of a Proxy that has already 
been setup in a Maven environment.
+                Repository wagonRepository = new Repository( "archetype", 
repositoryPath );
+                Wagon wagon = wagonManager.getWagon( wagonRepository );
+                File catalog = File.createTempFile( "archetype-catalog", 
".xml" );
+                wagon.connect( wagonRepository );
+                wagon.get( fileName , catalog );
+                wagon.disconnect();
+                return readCatalog( new FileReader( catalog ) );
+            }
+            catch ( Exception ex )
+            {
+                getLogger().warn( "Error reading archetype catalog "+ 
repository, ex );
+                return new ArchetypeCatalog();
+            }
         }
     }
 


Reply via email to