Author: rafale
Date: Wed Jun 11 12:50:00 2008
New Revision: 666805

URL: http://svn.apache.org/viewvc?rev=666805&view=rev
Log:
Fix for archetype-174
The Exception thrown when the archetype is not configured now contains the list 
of the missing properties

Modified:
    
maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/exception/ArchetypeNotConfigured.java
    
maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/generator/DefaultFilesetArchetypeGenerator.java
    
maven/archetype/trunk/archetype-common/src/test/java/org/apache/maven/archetype/generator/DefaultArchetypeGeneratorTest.java
    
maven/archetype/trunk/archetype-plugin/src/main/java/org/apache/maven/archetype/ui/DefaultArchetypeCreationConfigurator.java
    
maven/archetype/trunk/archetype-plugin/src/main/java/org/apache/maven/archetype/ui/DefaultArchetypeGenerationConfigurator.java

Modified: 
maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/exception/ArchetypeNotConfigured.java
URL: 
http://svn.apache.org/viewvc/maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/exception/ArchetypeNotConfigured.java?rev=666805&r1=666804&r2=666805&view=diff
==============================================================================
--- 
maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/exception/ArchetypeNotConfigured.java
 (original)
+++ 
maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/exception/ArchetypeNotConfigured.java
 Wed Jun 11 12:50:00 2008
@@ -19,26 +19,38 @@
 
 package org.apache.maven.archetype.exception;
 
+import java.util.List;
+
 public class ArchetypeNotConfigured
     extends Exception
 {
-    public ArchetypeNotConfigured()
+    private List missingProperties;
+
+    public List getMissingProperties() {
+        return missingProperties;
+    }
+    
+    public ArchetypeNotConfigured( List missingProperties )
     {
+        this.missingProperties = missingProperties;
     }
 
-    public ArchetypeNotConfigured( String msg )
+    public ArchetypeNotConfigured( String msg, List missingProperties )
     {
         super( msg );
+        this.missingProperties = missingProperties;
     }
 
-    public ArchetypeNotConfigured( Throwable cause )
+    public ArchetypeNotConfigured( Throwable cause, List missingProperties )
     {
         super( cause );
+        this.missingProperties = missingProperties;
     }
 
     public ArchetypeNotConfigured( String msg,
-                                   Throwable cause )
+                                   Throwable cause, List missingProperties )
     {
         super( msg, cause );
+        this.missingProperties = missingProperties;
     }
 }

Modified: 
maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/generator/DefaultFilesetArchetypeGenerator.java
URL: 
http://svn.apache.org/viewvc/maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/generator/DefaultFilesetArchetypeGenerator.java?rev=666805&r1=666804&r2=666805&view=diff
==============================================================================
--- 
maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/generator/DefaultFilesetArchetypeGenerator.java
 (original)
+++ 
maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/generator/DefaultFilesetArchetypeGenerator.java
 Wed Jun 11 12:50:00 2008
@@ -51,6 +51,7 @@
 import java.io.InputStream;
 import java.io.OutputStreamWriter;
 import java.io.Writer;
+import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 import java.util.zip.ZipEntry;
@@ -97,11 +98,36 @@
             {
                 if ( request.isInteractiveMode () )
                 {
-                    throw new ArchetypeNotConfigured ( "No archetype was 
chosen" );
+                    throw new ArchetypeNotConfigured ( "No archetype was 
chosen", null );
                 }
                 else
                 {
-                    throw new ArchetypeNotConfigured ( "The archetype is not 
configured" );
+                    StringBuffer exceptionMessage = new StringBuffer();
+                    exceptionMessage.append("Archetype " );
+                    exceptionMessage.append( request.getArchetypeGroupId() );
+                    exceptionMessage.append( ":" );
+                    exceptionMessage.append( request.getArchetypeArtifactId() 
);
+                    exceptionMessage.append( ":" );
+                    exceptionMessage.append( request.getArchetypeVersion() );
+                    exceptionMessage.append( " is not configured" );
+                    
+                    List missingProperties = new ArrayList( 0 );
+                    java.util.Iterator requiredProperties = 
+                            
archetypeDescriptor.getRequiredProperties().iterator();
+                    while( requiredProperties.hasNext() )
+                    {
+                        RequiredProperty requiredProperty = (RequiredProperty) 
requiredProperties.next ();
+                        if (org.codehaus.plexus.util.StringUtils.isEmpty(
+                            request.getProperties().getProperty ( 
requiredProperty.getKey() ) ) )
+                        {
+                            exceptionMessage.append( "\n\tProperty " );
+                            exceptionMessage.append( requiredProperty.getKey() 
);
+                            missingProperties.add( requiredProperty.getKey() );
+                            exceptionMessage.append( " is missing." );
+                        }
+                    }
+                    
+                    throw new ArchetypeNotConfigured( 
exceptionMessage.toString(), missingProperties );
                 }
             }
 
@@ -217,7 +243,7 @@
                         context
                     );
                 }
-            } // end if
+            }
         }
         catch ( FileNotFoundException ex )
         {
@@ -821,7 +847,7 @@
                 );
                 getLogger().debug( "Copied " + fileSetResources.size() + " 
files" );
             }
-        } // end while
+        }
     }
 
     private void restoreParentArtifactId( Context context,

Modified: 
maven/archetype/trunk/archetype-common/src/test/java/org/apache/maven/archetype/generator/DefaultArchetypeGeneratorTest.java
URL: 
http://svn.apache.org/viewvc/maven/archetype/trunk/archetype-common/src/test/java/org/apache/maven/archetype/generator/DefaultArchetypeGeneratorTest.java?rev=666805&r1=666804&r2=666805&view=diff
==============================================================================
--- 
maven/archetype/trunk/archetype-common/src/test/java/org/apache/maven/archetype/generator/DefaultArchetypeGeneratorTest.java
 (original)
+++ 
maven/archetype/trunk/archetype-common/src/test/java/org/apache/maven/archetype/generator/DefaultArchetypeGeneratorTest.java
 Wed Jun 11 12:50:00 2008
@@ -823,10 +823,12 @@
         }
         else
         {
-            assertEquals(
+            assertTrue(
                 "Exception not correct",
-                "The archetype is not configured",
-                result.getCause().getMessage()
+                result.getCause().getMessage().startsWith( 
+                    "Archetype archetypes:basic:1.0 is not configured" ) &&
+                result.getCause().getMessage().endsWith( 
+                    "Property property-without-default-4 is missing." )
             );
         }
     }

Modified: 
maven/archetype/trunk/archetype-plugin/src/main/java/org/apache/maven/archetype/ui/DefaultArchetypeCreationConfigurator.java
URL: 
http://svn.apache.org/viewvc/maven/archetype/trunk/archetype-plugin/src/main/java/org/apache/maven/archetype/ui/DefaultArchetypeCreationConfigurator.java?rev=666805&r1=666804&r2=666805&view=diff
==============================================================================
--- 
maven/archetype/trunk/archetype-plugin/src/main/java/org/apache/maven/archetype/ui/DefaultArchetypeCreationConfigurator.java
 (original)
+++ 
maven/archetype/trunk/archetype-plugin/src/main/java/org/apache/maven/archetype/ui/DefaultArchetypeCreationConfigurator.java
 Wed Jun 11 12:50:00 2008
@@ -236,7 +236,7 @@
             }
             else if ( !archetypeConfiguration.isConfigured() )
             {
-                throw new ArchetypeNotConfigured( "The archetype is not 
configured" );
+                throw new ArchetypeNotConfigured( "The archetype is not 
configured", null );
             }
         } // end if
 

Modified: 
maven/archetype/trunk/archetype-plugin/src/main/java/org/apache/maven/archetype/ui/DefaultArchetypeGenerationConfigurator.java
URL: 
http://svn.apache.org/viewvc/maven/archetype/trunk/archetype-plugin/src/main/java/org/apache/maven/archetype/ui/DefaultArchetypeGenerationConfigurator.java?rev=666805&r1=666804&r2=666805&view=diff
==============================================================================
--- 
maven/archetype/trunk/archetype-plugin/src/main/java/org/apache/maven/archetype/ui/DefaultArchetypeGenerationConfigurator.java
 (original)
+++ 
maven/archetype/trunk/archetype-plugin/src/main/java/org/apache/maven/archetype/ui/DefaultArchetypeGenerationConfigurator.java
 Wed Jun 11 12:50:00 2008
@@ -237,40 +237,35 @@
                 // in batch mode, we assume the defaults, and if still not 
configured fail
                 if( !archetypeConfiguration.isConfigured() )
                 {
-//                    StringBuffer missingProperties = new StringBuffer();
-//                    requiredProperties = 
archetypeConfiguration.getRequiredProperties().iterator();
-//                    while( requiredProperties.hasNext() )
-//                    {
-//                        String requiredProperty = 
(String)requiredProperties.next();
-//                        if (!archetypeConfiguration.isConfigured( 
requiredProperty ))
-//                        {
-//                            missingProperties.append("\nProperty ");
-//                            missingProperties.append(requiredProperty);
-//                            missingProperties.append(" is missing. Add -D");
-//                            missingProperties.append(requiredProperty);
-//                            missingProperties.append("=someValue");
-//                        }
-//                    }
-//                    
-//                    throw new ArchetypeNotConfigured( "Archetype " + 
request.getArchetypeGroupId() + ":"
-//                        + request.getArchetypeArtifactId() + ":" + 
request.getArchetypeVersion()
-//                        + " is not configured"+missingProperties.toString() 
);
+                    StringBuffer exceptionMessage = new StringBuffer();
+                    exceptionMessage.append("Archetype " );
+                    exceptionMessage.append( request.getArchetypeGroupId() );
+                    exceptionMessage.append( ":" );
+                    exceptionMessage.append( request.getArchetypeArtifactId() 
);
+                    exceptionMessage.append( ":" );
+                    exceptionMessage.append( request.getArchetypeVersion() );
+                    exceptionMessage.append( " is not configured" );
+                    
+                    List missingProperties = new ArrayList( 0 );
                     requiredProperties = 
archetypeConfiguration.getRequiredProperties().iterator();
                     while( requiredProperties.hasNext() )
                     {
                         String requiredProperty = 
(String)requiredProperties.next();
                         if (!archetypeConfiguration.isConfigured( 
requiredProperty ))
                         {
-                            getLogger().warn("Property "+requiredProperty+" is 
missing. Add -D"+requiredProperty+"=someValue");
+                            exceptionMessage.append( "\n\tProperty " );
+                            exceptionMessage.append( requiredProperty );
+                            missingProperties.add( requiredProperty );
+                            exceptionMessage.append( " is missing." );
+                            getLogger().warn( "Property " + requiredProperty + 
+                                " is missing. Add -D" + requiredProperty + 
"=someValue" );
                         }
                     }
                     
-                    throw new ArchetypeNotConfigured( "Archetype " + 
request.getArchetypeGroupId() + ":"
-                        + request.getArchetypeArtifactId() + ":" + 
request.getArchetypeVersion()
-                        + " is not configured" );
+                    throw new ArchetypeNotConfigured( 
exceptionMessage.toString(), missingProperties );
                 }
             }
-        } // end if-else
+        }
 
         request.setGroupId( archetypeConfiguration.getProperty( 
Constants.GROUP_ID ) );
 


Reply via email to