You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by jd...@apache.org on 2005/04/26 22:30:21 UTC
svn commit: r164872 -
/maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin
/maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor
/maven/components/trunk/maven-plugin-tools/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java
/maven/components/trunk/maven-plugins/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources
/maven/components/trunk/maven-project/src/main/java/org/apache/maven/artifact
/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/artifact
Author: jdcasey
Date: Tue Apr 26 13:30:21 2005
New Revision: 164872
URL: http://svn.apache.org/viewcvs?rev=164872&view=rev
Log:
Resolving MNG-221, simplify qdox with field-level mojo parameter annotations
Added:
maven/components/trunk/maven-project/src/main/java/org/apache/maven/artifact/
Removed:
maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/artifact/
Modified:
maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java
maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/Parameter.java
maven/components/trunk/maven-plugin-tools/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java
maven/components/trunk/maven-plugins/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java
maven/components/trunk/maven-plugins/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/TestResourcesMojo.java
Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java?rev=164872&r1=164871&r2=164872&view=diff
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java (original)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java Tue Apr 26 13:30:21 2005
@@ -18,6 +18,7 @@
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.metadata.MavenMetadataSource;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.ArtifactResolver;
@@ -33,7 +34,6 @@
import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
-import org.apache.maven.project.artifact.MavenMetadataSource;
import org.apache.maven.project.path.PathTranslator;
import org.codehaus.plexus.ArtifactEnabledContainer;
import org.codehaus.plexus.ArtifactEnabledContainerException;
@@ -635,7 +635,7 @@
}
/**
- * @deprecated
+ * @deprecated [JC] in favor of what?
*/
private Map getPluginConfigurationFromExpressions( MojoDescriptor goal, PlexusConfiguration configuration,
ExpressionEvaluator expressionEvaluator )
@@ -649,20 +649,29 @@
{
Parameter parameter = (Parameter) parameters.get( i );
+ // the key for the configuration map we're building.
String key = parameter.getName();
+
+ // the key used to lookup the parameter in the config from the POM, etc.
+ String lookupKey = parameter.getAlias();
+
+ if ( StringUtils.isEmpty( lookupKey ) )
+ {
+ lookupKey = key;
+ }
String expression;
- if ( configuration.getChild( key, false ) == null )
+ if ( configuration.getChild( lookupKey, false ) == null )
{
expression = parameter.getExpression();
}
else
{
- expression = configuration.getChild( key, false ).getValue( null );
+ expression = configuration.getChild( lookupKey, false ).getValue( null );
if ( expression != null && parameter.getDeprecated() != null )
{
- if ( !expression.equals( goal.getConfiguration().getChild( key, false ).getValue( null ) ) )
+ if ( !expression.equals( goal.getConfiguration().getChild( lookupKey, false ).getValue( null ) ) )
{
getLogger().warn(
"DEPRECATED: " + parameter.getName() + " is deprecated.\n\t" + parameter.getDeprecated() );
Modified: maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java?rev=164872&r1=164871&r2=164872&view=diff
==============================================================================
--- maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java (original)
+++ maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java Tue Apr 26 13:30:21 2005
@@ -203,7 +203,7 @@
this.requiresOnline = requiresOnline;
}
- // blech! this isn't even intelligible as a method name. provided for
+ // blech! this isn't even intelligible as a method name. provided for
// consistency...
public boolean isRequiresOnline()
{
Modified: maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/Parameter.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/Parameter.java?rev=164872&r1=164871&r2=164872&view=diff
==============================================================================
--- maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/Parameter.java (original)
+++ maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/Parameter.java Tue Apr 26 13:30:21 2005
@@ -22,6 +22,8 @@
*/
public class Parameter
{
+ private String alias;
+
private String name;
private String type;
@@ -120,5 +122,25 @@
public void setDeprecated( String deprecated )
{
this.deprecated = deprecated;
+ }
+
+ public int hashCode()
+ {
+ return name.hashCode();
+ }
+
+ public boolean equals(Object other)
+ {
+ return (other instanceof Parameter) && getName().equals(((Parameter)other).getName());
+ }
+
+ public String getAlias()
+ {
+ return alias;
+ }
+
+ public void setAlias( String alias )
+ {
+ this.alias = alias;
}
}
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=164872&r1=164871&r2=164872&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 Tue Apr 26 13:30:21 2005
@@ -16,16 +16,21 @@
* limitations under the License.
*/
-import com.thoughtworks.qdox.JavaDocBuilder;
-import com.thoughtworks.qdox.model.DocletTag;
-import com.thoughtworks.qdox.model.JavaClass;
-import com.thoughtworks.qdox.model.JavaSource;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.Parameter;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject;
import org.apache.maven.tools.plugin.extractor.InvalidParameterException;
import org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor;
+import org.codehaus.modello.StringUtils;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.codehaus.plexus.logging.Logger;
+
+import com.thoughtworks.qdox.JavaDocBuilder;
+import com.thoughtworks.qdox.model.DocletTag;
+import com.thoughtworks.qdox.model.JavaClass;
+import com.thoughtworks.qdox.model.JavaField;
+import com.thoughtworks.qdox.model.JavaSource;
import java.io.File;
import java.util.ArrayList;
@@ -40,6 +45,7 @@
* get validation directives to help users in IDEs.
*/
public class JavaMojoDescriptorExtractor
+ extends AbstractLogEnabled
implements MojoDescriptorExtractor
{
public static final String MAVEN_PLUGIN_ID = "maven.plugin.id";
@@ -81,15 +87,6 @@
throw new InvalidParameterException( "type", i );
}
- boolean required = parameter.isRequired();
-
- String validator = parameter.getValidator();
-
- if ( validator == null )
- {
- throw new InvalidParameterException( "validator", i );
- }
-
String expression = parameter.getExpression();
if ( expression == null )
@@ -125,21 +122,21 @@
mojoDescriptor.setId( pluginId );
- tag = javaClass.getTagByName( MAVEN_PLUGIN_DESCRIPTION );
+ tag = findInClassHierarchy( javaClass, MAVEN_PLUGIN_DESCRIPTION );
if ( tag != null )
{
mojoDescriptor.setDescription( tag.getValue() );
}
- tag = javaClass.getTagByName( MAVEN_PLUGIN_INSTANTIATION );
+ tag = findInClassHierarchy( javaClass, MAVEN_PLUGIN_INSTANTIATION );
if ( tag != null )
{
mojoDescriptor.setInstantiationStrategy( tag.getValue() );
}
- tag = javaClass.getTagByName( GOAL_MULTI_EXECUTION_STRATEGY );
+ tag = findInClassHierarchy( javaClass, GOAL_MULTI_EXECUTION_STRATEGY );
if ( tag != null )
{
@@ -154,7 +151,7 @@
// Goal name
// ----------------------------------------------------------------------
- DocletTag goal = javaClass.getTagByName( GOAL );
+ DocletTag goal = findInClassHierarchy( javaClass, GOAL );
if ( goal != null )
{
@@ -165,7 +162,7 @@
// Phase name
// ----------------------------------------------------------------------
- DocletTag phase = javaClass.getTagByName( PHASE );
+ DocletTag phase = findInClassHierarchy( javaClass, PHASE );
if ( phase != null )
{
@@ -176,7 +173,7 @@
// Dependency resolution flag
// ----------------------------------------------------------------------
- DocletTag requiresDependencyResolution = javaClass.getTagByName( GOAL_REQUIRES_DEPENDENCY_RESOLUTION );
+ DocletTag requiresDependencyResolution = findInClassHierarchy( javaClass, GOAL_REQUIRES_DEPENDENCY_RESOLUTION );
if ( requiresDependencyResolution != null )
{
@@ -188,42 +185,159 @@
mojoDescriptor.setRequiresDependencyResolution( value );
}
- // ----------------------------------------------------------------------
- //
- // ----------------------------------------------------------------------
+ extractParameters( mojoDescriptor, javaClass );
+
+ return mojoDescriptor;
+ }
+
+ private DocletTag findInClassHierarchy( JavaClass javaClass, String tagName )
+ {
+ DocletTag tag = javaClass.getTagByName( tagName );
- DocletTag[] parameterTags = javaClass.getTagsByName( PARAMETER );
+ if ( tag == null )
+ {
+ JavaClass superClass = javaClass.getSuperJavaClass();
+
+ if ( superClass != null )
+ {
+ tag = findInClassHierarchy( superClass, tagName );
+ }
+ }
- List parameters = new ArrayList();
+ return tag;
+ }
- for ( int j = 0; j < parameterTags.length; j++ )
+ private void extractParameters( MojoDescriptor mojoDescriptor, JavaClass javaClass )
+ {
+ // ---------------------------------------------------------------------------------
+ // We're resolving class-level, ancestor-class-field, local-class-field order here.
+ // ---------------------------------------------------------------------------------
+
+ List rawParams = new ArrayList();
+
+ // for backward compat, we'll toss on the params declared at the class level.
+ DocletTag[] classLevelParams = javaClass.getTagsByName( PARAMETER );
+ if ( classLevelParams != null )
{
- DocletTag parameter = parameterTags[j];
+ for ( int i = 0; i < classLevelParams.length; i++ )
+ {
+ DocletTag tag = classLevelParams[i];
+
+ String message = "DEPRECATED: Use field-level annotations "
+ + "for parameters instead of class-level annotations. (parameter \'"
+ + tag.getNamedParameter( "name" ) + "\'; class \'" + javaClass.getFullyQualifiedName() + ")";
+
+ Logger logger = getLogger();
+ if ( logger != null )
+ {
+ logger.warn( message );
+ }
+ else
+ {
+ // we're being used from pluggy, so this is okay...
+ System.err.println( message );
+ }
+
+ rawParams.add( tag );
+ }
+ }
+
+ extractFieldParameterTags( javaClass, rawParams );
+
+ Set parameters = new HashSet();
+
+ for ( Iterator it = rawParams.iterator(); it.hasNext(); )
+ {
+ Object parameterInfo = it.next();
+
+ JavaField field = null;
+ DocletTag parameter = null;
+
+ // FIXME: ICK! This is only here for backward compatibility to the class-level annotations of params.
+ if ( parameterInfo instanceof JavaField )
+ {
+ field = (JavaField) parameterInfo;
+
+ parameter = field.getTagByName( PARAMETER );
+ }
+ else
+ {
+ parameter = (DocletTag) parameterInfo;
+ }
Parameter pd = new Parameter();
- pd.setName( parameter.getNamedParameter( "name" ) );
+ // if the field is null, then we're using a deprecated annotation pattern...
+ // TODO: Remove this check once we're clear of the annotation-compat issues.
+ if ( field == null )
+ {
+ pd.setName( parameter.getNamedParameter( "name" ) );
- pd.setType( parameter.getNamedParameter( "type" ) );
+ pd.setType( parameter.getNamedParameter( "type" ) );
- pd.setRequired( parameter.getNamedParameter( "required" ).equals( "true" ) ? true : false );
+ pd.setDefaultValue( parameter.getNamedParameter( "default" ) );
+ }
+ else
+ {
+ pd.setName( field.getName() );
+
+ pd.setType( field.getType().getValue() );
+ }
+
+ String alias = parameter.getNamedParameter( "alias" );
- pd.setValidator( parameter.getNamedParameter( "validator" ) );
+ if ( StringUtils.isEmpty( alias ) )
+ {
+ pd.setAlias( alias );
+ }
+
+ pd.setRequired( parameter.getNamedParameter( "required" ).equals( "true" ) ? true : false );
pd.setExpression( parameter.getNamedParameter( "expression" ) );
pd.setDescription( parameter.getNamedParameter( "description" ) );
- pd.setDefaultValue( parameter.getNamedParameter( "default" ) );
-
pd.setDeprecated( parameter.getNamedParameter( "deprecated" ) );
parameters.add( pd );
}
- mojoDescriptor.setParameters( parameters );
+ if ( !parameters.isEmpty() )
+ {
+ List paramList = new ArrayList( parameters );
+
+ mojoDescriptor.setParameters( paramList );
+ }
+ }
+
+ private void extractFieldParameterTags( JavaClass javaClass, List rawParams )
+ {
+ // we have to add the parent fields first, so that they will be overwritten by the local fields if
+ // that actually happens...
+ JavaClass superClass = javaClass.getSuperJavaClass();
+
+ if ( superClass != null )
+ {
+ extractFieldParameterTags( superClass, rawParams );
+ }
+
+ JavaField[] classFields = javaClass.getFields();
+
+ if ( classFields != null )
+ {
+ for ( int i = 0; i < classFields.length; i++ )
+ {
+ JavaField field = classFields[i];
+
+ DocletTag paramTag = field.getTagByName( PARAMETER );
+
+ if ( paramTag != null )
+ {
+ rawParams.add( field );
+ }
+ }
+ }
- return mojoDescriptor;
}
private JavaClass getJavaClass( JavaSource javaSource )
@@ -278,19 +392,19 @@
// method: execute signature:
// (Ljava/lang/String;Lorg/apache/maven/project/MavenProject;)Ljava/util/Set;)
// Incompatible object argument for function call
- //
+ //
// Refactored to allow MavenMojoDescriptor.getComponentFactory()
// return MavenMojoDescriptor.getMojoDescriptor().getLanguage(),
// and removed all usage of MavenMojoDescriptor from extractors.
- //
- //
+ //
+ //
// MavenMojoDescriptor mmDescriptor = new
// MavenMojoDescriptor(mojoDescriptor);
- //
+ //
// JavaClass javaClass = getJavaClass(javaSources[i]);
- //
+ //
// mmDescriptor.setImplementation(javaClass.getFullyQualifiedName());
- //
+ //
// descriptors.add( mmDescriptor );
descriptors.add( mojoDescriptor );
Modified: maven/components/trunk/maven-plugins/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java?rev=164872&r1=164871&r2=164872&view=diff
==============================================================================
--- maven/components/trunk/maven-plugins/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java (original)
+++ maven/components/trunk/maven-plugins/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java Tue Apr 26 13:30:21 2005
@@ -39,29 +39,39 @@
* @version $Id$
* @goal resources
* @description copy application resources
- * @parameter name="outputDirectory"
- * type="String"
- * required="true"
- * validator=""
- * expression="${project.build.outputDirectory}"
- * description=""
- * @parameter name="resources"
- * type="List"
- * required="true"
- * validator=""
- * expression="${project.build.resources}"
- * description=""
*/
public class ResourcesMojo
extends AbstractPlugin
{
+ /**
+ * @parameter name="outputDirectory"
+ * type="String"
+ * required="true"
+ * validator=""
+ * expression="${project.build.outputDirectory}"
+ * description=""
+ */
private String outputDirectory;
+ /**
+ * @parameter name="resources"
+ * type="List"
+ * required="true"
+ * validator=""
+ * expression="${project.build.resources}"
+ * description=""
+ */
private List resources;
public void execute()
throws PluginExecutionException
{
+ copyResources( resources, outputDirectory );
+ }
+
+ protected void copyResources( List resources, String outputDirectory )
+ throws PluginExecutionException
+ {
try
{
for ( Iterator i = getJarResources( resources ).entrySet().iterator(); i.hasNext(); )
@@ -69,7 +79,7 @@
Map.Entry entry = (Map.Entry) i.next();
String source = (String) entry.getKey();
String destination = (String) entry.getValue();
-
+
File destinationFile = new File( outputDirectory, destination );
if ( !destinationFile.getParentFile().exists() )
@@ -160,7 +170,7 @@
int count;
byte[] b = new byte[512];
- while ( ( count = in.read( b ) ) > 0 ) // blocking read
+ while ( ( count = in.read( b ) ) > 0 ) // blocking read
{
buffer.write( b, 0, count );
}
Modified: maven/components/trunk/maven-plugins/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/TestResourcesMojo.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/TestResourcesMojo.java?rev=164872&r1=164871&r2=164872&view=diff
==============================================================================
--- maven/components/trunk/maven-plugins/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/TestResourcesMojo.java (original)
+++ maven/components/trunk/maven-plugins/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/TestResourcesMojo.java Tue Apr 26 13:30:21 2005
@@ -1,5 +1,9 @@
package org.apache.maven.plugin.resources;
+import org.apache.maven.plugin.PluginExecutionException;
+
+import java.util.List;
+
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
@@ -22,20 +26,34 @@
* @version $Id$
* @goal testResources
* @description copy test resources
- * @parameter name="outputDirectory"
- * type="String"
- * required="true"
- * validator=""
- * expression="${project.build.testOutputDirectory}"
- * description=""
- * @parameter name="resources"
- * type="List"
- * required="true"
- * validator=""
- * expression="${project.build.testResources}"
- * description=""
*/
public class TestResourcesMojo
extends ResourcesMojo
{
+ /**
+ * @parameter name="outputDirectory"
+ * type="String"
+ * required="true"
+ * validator=""
+ * expression="${project.build.testOutputDirectory}"
+ * description=""
+ */
+ private String outputDirectory;
+
+ /**
+ * @parameter name="resources"
+ * type="List"
+ * required="true"
+ * validator=""
+ * expression="${project.build.testResources}"
+ * description=""
+ */
+ private List resources;
+
+ public void execute()
+ throws PluginExecutionException
+ {
+ copyResources( resources, outputDirectory );
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org