Author: olamy
Date: Wed May 9 16:43:54 2012
New Revision: 1336290
URL: http://svn.apache.org/viewvc?rev=1336290&view=rev
Log:
@Execute can come from parent classes hierarchy
order parameters/components on fieldName order to ensure stability of tests.
Modified:
maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/verify.groovy
maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy
maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/pom.xml
maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/JavaAnnotationsMojoDescriptorExtractor.java
maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedField.java
maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/FooMojo.java
maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java
Modified:
maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/verify.groovy
URL:
http://svn.apache.org/viewvc/maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/verify.groovy?rev=1336290&r1=1336289&r2=1336290&view=diff
==============================================================================
---
maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/verify.groovy
(original)
+++
maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/verify.groovy
Wed May 9 16:43:54 2012
@@ -36,9 +36,9 @@ assert mojo.configuration.touchFile[0].'
assert mojo.requirements.requirement.size() == 3
-assert mojo.requirements.requirement[1].role.text() ==
'org.apache.maven.project.MavenProjectHelper'
-assert mojo.requirements.requirement[1].'role-hint'.text() == 'default'
-assert mojo.requirements.requirement[1].'field-name'.text() == 'projectHelper'
+assert mojo.requirements.requirement[2].role.text() ==
'org.apache.maven.project.MavenProjectHelper'
+assert mojo.requirements.requirement[2].'role-hint'.text() == 'default'
+assert mojo.requirements.requirement[2].'field-name'.text() == 'projectHelper'
assert mojo.parameters.parameter.size() == 3
Modified:
maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy
URL:
http://svn.apache.org/viewvc/maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy?rev=1336290&r1=1336289&r2=1336290&view=diff
==============================================================================
---
maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy
(original)
+++
maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy
Wed May 9 16:43:54 2012
@@ -34,9 +34,9 @@ assert mojo.configuration.touchFile[0].'
assert mojo.requirements.requirement.size() == 3
-assert mojo.requirements.requirement[1].role.text() ==
'org.apache.maven.project.MavenProjectHelper'
-assert mojo.requirements.requirement[1].'role-hint'.text() == 'default'
-assert mojo.requirements.requirement[1].'field-name'.text() == 'projectHelper'
+assert mojo.requirements.requirement[2].role.text() ==
'org.apache.maven.project.MavenProjectHelper'
+assert mojo.requirements.requirement[2].'role-hint'.text() == 'default'
+assert mojo.requirements.requirement[2].'field-name'.text() == 'projectHelper'
assert mojo.parameters.parameter.size() == 3
Modified:
maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/pom.xml
URL:
http://svn.apache.org/viewvc/maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/pom.xml?rev=1336290&r1=1336289&r2=1336290&view=diff
==============================================================================
---
maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/pom.xml
(original)
+++
maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/pom.xml
Wed May 9 16:43:54 2012
@@ -77,6 +77,19 @@
<artifactId>qdox</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-compiler-manager</artifactId>
+ <version>1.8.6</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-component-api</artifactId>
+ </exclusion>
+ </exclusions>
+ <scope>test</scope>
+ </dependency>
+
</dependencies>
<build>
@@ -92,6 +105,17 @@
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-source-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>test-jar-no-fork</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
Modified:
maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/JavaAnnotationsMojoDescriptorExtractor.java
URL:
http://svn.apache.org/viewvc/maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/JavaAnnotationsMojoDescriptorExtractor.java?rev=1336290&r1=1336289&r2=1336290&view=diff
==============================================================================
---
maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/JavaAnnotationsMojoDescriptorExtractor.java
(original)
+++
maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/JavaAnnotationsMojoDescriptorExtractor.java
Wed May 9 16:43:54 2012
@@ -53,6 +53,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
+import java.util.TreeSet;
/**
* @author Olivier Lamy
@@ -297,19 +298,6 @@ public class JavaAnnotationsMojoDescript
return javaClassMap;
}
- private List<File> toFiles( List<String> directories )
- {
- if ( directories == null )
- {
- return Collections.emptyList();
- }
- List<File> files = new ArrayList<File>( directories.size() );
- for ( String directory : directories )
- {
- files.add( new File( directory ) );
- }
- return files;
- }
private List<MojoDescriptor> toMojoDescriptors( Map<String,
MojoAnnotatedClass> mojoAnnotatedClasses,
PluginToolsRequest request
)
@@ -345,8 +333,7 @@ public class JavaAnnotationsMojoDescript
mojoDescriptor.setDeprecated( mojo.getDeprecated() );
mojoDescriptor.setThreadSafe( mojo.threadSafe() );
- ExecuteAnnotationContent execute = mojoAnnotatedClass.getExecute();
-
+ ExecuteAnnotationContent execute = findExecuteInParentHierarchy(
mojoAnnotatedClass, mojoAnnotatedClasses );
if ( execute != null )
{
mojoDescriptor.setExecuteGoal( execute.goal() );
@@ -355,7 +342,7 @@ public class JavaAnnotationsMojoDescript
}
mojoDescriptor.setExecutionStrategy( mojo.executionStrategy() );
- // FIXME olamy wtf ?
+ // ???
//mojoDescriptor.alwaysExecute(mojo.a)
mojoDescriptor.setGoal( mojo.name() );
@@ -367,7 +354,8 @@ public class JavaAnnotationsMojoDescript
getParametersParentHierarchy( mojoAnnotatedClass, new
HashMap<String, ParameterAnnotationContent>(),
mojoAnnotatedClasses );
- for ( ParameterAnnotationContent parameterAnnotationContent :
parameters.values() )
+ for ( ParameterAnnotationContent parameterAnnotationContent : new
TreeSet<ParameterAnnotationContent>(
+ parameters.values() ) )
{
org.apache.maven.plugin.descriptor.Parameter parameter =
new org.apache.maven.plugin.descriptor.Parameter();
@@ -388,7 +376,8 @@ public class JavaAnnotationsMojoDescript
getComponentsParentHierarchy( mojoAnnotatedClass, new
HashMap<String, ComponentAnnotationContent>(),
mojoAnnotatedClasses );
- for ( ComponentAnnotationContent componentAnnotationContent :
components.values() )
+ for ( ComponentAnnotationContent componentAnnotationContent : new
TreeSet<ComponentAnnotationContent>(
+ components.values() ) )
{
org.apache.maven.plugin.descriptor.Parameter parameter =
new org.apache.maven.plugin.descriptor.Parameter();
@@ -407,6 +396,29 @@ public class JavaAnnotationsMojoDescript
return mojoDescriptors;
}
+
+ protected ExecuteAnnotationContent findExecuteInParentHierarchy(
MojoAnnotatedClass mojoAnnotatedClass,
+
Map<String, MojoAnnotatedClass> mojoAnnotatedClasses )
+ {
+
+ if ( mojoAnnotatedClass.getExecute() != null )
+ {
+ return mojoAnnotatedClass.getExecute();
+ }
+ String parentClassName = mojoAnnotatedClass.getParentClassName();
+ if ( StringUtils.isEmpty( parentClassName ) )
+ {
+ return null;
+ }
+ MojoAnnotatedClass parent = mojoAnnotatedClasses.get( parentClassName
);
+ if ( parent == null )
+ {
+ return null;
+ }
+ return findExecuteInParentHierarchy( parent, mojoAnnotatedClasses );
+ }
+
+
protected Map<String, ParameterAnnotationContent>
getParametersParentHierarchy(
MojoAnnotatedClass mojoAnnotatedClass, Map<String,
ParameterAnnotationContent> parameters,
Map<String, MojoAnnotatedClass> mojoAnnotatedClasses )
Modified:
maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedField.java
URL:
http://svn.apache.org/viewvc/maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedField.java?rev=1336290&r1=1336289&r2=1336290&view=diff
==============================================================================
---
maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedField.java
(original)
+++
maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedField.java
Wed May 9 16:43:54 2012
@@ -24,6 +24,7 @@ package org.apache.maven.tools.plugin.an
*/
public class AnnotatedField
extends AnnotatedContent
+ implements Comparable<AnnotatedField>
{
private String fieldName;
@@ -51,4 +52,9 @@ public class AnnotatedField
sb.append( '}' );
return sb.toString();
}
+
+ public int compareTo( AnnotatedField annotatedField )
+ {
+ return getFieldName().compareTo( annotatedField.getFieldName() );
+ }
}
Modified:
maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/FooMojo.java
URL:
http://svn.apache.org/viewvc/maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/FooMojo.java?rev=1336290&r1=1336289&r2=1336290&view=diff
==============================================================================
---
maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/FooMojo.java
(original)
+++
maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/FooMojo.java
Wed May 9 16:43:54 2012
@@ -18,6 +18,7 @@ package org.apache.maven.tools.plugin.an
* under the License.
*/
+import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
@@ -26,6 +27,7 @@ import org.apache.maven.plugins.annotati
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
+import org.codehaus.plexus.compiler.manager.CompilerManager;
/**
* @author Olivier Lamy
@@ -35,17 +37,32 @@ import org.apache.maven.plugins.annotati
public class FooMojo
extends AbstractMojo
{
- @Parameter( expression = "${thebar}", required = true)
- private String bar;
-
- @Parameter( expression = "${thebeer}" )
- private String beer;
-
- @Component( role = "wine", roleHint = "bordeaux" )
- private Mojo wine;
-
- @Component( role = "wine", roleHint = "foo" )
- private Mojo foo;
+ /**
+ * the cool bar to go
+ * @since 1.0
+ *
+ */
+ @Parameter( expression = "${thebar}", required = true, defaultValue =
"coolbar" )
+ protected String bar;
+
+ /**
+ * beer for non french folks
+ * @deprecated wine is better
+ */
+ @Parameter( expression = "${thebeer}", defaultValue = "coolbeer" )
+ protected String beer;
+
+ /**
+ * Plexus compiler manager.
+ */
+ @Component
+ protected CompilerManager compilerManager;
+
+ /**
+ *
+ */
+ @Component( role =
"org.apache.maven.artifact.metadata.ArtifactMetadataSource", roleHint = "maven"
)
+ protected ArtifactMetadataSource artifactMetadataSource;
public void execute()
throws MojoExecutionException, MojoFailureException
Modified:
maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java
URL:
http://svn.apache.org/viewvc/maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java?rev=1336290&r1=1336289&r2=1336290&view=diff
==============================================================================
---
maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java
(original)
+++
maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java
Wed May 9 16:43:54 2012
@@ -51,7 +51,7 @@ public class TestAnnotationsReader
MojoAnnotationsScannerRequest request = new
MojoAnnotationsScannerRequest();
request.setClassesDirectories( Collections.singletonList( new File(
"target/test-classes" ) ) );
request.setIncludePatterns( Arrays.asList( "**/FooMojo.class" ) );
- request.setProject( new MavenProject( ) );
+ request.setProject( new MavenProject() );
Map<String, MojoAnnotatedClass> mojoAnnotatedClasses =
mojoAnnotationsScanner.scan( request );
@@ -82,7 +82,8 @@ public class TestAnnotationsReader
Collection<ParameterAnnotationContent> parameters =
mojoAnnotatedClass.getParameters().values();
Assertions.assertThat( parameters ).isNotNull().isNotEmpty().hasSize(
2 ).contains(
- new ParameterAnnotationContent( "bar", null, "${thebar}", null,
true, false, String.class.getName() ),
- new ParameterAnnotationContent( "beer", null, "${thebeer}", null,
false, false, String.class.getName() ) );
+ new ParameterAnnotationContent( "bar", null, "${thebar}",
"coolbar", true, false, String.class.getName() ),
+ new ParameterAnnotationContent( "beer", null, "${thebeer}",
"coolbeer", false, false,
+ String.class.getName() ) );
}
}