donaldp 2002/11/15 21:49:50
Modified: info/src/java/org/apache/avalon/framework/tools/ant
MetaGenerateTask.java
info/src/test/org/apache/avalon/framework/tools/infobuilder/test
InfoBuilderTestCase.java
Added: info/src/java/org/apache/avalon/framework/tools/qdox
LegacyInfoBuilder.java
info/src/test/org/apache/avalon/framework/tools/infobuilder/test/data
QDoxLegacyComponent1-info.xml
QDoxLegacyComponent1.java
Log:
Add support for generating ComponentInfo objects from Phoenixs javadoc markup
Revision Changes Path
1.4 +9 -3
jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/ant/MetaGenerateTask.java
Index: MetaGenerateTask.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/ant/MetaGenerateTask.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- MetaGenerateTask.java 16 Nov 2002 05:15:45 -0000 1.3
+++ MetaGenerateTask.java 16 Nov 2002 05:49:49 -0000 1.4
@@ -19,6 +19,7 @@
import org.apache.avalon.framework.tools.infobuilder.InfoWriter;
import org.apache.avalon.framework.tools.infobuilder.XMLInfoWriter;
import org.apache.avalon.framework.tools.qdox.DefaultInfoBuilder;
+import org.apache.avalon.framework.tools.qdox.LegacyInfoBuilder;
import org.apache.avalon.framework.tools.ant.FormatEnum;
import org.apache.tools.ant.BuildException;
@@ -133,7 +134,7 @@
{
final JavaClass javaClass = (JavaClass)allClasses.get( i );
ComponentInfo info = null;
- final DocletTag tag = javaClass.getTagByName( "avalon.component" );
+ DocletTag tag = javaClass.getTagByName( "avalon.component" );
if( null != tag )
{
final DefaultInfoBuilder infoBuilder = new DefaultInfoBuilder();
@@ -141,7 +142,12 @@
}
else
{
-
+ tag = javaClass.getTagByName( "phoenix:block" );
+ if( null != tag )
+ {
+ final LegacyInfoBuilder infoBuilder = new LegacyInfoBuilder();
+ info = infoBuilder.buildComponentInfo( javaClass );
+ }
}
//If we have built an info object
1.1
jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/qdox/LegacyInfoBuilder.java
Index: LegacyInfoBuilder.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 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.SchemaDescriptor;
import org.apache.avalon.framework.info.ServiceDescriptor;
/**
* Build a ComponentInfo object by interpreting Phoenix style javadoc
* markup in source.
*
* @author Paul Hammant
* @author <a href="mailto:peter at apache.org">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2002/11/16 05:49:49 $
*/
public class LegacyInfoBuilder
extends AbstractInfoBuilder
{
/**
* Build a ComponentInfo object for specified class.
*
* @param javaClass the class
* @return the ComponentInfo object
*/
public ComponentInfo buildComponentInfo( final JavaClass javaClass )
{
final ComponentDescriptor component = buildComponent( javaClass );
final ServiceDescriptor[] services = buildServices( javaClass );
final ContextDescriptor context = buildPhoenixContext();
final LoggerDescriptor[] loggers = new LoggerDescriptor[ 0 ];
final SchemaDescriptor schema = buildSchema( javaClass );
final DependencyDescriptor[] dependencies = buildDependencies( javaClass );
return new ComponentInfo( component, services, loggers, context,
dependencies, schema );
}
/**
* A utility method to build a descriptor for Phoenixs BlockContext
* object,
*
* @return the a descriptor for Phoenixs BlockContext object,
*/
private ContextDescriptor buildPhoenixContext()
{
return new ContextDescriptor( "org.apache.avalon.phoenix.BlockContext",
new EntryDescriptor[ 0 ],
new Attribute[ 0 ] );
}
/**
* Build the component descriptor for specified class.
*
* @param javaClass the class
* @return the component descriptor
*/
private ComponentDescriptor buildComponent( final JavaClass javaClass )
{
final String type = javaClass.getFullyQualifiedName();
return new ComponentDescriptor( type, 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( "phoenix:service" );
for( int i = 0; i < tags.length; i++ )
{
final String type = getNamedParameter( tags[ i ], "name" );
final ServiceDescriptor service = new ServiceDescriptor( type,
EMPTY_ATTRIBUTES );
services.add( service );
}
return (ServiceDescriptor[])services.toArray( new ServiceDescriptor[
services.size() ] );
}
/**
* Build the schema descriptor for specified class.
*
* @param javaClass the class
* @return the schema descriptor
*/
private SchemaDescriptor buildSchema( final JavaClass javaClass )
{
final JavaMethod method =
getLifecycleMethod( javaClass, "configure", CONFIGURATION_CLASS );
if( null != method )
{
final DocletTag tag =
method.getTagByName( "phoenix:configuration-schema" );
if( null != tag )
{
final String type = getNamedParameter( tag, "type", "" );
//TODO: Translate type into a uri type string
return new SchemaDescriptor( "configuration",
"", type, EMPTY_ATTRIBUTES );
}
}
return new SchemaDescriptor( "", "", "", new Attribute[ 0 ] );
}
/**
* 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( "phoenix:dependency" );
for( int i = 0; i < tags.length; i++ )
{
final DocletTag tag = tags[ i ];
final String unresolvedType = getNamedParameter( tag, "name" );
final String type = resolveType( javaClass, unresolvedType );
final String key = getNamedParameter( tag, "role", type );
final DependencyDescriptor dependency =
new DependencyDescriptor( key, type, false, EMPTY_ATTRIBUTES );
deps.add( dependency );
}
return (DependencyDescriptor[])deps.toArray( new DependencyDescriptor[
deps.size() ] );
}
}
}
1.15 +54 -34
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.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- InfoBuilderTestCase.java 16 Nov 2002 05:15:45 -0000 1.14
+++ InfoBuilderTestCase.java 16 Nov 2002 05:49:49 -0000 1.15
@@ -7,37 +7,37 @@
*/
package org.apache.avalon.framework.tools.infobuilder.test;
+import com.thoughtworks.qdox.JavaDocBuilder;
+import com.thoughtworks.qdox.model.JavaClass;
+import com.thoughtworks.qdox.model.JavaSource;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.util.Properties;
import junit.framework.TestCase;
-import org.apache.avalon.framework.info.ComponentInfo;
-import org.apache.avalon.framework.info.DependencyDescriptor;
+import org.apache.avalon.framework.container.ContainerUtil;
import org.apache.avalon.framework.info.Attribute;
-import org.apache.avalon.framework.info.LoggerDescriptor;
import org.apache.avalon.framework.info.ComponentDescriptor;
-import org.apache.avalon.framework.info.EntryDescriptor;
+import org.apache.avalon.framework.info.ComponentInfo;
import org.apache.avalon.framework.info.ContextDescriptor;
-import org.apache.avalon.framework.info.ServiceDescriptor;
+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.SchemaDescriptor;
+import org.apache.avalon.framework.info.ServiceDescriptor;
import org.apache.avalon.framework.logger.ConsoleLogger;
import org.apache.avalon.framework.tools.infobuilder.InfoBuilder;
-import org.apache.avalon.framework.tools.infobuilder.SerializedInfoWriter;
-import org.apache.avalon.framework.tools.infobuilder.SerializedInfoReader;
-import org.apache.avalon.framework.tools.infobuilder.XMLInfoWriter;
-import org.apache.avalon.framework.tools.infobuilder.InfoWriter;
import org.apache.avalon.framework.tools.infobuilder.InfoReader;
+import org.apache.avalon.framework.tools.infobuilder.InfoWriter;
+import org.apache.avalon.framework.tools.infobuilder.SerializedInfoReader;
+import org.apache.avalon.framework.tools.infobuilder.SerializedInfoWriter;
import org.apache.avalon.framework.tools.infobuilder.XMLInfoReader;
+import org.apache.avalon.framework.tools.infobuilder.XMLInfoWriter;
import org.apache.avalon.framework.tools.qdox.DefaultInfoBuilder;
-import org.apache.avalon.framework.container.ContainerUtil;
-import java.util.Properties;
-import java.util.Arrays;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.FileInputStream;
-import java.io.Reader;
-import java.io.InputStreamReader;
-import java.io.InputStream;
-import com.thoughtworks.qdox.JavaDocBuilder;
-import com.thoughtworks.qdox.model.JavaSource;
-import com.thoughtworks.qdox.model.JavaClass;
+import org.apache.avalon.framework.tools.qdox.LegacyInfoBuilder;
/**
* Abstract class which TestCases can extend.
@@ -60,6 +60,9 @@
private static final String SOURCE1 = BASE_DIR + "QDoxComponent1.java";
private static final String SOURCE1_INFO = BASE_PACKAGE + "QDoxComponent1";
+ private static final String LSOURCE1 = BASE_DIR + "QDoxLegacyComponent1.java";
+ private static final String LSOURCE1_INFO = BASE_PACKAGE +
"QDoxLegacyComponent1";
+
public InfoBuilderTestCase( String name )
{
super( name );
@@ -106,9 +109,34 @@
public void testQDoxScan()
throws Exception
{
+ final ComponentInfo expected = loadComponentInfo( SOURCE1_INFO );
+ final JavaClass javaClass = loadJavaSource( SOURCE1 );
+ final DefaultInfoBuilder infoBuilder = new DefaultInfoBuilder();
+ final ComponentInfo actual = infoBuilder.buildComponentInfo( javaClass );
+
+ InfoAssert.assertEqualInfos( " ComponentInfo generated from source file",
+ expected,
+ actual );
+ }
+
+ public void testLegacyQDoxScan()
+ throws Exception
+ {
+ final ComponentInfo expected = loadComponentInfo( LSOURCE1_INFO );
+ final JavaClass javaClass = loadJavaSource( LSOURCE1 );
+ final LegacyInfoBuilder infoBuilder = new LegacyInfoBuilder();
+ final ComponentInfo actual = infoBuilder.buildComponentInfo( javaClass );
+
+ InfoAssert.assertEqualInfos( " ComponentInfo generated from source file",
+ expected,
+ actual );
+ }
+
+ private JavaClass loadJavaSource( final String resource )
+ {
final JavaDocBuilder builder = new JavaDocBuilder();
- final InputStream inputStream = getClass().getResourceAsStream( SOURCE1 );
- assertNotNull( "resource " + SOURCE1 + " not null", inputStream );
+ final InputStream inputStream = getClass().getResourceAsStream( resource );
+ assertNotNull( "resource " + resource + " not null", inputStream );
final Reader reader = new InputStreamReader( inputStream );
builder.addSource( reader );
@@ -117,16 +145,8 @@
final JavaSource source = sources[ 0 ];
final JavaClass[] classes = source.getClasses();
assertEquals( "source.getClasses()", 1, classes.length );
-
- System.out.println( "source.getImports() = " + Arrays.asList(
source.getImports() ) );
-
- final DefaultInfoBuilder infoBuilder = new DefaultInfoBuilder();
- final ComponentInfo actual = infoBuilder.buildComponentInfo( classes[ 0 ] );
- final ComponentInfo expected = loadComponentInfo( SOURCE1_INFO );
-
- InfoAssert.assertEqualInfos( " ComponentInfo generated from source file",
- expected,
- actual );
+ final JavaClass javaClass = classes[ 0 ];
+ return javaClass;
}
private void runWriteReadTest( final ComponentInfo expected,
1.1
jakarta-avalon-excalibur/info/src/test/org/apache/avalon/framework/tools/infobuilder/test/data/QDoxLegacyComponent1-info.xml
Index: QDoxLegacyComponent1-info.xml
===================================================================
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE component-info
PUBLIC "-//AVALON/Component Info DTD Version 1.0//EN"
"http://jakarta.apache.org/avalon/dtds/info/componentinfo_1_0.dtd" >
<component-info>
<component
type="org.apache.avalon.framework.tools.infobuilder.test.data.QDoxLegacyComponent1"/>
<context type="org.apache.avalon.phoenix.BlockContext" />
<services>
<service
type="org.apache.avalon.framework.tools.infobuilder.test.data.Service1"/>
<service
type="org.apache.avalon.framework.tools.infobuilder.test.data.otherpkg.Service2"/>
<service
type="org.apache.avalon.framework.tools.infobuilder.test.data.otherpkg.Service3"/>
</services>
<dependencies>
<dependency key="foo"
type="org.apache.avalon.framework.tools.infobuilder.test.data.otherpkg.Service3"/>
<dependency
type="org.apache.avalon.framework.tools.infobuilder.test.data.otherpkg.Service3"/>
<dependency
type="org.apache.avalon.framework.tools.infobuilder.test.data.otherpkg.Service2"/>
</dependencies>
<schema category="configuration" type="rlng"/>
</component-info>
1.1
jakarta-avalon-excalibur/info/src/test/org/apache/avalon/framework/tools/infobuilder/test/data/QDoxLegacyComponent1.java
Index: QDoxLegacyComponent1.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.infobuilder.test.data;
import java.io.Serializable;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
import org.apache.avalon.framework.tools.infobuilder.test.data.otherpkg.Service2;
import org.apache.avalon.framework.tools.infobuilder.test.data.otherpkg.Service3;
/**
* A simple avalon component to test QDox loading of info etc.
*
* @author <a href="mailto:peter at apache.org">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2002/11/16 05:49:49 $
* @avalon.component
* @phoenix:service
name="org.apache.avalon.framework.tools.infobuilder.test.data.Service1"
* @phoenix:service
name="org.apache.avalon.framework.tools.infobuilder.test.data.otherpkg.Service2"
* @phoenix:service
name="org.apache.avalon.framework.tools.infobuilder.test.data.otherpkg.Service3"
*/
public class QDoxLegacyComponent1
extends AbstractLogEnabled
implements Serializable, Service1, Service2, Service3, Serviceable, Configurable
{
/**
* @phoenix:dependency role="foo"
name="org.apache.avalon.framework.tools.infobuilder.test.data.otherpkg.Service3"
* @phoenix:dependency
name="org.apache.avalon.framework.tools.infobuilder.test.data.otherpkg.Service3"
* @phoenix:dependency
name="org.apache.avalon.framework.tools.infobuilder.test.data.otherpkg.Service2"
*/
public void service( ServiceManager manager )
throws ServiceException
{
}
/**
* @phoenix:configuration-schema type="rlng"
*/
public void configure( Configuration configuration )
throws ConfigurationException
{
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>