Author: hboutemy
Date: Fri Aug 19 23:24:13 2011
New Revision: 1159816

URL: http://svn.apache.org/viewvc?rev=1159816&view=rev
Log:
[ARCHETYPE-332] added a warning message if required property name contains a dot

Modified:
    
maven/archetype/trunk/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/JarMojo.java

Modified: 
maven/archetype/trunk/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/JarMojo.java
URL: 
http://svn.apache.org/viewvc/maven/archetype/trunk/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/JarMojo.java?rev=1159816&r1=1159815&r2=1159816&view=diff
==============================================================================
--- 
maven/archetype/trunk/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/JarMojo.java
 (original)
+++ 
maven/archetype/trunk/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/JarMojo.java
 Fri Aug 19 23:24:13 2011
@@ -20,6 +20,10 @@ package org.apache.maven.archetype.mojos
  */
 
 import org.apache.maven.archetype.ArchetypeManager;
+import org.apache.maven.archetype.common.ArchetypeArtifactManager;
+import org.apache.maven.archetype.exception.UnknownArchetype;
+import org.apache.maven.archetype.metadata.ArchetypeDescriptor;
+import org.apache.maven.archetype.metadata.RequiredProperty;
 import org.apache.maven.artifact.DependencyResolutionRequiredException;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
@@ -74,19 +78,30 @@ public class JarMojo
     private MavenProject project;
 
     /**
-     * The archetype component.
+     * The archetype manager component.
      *
      * @component
      */
     private ArchetypeManager manager;
 
+    /**
+     * The archetype artifact manager component.
+     *
+     * @component
+     */
+    private ArchetypeArtifactManager archetypeArtifactManager;
+
     public void execute()
         throws MojoExecutionException, MojoFailureException
     {
         try
         {
+            getLog().info( "Building archetype jar: " + new File( 
outputDirectory, finalName ) );
+
             File jarFile = manager.archiveArchetype( archetypeDirectory, 
outputDirectory, finalName );
 
+            checkArchetypeFile( jarFile );
+
             project.getArtifact().setFile( jarFile );
         }
         catch ( DependencyResolutionRequiredException ex )
@@ -98,4 +113,43 @@ public class JarMojo
             throw new MojoExecutionException( ex.getMessage(), ex );
         }
     }
+
+    private void checkArchetypeFile( File jarFile )
+        throws MojoExecutionException
+    {
+        try
+        {
+            if ( archetypeArtifactManager.isFileSetArchetype( jarFile ) )
+            {
+                checkFileSetArchetypeFile( jarFile );
+            }
+            else if ( !archetypeArtifactManager.isOldArchetype( jarFile ) )
+            {
+                getLog().warn( "Building an Old (1.x) Archetype: consider 
migrating it to current 2.x Archetype." );
+            }
+            else
+            {
+                throw new MojoExecutionException( "The current project does 
not built an archetype" );
+            }
+        }
+        catch ( UnknownArchetype ua )
+        {
+            throw new MojoExecutionException( ua.getMessage(), ua );
+        }
+    }
+
+    private void checkFileSetArchetypeFile( File jarFile )
+        throws UnknownArchetype
+    {
+        ArchetypeDescriptor archetypeDescriptor = 
archetypeArtifactManager.getFileSetArchetypeDescriptor( jarFile );
+
+        for ( RequiredProperty rp : 
archetypeDescriptor.getRequiredProperties() )
+        {
+            if ( rp.getKey().contains( "." ) )
+            {
+                getLog().warn( "Invalid required property name '" + rp.getKey()
+                                   + "': dot character makes is unusable in 
Velocity template" );
+            }
+        }
+    }
 }
\ No newline at end of file


Reply via email to