avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/ant MetaGenerateTask.java
Date Sat, 16 Nov 2002 05:00:05 GMT
donaldp     2002/11/15 21:00:05

  Modified:    info/src/java/org/apache/avalon/framework/tools/ant
                        MetaGenerateTask.java
  Log:
  Refactor task to enable future enhancements that allow infos to be
  built from alternative mechanisms
  
  Revision  Changes    Path
  1.2       +68 -35    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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MetaGenerateTask.java	12 Nov 2002 06:55:41 -0000	1.1
  +++ MetaGenerateTask.java	16 Nov 2002 05:00:05 -0000	1.2
  @@ -132,46 +132,79 @@
           for( int i = 0; i < size; i++ )
           {
               final JavaClass javaClass = (JavaClass)allClasses.get( i );
  +            ComponentInfo info = null;
               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();
  +                info = infoBuilder.buildComponentInfo( javaClass );
  +            }
  +            else
  +            {
   
  -                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 );
  -                }
  +            //If we have built an info object
  +            //then write it out
  +            if( null != info )
  +            {
  +                writeInfo( info );
               }
           }
  +    }
  +
  +    /**
  +     * Write ComponentInfo out into a file.
  +     *
  +     * @param info the ComponentInfo object
  +     * @throws IOException if unable to write info out
  +     */
  +    private void writeInfo( final ComponentInfo info )
  +        throws IOException
  +    {
  +        InfoWriter writer;
  +        String extension;
  +        if( m_xmlOutput )
  +        {
  +            extension = ".xml";
  +            writer = c_xmlWriter;
  +        }
  +        else
  +        {
  +            extension = ".ser";
  +            writer = c_serWriter;
  +        }
  +
  +        final String filename = calcBaseFile( info ) + extension;
  +        final OutputStream outputStream = new FileOutputStream( filename );
  +        try
  +        {
  +            writer.writeComponentInfo( info, outputStream );
  +        }
  +        catch( final Exception e )
  +        {
  +            log( "Error writing " + filename + ". Cause: " + e );
  +        }
  +        finally
  +        {
  +            shutdownStream( outputStream );
  +        }
  +    }
  +
  +    /**
  +     * Determine the base file for specified {@link ComponentInfo}.
  +     *
  +     * @param info the info object that name is created for
  +     * @return the base file for info
  +     * @throws IOException if unable to determine base file
  +     */
  +    private String calcBaseFile( final ComponentInfo info )
  +        throws IOException
  +    {
  +        final String fqn = info.getDescriptor().getImplementationKey();
  +        final String filename =
  +            fqn.replace( '.', File.separatorChar ) + "-info";
  +        return new File( m_destDir, filename ).getCanonicalPath();
       }
   
       /**
  
  
  

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


Mime
View raw message