o Extended mojo to allow checking injected Plexus components

git-svn-id: https://svn.apache.org/repos/asf/maven/core-integration-testing/trunk@705864 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2008-10-18 09:22:46 +00:00
parent f2b69026a5
commit 3afaffd185

View File

@ -28,6 +28,8 @@
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
@ -68,6 +70,13 @@ public class InstanceofMojo
*/ */
private String[] objectExpressions; private String[] objectExpressions;
/**
* A list of injected component instances that should be type-checked.
*
* @component role="org.apache.maven.plugin.coreit.Component"
*/
private List components;
/** /**
* The current Maven project against which expressions are evaluated. * The current Maven project against which expressions are evaluated.
* *
@ -98,22 +107,39 @@ public void execute()
Properties instanceofProperties = new Properties(); Properties instanceofProperties = new Properties();
Map contexts = new HashMap(); if ( objectExpressions != null && objectExpressions.length > 0 )
contexts.put( "project", project );
contexts.put( "pom", project );
for ( int i = 0; i < objectExpressions.length; i++ )
{ {
String expression = objectExpressions[i]; Map contexts = new HashMap();
getLog().info( "[MAVEN-CORE-IT-LOG] Evaluating expression " + expression ); contexts.put( "project", project );
Object object = ExpressionUtil.evaluate( expression, contexts ); contexts.put( "pom", project );
getLog().info( "[MAVEN-CORE-IT-LOG] Checking object " + object );
if ( object != null ) for ( int i = 0; i < objectExpressions.length; i++ )
{ {
getLog().info( "[MAVEN-CORE-IT-LOG] Loaded object from " + object.getClass().getClassLoader() ); String expression = objectExpressions[i];
getLog().info( "[MAVEN-CORE-IT-LOG] Evaluating expression " + expression );
Object object = ExpressionUtil.evaluate( expression, contexts );
getLog().info( "[MAVEN-CORE-IT-LOG] Checking object " + object );
if ( object != null )
{
getLog().info( "[MAVEN-CORE-IT-LOG] Loaded class " + object.getClass().getName() );
getLog().info( "[MAVEN-CORE-IT-LOG] Loaded class from " + object.getClass().getClassLoader() );
}
instanceofProperties.setProperty( expression.replace( '/', '.' ),
Boolean.toString( type.isInstance( object ) ) );
}
}
if ( components != null && !components.isEmpty() )
{
for ( Iterator it = components.iterator(); it.hasNext(); )
{
Object object = it.next();
getLog().info( "[MAVEN-CORE-IT-LOG] Checking component " + object );
getLog().info( "[MAVEN-CORE-IT-LOG] Loaded class " + object.getClass().getName() );
getLog().info( "[MAVEN-CORE-IT-LOG] Loaded class from " + object.getClass().getClassLoader() );
instanceofProperties.setProperty( object.getClass().getName(),
Boolean.toString( type.isInstance( object ) ) );
} }
instanceofProperties.setProperty( expression.replace( '/', '.' ),
Boolean.toString( type.isInstance( object ) ) );
} }
getLog().info( "[MAVEN-CORE-IT-LOG] Creating output file " + instanceofPropertiesFile ); getLog().info( "[MAVEN-CORE-IT-LOG] Creating output file " + instanceofPropertiesFile );