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/containerkit/src/java/org/apache/excalibur/containerkit/ant SerializeInfoTask.java
Date Fri, 28 Jun 2002 02:03:03 GMT
donaldp     2002/06/27 19:03:02

  Added:       containerkit/src/java/org/apache/excalibur/containerkit/ant
                        SerializeInfoTask.java
  Log:
  Add in basic ant task that puts the xinfo descriptors into serialized objects
  
  Revision  Changes    Path
  1.1                  jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/ant/SerializeInfoTask.java
  
  Index: SerializeInfoTask.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.excalibur.containerkit.ant;
  
  import org.apache.excalibur.containerkit.metainfo.ComponentInfo;
  import org.apache.excalibur.containerkit.infobuilder.XMLInfoCreator;
  import org.apache.tools.ant.Task;
  import org.apache.tools.ant.BuildException;
  import org.apache.tools.ant.types.FileSet;
  import org.apache.tools.ant.DirectoryScanner;
  import org.apache.avalon.framework.logger.ConsoleLogger;
  import java.util.ArrayList;
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.IOException;
  import java.io.ObjectOutputStream;
  import java.io.FileOutputStream;
  import java.io.OutputStream;
  
  /**
   * Simple task to load an XML descriptor into {@link ComponentInfo}
   * object and then serialize object to file.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/06/28 02:03:02 $
   */
  public class SerializeInfoTask
      extends Task
  {
      private final ArrayList m_fileSets = new ArrayList();
      private File m_destDir;
  
      public void setDestDir( final File destDir )
      {
          m_destDir = destDir;
      }
  
      public void addFileset( final FileSet fileSet )
      {
          m_fileSets.add( fileSet );
      }
  
      public void execute()
        throws BuildException
      {
          if( null == m_destDir )
          {
              m_destDir = getProject().resolveFile( "." );
          }
  
          final XMLInfoCreator infoCreator = new XMLInfoCreator();
          infoCreator.enableLogging( new ConsoleLogger() );
  
          final int count = m_fileSets.size();
          for( int i = 0; i < count; i++ )
          {
              final FileSet fileSet = (FileSet)m_fileSets.get( i );
              final DirectoryScanner scanner = fileSet.getDirectoryScanner( getProject() );
              final File baseDir = fileSet.getDir( getProject() );
  
              final String[] srcFiles = scanner.getIncludedFiles();
              for( int j = 0; j < srcFiles.length; j++ )
              {
                  final String srcFilename = srcFiles[ j ];
                  final String baseName =
                      srcFilename.substring( 0, srcFilename.length() - 5 );
                  final String classname = baseName.replace( File.separatorChar, '.' );
                  final String destFilename = baseName + "sinfo";
                  final File src = new File( baseDir, srcFilename );
                  final File dest = new File( m_destDir, destFilename );
                  FileInputStream inputStream = null;
                  OutputStream outputStream = null;
                  try
                  {
                      inputStream = new FileInputStream( src );
                      final ComponentInfo info =
                          infoCreator.createComponentInfo( classname, inputStream );
                      inputStream.close();
                      outputStream = new FileOutputStream( dest );
                      final ObjectOutputStream oos = new ObjectOutputStream( outputStream
);
                      oos.writeObject( info );
                      oos.close();
  
                  }
                  catch( Exception e )
                  {
                      throw new BuildException( e.getMessage(), e );
                  }
                  finally
                  {
                      if( null != inputStream )
                      {
                          try
                          {
                              inputStream.close();
                          }
                          catch( IOException e )
                          {
                          }
                      }
                      if( null != outputStream )
                      {
                          try
                          {
                              outputStream.close();
                          }
                          catch( IOException e )
                          {
                          }
                      }
                  }
              }
  
          }
      }
  }
  
  
  

--
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