[MPLUGIN-189] support components field inheritance
git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1335091 13f79535-47bb-0310-9956-ffa450edef68master
parent
1a12b44178
commit
e008c8012c
|
|
@ -36,6 +36,7 @@ under the License.
|
|||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<plexusCompilerVersion>1.8.6</plexusCompilerVersion>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
|
@ -54,6 +55,28 @@ under the License.
|
|||
<artifactId>maven-plugin-annotations</artifactId>
|
||||
<version>@project.version@</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.plexus</groupId>
|
||||
<artifactId>plexus-compiler-manager</artifactId>
|
||||
<version>${plexusCompilerVersion}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.codehaus.plexus</groupId>
|
||||
<artifactId>plexus-component-api</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.plexus</groupId>
|
||||
<artifactId>plexus-compiler-javac</artifactId>
|
||||
<version>${plexusCompilerVersion}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.codehaus.plexus</groupId>
|
||||
<artifactId>plexus-component-api</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@ 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;
|
||||
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
|
|
@ -47,6 +49,18 @@ public abstract class AbstractFirstMojo
|
|||
required = true )
|
||||
protected File touchFile;
|
||||
|
||||
/**
|
||||
* Plexus compiler manager.
|
||||
*/
|
||||
@Component(role = "org.codehaus.plexus.compiler.manager.CompilerManager")
|
||||
protected CompilerManager compilerManager;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Component(role = "org.apache.maven.artifact.metadata.ArtifactMetadataSource", roleHint = "maven")
|
||||
protected ArtifactMetadataSource artifactMetadataSource;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,14 +51,23 @@ public class FirstMojo
|
|||
public void execute()
|
||||
throws MojoExecutionException
|
||||
{
|
||||
if (basedir == null)
|
||||
{
|
||||
throw new MojoExecutionException( "basedir == null" );
|
||||
}
|
||||
if (touchFile == null)
|
||||
{
|
||||
throw new MojoExecutionException( "touchFile == null" );
|
||||
}
|
||||
if ( projectHelper == null )
|
||||
{
|
||||
throw new MojoExecutionException( "projectHelper == null" );
|
||||
}
|
||||
if (basedir == null || touchFile == null)
|
||||
if ( compilerManager == null )
|
||||
{
|
||||
throw new MojoExecutionException( "basedir == null || touchFile == null" );
|
||||
}
|
||||
throw new MojoExecutionException( "compilerManager == null" );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,11 +32,11 @@ assert mojo.configuration.touchFile[0].text() == '${first.touchFile}'
|
|||
assert mojo.configuration.touchFile[0].'@implementation' == 'java.io.File'
|
||||
assert mojo.configuration.touchFile[0].'@default-value' == '${project.build.directory}/touch.txt'
|
||||
|
||||
assert mojo.requirements.requirement.size() == 1
|
||||
assert mojo.requirements.requirement.size() == 3
|
||||
|
||||
assert mojo.requirements.requirement[0].role.text() == 'org.apache.maven.project.MavenProjectHelper'
|
||||
assert mojo.requirements.requirement[0].'role-hint'.text() == 'default'
|
||||
assert mojo.requirements.requirement[0].'field-name'.text() == 'projectHelper'
|
||||
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.parameters.parameter.size() == 3
|
||||
|
||||
|
|
|
|||
|
|
@ -357,7 +357,11 @@ public class JavaAnnotationsMojoDescriptorExtractor
|
|||
mojoDescriptor.addParameter( parameter );
|
||||
}
|
||||
|
||||
for ( ComponentAnnotationContent componentAnnotationContent : mojoAnnotatedClass.getComponents().values() )
|
||||
Map<String, ComponentAnnotationContent> components =
|
||||
getComponentsParentHierarchy( mojoAnnotatedClass, new HashMap<String, ComponentAnnotationContent>(),
|
||||
mojoAnnotatedClasses );
|
||||
|
||||
for ( ComponentAnnotationContent componentAnnotationContent : components.values() )
|
||||
{
|
||||
org.apache.maven.plugin.descriptor.Parameter parameter =
|
||||
new org.apache.maven.plugin.descriptor.Parameter();
|
||||
|
|
@ -383,7 +387,7 @@ public class JavaAnnotationsMojoDescriptorExtractor
|
|||
List<ParameterAnnotationContent> parameterAnnotationContents = new ArrayList<ParameterAnnotationContent>();
|
||||
|
||||
parameterAnnotationContents =
|
||||
getParent( mojoAnnotatedClass, parameterAnnotationContents, mojoAnnotatedClasses );
|
||||
getParametersParent( mojoAnnotatedClass, parameterAnnotationContents, mojoAnnotatedClasses );
|
||||
|
||||
// move to parent first to build the Map
|
||||
Collections.reverse( parameterAnnotationContents );
|
||||
|
|
@ -398,7 +402,7 @@ public class JavaAnnotationsMojoDescriptorExtractor
|
|||
return map;
|
||||
}
|
||||
|
||||
protected List<ParameterAnnotationContent> getParent( MojoAnnotatedClass mojoAnnotatedClass,
|
||||
protected List<ParameterAnnotationContent> getParametersParent( MojoAnnotatedClass mojoAnnotatedClass,
|
||||
List<ParameterAnnotationContent> parameterAnnotationContents,
|
||||
Map<String, MojoAnnotatedClass> mojoAnnotatedClasses )
|
||||
{
|
||||
|
|
@ -409,9 +413,49 @@ public class JavaAnnotationsMojoDescriptorExtractor
|
|||
MojoAnnotatedClass parent = mojoAnnotatedClasses.get( parentClassName );
|
||||
if ( parent != null )
|
||||
{
|
||||
return getParent( parent, parameterAnnotationContents, mojoAnnotatedClasses );
|
||||
return getParametersParent( parent, parameterAnnotationContents, mojoAnnotatedClasses );
|
||||
}
|
||||
}
|
||||
return parameterAnnotationContents;
|
||||
}
|
||||
|
||||
|
||||
protected Map<String, ComponentAnnotationContent> getComponentsParentHierarchy(
|
||||
MojoAnnotatedClass mojoAnnotatedClass, Map<String, ComponentAnnotationContent> components,
|
||||
Map<String, MojoAnnotatedClass> mojoAnnotatedClasses )
|
||||
{
|
||||
List<ComponentAnnotationContent> componentAnnotationContents = new ArrayList<ComponentAnnotationContent>();
|
||||
|
||||
componentAnnotationContents =
|
||||
getComponentParent( mojoAnnotatedClass, componentAnnotationContents, mojoAnnotatedClasses );
|
||||
|
||||
// move to parent first to build the Map
|
||||
Collections.reverse( componentAnnotationContents );
|
||||
|
||||
Map<String, ComponentAnnotationContent> map =
|
||||
new HashMap<String, ComponentAnnotationContent>( componentAnnotationContents.size() );
|
||||
|
||||
for ( ComponentAnnotationContent componentAnnotationContent : componentAnnotationContents )
|
||||
{
|
||||
map.put( componentAnnotationContent.getFieldName(), componentAnnotationContent );
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
protected List<ComponentAnnotationContent> getComponentParent( MojoAnnotatedClass mojoAnnotatedClass,
|
||||
List<ComponentAnnotationContent> componentAnnotationContents,
|
||||
Map<String, MojoAnnotatedClass> mojoAnnotatedClasses )
|
||||
{
|
||||
componentAnnotationContents.addAll( mojoAnnotatedClass.getComponents().values() );
|
||||
String parentClassName = mojoAnnotatedClass.getParentClassName();
|
||||
if ( parentClassName != null )
|
||||
{
|
||||
MojoAnnotatedClass parent = mojoAnnotatedClasses.get( parentClassName );
|
||||
if ( parent != null )
|
||||
{
|
||||
return getComponentParent( parent, componentAnnotationContents, mojoAnnotatedClasses );
|
||||
}
|
||||
}
|
||||
return componentAnnotationContents;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue