Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 211   Methods: 5
NCLOC: 106   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
LibraryDisplayer.java 0% 0% 0% 0%
 1   
 /*
 2   
  * The Apache Software License, Version 1.1
 3   
  *
 4   
  * Copyright (c) 2002 The Apache Software Foundation.  All rights
 5   
  * reserved.
 6   
  *
 7   
  * Redistribution and use in source and binary forms, with or without
 8   
  * modification, are permitted provided that the following conditions
 9   
  * are met:
 10   
  *
 11   
  * 1. Redistributions of source code must retain the above copyright
 12   
  *    notice, this list of conditions and the following disclaimer.
 13   
  *
 14   
  * 2. Redistributions in binary form must reproduce the above copyright
 15   
  *    notice, this list of conditions and the following disclaimer in
 16   
  *    the documentation and/or other materials provided with the
 17   
  *    distribution.
 18   
  *
 19   
  * 3. The end-user documentation included with the redistribution, if
 20   
  *    any, must include the following acknowlegement:
 21   
  *       "This product includes software developed by the
 22   
  *        Apache Software Foundation (http://www.apache.org/)."
 23   
  *    Alternately, this acknowlegement may appear in the software itself,
 24   
  *    if and wherever such third-party acknowlegements normally appear.
 25   
  *
 26   
  * 4. The names "Ant" and "Apache Software
 27   
  *    Foundation" must not be used to endorse or promote products derived
 28   
  *    from this software without prior written permission. For written
 29   
  *    permission, please contact apache@apache.org.
 30   
  *
 31   
  * 5. Products derived from this software may not be called "Apache"
 32   
  *    nor may "Apache" appear in their names without prior written
 33   
  *    permission of the Apache Group.
 34   
  *
 35   
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 36   
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 37   
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 38   
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 39   
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 40   
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 41   
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 42   
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 43   
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 44   
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 45   
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 46   
  * SUCH DAMAGE.
 47   
  * ====================================================================
 48   
  *
 49   
  * This software consists of voluntary contributions made by many
 50   
  * individuals on behalf of the Apache Software Foundation.  For more
 51   
  * information on the Apache Software Foundation, please see
 52   
  * <http://www.apache.org/>.
 53   
  */
 54   
 package org.apache.tools.ant.taskdefs.optional.extension;
 55   
 
 56   
 import java.io.File;
 57   
 import java.text.ParseException;
 58   
 import java.util.jar.Manifest;
 59   
 import org.apache.tools.ant.BuildException;
 60   
 
 61   
 /**
 62   
  * Utility class to output the information in a jar relating
 63   
  * to "Optional Packages" (formely known as "Extensions")
 64   
  * and Package Specifications.
 65   
  *
 66   
  * @author <a href="mailto:peter@apache.org">Peter Donald</a>
 67   
  * @version $Revision: 1.3 $ $Date: 2003/02/10 14:14:03 $
 68   
  */
 69   
 class LibraryDisplayer
 70   
 {
 71   
     /**
 72   
      * Display the extensions and specifications contained
 73   
      * within specified file.
 74   
      *
 75   
      * @param file the file
 76   
      * @throws BuildException if fail to read file
 77   
      */
 78  0
     void displayLibrary( final File file )
 79   
         throws BuildException
 80   
     {
 81  0
         final Manifest manifest = ExtensionUtil.getManifest( file );
 82  0
         displayLibrary( file, manifest );
 83   
     }
 84   
 
 85   
     /**
 86   
      * Display the extensions and specifications contained
 87   
      * within specified file.
 88   
      *
 89   
      * @param file the file to use while reporting
 90   
      * @param manifest the manifest of file
 91   
      * @throws BuildException if fail to read file
 92   
      */
 93  0
     void displayLibrary( final File file,
 94   
                          final Manifest manifest )
 95   
         throws BuildException
 96   
     {
 97  0
         final Extension[] available = Extension.getAvailable( manifest );
 98  0
         final Extension[] required = Extension.getRequired( manifest );
 99  0
         final Extension[] options = Extension.getOptions( manifest );
 100  0
         final Specification[] specifications = getSpecifications( manifest );
 101   
 
 102  0
         if( 0 == available.length &&
 103   
             0 == required.length &&
 104   
             0 == options.length &&
 105   
             0 == specifications.length )
 106   
         {
 107  0
             return;
 108   
         }
 109   
 
 110  0
         final String message = "File: " + file;
 111  0
         final int size = message.length();
 112  0
         printLine( size );
 113  0
         System.out.println( message );
 114  0
         printLine( size );
 115  0
         if( 0 != available.length )
 116   
         {
 117  0
             System.out.println( "Extensions Supported By Library:" );
 118  0
             for( int i = 0; i < available.length; i++ )
 119   
             {
 120  0
                 final Extension extension = available[ i ];
 121  0
                 System.out.println( extension.toString() );
 122   
             }
 123   
         }
 124   
 
 125  0
         if( 0 != required.length )
 126   
         {
 127  0
             System.out.println( "Extensions Required By Library:" );
 128  0
             for( int i = 0; i < required.length; i++ )
 129   
             {
 130  0
                 final Extension extension = required[ i ];
 131  0
                 System.out.println( extension.toString() );
 132   
             }
 133   
         }
 134   
 
 135  0
         if( 0 != options.length )
 136   
         {
 137  0
             System.out.println( "Extensions that will be used by Library if present:" );
 138  0
             for( int i = 0; i < options.length; i++ )
 139   
             {
 140  0
                 final Extension extension = options[ i ];
 141  0
                 System.out.println( extension.toString() );
 142   
             }
 143   
         }
 144   
 
 145  0
         if( 0 != specifications.length )
 146   
         {
 147  0
             System.out.println( "Specifications Supported By Library:" );
 148  0
             for( int i = 0; i < specifications.length; i++ )
 149   
             {
 150  0
                 final Specification specification = specifications[ i ];
 151  0
                 displaySpecification( specification );
 152   
             }
 153   
         }
 154   
     }
 155   
 
 156   
     /**
 157   
      * Print out a line of '-'s equal to specified size.
 158   
      *
 159   
      * @param size the number of dashes to printout
 160   
      */
 161  0
     private void printLine( final int size )
 162   
     {
 163  0
         for( int i = 0; i < size; i++ )
 164   
         {
 165  0
             System.out.print( "-" );
 166   
         }
 167  0
         System.out.println();
 168   
     }
 169   
 
 170   
     /**
 171   
      * Get specifications from manifest.
 172   
      *
 173   
      * @param manifest the manifest
 174   
      * @return the specifications or null if none
 175   
      * @throws BuildException if malformed specification sections
 176   
      */
 177  0
     private Specification[] getSpecifications( final Manifest manifest )
 178   
         throws BuildException
 179   
     {
 180  0
         try
 181   
         {
 182  0
             return Specification.getSpecifications( manifest );
 183   
         }
 184   
         catch( final ParseException pe )
 185   
         {
 186  0
             throw new BuildException( pe.getMessage(), pe );
 187   
         }
 188   
     }
 189   
 
 190   
     /**
 191   
      * Print out specification details.
 192   
      *
 193   
      * @param specification the specification
 194   
      */
 195  0
     private void displaySpecification( final Specification specification )
 196   
     {
 197  0
         final String[] sections = specification.getSections();
 198  0
         if( null != sections )
 199   
         {
 200  0
             final StringBuffer sb = new StringBuffer( "Sections: " );
 201  0
             for( int i = 0; i < sections.length; i++ )
 202   
             {
 203  0
                 sb.append( " " );
 204  0
                 sb.append( sections[ i ] );
 205   
             }
 206  0
             System.out.println( sb );
 207   
         }
 208  0
         System.out.println( specification.toString() );
 209   
     }
 210   
 }
 211