You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ra...@apache.org on 2008/03/10 22:55:24 UTC

svn commit: r635711 - in /maven/archetype/trunk: archetype-common/src/main/java/org/apache/maven/archetype/common/ archetype-common/src/main/java/org/apache/maven/archetype/creator/ archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/ arche...

Author: rafale
Date: Mon Mar 10 14:55:19 2008
New Revision: 635711

URL: http://svn.apache.org/viewvc?rev=635711&view=rev
Log:
FilteredExtensions and languages can now be defined in the property file
defnied by -Darchetype.properties.
This nearly fix the ARCHETYPE-112 issue

Modified:
    maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/common/Constants.java
    maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeRegistryManager.java
    maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/creator/FilesetArchetypeCreator.java
    maven/archetype/trunk/archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/CreateArchetypeFromProjectMojo.java
    maven/archetype/trunk/archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/CreateProjectFromArchetypeMojo.java
    maven/archetype/trunk/archetype-plugin/src/main/java/org/apache/maven/archetype/ui/ArchetypeCreationConfigurator.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/DefaultArchetypeFactory.java

Modified: maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/common/Constants.java
URL: http://svn.apache.org/viewvc/maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/common/Constants.java?rev=635711&r1=635710&r2=635711&view=diff
==============================================================================
--- maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/common/Constants.java (original)
+++ maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/common/Constants.java Mon Mar 10 14:55:19 2008
@@ -44,6 +44,10 @@
 
     String ARTIFACT_ID = "artifactId";
 
+    String ARCHETYPE_FILTERED_EXTENSIONS = "archetype.filteredExtensions";
+    
+    String ARCHETYPE_LANGUAGES = "archetype.languages";
+
     List DEFAULT_FILTERED_EXTENSIONS =
         Arrays.asList(
             new String[]

Modified: maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeRegistryManager.java
URL: http://svn.apache.org/viewvc/maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeRegistryManager.java?rev=635711&r1=635710&r2=635711&view=diff
==============================================================================
--- maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeRegistryManager.java (original)
+++ maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeRegistryManager.java Mon Mar 10 14:55:19 2008
@@ -45,7 +45,7 @@
     extends AbstractLogEnabled
     implements ArchetypeRegistryManager
 {
-    private static File DEFAULT_REGISTRY = new File( System.getProperty( "user.home" ), ".m2/archetype.xml" );
+//    private static File DEFAULT_REGISTRY = new File( System.getProperty( "user.home" ), ".m2/archetype.xml" );
 
     /**
      * Used to create ArtifactRepository objects given the urls of the remote repositories.

Modified: maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/creator/FilesetArchetypeCreator.java
URL: http://svn.apache.org/viewvc/maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/creator/FilesetArchetypeCreator.java?rev=635711&r1=635710&r2=635711&view=diff
==============================================================================
--- maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/creator/FilesetArchetypeCreator.java (original)
+++ maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/creator/FilesetArchetypeCreator.java Mon Mar 10 14:55:19 2008
@@ -84,8 +84,8 @@
     /** @plexus.requirement */
     private PomManager pomManager;
 
-    /** @plexus.requirement */
-    private ArchetypeRegistryManager archetypeRegistryManager;
+//    /** @plexus.requirement */
+//    private ArchetypeRegistryManager archetypeRegistryManager;
 
     /** @plexus.requirement */
     private MavenProjectBuilder projectBuilder;
@@ -95,7 +95,7 @@
     {
         MavenProject project = request.getProject();
 
-        File propertyFile = request.getPropertyFile();
+//        File propertyFile = request.getPropertyFile();
 
         List languages = request.getLanguages();
 

Modified: maven/archetype/trunk/archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/CreateArchetypeFromProjectMojo.java
URL: http://svn.apache.org/viewvc/maven/archetype/trunk/archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/CreateArchetypeFromProjectMojo.java?rev=635711&r1=635710&r2=635711&view=diff
==============================================================================
--- maven/archetype/trunk/archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/CreateArchetypeFromProjectMojo.java (original)
+++ maven/archetype/trunk/archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/CreateArchetypeFromProjectMojo.java Mon Mar 10 14:55:19 2008
@@ -19,6 +19,8 @@
 
 package org.apache.maven.archetype.mojos;
 
+import java.io.FileNotFoundException;
+import java.io.IOException;
 import org.apache.maven.archetype.ArchetypeCreationRequest;
 import org.apache.maven.archetype.ArchetypeCreationResult;
 import org.apache.maven.archetype.Archetype;
@@ -31,7 +33,14 @@
 import org.apache.maven.project.MavenProject;
 
 import java.io.File;
+import java.io.FileReader;
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
+import java.util.Properties;
+import org.apache.maven.archetype.common.Constants;
+import org.apache.maven.execution.MavenSession;
+import org.codehaus.plexus.util.StringUtils;
 
 /**
  * Creates sample archetype from current project.
@@ -140,11 +149,18 @@
     /** @parameter expression="${packageName}" */
     private String packageName;//Find a better way to resolve the package!!! enforce usage of the configurator
 
+    /** 
+     *  @parameter expression="${session}" 
+     *  @readonly
+     */
+    private MavenSession session;
+
     public void execute()
         throws
         MojoExecutionException,
         MojoFailureException
     {
+        Properties executionProperties = session.getExecutionProperties();
         try
         {
             if ( propertyFile != null )
@@ -152,20 +168,20 @@
                 propertyFile.getParentFile().mkdirs();
             }
 
-            List languages = archetypeRegistryManager.getLanguages( archetypeLanguages, archetypeRegistryFile );
+            List languages = getLanguages( archetypeLanguages, propertyFile );
 
-            configurator.configureArchetypeCreation(
+            Properties properties = configurator.configureArchetypeCreation(
                 project,
                 new Boolean( interactive ),
-                System.getProperties(),
+                executionProperties,
                 propertyFile,
                 languages
             );
 
             List filtereds =
-                archetypeRegistryManager.getFilteredExtensions(
+                getFilteredExtensions(
                     archetypeFilteredExtentions,
-                    archetypeRegistryFile
+                    propertyFile
                 );
 
             ArchetypeCreationRequest request = new ArchetypeCreationRequest()
@@ -192,7 +208,7 @@
                 throw new MojoExecutionException( result.getCause().getMessage(), result.getCause() );
             }
 
-            getLog().info( "OldArchetype created in target/generated-sources/archetype" );
+            getLog().info( "Archetype created in target/generated-sources/archetype" );
 
             if ( testMode )
             {
@@ -212,5 +228,90 @@
         {
             throw new MojoExecutionException( ex.getMessage(), ex );
         }
+    }
+
+    private List getFilteredExtensions( String archetypeFilteredExtentions, File propertyFile )
+    {
+        List filteredExtensions = new ArrayList();
+
+        if( StringUtils.isNotEmpty( archetypeFilteredExtentions ) )
+        {
+            filteredExtensions.addAll(
+                Arrays.asList( StringUtils.split( archetypeFilteredExtentions, "," ) )
+            );
+            getLog().debug("Found in command line extensions = " + filteredExtensions);
+        }
+
+        if( filteredExtensions.isEmpty() && propertyFile.exists() )
+        {
+            try
+            {
+                Properties properties = new Properties();
+                properties.load( new FileReader( propertyFile ) );
+
+                String extensions =
+                    properties.getProperty( Constants.ARCHETYPE_FILTERED_EXTENSIONS );
+                if( StringUtils.isNotEmpty( extensions ) )
+                {
+                    filteredExtensions.addAll(
+                        Arrays.asList( StringUtils.split( extensions, "," ) )
+                    );
+                }
+            getLog().debug("Found in propertyFile " +  propertyFile.getName() + " extensions = " + filteredExtensions);
+            }
+            catch( IOException e )
+            {
+                getLog().warn( "Can not read " + propertyFile.getName() );
+            }
+        }
+
+        if( filteredExtensions.isEmpty() )
+        {
+            filteredExtensions.addAll( Constants.DEFAULT_FILTERED_EXTENSIONS );
+            getLog().debug("Using default extensions = " + filteredExtensions);
+        }
+
+        return filteredExtensions;
+    }
+
+    private List getLanguages(String archetypeLanguages, File propertyFile) {
+        List resultingLanguages = new ArrayList();
+
+        if ( StringUtils.isNotEmpty( archetypeLanguages ) )
+        {
+            resultingLanguages.addAll( Arrays.asList( StringUtils.split( archetypeLanguages, "," ) ) );
+            getLog().debug("Found in command line languages = " + resultingLanguages);
+        }
+
+        if( resultingLanguages.isEmpty() && propertyFile.exists() )
+        {
+            try
+            {
+                Properties properties = new Properties();
+                properties.load( new FileReader( propertyFile ) );
+
+                String languages =
+                    properties.getProperty( Constants.ARCHETYPE_LANGUAGES );
+                if( StringUtils.isNotEmpty( languages ) )
+                {
+                    resultingLanguages.addAll(
+                        Arrays.asList( StringUtils.split( languages, "," ) )
+                    );
+                }
+            getLog().debug("Found in propertyFile " +  propertyFile.getName() + " languages = " + resultingLanguages);
+            }
+            catch( IOException e )
+            {
+                getLog().warn( "Can not read " + propertyFile.getName() );
+            }
+        }
+
+        if ( resultingLanguages.isEmpty() )
+        {
+            resultingLanguages.addAll( Constants.DEFAULT_LANGUAGES );
+            getLog().debug("Using default languages = " + resultingLanguages);
+        }
+
+        return resultingLanguages;
     }
 }

Modified: maven/archetype/trunk/archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/CreateProjectFromArchetypeMojo.java
URL: http://svn.apache.org/viewvc/maven/archetype/trunk/archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/CreateProjectFromArchetypeMojo.java?rev=635711&r1=635710&r2=635711&view=diff
==============================================================================
--- maven/archetype/trunk/archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/CreateProjectFromArchetypeMojo.java (original)
+++ maven/archetype/trunk/archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/CreateProjectFromArchetypeMojo.java Mon Mar 10 14:55:19 2008
@@ -22,7 +22,6 @@
 import org.apache.maven.archetype.Archetype;
 import org.apache.maven.archetype.ArchetypeGenerationRequest;
 import org.apache.maven.archetype.ArchetypeGenerationResult;
-import org.apache.maven.archetype.common.ArchetypeRegistryManager;
 import org.apache.maven.archetype.generator.ArchetypeGenerator;
 import org.apache.maven.archetype.ui.ArchetypeGenerationConfigurator;
 import org.apache.maven.archetype.ui.ArchetypeSelector;
@@ -61,9 +60,6 @@
     private ArchetypeSelector selector;
 
     /** @component */
-    ArchetypeRegistryManager archetypeRegistryManager;
-
-    /** @component */
     ArchetypeGenerationConfigurator configurator;
 
     /** @component */
@@ -148,8 +144,7 @@
 
     public void execute()
         throws MojoExecutionException, MojoFailureException
-    {
-        
+    {        
         Properties executionProperties = session.getExecutionProperties();
         
         ArchetypeGenerationRequest request = new ArchetypeGenerationRequest()

Modified: maven/archetype/trunk/archetype-plugin/src/main/java/org/apache/maven/archetype/ui/ArchetypeCreationConfigurator.java
URL: http://svn.apache.org/viewvc/maven/archetype/trunk/archetype-plugin/src/main/java/org/apache/maven/archetype/ui/ArchetypeCreationConfigurator.java?rev=635711&r1=635710&r2=635711&view=diff
==============================================================================
--- maven/archetype/trunk/archetype-plugin/src/main/java/org/apache/maven/archetype/ui/ArchetypeCreationConfigurator.java (original)
+++ maven/archetype/trunk/archetype-plugin/src/main/java/org/apache/maven/archetype/ui/ArchetypeCreationConfigurator.java Mon Mar 10 14:55:19 2008
@@ -35,7 +35,7 @@
 {
     String ROLE = ArchetypeCreationConfigurator.class.getName();
 
-    void configureArchetypeCreation(
+    Properties configureArchetypeCreation(
         MavenProject project,
         Boolean interactiveMode,
         Properties commandLineProperties,

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=635711&r1=635710&r2=635711&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 Mon Mar 10 14:55:19 2008
@@ -58,7 +58,7 @@
     /** @plexus.requirement */
     private ArchetypeFilesResolver archetypeFilesResolver;
 
-    public void configureArchetypeCreation(
+    public Properties configureArchetypeCreation(
         MavenProject project,
         Boolean interactiveMode,
         Properties commandLineProperties,
@@ -113,7 +113,7 @@
             {
                 if ( !archetypeDefinition.isDefined() )//<editor-fold text="...">
                 {
-                    getLogger().debug( "OldArchetype is not defined" );
+                    getLogger().debug( "Archetype is yet not defined" );
                     if ( !archetypeDefinition.isGroupDefined() )
                     {
                         getLogger().debug( "Asking for archetype's groupId" );
@@ -146,7 +146,7 @@
 
                 if ( !archetypeConfiguration.isConfigured() )//<editor-fold text="...">
                 {
-                    getLogger().debug( "OldArchetype is not configured" );
+                    getLogger().debug( "Archetype is not yet configured" );
                     if ( !archetypeConfiguration.isConfigured( Constants.GROUP_ID ) )
                     {
                         getLogger().debug( "Asking for project's groupId" );
@@ -240,10 +240,7 @@
             }
         } // end if
 
-        writeProperties(
-            archetypeConfiguration.toProperties(),
-            propertyFile
-        );
+        return archetypeConfiguration.toProperties();
     }
 
     private ArchetypeDefinition defineDefaultArchetype(
@@ -402,17 +399,17 @@
             getLogger().debug( "archetype.properties does not exist" );
         }
 
-        Iterator commandLinePropertiesIterator =
-            new ArrayList( commandLineProperties.keySet() ).iterator();
-        while ( commandLinePropertiesIterator.hasNext() )
-        {
-            String propertyKey = (String) commandLinePropertiesIterator.next();
-
-            properties.setProperty(
-                propertyKey,
-                commandLineProperties.getProperty( propertyKey )
-            );
-        }
+//        Iterator commandLinePropertiesIterator =
+//            new ArrayList( commandLineProperties.keySet() ).iterator();
+//        while ( commandLinePropertiesIterator.hasNext() )
+//        {
+//            String propertyKey = (String) commandLinePropertiesIterator.next();
+//
+//            properties.setProperty(
+//                propertyKey,
+//                commandLineProperties.getProperty( propertyKey )
+//            );
+//        }
 
         return properties;
     }

Modified: maven/archetype/trunk/archetype-plugin/src/main/java/org/apache/maven/archetype/ui/DefaultArchetypeFactory.java
URL: http://svn.apache.org/viewvc/maven/archetype/trunk/archetype-plugin/src/main/java/org/apache/maven/archetype/ui/DefaultArchetypeFactory.java?rev=635711&r1=635710&r2=635711&view=diff
==============================================================================
--- maven/archetype/trunk/archetype-plugin/src/main/java/org/apache/maven/archetype/ui/DefaultArchetypeFactory.java (original)
+++ maven/archetype/trunk/archetype-plugin/src/main/java/org/apache/maven/archetype/ui/DefaultArchetypeFactory.java Mon Mar 10 14:55:19 2008
@@ -27,6 +27,7 @@
 
 import java.util.Iterator;
 import java.util.Properties;
+import org.codehaus.plexus.util.StringUtils;
 
 /** @plexus.component */
 public class DefaultArchetypeFactory
@@ -309,6 +310,30 @@
         configuration.setGroupId( archetypeDefinition.getGroupId() );
         configuration.setArtifactId( archetypeDefinition.getArtifactId() );
         configuration.setVersion( archetypeDefinition.getVersion() );
+        
+        
+        
+        Iterator requiredProperties = properties.keySet().iterator();
+
+        while( requiredProperties.hasNext() )
+        {
+            String requiredProperty = (String) requiredProperties.next();
+
+            if( requiredProperty.indexOf( "." ) < 0 )
+            {
+                configuration.addRequiredProperty( requiredProperty );
+                getLogger().debug( "Adding requiredProperty " + requiredProperty );
+                configuration.setProperty(
+                    requiredProperty,
+                    properties.getProperty( requiredProperty )
+                );
+                getLogger().debug(
+                    "Setting property " + requiredProperty + "="
+                    + configuration.getProperty( requiredProperty )
+                );
+            }
+        }
+        
 
         configuration.addRequiredProperty( Constants.GROUP_ID );
         getLogger().debug( "Adding requiredProperty " + Constants.GROUP_ID );