ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adammurd...@apache.org
Subject cvs commit: jakarta-ant-myrmidon/buildtools/src/java/org/apache/myrmidon/build AntTypeTagHandler.java type.j types.j AntDocSubTask.java AntlibDescriptorTask.java ant-descriptor.j
Date Sat, 01 Jun 2002 06:46:01 GMT
adammurdoch    2002/05/31 23:46:01

  Modified:    buildtools/src/java/org/apache/myrmidon/build
                        AntDocSubTask.java AntlibDescriptorTask.java
                        ant-descriptor.j
  Added:       buildtools/src/java/org/apache/myrmidon/build
                        AntTypeTagHandler.java type.j types.j
  Log:
  Changes to <antlib-descriptor> to generate type docs:
  
  * Added a bunch of xdoclet tags for dealing with types.
  
  * Added a template to generate a doc file per class (format
    is pretty similar to the proposal in the ant1 tree).
  
  * Added a template to generate a summary file.
  
  * Don't generate ant-descriptor.xml or ant-roles.xml unless asked.
  
  Revision  Changes    Path
  1.4       +3 -9      jakarta-ant-myrmidon/buildtools/src/java/org/apache/myrmidon/build/AntDocSubTask.java
  
  Index: AntDocSubTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/buildtools/src/java/org/apache/myrmidon/build/AntDocSubTask.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AntDocSubTask.java	6 May 2002 09:29:44 -0000	1.3
  +++ AntDocSubTask.java	1 Jun 2002 06:46:01 -0000	1.4
  @@ -12,12 +12,13 @@
   import xdoclet.TemplateSubTask;
   import xdoclet.XDocletException;
   import xjavadoc.XClass;
  +import xjavadoc.XTag;
   
   /**
    * Generates the XML Documentation for Ant types (including tasks and DataTypes).
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.3 $ $Date: 2002/05/06 09:29:44 $
  + * @version $Revision: 1.4 $ $Date: 2002/06/01 06:46:01 $
    */
   public class AntDocSubTask
       extends TemplateSubTask
  @@ -76,13 +77,6 @@
           {
               return false;
           }
  -        else if( clazz.isAbstract() )
  -        {
  -            return false;
  -        }
  -        else
  -        {
  -            return true;
  -        }
  +        return AntTypeTagHandler.hasTypeTag( clazz );
       }
   }
  
  
  
  1.6       +16 -48    jakarta-ant-myrmidon/buildtools/src/java/org/apache/myrmidon/build/AntlibDescriptorTask.java
  
  Index: AntlibDescriptorTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/buildtools/src/java/org/apache/myrmidon/build/AntlibDescriptorTask.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AntlibDescriptorTask.java	29 May 2002 13:03:32 -0000	1.5
  +++ AntlibDescriptorTask.java	1 Jun 2002 06:46:01 -0000	1.6
  @@ -23,20 +23,12 @@
   {
       private static final String DESCRIPTOR_TEMPLATE = "/org/apache/myrmidon/build/ant-descriptor.j";
       private static final String ROLES_TEMPLATE = "/org/apache/myrmidon/build/ant-roles.j";
  +    private static final String TYPES_TEMPLATE = "/org/apache/myrmidon/build/types.j";
   
  -    private String m_libName;
       private String m_descriptorFileName;
       private String m_rolesFileName;
   
       /**
  -     * Specifies the Antlib name, which is used to name the generated files.
  -     */
  -    public void setLibName( final String libName )
  -    {
  -        m_libName = libName;
  -    }
  -
  -    /**
        * Specifies the name of the file for the antlib types descriptor (optional).
        */
       public void setDescriptorName( final String descriptorFileName )
  @@ -55,6 +47,8 @@
       public void addAntdoc( final AntDocSubTask antDocs )
       {
           addTemplate( antDocs );
  +        final TemplateSubTask typesTemplate = makeTemplateSubTask( TYPES_TEMPLATE, "types.xml"
);
  +        addTemplate( typesTemplate );
       }
   
       /**
  @@ -65,13 +59,19 @@
       protected void validateSubTasks() throws BuildException
       {
           // Add template subtasks.
  -        final TemplateSubTask descriptorTemplate =
  -            makeTemplateSubTask( DESCRIPTOR_TEMPLATE, getDescriptorFileName() );
  -        addTemplate( descriptorTemplate );
  -
  -        final TemplateSubTask rolesTemplate =
  -            makeTemplateSubTask( ROLES_TEMPLATE, getRolesFileName() );
  -        addTemplate( rolesTemplate );
  +        if( m_descriptorFileName != null )
  +        {
  +            final TemplateSubTask descriptorTemplate =
  +                makeTemplateSubTask( DESCRIPTOR_TEMPLATE, m_descriptorFileName );
  +            addTemplate( descriptorTemplate );
  +        }
  +
  +        if( m_rolesFileName != null )
  +        {
  +            final TemplateSubTask rolesTemplate =
  +                makeTemplateSubTask( ROLES_TEMPLATE, m_rolesFileName );
  +            addTemplate( rolesTemplate );
  +        }
   
           super.validateSubTasks();
       }
  @@ -88,37 +88,5 @@
           templateSubTask.setTemplateURL( resource );
           templateSubTask.setDestinationFile( destinationFile );
           return templateSubTask;
  -    }
  -
  -    /**
  -     * Return the filename for the antlib type descriptor. If not specified,
  -     * the default filename is returned.
  -     */
  -    private String getDescriptorFileName()
  -    {
  -        if( m_descriptorFileName == null )
  -        {
  -            return m_libName + "-ant-descriptor.xml";
  -        }
  -        else
  -        {
  -            return m_descriptorFileName;
  -        }
  -    }
  -
  -    /**
  -     * Return the filename for the antlib roles descriptor. If not specified,
  -     * the default filename is returned.
  -     */
  -    private String getRolesFileName()
  -    {
  -        if( m_rolesFileName == null )
  -        {
  -            return m_libName + "-ant-roles.xml";
  -        }
  -        else
  -        {
  -            return m_rolesFileName;
  -        }
       }
   }
  
  
  
  1.5       +4 -13     jakarta-ant-myrmidon/buildtools/src/java/org/apache/myrmidon/build/ant-descriptor.j
  
  Index: ant-descriptor.j
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/buildtools/src/java/org/apache/myrmidon/build/ant-descriptor.j,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ant-descriptor.j	29 May 2002 10:50:35 -0000	1.4
  +++ ant-descriptor.j	1 Jun 2002 06:46:01 -0000	1.5
  @@ -1,18 +1,14 @@
  +<XDtTagDef:tagDef namespace="Ant" handler="org.apache.myrmidon.build.AntTypeTagHandler"/>
   <ant-lib version="1.0">
   
     <types>
   
       <XDtClass:forAllClasses extent="concrete-type">
   
  -      <XDtClass:forAllClassTags tagName="ant.task" superclasses="false">
  -        <task name="<XDtClass:classTagValue tagName="ant.task" paramName="name"/>"
  +      <XDtAnt:forAllTypeTags>
  +        <<XDtAnt:typeTagRoleName/> name="<XDtAnt:typeTagTypeName/>"
                 classname="<XDtClass:fullClassName/>"/>
  -      </XDtClass:forAllClassTags>
  -
  -      <XDtClass:forAllClassTags tagName="ant.data-type" superclasses="false">
  -        <data-type name="<XDtClass:classTagValue tagName="ant.data-type" paramName="name"/>"
  -              classname="<XDtClass:fullClassName/>"/>
  -      </XDtClass:forAllClassTags>
  +      </XDtAnt:forAllTypeTags>
   
         <XDtClass:forAllClassTags tagName="ant.service-factory" superclasses="false">
           <service-factory name="<XDtClass:classTagValue tagName="ant.service-factory"
paramName="role"/>"
  @@ -25,11 +21,6 @@
                      destination="<XDtClass:classTagValue tagName="ant.converter" paramName="destination"/>"/>
         </XDtClass:forAllClassTags>
   
  -      <XDtClass:forAllClassTags tagName="ant.type" superclasses="false">
  -        <<XDtClass:classTagValue tagName="ant.type" paramName="type" superclasses="false"/>
  -          name="<XDtClass:classTagValue tagName="ant.type" paramName="name" superclasses="false"/>"
  -          classname="<XDtClass:fullClassName/>" />
  -      </XDtClass:forAllClassTags>
       </XDtClass:forAllClasses>
   
     </types>
  
  
  
  1.1                  jakarta-ant-myrmidon/buildtools/src/java/org/apache/myrmidon/build/AntTypeTagHandler.java
  
  Index: AntTypeTagHandler.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.myrmidon.build;
  
  import java.util.ArrayList;
  import java.util.List;
  import java.util.Map;
  import java.util.HashMap;
  import java.util.Collection;
  import xdoclet.XDocletException;
  import xdoclet.XDocletTagSupport;
  import xjavadoc.XClass;
  import xjavadoc.XTag;
  import xjavadoc.XMethod;
  import xjavadoc.XParameter;
  
  /**
   * Handler for Ant xdoclet tags.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/06/01 06:46:01 $
   */
  public class AntTypeTagHandler
      extends XDocletTagSupport
  {
      /**
       * Iterates over the type tags of the current class.
       */
      public void forAllTypeTags( final String template ) throws XDocletException
      {
          final XClass currentClass = getCurrentClass();
          final XTag[] tags = getTypeTags( currentClass );
  
          for( int i = 0; i < tags.length; i++ )
          {
              final XTag tag = tags[ i ];
              setCurrentClassTag( tag );
              generate( template );
          }
      }
  
      /**
       * Returns the role name of the current type tag
       */
      public String typeTagRoleName() throws XDocletException
      {
          final XTag tag = getCurrentClassTag();
          if( tag.getName().equals( "ant.task" ) )
          {
              return "task";
          }
          else if( tag.getName().equals( "ant.data-type" ) )
          {
              return "data-type";
          }
          else
          {
              return tag.getAttributeValue( "type" );
          }
      }
  
      /**
       * Returns the type name of the current type tag.
       */
      public String typeTagTypeName()
      {
          final XTag tag = getCurrentClassTag();
          return tag.getAttributeValue( "name" );
      }
  
      /**
       * Iterates over the attributes of the current class.
       */
      public void forAllAttributes( final String template )
          throws XDocletException
      {
          final XClass currentClass = getCurrentClass();
          final XMethod[] methods = getPropertyMethods( currentClass, "set", false );
  
          for( int i = 0; i < methods.length; i++ )
          {
              setCurrentMethod( methods[ i ] );
              generate( template );
          }
      }
  
      /**
       * Iterates over the elements of the current class.
       */
      public void forAllElements( final String template )
          throws XDocletException
      {
          final XClass currentClass = getCurrentClass();
          final XMethod[] methods = getPropertyMethods( currentClass, "add", false );
  
          for( int i = 0; i < methods.length; i++ )
          {
              final XMethod method = methods[ i ];
              if( method.getName().equals( "addContent" ) )
              {
                  continue;
              }
              setCurrentMethod( method );
              generate( template );
          }
      }
  
      /**
       * Block tag that gets generated if the current class has text content.
       */
      public void ifHasContent( final String template )
          throws XDocletException
      {
          final XClass currentClass = getCurrentClass();
          final XMethod[] methods = getPropertyMethods( currentClass, "addContent", true );
          if( methods.length > 0 )
          {
              setCurrentMethod( methods[ 0 ] );
              generate( template );
          }
      }
  
      /**
       * Returns the current property name.
       */
      public String propertyName() throws XDocletException
      {
          final XMethod method = getCurrentMethod();
          return method.getName().substring( 3 ).toLowerCase();
      }
  
      /**
       * Returns the current property type.
       */
      public String propertyType() throws XDocletException
      {
          final XMethod method = getCurrentMethod();
          return method.getParameters()[ 0 ].getType().getQualifiedName();
      }
  
      /**
       * Locates all public non static methods of a class that match
       * a particular name, and that take a single non-primitive, non-array
       * argument.
       */
      private XMethod[] getPropertyMethods( final XClass clazz,
                                            final String name,
                                            final boolean exactMatch )
      {
          final Map attributeMethods = new HashMap();
  
          final ArrayList methods = getMethods( clazz );
          for( int i = 0; i < methods.size(); i++ )
          {
              final XMethod method = (XMethod)methods.get( i );
              if( !method.isPublic()
                  || method.isStatic()
                  || !method.getReturnType().getQualifiedName().equals( "void" )
                  || (exactMatch && ! method.getName().equals( name ) )
                  || (!exactMatch && !method.getName().startsWith( name ) ) )
              {
                  continue;
              }
              final XParameter[] params = method.getParameters();
              if( params.length != 1
                  || params[0].getDimension() > 0 )
              {
                  continue;
              }
              if( attributeMethods.containsKey( method.getName() ) )
              {
                  if( params[ 0 ].getType().getQualifiedName().equals( "java.lang.String"
) )
                  {
                      // Ignore string methods
                      continue;
                  }
              }
              attributeMethods.put( method.getName(), method );
          }
  
          final Collection matches = attributeMethods.values();
          return (XMethod[])matches.toArray( new XMethod[ matches.size() ] );
      }
  
      /**
       * Returns the methods of a class, including all inherited methods.
       */
      private ArrayList getMethods( final XClass origClazz )
      {
          final ArrayList methods = new ArrayList();
  
          for( XClass clazz = origClazz; clazz != null; clazz = clazz.getSuperclass() )
          {
              final XMethod[] curMethods = clazz.getMethods();
              for( int i = 0; i < curMethods.length; i++ )
              {
                  final XMethod method = curMethods[ i ];
                  methods.add( method );
              }
          }
  
          return methods;
      }
  
      /**
       * Returns true if the supplied class has at least one type tag.
       */
      public static boolean hasTypeTag( final XClass clazz )
      {
          return ( getTypeTags( clazz ).length > 0 );
      }
  
      /**
       * Returns the type tags of a class.
       */
      private static XTag[] getTypeTags( final XClass clazz )
      {
          final XTag[] tags = clazz.getDoc().getTags();
          final ArrayList retval = new ArrayList();
          for( int i = 0; i < tags.length; i++ )
          {
              final XTag tag = tags[ i ];
              if( tag.getName().equals( "ant.task" ) )
              {
                  retval.add( tag );
              }
              else if( tag.getName().equals( "ant.data-type" ) )
              {
                  retval.add( tag );
              }
              else if( tag.getName().equals( "ant.type" ) )
              {
                  retval.add( tag );
              }
          }
  
          return (XTag[])retval.toArray( new XTag[ retval.size() ] );
      }
  }
  
  
  
  1.1                  jakarta-ant-myrmidon/buildtools/src/java/org/apache/myrmidon/build/type.j
  
  Index: type.j
  ===================================================================
  <XDtTagDef:tagDef namespace="Ant" handler="org.apache.myrmidon.build.AntTypeTagHandler"/>
  <type classname="<XDtClass:fullClassName/>">
    <names>
      <XDtAnt:forAllTypeTags>
        <name role="<XDtAnt:typeTagRoleName/>" name="<XDtAnt:typeTagTypeName/>"/>
      </XDtAnt:forAllTypeTags>
    </names>
    <short-description>
      <![CDATA[<XDtClass:firstSentenceDescription/>]]>
    </short-description>
    <long-description>
      <![CDATA[<XDtClass:classComment no-comment-signs="true"/>]]>
    </long-description>
  
    <structure>
      <attributes>
      <XDtAnt:forAllAttributes>
        <attribute name="<XDtAnt:propertyName/>" type="<XDtAnt:propertyType/>">
          <description>
            <![CDATA[<XDtMethod:methodComment no-comment-signs="true"/>]]></description>
        </attribute>
      </XDtAnt:forAllAttributes>
      </attributes>
  
      <elements>
      <XDtAnt:forAllElements>
        <element name="<XDtAnt:propertyName/>" type="<XDtAnt:propertyType/>">
          <description>
            <![CDATA[<XDtMethod:methodComment no-comment-signs="true"/>]]>
          </description>
        </element>
      </XDtAnt:forAllElements>
      </elements>
  
      <XDtAnt:ifHasContent>
      <body type="<XDtAnt:propertyType/>">
          <description>
            <![CDATA[<XDtMethod:methodComment no-comment-signs="true"/>]]>
          </description>
      </body>
      </XDtAnt:ifHasContent>
  
    </structure>
  
  </type>
  
  
  
  1.1                  jakarta-ant-myrmidon/buildtools/src/java/org/apache/myrmidon/build/types.j
  
  Index: types.j
  ===================================================================
  <XDtTagDef:tagDef namespace="Ant" handler="org.apache.myrmidon.build.AntTypeTagHandler"/>
  <types>
    <XDtClass:forAllClasses extent="concrete-type">
  
      <XDtAnt:forAllTypeTags>
        <type role="<XDtAnt:typeTagRoleName/>"
              name="<XDtAnt:typeTagTypeName/>"
              classname="<XDtClass:fullClassName/>">
          <short-description>
            <![CDATA[<XDtClass:firstSentenceDescription/>]]>
          </short-description>
        </type>
      </XDtAnt:forAllTypeTags>
  
    </XDtClass:forAllClasses>
  </types>
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message