donaldp 2002/11/11 22:55:42
Modified: info build.xml
info/src/test/org/apache/avalon/framework/tools/infobuilder/test
InfoBuilderTestCase.java
Added: info/src/java/org/apache/avalon/framework/tools/ant
FormatEnum.java MetaGenerateTask.java
info/src/java/org/apache/avalon/framework/tools/qdox
QDoxInfoBuilder.java
Removed: info/src/java/org/apache/avalon/framework/tools/generator
FormatEnum.java MetaGenerateTask.java
QDoxInfoBuilder.java
Log:
Migrate all the ant tasks to ant package and the QDox processor to a new qdox package
Revision Changes Path
1.4 +7 -0 jakarta-avalon-excalibur/info/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/info/build.xml,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- build.xml 11 Nov 2002 23:52:02 -0000 1.3
+++ build.xml 12 Nov 2002 06:55:41 -0000 1.4
@@ -97,6 +97,13 @@
<include name="**/*.java"/>
</javac>
+ <!-- copy the java source files across so we can read them in for tests -->
+ <copy todir="${build.testclasses}">
+ <fileset dir="${test.dir}">
+ <include name="**/data/**/*.java"/>
+ </fileset>
+ </copy>
+
<copy todir="${build.testclasses}">
<fileset dir="${test.dir}">
<exclude name="**/*.java"/>
1.1
jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/ant/FormatEnum.java
Index: FormatEnum.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.tools.ant.types.EnumeratedAttribute;
/**
* This is an enumeration that gives the option of either
* outputting as xml or as a serialized format.
*
* @author <a href="mailto:peter at apache.org">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2002/11/12 06:55:41 $
*/
public class FormatEnum
extends EnumeratedAttribute
{
public String[] getValues()
{
return new String[]{"xml", "serialized"};
}
}
1.1
jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/ant/MetaGenerateTask.java
Index: MetaGenerateTask.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 com.thoughtworks.qdox.ant.AbstractQdoxTask;
import com.thoughtworks.qdox.model.DocletTag;
import com.thoughtworks.qdox.model.JavaClass;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.FileOutputStream;
import org.apache.avalon.framework.info.ComponentInfo;
import org.apache.avalon.framework.tools.infobuilder.SerializedInfoWriter;
import org.apache.avalon.framework.tools.infobuilder.InfoWriter;
import org.apache.avalon.framework.tools.infobuilder.XMLInfoWriter;
import org.apache.avalon.framework.tools.qdox.QDoxInfoBuilder;
import org.apache.avalon.framework.tools.ant.FormatEnum;
import org.apache.tools.ant.BuildException;
/**
* Generate MetaData for info package from the source files.
* See XXXXXXX for a description of the format in which the
*
* @author Paul Hammant
* @author <a href="mailto:peter at apache.org">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2002/11/12 06:55:41 $
*/
public final class MetaGenerateTask
extends AbstractQdoxTask
{
/**
* A utility object that writes out info as xml files.
*/
private static final InfoWriter c_xmlWriter = new XMLInfoWriter();
/**
* A utility object that writes out info as serialized object files.
*/
private static final InfoWriter c_serWriter = new SerializedInfoWriter();
/**
* The destination directory for metadata files.
*/
private File m_destDir;
/**
* Variable that indicates whether the output
* should be done as xml (if true) or as serialized
* objests (if false).
*/
private boolean m_xmlOutput = true;
/**
* Set the desitation directory to generate output files to.
*
* @param destDir The destination directory
*/
public void setDestDir( final File destDir )
{
m_destDir = destDir;
}
/**
* Specify the output format. Must be one of xml or serialized.
*
* @param format the output format
*/
public void setFormat( final FormatEnum format )
{
m_xmlOutput = "xml".equals( format.getValue() );
}
/**
* Execute generator task.
*/
public void execute()
throws BuildException
{
if( null == m_destDir )
{
final String message = "DestDir not specified";
throw new BuildException( message );
}
if( !m_destDir.isDirectory() )
{
final String message = "DestDir is not a directory.";
throw new BuildException( message );
}
if( !m_destDir.mkdirs() )
{
final String message = "DestDir could not be created.";
throw new BuildException( message );
}
String message = "Writing Info descriptors as ";
if( m_xmlOutput )
{
message += "xml.";
}
else
{
message += "serialized objects.";
}
log( message );
super.execute();
try
{
writeInfoMetaData();
}
catch( final Exception e )
{
throw new BuildException( e.toString(), e );
}
}
/**
* Output the metadata files.
*
* @throws java.io.IOException If a problem writing output
*/
private void writeInfoMetaData() throws IOException
{
final int size = allClasses.size();
for( int i = 0; i < size; i++ )
{
final JavaClass javaClass = (JavaClass)allClasses.get( i );
final DocletTag tag = javaClass.getTagByName( "avalon.component" );
if( null != tag )
{
final QDoxInfoBuilder infoBuilder = new QDoxInfoBuilder();
final ComponentInfo info = infoBuilder.buildComponentInfo( javaClass
);
final String fqn = javaClass.getFullyQualifiedName();
final String filename =
fqn.replace( '.', File.separatorChar ) + "-info";
final String baseFile =
new File( m_destDir, filename ).getCanonicalPath();
InfoWriter writer;
String extension;
if( m_xmlOutput )
{
extension = ".xml";
writer = c_xmlWriter;
}
else
{
extension = ".ser";
writer = c_serWriter;
}
final String fullFilename = baseFile + extension;
final OutputStream outputStream = new FileOutputStream( fullFilename
);
try
{
writer.writeComponentInfo( info, outputStream );
}
catch( final Exception e )
{
log( "Error writing " + fullFilename + ". Cause: " + e );
}
finally
{
shutdownStream( outputStream );
}
}
}
}
/**
* Close the specified output stream and swallow any exceptions.
*
* @param outputStream the output stream
*/
private void shutdownStream( final OutputStream outputStream )
{
if( null != outputStream )
{
try
{
outputStream.close();
}
catch( IOException e )
{
}
}
}
}
1.1
jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/qdox/QDoxInfoBuilder.java
Index: QDoxInfoBuilder.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.qdox;
import com.thoughtworks.qdox.model.DocletTag;
import com.thoughtworks.qdox.model.JavaClass;
import com.thoughtworks.qdox.model.JavaMethod;
import com.thoughtworks.qdox.model.Type;
import java.util.ArrayList;
import org.apache.avalon.framework.info.Attribute;
import org.apache.avalon.framework.info.ComponentDescriptor;
import org.apache.avalon.framework.info.ComponentInfo;
import org.apache.avalon.framework.info.ContextDescriptor;
import org.apache.avalon.framework.info.DependencyDescriptor;
import org.apache.avalon.framework.info.EntryDescriptor;
import org.apache.avalon.framework.info.LoggerDescriptor;
import org.apache.avalon.framework.info.ServiceDescriptor;
/**
* This is a utility class that is used to build a ComponentInfo object
* from QDoxs JavaClass object model. This essentially involves interpreting
* all of the javadoc tags present in JavaClass object model.
*
* @author <a href="mailto:peter at apache.org">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2002/11/12 06:55:42 $
*/
public class QDoxInfoBuilder
{
private static final String CONTEXT_CLASS =
"org.apache.avalon.framework.context.Context";
private static final String LOGGER_CLASS =
"org.apache.avalon.framework.logger.Logger";
private static final String COMPONENT_MANAGER_CLASS =
"org.apache.avalon.framework.component.ComponentManager";
private static final String SERVICE_MANAGER_CLASS =
"org.apache.avalon.framework.service.ServiceManager";
private static final Attribute[] EMPTY_ATTRIBUTES = new Attribute[ 0 ];
/**
* Build a ComponentInfo object for specified class.
*
* @param javaClass the class
* @return the ComponentInfo object
*/
public ComponentInfo buildComponentInfo( final JavaClass javaClass )
{
final ComponentDescriptor component = buildComponentDescriptor( javaClass );
final ContextDescriptor context = buildContextDescriptor( javaClass );
final LoggerDescriptor[] loggers = buildLoggers( javaClass );
final ServiceDescriptor[] services = buildServices( javaClass );
final DependencyDescriptor[] dependencies = buildDependencies( javaClass );
return new ComponentInfo( component, loggers, context, services,
dependencies );
}
/**
* Build the component descriptor for specified class.
*
* @param javaClass the class
* @return the component descriptor
*/
private ComponentDescriptor buildComponentDescriptor( final JavaClass javaClass )
{
final String type = javaClass.getFullyQualifiedName();
return new ComponentDescriptor( type, EMPTY_ATTRIBUTES );
}
/**
* Build the set of logger descriptors for specified class.
*
* @param javaClass the class
* @return the set of logger descriptors
*/
private LoggerDescriptor[] buildLoggers( final JavaClass javaClass )
{
final JavaMethod method =
getLifecycleMethod( javaClass, "enableLogging", LOGGER_CLASS );
if( null == method )
{
return new LoggerDescriptor[ 0 ];
}
else
{
final ArrayList loggers = new ArrayList();
final DocletTag[] tags = method.getTagsByName( "avalon.logger" );
for( int i = 0; i < tags.length; i++ )
{
final String name =
getNamedParameter( tags[ i ], "name", "" );
final LoggerDescriptor logger =
new LoggerDescriptor( name, EMPTY_ATTRIBUTES );
loggers.add( logger );
}
return (LoggerDescriptor[])loggers.toArray( new LoggerDescriptor[
loggers.size() ] );
}
}
/**
* Build the context descriptor for specified class.
*
* @param javaClass the class
* @return the context descriptor
*/
private ContextDescriptor buildContextDescriptor( final JavaClass javaClass )
{
final JavaMethod method =
getLifecycleMethod( javaClass, "contextualize", CONTEXT_CLASS );
if( null == method )
{
return new ContextDescriptor( CONTEXT_CLASS,
new EntryDescriptor[ 0 ],
EMPTY_ATTRIBUTES );
}
else
{
String type = CONTEXT_CLASS;
final DocletTag tag = method.getTagByName( "avalon.context" );
if( null != tag && null != tag.getNamedParameter( "type" ) )
{
final String value = getNamedParameter( tag, "type" );
type = resolveType( javaClass, value );
}
final ArrayList entrySet = new ArrayList();
final DocletTag[] tags = method.getTagsByName( "avalon.entry" );
for( int i = 0; i < tags.length; i++ )
{
final String key = getNamedParameter( tags[ i ], "key" );
final String entryType = getNamedParameter( tags[ i ], "type" );
final String optional = getNamedParameter( tags[ i ], "optional",
"false" );
final boolean isOptional = "true".equals( optional );
final EntryDescriptor entry =
new EntryDescriptor( key, entryType, isOptional,
EMPTY_ATTRIBUTES );
entrySet.add( entry );
}
final EntryDescriptor[] entrys =
(EntryDescriptor[])entrySet.toArray( new EntryDescriptor[
entrySet.size() ] );
return new ContextDescriptor( type, entrys, EMPTY_ATTRIBUTES );
}
}
/**
* Build the set of service descriptors for specified class.
*
* @param javaClass the class
* @return the set of service descriptors
*/
private ServiceDescriptor[] buildServices( final JavaClass javaClass )
{
final ArrayList services = new ArrayList();
final DocletTag[] tags = javaClass.getTagsByName( "avalon.service" );
for( int i = 0; i < tags.length; i++ )
{
final DocletTag tag = tags[ i ];
final String unresolvedType = getNamedParameter( tag, "type" );
final String type = resolveType( javaClass, unresolvedType );
final ServiceDescriptor service = new ServiceDescriptor( type,
EMPTY_ATTRIBUTES );
services.add( service );
}
return (ServiceDescriptor[])services.toArray( new ServiceDescriptor[
services.size() ] );
}
/**
* Build the set of dependency descriptors for specified class.
*
* @param javaClass the class
* @return the set of dependency descriptors
*/
private DependencyDescriptor[] buildDependencies( final JavaClass javaClass )
{
JavaMethod method =
getLifecycleMethod( javaClass, "compose", COMPONENT_MANAGER_CLASS );
//If no compose then try for a service method ...
if( null == method )
{
method =
getLifecycleMethod( javaClass, "service", SERVICE_MANAGER_CLASS );
}
if( null == method )
{
return new DependencyDescriptor[ 0 ];
}
else
{
final ArrayList deps = new ArrayList();
final DocletTag[] tags = method.getTagsByName( "avalon.dependency" );
for( int i = 0; i < tags.length; i++ )
{
final DocletTag tag = tags[ i ];
final String unresolvedType = getNamedParameter( tag, "type" );
final String type = resolveType( javaClass, unresolvedType );
final String key = getNamedParameter( tag, "key", type );
final String optional = getNamedParameter( tag, "optional", "false"
);
final boolean isOptional = "true".equals( optional );
final DependencyDescriptor dependency =
new DependencyDescriptor( key, type, isOptional,
EMPTY_ATTRIBUTES );
deps.add( dependency );
}
return (DependencyDescriptor[])deps.toArray( new DependencyDescriptor[
deps.size() ] );
}
}
/**
* Resolve the specified type.
* Resolving essentially means finding the fully qualified name of
* a class from just it's short name.
*
* @param javaClass the java class relative to which the type must be resolved
* @param type the unresolved type
* @return the resolved type
*/
private String resolveType( final JavaClass javaClass,
final String type )
{
return javaClass.getParentSource().resolveType( type );
}
/**
* Retrieve a method with specified name and one parameter of specified
* type. The method must also return void.
*
* @param javaClass the java class to retrieve method for
* @param methodName the name of the method
* @param parameterType the class name of parameter
* @return the method if such a method exists
*/
private JavaMethod getLifecycleMethod( final JavaClass javaClass,
final String methodName,
final String parameterType )
{
final JavaMethod[] methods = javaClass.getMethods();
for( int i = 0; i < methods.length; i++ )
{
final JavaMethod method = methods[ i ];
if( methodName.equals( method.getName() ) &&
method.getReturns().equals( new Type( "void", 0 ) ) &&
method.getParameters().length == 1 &&
method.getParameters()[ 0 ].getType().getValue().equals(
parameterType ) )
{
return method;
}
}
return null;
}
/**
* Retrieve specified named parameter from tag. If the parameter
* does not exist then return specified default value.
*
* @param tag the tag
* @param name the name of parameter
* @return the value of named parameter
*/
private String getNamedParameter( final DocletTag tag,
final String name,
final String defaultValue )
{
String value = tag.getNamedParameter( name );
if( null == value )
{
return defaultValue;
}
value = value.trim();
if( value.startsWith( "\"" ) || value.startsWith( "'" ) )
{
value = value.substring( 1 );
}
if( value.endsWith( "\"" ) || value.endsWith( "'" ) )
{
value = value.substring( 0, value.length() - 1 );
}
return value;
}
/**
* Retrieve specified named parameter from tag. If the parameter
* does not exist then throw an exception.
*
* @param tag the tag
* @param name the name of parameter
* @return the value of named parameter
*/
private String getNamedParameter( final DocletTag tag, final String name )
{
final String value = getNamedParameter( tag, name, null );
if( null == value )
{
final String message =
"Malformed tag '" + tag.getName() + "'. " +
"Missing required parameter '" + name + "'";
throw new IllegalArgumentException( message );
}
return value;
}
}
1.10 +2 -2
jakarta-avalon-excalibur/info/src/test/org/apache/avalon/framework/tools/infobuilder/test/InfoBuilderTestCase.java
Index: InfoBuilderTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/info/src/test/org/apache/avalon/framework/tools/infobuilder/test/InfoBuilderTestCase.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- InfoBuilderTestCase.java 12 Nov 2002 06:45:43 -0000 1.9
+++ InfoBuilderTestCase.java 12 Nov 2002 06:55:42 -0000 1.10
@@ -27,7 +27,7 @@
import org.apache.avalon.framework.tools.infobuilder.InfoWriter;
import org.apache.avalon.framework.tools.infobuilder.InfoReader;
import org.apache.avalon.framework.tools.infobuilder.XMLInfoReader;
-import org.apache.avalon.framework.tools.generator.QDoxInfoBuilder;
+import org.apache.avalon.framework.tools.qdox.QDoxInfoBuilder;
import org.apache.avalon.framework.container.ContainerUtil;
import java.util.Properties;
import java.util.Arrays;
--
To unsubscribe, e-mail: <mailto:avalon-cvs-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@;jakarta.apache.org>