Clover coverage report - groovy - 1.0-beta-7
Coverage timestamp: Wed Sep 29 2004 16:55:52 BST
file stats: LOC: 230   Methods: 7
NCLOC: 130   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
FileSystemCompiler.java 0% 0% 0% 0%
coverage
 1   
 /*
 2   
  $Id: FileSystemCompiler.java,v 1.8 2004/07/10 03:31:45 bran Exp $
 3   
 
 4   
  Copyright 2003 (C) James Strachan and Bob Mcwhirter. All Rights Reserved.
 5   
 
 6   
  Redistribution and use of this software and associated documentation
 7   
  ("Software"), with or without modification, are permitted provided
 8   
  that the following conditions are met:
 9   
 
 10   
  1. Redistributions of source code must retain copyright
 11   
     statements and notices.  Redistributions must also contain a
 12   
     copy of this document.
 13   
 
 14   
  2. Redistributions in binary form must reproduce the
 15   
     above copyright notice, this list of conditions and the
 16   
     following disclaimer in the documentation and/or other
 17   
     materials provided with the distribution.
 18   
 
 19   
  3. The name "groovy" must not be used to endorse or promote
 20   
     products derived from this Software without prior written
 21   
     permission of The Codehaus.  For written permission,
 22   
     please contact info@codehaus.org.
 23   
 
 24   
  4. Products derived from this Software may not be called "groovy"
 25   
     nor may "groovy" appear in their names without prior written
 26   
     permission of The Codehaus. "groovy" is a registered
 27   
     trademark of The Codehaus.
 28   
 
 29   
  5. Due credit should be given to The Codehaus -
 30   
     http://groovy.codehaus.org/
 31   
 
 32   
  THIS SOFTWARE IS PROVIDED BY THE CODEHAUS AND CONTRIBUTORS
 33   
  ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
 34   
  NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 35   
  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
 36   
  THE CODEHAUS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 37   
  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 38   
  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 39   
  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 40   
  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 41   
  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 42   
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 43   
  OF THE POSSIBILITY OF SUCH DAMAGE.
 44   
 
 45   
  */
 46   
 package org.codehaus.groovy.tools;
 47   
 
 48   
 import java.io.File;
 49   
 
 50   
 import org.apache.commons.cli.CommandLine;
 51   
 import org.apache.commons.cli.OptionBuilder;
 52   
 import org.apache.commons.cli.Options;
 53   
 import org.apache.commons.cli.PosixParser;
 54   
 import org.codehaus.groovy.control.CompilationUnit;
 55   
 import org.codehaus.groovy.control.CompilerConfiguration;
 56   
 import org.codehaus.groovy.control.ConfigurationException;
 57   
 
 58   
 public class FileSystemCompiler  
 59   
 {
 60   
     private CompilationUnit unit;
 61   
 
 62   
     
 63  0
     public FileSystemCompiler( CompilerConfiguration configuration ) throws ConfigurationException
 64   
     {
 65  0
         this.unit = new CompilationUnit( configuration );
 66   
     }
 67   
 
 68   
     
 69  0
     public void compile( String[] paths ) throws Exception 
 70   
     {
 71  0
         unit.addSources( paths );
 72  0
         unit.compile( );
 73   
     }
 74   
 
 75   
     
 76  0
     public void compile( File[] files ) throws Exception 
 77   
     {
 78  0
         unit.addSources( files );
 79  0
         unit.compile( );
 80   
     }
 81   
 
 82   
 
 83  0
     public static void displayHelp() 
 84   
     {
 85  0
         System.err.println("Usage: groovy <options> <source files>");
 86  0
         System.err.println("where possible options include: ");
 87  0
         System.err.println("  --classpath <path>        Specify where to find user class files");
 88  0
         System.err.println("  -d <directory>            Specify where to place generated class files");
 89  0
         System.err.println("  --encoding <encoding>     Specify the encoding of the user class files");
 90  0
         System.err.println("  --strict                  Turn on strict type safety");
 91  0
         System.err.println("  --version                 Print the verion");
 92  0
         System.err.println("  --help                    Print a synopsis of standard options");
 93  0
         System.err.println("  --exception               Print stack trace on error");
 94  0
         System.err.println("");
 95   
     }
 96   
 
 97  0
     public static void displayVersion() 
 98   
     {
 99  0
         System.err.println("groovy compiler version 1.0-rc1");
 100  0
         System.err.println("Copyright 2003-2004 The Codehaus. http://groovy.codehaus.org/");
 101  0
         System.err.println("");
 102   
     }
 103   
 
 104  0
     public static int checkFiles( String[] filenames ) 
 105   
     {
 106  0
         int errors = 0;
 107   
 
 108  0
         for(int i = 0; i < filenames.length; ++i ) 
 109   
         {
 110  0
             File file = new File( filenames[i] );
 111   
 
 112  0
             if( !file.exists() ) 
 113   
             {
 114  0
                 System.err.println( "error: file not found: " + file );
 115  0
                 ++errors;
 116   
             }
 117  0
             else if( !file.canRead() ) 
 118   
             {
 119  0
                 System.err.println( "error: file not readable: " + file );
 120  0
                 ++errors;
 121   
             } else {
 122  0
                 String name = file.getName();
 123  0
                 int p = name.lastIndexOf(".");
 124  0
                 if ( p++ >= 0) {
 125  0
                     if (name.substring(p).equals("java")) {
 126  0
                         System.err.println( "error: cannot compile file with .java extension: " + file );
 127  0
                         ++errors;
 128   
                     }
 129   
                 }
 130   
             }
 131   
         }
 132   
 
 133  0
         return errors;
 134   
     }
 135   
 
 136   
     
 137   
     
 138   
    /**
 139   
     *  Primary entry point for compiling from the command line
 140   
     *  (using the groovyc script).
 141   
     */
 142   
     
 143  0
     public static void main( String[] args )
 144   
     {
 145  0
         boolean displayStackTraceOnError = false;
 146   
         
 147  0
         try
 148   
         {
 149   
             //
 150   
             // Parse the command line
 151   
             
 152  0
             Options options = new Options();
 153   
     
 154  0
             options.addOption(OptionBuilder.withLongOpt("classpath").hasArg().withArgName("classpath").create());
 155  0
             options.addOption(OptionBuilder.withLongOpt("sourcepath").hasArg().withArgName("sourcepath").create());
 156  0
             options.addOption(OptionBuilder.withLongOpt("encoding").hasArg().withArgName("encoding").create());
 157  0
             options.addOption(OptionBuilder.hasArg().create('d'));
 158  0
             options.addOption(OptionBuilder.withLongOpt("strict").create('s'));
 159  0
             options.addOption(OptionBuilder.withLongOpt("help").create('h'));
 160  0
             options.addOption(OptionBuilder.withLongOpt("version").create('v'));
 161  0
             options.addOption(OptionBuilder.withLongOpt("exception").create('e'));
 162   
     
 163  0
             PosixParser cliParser = new PosixParser();
 164   
     
 165  0
             CommandLine cli = cliParser.parse(options, args);
 166   
     
 167  0
             if( cli.hasOption('h') ) 
 168   
             {
 169  0
                 displayHelp();
 170  0
                 return;
 171   
             }
 172   
     
 173  0
             if( cli.hasOption('v') ) 
 174   
             {
 175  0
                 displayVersion();
 176   
             }
 177   
     
 178   
             
 179   
             //
 180   
             // Setup the configuration data
 181   
             
 182  0
             CompilerConfiguration configuration = new CompilerConfiguration();
 183   
     
 184  0
             if( cli.hasOption("classpath") ) 
 185   
             {
 186  0
                 configuration.setClasspath( cli.getOptionValue("classpath") );
 187   
             }
 188   
     
 189  0
             if( cli.hasOption('d') ) 
 190   
             {
 191  0
                 configuration.setTargetDirectory( cli.getOptionValue('d') );
 192   
             }
 193   
 
 194  0
             if (cli.hasOption("encoding")) {
 195  0
                 configuration.setSourceEncoding(cli.getOptionValue("encoding"));
 196   
             }
 197   
 
 198  0
             displayStackTraceOnError = cli.hasOption('e');
 199   
             
 200   
             
 201   
             //
 202   
             // Load the file name list
 203   
             
 204  0
             String[] filenames = cli.getArgs();
 205  0
             if( filenames.length == 0 ) 
 206   
             {
 207  0
                 displayHelp();
 208  0
                 return;
 209   
             }
 210   
     
 211  0
             int errors = checkFiles( filenames );
 212   
     
 213   
             
 214   
             //
 215   
             // Create and start the compiler
 216   
             
 217  0
             if( errors == 0 ) 
 218   
             {
 219  0
                 FileSystemCompiler compiler = new FileSystemCompiler( configuration );
 220  0
                 compiler.compile( filenames );
 221   
             }
 222   
         }
 223   
         catch( Throwable e ) 
 224   
         {
 225  0
             new ErrorReporter( e, displayStackTraceOnError ).write( System.err );
 226   
         }
 227   
     }
 228   
     
 229   
 }
 230