@Execute can come from parent classes hierarchy

order parameters/components on fieldName order to ensure stability of tests.

git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1336290 13f79535-47bb-0310-9956-ffa450edef68
master
Olivier Lamy 2012-05-09 16:43:54 +00:00
parent d1e2e09ba8
commit ccc68be0c6
7 changed files with 95 additions and 35 deletions

View File

@ -36,9 +36,9 @@ assert mojo.configuration.touchFile[0].'@default-value' == '${project.build.dire
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

View File

@ -34,9 +34,9 @@ assert mojo.configuration.touchFile[0].'@default-value' == '${project.build.dire
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

View File

@ -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>

View File

@ -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 JavaAnnotationsMojoDescriptorExtractor
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 JavaAnnotationsMojoDescriptorExtractor
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 JavaAnnotationsMojoDescriptorExtractor
}
mojoDescriptor.setExecutionStrategy( mojo.executionStrategy() );
// FIXME olamy wtf ?
// ???
//mojoDescriptor.alwaysExecute(mojo.a)
mojoDescriptor.setGoal( mojo.name() );
@ -367,7 +354,8 @@ public class JavaAnnotationsMojoDescriptorExtractor
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 JavaAnnotationsMojoDescriptorExtractor
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 JavaAnnotationsMojoDescriptorExtractor
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 )

View File

@ -24,6 +24,7 @@ package org.apache.maven.tools.plugin.annotations.datamodel;
*/
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() );
}
}

View File

@ -18,6 +18,7 @@ package org.apache.maven.tools.plugin.annotations;
* 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.annotations.Execute;
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.annotations.Parameter;
public class FooMojo
extends AbstractMojo
{
@Parameter( expression = "${thebar}", required = true)
private String bar;
/**
* the cool bar to go
* @since 1.0
*
*/
@Parameter( expression = "${thebar}", required = true, defaultValue = "coolbar" )
protected String bar;
@Parameter( expression = "${thebeer}" )
private String beer;
/**
* beer for non french folks
* @deprecated wine is better
*/
@Parameter( expression = "${thebeer}", defaultValue = "coolbeer" )
protected String beer;
@Component( role = "wine", roleHint = "bordeaux" )
private Mojo wine;
/**
* Plexus compiler manager.
*/
@Component
protected CompilerManager compilerManager;
@Component( role = "wine", roleHint = "foo" )
private Mojo foo;
/**
*
*/
@Component( role = "org.apache.maven.artifact.metadata.ArtifactMetadataSource", roleHint = "maven" )
protected ArtifactMetadataSource artifactMetadataSource;
public void execute()
throws MojoExecutionException, MojoFailureException

View File

@ -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() ) );
}
}