ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/extensions LibraryDisplayer.java JarLibDisplayTask.java LibraryDisplay.java ExtensionDisplayTask.java
Date Wed, 03 Apr 2002 11:16:06 GMT
donaldp     02/04/03 03:16:06

  Modified:    proposal/myrmidon/src/samples sample.ant
  Added:       proposal/myrmidon/src/java/org/apache/antlib/extensions
                        LibraryDisplayer.java JarLibDisplayTask.java
  Removed:     proposal/myrmidon/src/java/org/apache/antlib/extensions
                        LibraryDisplay.java ExtensionDisplayTask.java
  Log:
  Rename extension-display task to jarlib-display because it operated on both extensions and
package specifications
  
  Revision  Changes    Path
  1.4       +3 -3      jakarta-ant/proposal/myrmidon/src/samples/sample.ant
  
  Index: sample.ant
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/samples/sample.ant,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- sample.ant	2 Apr 2002 12:06:37 -0000	1.3
  +++ sample.ant	3 Apr 2002 11:16:05 -0000	1.4
  @@ -324,13 +324,13 @@
       </target>
   
       <target name="extension-test">
  -        <extension-display file="../../src/ant1compat/jar/ant.jar"/>
  -        <extension-display>
  +        <jarlib-display file="../../src/ant1compat/jar/ant.jar"/>
  +        <jarlib-display>
               <fileset dir="../../">
                   <include name="src/ant1compat/jar/*.jar"/>
                   <include name="lib/*.jar"/>
               </fileset>
  -        </extension-display>
  +        </jarlib-display>
       </target>
   
   </project>
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/extensions/LibraryDisplayer.java
  
  Index: LibraryDisplayer.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.antlib.extensions;
  
  import java.io.File;
  import java.io.IOException;
  import java.util.jar.Manifest;
  import java.util.jar.JarFile;
  import java.text.ParseException;
  import java.lang.StringBuffer;
  import org.apache.myrmidon.api.TaskException;
  import org.apache.avalon.excalibur.extension.Extension;
  import org.apache.avalon.excalibur.extension.Specification;
  
  /**
   * Utility class to output the information in a jar relating
   * to "Optional Packages" (formely known as "Extensions")
   * and Package Specifications.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/04/03 11:16:06 $
   */
  class LibraryDisplayer
  {
      /**
       * Display the extensions and specifications contained
       * within specified file.
       *
       * @param file the file
       * @throws TaskException if fail to read file
       */
      public void displayLibrary( final File file )
          throws TaskException
      {
          final Manifest manifest = getManifest( file );
          final Extension[] available = Extension.getAvailable( manifest );
          final Extension[] required = Extension.getRequired( manifest );
          final Specification[] specifications = getSpecifications( manifest );
  
          if( 0 == available.length &&
              0 == required.length &&
              0 == specifications.length )
          {
              return;
          }
  
          final String message = "File: " + file;
          final int size = message.length();
          printLine( size );
          System.out.println( message );
          printLine( size );
          if( 0 != available.length )
          {
              System.out.println( "Extensions Supported By Library:" );
              for( int i = 0; i < available.length; i++ )
              {
                  final Extension extension = available[ i ];
                  System.out.println( extension.toString() );
              }
          }
  
          if( 0 != required.length )
          {
              System.out.println( "Extensions Required By Library:" );
              for( int i = 0; i < required.length; i++ )
              {
                  final Extension extension = required[ i ];
                  System.out.println( extension.toString() );
              }
          }
  
          if( 0 != specifications.length )
          {
              System.out.println( "Specifications Supported By Library:" );
              for( int i = 0; i < specifications.length; i++ )
              {
                  final Specification specification = specifications[ i ];
                  displaySpecification( specification );
              }
          }
      }
  
      /**
       * Print out a line of '-'s equal to specified size.
       *
       * @param size the number of dashes to printout
       */
      private void printLine( final int size )
      {
          for( int i = 0; i < size; i++ )
          {
              System.out.print( "-" );
          }
          System.out.println();
      }
  
      /**
       * Get specifications from manifest.
       *
       * @param manifest the manifest
       * @return the specifications or null if none
       * @throws TaskException if malformed specification sections
       */
      private Specification[] getSpecifications( final Manifest manifest )
          throws TaskException
      {
          try
          {
              return Specification.getSpecifications( manifest );
          }
          catch( final ParseException pe )
          {
              throw new TaskException( pe.getMessage(), pe );
          }
      }
  
      /**
       * Print out specification details.
       *
       * @param specification the specification
       */
      private void displaySpecification( final Specification specification )
      {
          final String[] sections = specification.getSections();
          if( null != sections )
          {
              final StringBuffer sb = new StringBuffer( "Sections: " );
              for( int i = 0; i < sections.length; i++ )
              {
                  sb.append( " " );
                  sb.append( sections[ i ] );
              }
              System.out.println( sb );
          }
          System.out.println( specification.toString() );
      }
  
      /**
       * retrieve manifest for specified file.
       *
       * @param file the file
       * @return the manifest
       * @throws org.apache.myrmidon.api.TaskException if errror occurs (file not exist,
       *         file not a jar, manifest not exist in file)
       */
      private Manifest getManifest( final File file )
          throws TaskException
      {
          try
          {
              final JarFile jarFile = new JarFile( file );
              return jarFile.getManifest();
          }
          catch( final IOException ioe )
          {
              throw new TaskException( ioe.getMessage(), ioe );
          }
      }
  }
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/extensions/JarLibDisplayTask.java
  
  Index: JarLibDisplayTask.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.antlib.extensions;
  
  import java.io.File;
  import java.util.Iterator;
  import java.util.Vector;
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.myrmidon.api.AbstractTask;
  import org.apache.myrmidon.api.TaskException;
  import org.apache.myrmidon.framework.FileSet;
  import org.apache.tools.todo.types.DirectoryScanner;
  import org.apache.tools.todo.types.ScannerUtil;
  
  /**
   * Display the "Optional Package" and "Package Specification" information
   * contained within the specified jars.
   *
   * <p>Prior to JDK1.3, an "Optional Package" was known as an Extension.
   * The specification for this mechanism is available in the JDK1.3
   * documentation in the directory
   * $JDK_HOME/docs/guide/extensions/versioning.html. Alternatively it is
   * available online at <a href="http://java.sun.com/j2se/1.3/docs/guide/extensions/versioning.html">
   * http://java.sun.com/j2se/1.3/docs/guide/extensions/versioning.html</a>.</p>
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @ant.task name="jarlib-display"
   */
  public class JarLibDisplayTask
      extends AbstractTask
  {
      private final static Resources REZ =
          ResourceManager.getPackageResources( JarLibDisplayTask.class );
  
      /**
       * The library to display information about.
       */
      private File m_file;
  
      /**
       * Filesets specifying all the librarys
       * to display information about.
       */
      private final Vector m_filesets = new Vector();
  
      /**
       * The jar library to display information for.
       *
       * @param file The jar library to display information for.
       */
      public void setFile( final File file )
      {
          m_file = file;
      }
  
      /**
       * Adds a set of files about which library data will be displayed.
       *
       * @param fileSet a set of files about which library data will be displayed.
       */
      public void addFileset( final FileSet fileSet )
      {
          m_filesets.addElement( fileSet );
      }
  
      public void execute()
          throws TaskException
      {
          validate();
  
          final LibraryDisplayer displayer = new LibraryDisplayer();
          // Check if list of files to check has been specified
          if( !m_filesets.isEmpty() )
          {
              final Iterator iterator = m_filesets.iterator();
              while( iterator.hasNext() )
              {
                  final FileSet fileSet = (FileSet)iterator.next();
                  final DirectoryScanner scanner = ScannerUtil.getDirectoryScanner( fileSet
);
                  final File basedir = scanner.getBasedir();
                  final String[] files = scanner.getIncludedFiles();
                  for( int i = 0; i < files.length; i++ )
                  {
                      final File file = new File( basedir, files[ i ] );
                      displayer.displayLibrary( file );
                  }
              }
          }
          else
          {
              displayer.displayLibrary( m_file );
          }
      }
  
      /**
       * Validate the tasks parameters.
       *
       * @throws TaskException if invalid parameters found
       */
      private void validate()
          throws TaskException
      {
          if( null == m_file && m_filesets.isEmpty() )
          {
              final String message = REZ.getString( "extension.missing-file.error" );
              throw new TaskException( message );
          }
          if( null != m_file && !m_file.exists() )
          {
              final String message = REZ.getString( "extension.file-noexist.error", m_file
);
              throw new TaskException( message );
          }
          if( null != m_file && !m_file.isFile() )
          {
              final String message = REZ.getString( "extension.bad-file.error", m_file );
              throw new TaskException( message );
          }
      }
  }
  
  
  

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