You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2010/08/16 19:22:42 UTC

svn commit: r986059 - /maven/archetype/trunk/archetype-plugin/src/main/java/org/apache/maven/archetype/ui/DefaultArchetypeSelector.java

Author: hboutemy
Date: Mon Aug 16 17:22:42 2010
New Revision: 986059

URL: http://svn.apache.org/viewvc?rev=986059&view=rev
Log:
code simplification

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=986059&r1=986058&r2=986059&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 Aug 16 17:22:42 2010
@@ -51,6 +51,7 @@ public class DefaultArchetypeSelector
 
     /** @plexus.requirement */
     private ArchetypeSelectionQueryer archetypeSelectionQueryer;
+
     /** @plexus.requirement */
     private ArchetypeManager archetype;
 
@@ -71,103 +72,100 @@ public class DefaultArchetypeSelector
         {
             getLogger().info( "Archetype defined by properties" );
         }
-        else
+        else if ( definition.isDefined() )
         {
-            if ( definition.isDefined() && StringUtils.isEmpty( request.getArchetypeRepository() ) )
+            boolean found = false;
+            for ( String catalogKey : StringUtils.split ( catalogs, "," ) )
             {
-                boolean found = false;
-                for ( String catalogKey : StringUtils.split ( catalogs, "," ) )
-                {
-                    String[] keySplitted = catalogKey.split( "-", 2 );
+                String[] keySplitted = catalogKey.split( "-", 2 );
 
-                    List<Archetype> catalog = archetypes.get( catalogKey );
+                List<Archetype> catalog = archetypes.get( catalogKey );
 
-                    Archetype example = new Archetype();
-                    example.setGroupId( request.getArchetypeGroupId() );
-                    example.setArtifactId( request.getArchetypeArtifactId() );
+                Archetype example = new Archetype();
+                example.setGroupId( request.getArchetypeGroupId() );
+                example.setArtifactId( request.getArchetypeArtifactId() );
 
-                    if ( catalog.contains( example ) )
-                    {
-                        found = true;
+                if ( catalog.contains( example ) )
+                {
+                    found = true;
 
-                        Archetype foundArchetype = (Archetype) catalog.get( catalog.indexOf( example ) );
-                        definition.setName( foundArchetype.getArtifactId() );
-                        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
-                                              + " found in catalog " + catalogKey );
-                        break;
+                    Archetype foundArchetype = (Archetype) catalog.get( catalog.indexOf( example ) );
+                    definition.setName( foundArchetype.getArtifactId() );
+                    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 );
                     }
-                }
-                if ( !found )
-                {
-                    getLogger().warn( "No archetype repository found. Falling back to central repository (http://repo1.maven.org/maven2). " );
-                    getLogger().warn( "Use -DarchetypeRepository=<your repository> if archetype's repository is elsewhere." );
 
-                    definition.setRepository( "http://repo1.maven.org/maven2" );
+                    getLogger().info( "Archetype repository missing. Using the one from " + foundArchetype
+                                          + " found in catalog " + catalogKey );
+                    break;
                 }
             }
-            if ( !definition.isDefined() && definition.isPartiallyDefined() )
+            if ( !found )
             {
-                boolean found = false;
-                for ( String catalogKey : StringUtils.split( catalogs, "," ) )
-                {
-                    List<Archetype> catalog = archetypes.get( catalogKey );
+                getLogger().warn( "No archetype repository found. Falling back to central repository (http://repo1.maven.org/maven2). " );
+                getLogger().warn( "Use -DarchetypeRepository=<your repository> if archetype's repository is elsewhere." );
 
-                    String[] keySplitted = catalogKey.split( ":", 2 );
+                definition.setRepository( "http://repo1.maven.org/maven2" );
+            }
+        }
+        else if ( definition.isPartiallyDefined() )
+        {
+            boolean found = false;
+            for ( String catalogKey : StringUtils.split( catalogs, "," ) )
+            {
+                List<Archetype> catalog = archetypes.get( catalogKey );
 
-                    Archetype example = new Archetype();
-                    example.setGroupId( request.getArchetypeGroupId() );
-                    example.setArtifactId( request.getArchetypeArtifactId() );
+                String[] keySplitted = catalogKey.split( ":", 2 );
 
-                    if ( catalog.contains ( example ) )
-                    {
-                        found = true;
+                Archetype example = new Archetype();
+                example.setGroupId( request.getArchetypeGroupId() );
+                example.setArtifactId( request.getArchetypeArtifactId() );
 
-                        Archetype foundArchetype = (Archetype) catalog.get( catalog.indexOf( example ) );
-                        definition.setGroupId( foundArchetype.getGroupId() );
-                        definition.setArtifactId( foundArchetype.getArtifactId() );
-                        definition.setVersion( foundArchetype.getVersion() );
-                        definition.setName( foundArchetype.getArtifactId() );
-
-                        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 );
-                        }
+                if ( catalog.contains( example ) )
+                {
+                    found = true;
 
-                        String goals = StringUtils.join( foundArchetype.getGoals().iterator(), "," );
-                        definition.setGoals( goals );
+                    Archetype foundArchetype = catalog.get( catalog.indexOf( example ) );
+                    definition.setGroupId( foundArchetype.getGroupId() );
+                    definition.setArtifactId( foundArchetype.getArtifactId() );
+                    definition.setVersion( foundArchetype.getVersion() );
+                    definition.setName( foundArchetype.getArtifactId() );
 
-                        getLogger().info( "Archetype " + foundArchetype + " found in catalog " + catalogKey );
-                        break;
+                    if ( StringUtils.isNotEmpty( foundArchetype.getRepository() ) )
+                    {
+                        definition.setRepository( foundArchetype.getRepository() );
                     }
-                }
-                if ( !found )
-                {
-                    getLogger().warn( "Specified archetype not found." );
-                    if ( interactiveMode.booleanValue() )
+                    else if ( keySplitted.length > 1 )
                     {
-                        definition.setVersion( null );
-                        definition.setGroupId( null );
-                        definition.setArtifactId( null );
+                        int lastIndex = catalogKey.lastIndexOf( "/" );
+                        String catalogBase =
+                            catalogKey.substring( 0, ( lastIndex > 7 ? lastIndex : catalogKey.length() ) );
+                        definition.setRepository( catalogBase );
                     }
+
+                    String goals = StringUtils.join( foundArchetype.getGoals().iterator(), "," );
+                    definition.setGoals( goals );
+
+                    getLogger().info( "Archetype " + foundArchetype + " found in catalog " + catalogKey );
+                    break;
+                }
+            }
+            if ( !found )
+            {
+                getLogger().warn( "Specified archetype not found." );
+                if ( interactiveMode.booleanValue() )
+                {
+                    definition.setVersion( null );
+                    definition.setGroupId( null );
+                    definition.setArtifactId( null );
                 }
             }
         }