Author: jvanzyl
Date: Sat Sep 10 05:12:40 2005
New Revision: 279997

URL: http://svn.apache.org/viewcvs?rev=279997&view=rev
Log:
o allowing the specification of the bean property that should be used for
  reading/writing configuration values. I briefly discussed this with John but
  is up for discussion. We felt the most "bean" like way would be to allow
  something like the following:
  
  @parameter property="project"
  
  Which would mean that for that particular field to read/write it a
  getProject() and setProject(Project) method would be present.
  

Modified:
    
maven/components/trunk/maven-plugin-tools/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java

Modified: 
maven/components/trunk/maven-plugin-tools/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java
URL: 
http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugin-tools/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java?rev=279997&r1=279996&r2=279997&view=diff
==============================================================================
--- 
maven/components/trunk/maven-plugin-tools/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java
 (original)
+++ 
maven/components/trunk/maven-plugin-tools/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java
 Sat Sep 10 05:12:40 2005
@@ -59,6 +59,19 @@
 
     public static final String PARAMETER_DEFAULT_VALUE = "default-value";
 
+    /**
+     * This indicates the base name of the bean properties used to read/write 
this parameter's value.
+     * So:
+     *
+     * @parameter property="project"
+     *
+     * Would say there is a getProject() method and a setProject(Project) 
method. Here the field
+     * name would not be the basis for the parameter's name. This mode of 
operation will allow the
+     * mojos to be usable as beans and will be the promoted form of use.
+     *
+     **/
+    public static final String PARAMETER_PROPERTY = "property";
+
     public static final String REQUIRED = "required";
 
     public static final String DEPRECATED = "deprecated";
@@ -125,6 +138,7 @@
         throws InvalidPluginDescriptorException
     {
         MojoDescriptor mojoDescriptor = new MojoDescriptor();
+
         mojoDescriptor.setPluginDescriptor( pluginDescriptor );
 
         JavaClass javaClass = getJavaClass( javaSource );
@@ -202,6 +216,7 @@
         if ( execute != null )
         {
             String executePhase = execute.getNamedParameter( "phase" );
+
             if ( executePhase == null )
             {
                 throw new InvalidPluginDescriptorException( "@execute tag 
requires a 'phase' parameter" );
@@ -209,6 +224,7 @@
             mojoDescriptor.setExecutePhase( executePhase );
 
             String lifecycle = execute.getNamedParameter( "lifecycle" );
+
             if ( lifecycle != null )
             {
                 mojoDescriptor.setExecuteLifecycle( lifecycle );
@@ -224,10 +240,12 @@
         if ( requiresDependencyResolution != null )
         {
             String value = requiresDependencyResolution.getValue();
+
             if ( value == null || value.length() == 0 )
             {
                 value = "runtime";
             }
+
             mojoDescriptor.setDependencyResolutionRequired( value );
         }
 
@@ -325,39 +343,63 @@
         for ( Iterator it = rawParams.entrySet().iterator(); it.hasNext(); )
         {
             Map.Entry entry = (Map.Entry) it.next();
-            String paramName = (String) entry.getKey();
 
             JavaField field = (JavaField) entry.getValue();
 
             Parameter pd = new Parameter();
 
-            pd.setName( paramName );
-
             pd.setType( field.getType().getValue() );
 
             pd.setDescription( field.getComment() );
 
             DocletTag componentTag = field.getTagByName( COMPONENT );
+
             if ( componentTag != null )
             {
                 String role = componentTag.getNamedParameter( "role" );
+
                 if ( role == null )
                 {
                     role = field.getType().toString();
                 }
 
                 String roleHint = componentTag.getNamedParameter( "roleHint" );
+
                 pd.setRequirement( new Requirement( role, roleHint ) );
+
+                pd.setName( (String) entry.getKey() );
             }
             else
             {
                 DocletTag parameter = field.getTagByName( PARAMETER );
 
+                // 
----------------------------------------------------------------------
+                // We will look for a property name here first and use that if 
present
+                // i.e:
+                //
+                // @parameter property="project"
+                //
+                // Which will become the name used for the configuration 
element which
+                // will in turn will allow plexus to use the corresponding 
setter.
+                // 
----------------------------------------------------------------------
+
+                String property = parameter.getNamedParameter( 
PARAMETER_PROPERTY );
+
+                if ( !StringUtils.isEmpty( property ) )
+                {
+                    pd.setName( property );
+                }
+                else
+                {
+                    pd.setName( (String) entry.getKey() );
+                }
+
                 pd.setRequired( field.getTagByName( REQUIRED ) != null );
 
                 pd.setEditable( field.getTagByName( READONLY ) == null );
 
                 DocletTag deprecationTag = field.getTagByName( DEPRECATED );
+
                 if ( deprecationTag != null )
                 {
                     pd.setDeprecated( deprecationTag.getValue() );
@@ -374,6 +416,7 @@
 
                 pd.setDefaultValue( parameter.getNamedParameter( 
PARAMETER_DEFAULT_VALUE ) );
             }
+
             mojoDescriptor.addParameter( pd );
         }
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to