Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 464   Methods: 24
NCLOC: 118   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
CSharp.java 0% 0% 0% 0%
 1   
 /*
 2   
  * The Apache Software License, Version 1.1
 3   
  *
 4   
  * Copyright (c) 2001-2003 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   
 
 55   
 /*
 56   
  *  build notes
 57   
  *  -The reference CD to listen to while editing this file is
 58   
  *  nap: Underworld  - Everything, Everything
 59   
  */
 60   
 // ====================================================================
 61   
 // place in the optional ant tasks package
 62   
 // but in its own dotnet group
 63   
 // ====================================================================
 64   
 
 65   
 package org.apache.tools.ant.taskdefs.optional.dotnet;
 66   
 
 67   
 // ====================================================================
 68   
 // imports
 69   
 // ====================================================================
 70   
 
 71   
 import java.io.File;
 72   
 import java.util.Vector;
 73   
 import java.util.Enumeration;
 74   
 
 75   
 import org.apache.tools.ant.BuildException;
 76   
 import org.apache.tools.ant.DirectoryScanner;
 77   
 import org.apache.tools.ant.Project;
 78   
 import org.apache.tools.ant.types.Path;
 79   
 
 80   
 // ====================================================================
 81   
 
 82   
 /**
 83   
  *  Compiles C# source into executables or modules.
 84   
  *
 85   
  *  The task will only work on win2K until other platforms support
 86   
  *  csc.exe or an equivalent. CSC.exe must be on the execute path too. <p>
 87   
  *
 88   
  *  All parameters are optional: &lt;csc/&gt; should suffice to produce a debug
 89   
  *  build of all *.cs files. References to external files do require explicit
 90   
  *  enumeration, so are one of the first attributes to consider adding. <p>
 91   
  *
 92   
  *  The task is a directory based task, so attributes like <b>includes="*.cs"
 93   
  *  </b> and <b>excludes="broken.cs"</b> can be used to control the files pulled
 94   
  *  in. By default, all *.cs files from the project folder down are included in
 95   
  *  the command. When this happens the output file -if not specified- is taken
 96   
  *  as the first file in the list, which may be somewhat hard to control.
 97   
  *  Specifying the output file with <b>'outfile'</b> seems prudent. <p>
 98   
  *
 99   
  *  <p>
 100   
  *
 101   
  *  TODO
 102   
  *  <ol>
 103   
  *    <li> is incremental build still broken in beta-1?
 104   
  *    <li> is Win32Icon broken?
 105   
  *    <li> all the missing options
 106   
  *  </ol>
 107   
  *  <p>
 108   
  *
 109   
  *  History
 110   
  *  <Table>
 111   
  *
 112   
  *    <tr>
 113   
  *
 114   
  *      <td>
 115   
  *        0.3
 116   
  *      </td>
 117   
  *
 118   
  *      <td>
 119   
  *        Beta 1 edition
 120   
  *      </td>
 121   
  *
 122   
  *      <td>
 123   
  *        To avoid having to remember which assemblies to include, the task
 124   
  *        automatically refers to the main dotnet libraries in Beta1.
 125   
  *      </tr>
 126   
  *
 127   
  *      <tr>
 128   
  *
 129   
  *        <td>
 130   
  *          0.2
 131   
  *        </td>
 132   
  *
 133   
  *        <td>
 134   
  *          Slightly different
 135   
  *        </td>
 136   
  *
 137   
  *        <td>
 138   
  *          Split command execution to a separate class;
 139   
  *        </tr>
 140   
  *
 141   
  *        <tr>
 142   
  *
 143   
  *          <td>
 144   
  *            0.1
 145   
  *          </td>
 146   
  *
 147   
  *          <td>
 148   
  *            "I can't believe it's so rudimentary"
 149   
  *          </td>
 150   
  *
 151   
  *          <td>
 152   
  *            First pass; minimal builds only support;
 153   
  *          </tr>
 154   
  *
 155   
  *        </table>
 156   
  *
 157   
  *
 158   
  * @author      Steve Loughran steve_l@iseran.com
 159   
  * @version     0.5
 160   
  * @ant.task    name="csc" category="dotnet"
 161   
  * @since Ant 1.3
 162   
  */
 163   
 
 164   
 public class CSharp extends DotnetCompile {
 165   
 
 166   
     /**
 167   
      *  defines list: RELEASE;WIN32;NO_SANITY_CHECKS;;SOMETHING_ELSE'
 168   
      */
 169   
     String definitions;
 170   
 
 171   
 
 172   
     /**
 173   
      *  output XML documentation flag
 174   
      */
 175   
     private File docFile;
 176   
 
 177   
     /**
 178   
      *  file alignment; 0 means let the compiler decide
 179   
      */
 180   
     private int fileAlign = 0;
 181   
 
 182   
     /**
 183   
      *  use full paths to things
 184   
      */
 185   
     private boolean fullpaths = false;
 186   
 
 187   
     /**
 188   
      *  incremental build flag
 189   
      */
 190   
     private boolean incremental;
 191   
 
 192   
     /**
 193   
      *  enable unsafe code flag. Clearly set to false by default
 194   
      */
 195   
     protected boolean unsafe;
 196   
 
 197   
     /**
 198   
      * A flag that tells the compiler not to read in the compiler
 199   
      * settings files 'csc.rsp' in its bin directory and then the local directory
 200   
      */
 201   
     private boolean noconfig = false;
 202   
 
 203   
 
 204   
     /**
 205   
      *  constructor inits everything and set up the search pattern
 206   
      */
 207   
 
 208  0
     public CSharp() {
 209   
     }
 210   
 
 211   
     /**
 212   
      * full cleanup
 213   
      */
 214  0
     public void clear() {
 215  0
         super.clear();
 216  0
         docFile = null;
 217  0
         fileAlign = 0;
 218  0
         fullpaths = true;
 219  0
         incremental = false;
 220  0
         unsafe = false;
 221  0
         noconfig = false;
 222  0
         definitions = null;
 223   
 
 224   
     }
 225   
 
 226   
 
 227   
 
 228   
     /**
 229   
      *  file for generated XML documentation
 230   
      *
 231   
      *@param  f  output file
 232   
      */
 233  0
     public void setDocFile(File f) {
 234  0
         docFile = f;
 235   
     }
 236   
 
 237   
 
 238   
     /**
 239   
      *  get the argument or null for no argument needed
 240   
      *
 241   
      *@return    The DocFile Parameter to CSC
 242   
      */
 243  0
     protected String getDocFileParameter() {
 244  0
         if (docFile != null) {
 245  0
             return "/doc:" + docFile.toString();
 246   
         } else {
 247  0
             return null;
 248   
         }
 249   
     }
 250   
 
 251   
     /**
 252   
      * Set the file alignment.
 253   
      * Valid values are 0,512, 1024, 2048, 4096, 8192,
 254   
      * and 16384, 0 means 'leave to the compiler'
 255   
      */
 256  0
     public void setFileAlign(int fileAlign) {
 257  0
         this.fileAlign = fileAlign;
 258   
     }
 259   
 
 260   
     /**
 261   
      *  get the argument or null for no argument needed
 262   
      *
 263   
      *@return    The OutputFile Parameter to CSC
 264   
      */
 265  0
     protected String getFileAlignParameter() {
 266  0
         if (fileAlign != 0) {
 267  0
             return "/filealign:" + fileAlign;
 268   
         } else {
 269  0
             return null;
 270   
         }
 271   
     }
 272   
 
 273   
 
 274   
     /**
 275   
      * If true, print the full path of files on errors.
 276   
      *
 277   
      *@param  enabled  The new fullPaths value
 278   
      */
 279  0
     public void setFullPaths(boolean enabled) {
 280  0
         fullpaths = enabled;
 281   
     }
 282   
 
 283   
 
 284   
     /**
 285   
      *  Gets the fullPathsParameter attribute of the CSharp object
 286   
      *
 287   
      *@return    The fullPathsParameter value or null if unset
 288   
      */
 289  0
     protected String getFullPathsParameter() {
 290  0
         return fullpaths ? "/fullpaths" : null;
 291   
     }
 292   
 
 293   
 
 294   
     /**
 295   
      *  set the incremental compilation flag on or off.
 296   
      *
 297   
      *@param  incremental  on/off flag
 298   
      */
 299  0
     public void setIncremental(boolean incremental) {
 300  0
         this.incremental = incremental;
 301   
     }
 302   
 
 303   
 
 304   
     /**
 305   
      *  query the incrementalflag
 306   
      *
 307   
      *@return    true iff incremental compilation is turned on
 308   
      */
 309  0
     public boolean getIncremental() {
 310  0
         return incremental;
 311   
     }
 312   
 
 313   
 
 314   
     /**
 315   
      *  get the incremental build argument
 316   
      *
 317   
      *@return    The Incremental Parameter to CSC
 318   
      */
 319  0
     protected String getIncrementalParameter() {
 320  0
         return "/incremental" + (incremental ? "+" : "-");
 321   
     }
 322   
 
 323   
     /**
 324   
      *  The output file. This is identical to the destFile attribute.
 325   
      *
 326   
      *@param  params  The new outputFile value
 327   
      */
 328  0
     public void setOutputFile(File params) {
 329  0
         setDestFile(params);
 330   
     }
 331   
 
 332   
 
 333   
     /**
 334   
      * If true, enables the unsafe keyword.
 335   
      *
 336   
      *@param  unsafe  The new Unsafe value
 337   
      */
 338  0
     public void setUnsafe(boolean unsafe) {
 339  0
         this.unsafe = unsafe;
 340   
     }
 341   
 
 342   
 
 343   
     /**
 344   
      *  query the Unsafe attribute
 345   
      *
 346   
      *@return    The Unsafe value
 347   
      */
 348  0
     public boolean getUnsafe() {
 349  0
         return this.unsafe;
 350   
     }
 351   
 
 352   
 
 353   
     /**
 354   
      *  get the argument or null for no argument needed
 355   
      *
 356   
      *@return    The Unsafe Parameter to CSC
 357   
      */
 358  0
     protected String getUnsafeParameter() {
 359  0
         return unsafe ? "/unsafe" : null;
 360   
     }
 361   
 
 362   
 
 363   
     /**
 364   
      * A flag that tells the compiler not to read in the compiler
 365   
      * settings files 'csc.rsp' in its bin directory and then the local directory
 366   
      *
 367   
      *@param  enabled  The new noConfig value
 368   
      */
 369  0
     public void setNoConfig(boolean enabled) {
 370  0
         noconfig = enabled;
 371   
     }
 372   
 
 373   
 
 374   
     /**
 375   
      *  Gets the noConfigParameter attribute of the CSharp object
 376   
      *
 377   
      *@return    The noConfigParameter value
 378   
      */
 379  0
     protected String getNoConfigParameter() {
 380  0
         return noconfig ? "/noconfig" : null;
 381   
     }
 382   
 
 383   
 
 384   
     /**
 385   
      *  Semicolon separated list of defined constants.
 386   
      *
 387   
      *@param  params  The new definitions value
 388   
      */
 389  0
     public void setDefinitions(String params) {
 390  0
         definitions = params;
 391   
     }
 392   
 
 393   
     /**
 394   
      * override the superclasses version of this method (which we call)
 395   
      * with a check for a definitions attribute, the contents of which
 396   
      * are appended to the list.
 397   
      *@return    The Definitions Parameter to CSC
 398   
      */
 399  0
     protected String getDefinitionsParameter() {
 400  0
         String predecessors=super.getDefinitionsParameter();
 401  0
         if (notEmpty(definitions)) {
 402  0
             if(predecessors==null) {
 403  0
                 predecessors= "/define:";
 404   
             }
 405  0
             return  predecessors+ definitions;
 406   
         } else {
 407  0
             return predecessors;
 408   
         }
 409   
     }
 410   
 
 411   
 
 412   
     /**
 413   
      * add Commands unique to C#.
 414   
      * @param command ongoing command
 415   
      */
 416  0
     public void addCompilerSpecificOptions(NetCommand command) {
 417  0
         command.addArgument(getIncludeDefaultReferencesParameter());
 418  0
         command.addArgument(getWarnLevelParameter());
 419  0
         command.addArgument(getDocFileParameter());
 420  0
         command.addArgument(getFullPathsParameter());
 421  0
         command.addArgument(getFileAlignParameter());
 422  0
         command.addArgument(getIncrementalParameter());
 423  0
         command.addArgument(getNoConfigParameter());
 424  0
         command.addArgument(getUnsafeParameter());
 425   
     }
 426   
 
 427   
     // end execute
 428   
 
 429   
     /**
 430   
      * how does C# separate references? with a semi colon
 431   
      */
 432  0
     public String getReferenceDelimiter() {
 433  0
         return ";";
 434   
     }
 435   
 
 436   
     /**
 437   
      * compiler is 'csc'
 438   
      * @return
 439   
      */
 440  0
     public String getCompilerExeName() {
 441  0
         return "csc";
 442   
     }
 443   
 
 444   
     /**
 445   
      * extension is '.cs'
 446   
      * @return
 447   
      */
 448  0
     public String getFileExtension() {
 449  0
         return "cs";
 450   
     }
 451   
 
 452   
     /**
 453   
      * from a resource, get the resource param string
 454   
      * @param resource
 455   
      * @return a string containing the resource param, or a null string
 456   
      * to conditionally exclude a resource.
 457   
      */
 458  0
     protected String createResourceParameter(DotnetResource resource) {
 459  0
         return resource.getCSharpStyleParameter();
 460   
     }
 461   
 
 462   
 }
 463   
 
 464