donaldp 2002/09/13 23:24:34
Added: info/src/java/org/apache/avalon/framework/tools/ant
ComponentVerifierTask.java
Log:
Add an ant task for verifying a Component matches its Info descriptor
Revision Changes Path
1.1
jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/ant/ComponentVerifierTask.java
Index: ComponentVerifierTask.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.avalon.framework.tools.ant;
import org.apache.avalon.framework.info.ComponentInfo;
import org.apache.avalon.framework.logger.ConsoleLogger;
import org.apache.avalon.framework.tools.infobuilder.ComponentInfoBuilder;
import org.apache.avalon.framework.tools.verifier.InfoVerifier;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.Path;
/**
* Simple task to load a [EMAIL PROTECTED] ComponentInfo} descriptor,
* a component class and verify that the implementation class
* is compatible with the [EMAIL PROTECTED] ComponentInfo}.
*
* @author <a href="mailto:peter at apache.org">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2002/09/14 06:24:34 $
*/
public class ComponentVerifierTask
extends Task
{
private Path m_classpath;
private String m_classname;
public void setClassname( String classname )
{
m_classname = classname;
}
public Path createClasspath()
{
if( m_classpath == null )
{
m_classpath = new Path( getProject() );
}
return m_classpath.createPath();
}
public void execute()
throws BuildException
{
if( null == m_classname )
{
final String message = "User did not specify classname";
throw new BuildException( message );
}
if( null == m_classpath )
{
final String message = "User did not specify classpath";
throw new BuildException( message );
}
final AntClassLoader classLoader = new AntClassLoader( getProject(),
m_classpath );
final ComponentInfoBuilder builder = new ComponentInfoBuilder();
builder.enableLogging( new ConsoleLogger() );
final InfoVerifier verifier = new InfoVerifier();
verifier.enableLogging( new ConsoleLogger() );
try
{
final Class implementation =
classLoader.loadClass( m_classname );
final ComponentInfo componentInfo =
builder.build( implementation );
verifier.verifyType( "test",
m_classname,
componentInfo,
implementation );
}
catch( final Exception e )
{
final String message =
"Failed to validate " + m_classname + " due to " + e;
throw new BuildException( message, e );
}
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>