Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 1,020   Methods: 58
NCLOC: 390   Classes: 2
 
 Source file Conditionals Statements Methods TOTAL
DotnetCompile.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:Cream+Live+2001+CD+2
 59   
  */
 60   
 
 61   
 // place in the optional ant tasks package
 62   
 // but in its own dotnet group
 63   
 
 64   
 package org.apache.tools.ant.taskdefs.optional.dotnet;
 65   
 
 66   
 // imports
 67   
 
 68   
 import java.io.File;
 69   
 import java.util.Vector;
 70   
 import java.util.Enumeration;
 71   
 import java.util.Hashtable;
 72   
 
 73   
 import org.apache.tools.ant.BuildException;
 74   
 import org.apache.tools.ant.DirectoryScanner;
 75   
 import org.apache.tools.ant.Project;
 76   
 import org.apache.tools.ant.Task;
 77   
 import org.apache.tools.ant.taskdefs.MatchingTask;
 78   
 import org.apache.tools.ant.types.Path;
 79   
 import org.apache.tools.ant.types.FileSet;
 80   
 import org.apache.tools.ant.types.EnumeratedAttribute;
 81   
 
 82   
 
 83   
 /**
 84   
  *  Abstract superclass for dotnet compiler tasks.
 85   
  *
 86   
  *  History
 87   
  *  <table>
 88   
  *    <tr>
 89   
  *      <td>
 90   
  *        0.1
 91   
  *      </td>
 92   
  *      <td>
 93   
  *        First creation
 94   
  *      </td>
 95   
  *      <td>
 96   
  *        Most of the code here was copied verbatim from v0.3 of
 97   
  *        Steve Loughran's CSharp optional task. Abstracted functionality
 98   
  *        to allow subclassing of other dotnet compiler types.
 99   
  *      </td>
 100   
  *    </tr>
 101   
  *
 102   
  *  </table>
 103   
  *
 104   
  *
 105   
  * @author      Brian Felder bfelder@providence.org
 106   
  * @author      Steve Loughran
 107   
  * @version     0.1
 108   
  */
 109   
 
 110   
 public abstract class DotnetCompile
 111   
          extends DotnetBaseMatchingTask {
 112   
 
 113   
     /**
 114   
      *  list of reference classes. (pretty much a classpath equivalent)
 115   
      */
 116   
     private String references;
 117   
 
 118   
     /**
 119   
      *  flag to enable automatic reference inclusion
 120   
      */
 121   
     private boolean includeDefaultReferences;
 122   
 
 123   
     /**
 124   
      *  icon for incorporation into apps
 125   
      */
 126   
     private File win32icon;
 127   
 
 128   
     /**
 129   
      *  icon for incorporation into apps
 130   
      */
 131   
     private File win32res;
 132   
 
 133   
     /**
 134   
      *  flag to control action on execution trouble
 135   
      */
 136   
     private boolean failOnError;
 137   
 
 138   
     /**
 139   
      *  using the path approach didnt work as it could not handle the implicit
 140   
      *  execution path. Perhaps that could be extracted from the runtime and
 141   
      *  then the path approach would be viable
 142   
      */
 143   
     private Path referenceFiles;
 144   
 
 145   
     /**
 146   
      *  optimise flag
 147   
      */
 148   
     private boolean optimize;
 149   
 
 150   
     /**
 151   
      * a list of definitions to support;
 152   
      */
 153   
     protected Vector definitionList = new Vector();
 154   
 
 155   
     /**
 156   
      * our resources
 157   
      */
 158   
     protected Vector resources = new Vector();
 159   
 
 160   
     /**
 161   
      *  Fix .NET reference inclusion. .NET is really dumb in how it handles
 162   
      *  inclusion. You have to list every 'assembly' -read DLL that is imported.
 163   
      *  So already you are making a platform assumption -shared libraries have a
 164   
      *  .dll;"+ extension and the poor developer has to know every library which
 165   
      *  is included why the compiler cant find classes on the path or in a
 166   
      *  directory, is a mystery. To reduce the need to be explicit, here is a
 167   
      *  long list of the core libraries used in Beta-1 of .NET ommitting the
 168   
      *  blatantly non portable (MS.win32.interop) and the .designer libraries.
 169   
      *  (ripping out Com was tempting) Casing is chosen to match that of the
 170   
      *  file system <i>exactly</i> so may work on a unix box too. there is no
 171   
      *  need to reference mscorlib.dll, cos it is always there
 172   
      */
 173   
 
 174   
     protected static final String[] DEFAULT_REFERENCE_LIST_DOTNET_10 =
 175   
            {"Accessibility.dll",
 176   
             "cscompmgd.dll",
 177   
             "CustomMarshalers.dll",
 178   
             "Mscorcfg.dll",
 179   
             "System.Configuration.Install.dll",
 180   
             "System.Data.dll",
 181   
             "System.Design.dll",
 182   
             "System.DirectoryServices.dll",
 183   
             "System.EnterpriseServices.dll",
 184   
             "System.dll",
 185   
             "System.Drawing.Design.dll",
 186   
             "System.Drawing.dll",
 187   
             "System.Management.dll",
 188   
             "System.Messaging.dll",
 189   
             "System.Runtime.Remoting.dll",
 190   
             "System.Runtime.Serialization.Formatters.Soap.dll",
 191   
             "System.Security.dll",
 192   
             "System.ServiceProcess.dll",
 193   
             "System.Web.dll",
 194   
             "System.Web.RegularExpressions.dll",
 195   
             "System.Web.Services.dll",
 196   
             "System.Windows.Forms.dll",
 197   
             "System.XML.dll"};
 198   
 
 199   
     protected static final String REFERENCE_OPTION= "/reference:";
 200   
 
 201   
     /**
 202   
      *  debug flag. Controls generation of debug information.
 203   
      */
 204   
     protected boolean debug;
 205   
 
 206   
     /**
 207   
      *  warning level: 0-4, with 4 being most verbose
 208   
      */
 209   
     private int warnLevel;
 210   
 
 211   
     /**
 212   
      *  main class (or null for automatic choice)
 213   
      */
 214   
     protected String mainClass;
 215   
 
 216   
     /**
 217   
      *  any extra command options?
 218   
      */
 219   
     protected String extraOptions;
 220   
 
 221   
     /**
 222   
      *  type of target. Should be one of exe|library|module|winexe|(null)
 223   
      *  default is exe; the actual value (if not null) is fed to the command
 224   
      *  line. <br>
 225   
      *  See /target
 226   
      */
 227   
     protected String targetType;
 228   
 
 229   
     /**
 230   
      *  utf out flag
 231   
      */
 232   
 
 233   
     protected boolean utf8output = false;
 234   
 
 235   
     /**
 236   
      *  list of extra modules to refer to
 237   
      */
 238   
     protected String additionalModules;
 239   
     /**
 240   
      * filesets of references
 241   
      */
 242   
     protected Vector referenceFilesets =new Vector();
 243   
 
 244   
 
 245   
     /**
 246   
      *  constructor inits everything and set up the search pattern
 247   
      */
 248   
 
 249  0
     public DotnetCompile() {
 250  0
         clear();
 251  0
         setIncludes(getFilePattern());
 252   
     }
 253   
 
 254   
     /**
 255   
      *  reset all contents.
 256   
      */
 257  0
     public void clear() {
 258  0
         targetType = null;
 259  0
         win32icon = null;
 260  0
         srcDir = null;
 261  0
         mainClass = null;
 262  0
         warnLevel = 3;
 263  0
         optimize = false;
 264  0
         debug = true;
 265  0
         references = null;
 266  0
         failOnError = true;
 267  0
         additionalModules = null;
 268  0
         includeDefaultReferences = true;
 269  0
         extraOptions = null;
 270   
     }
 271   
 
 272   
 
 273   
     /**
 274   
      * Semicolon separated list of DLLs to refer to.
 275   
      *
 276   
      *@param  s  The new References value
 277   
      */
 278  0
     public void setReferences(String s) {
 279  0
         references = s;
 280   
     }
 281   
 
 282   
 
 283   
     /**
 284   
      *  get the reference string or null for no argument needed
 285   
      *
 286   
      *@return    The References Parameter to CSC
 287   
      */
 288  0
     protected String getReferencesParameter() {
 289   
         //bail on no references
 290  0
         if (notEmpty(references)) {
 291  0
             return REFERENCE_OPTION + references;
 292   
         } else {
 293  0
             return null;
 294   
         }
 295   
     }
 296   
 
 297   
     /**
 298   
      * Path of references to include.
 299   
      * Wildcards should work.
 300   
      *
 301   
      *@param  path  another path to append
 302   
      */
 303  0
     public void setReferenceFiles(Path path) {
 304   
         //demand create pathlist
 305  0
         if (referenceFiles == null) {
 306  0
             referenceFiles = new Path(this.getProject());
 307   
         }
 308  0
         referenceFiles.append(path);
 309   
     }
 310   
 
 311   
     /**
 312   
      * add a new reference fileset to the compilation
 313   
      * @param reference
 314   
      */
 315  0
     public void addReference(FileSet reference) {
 316  0
         referenceFilesets.add(reference);
 317   
     }
 318   
 
 319   
 
 320   
 
 321   
     /**
 322   
      *  turn the path list into a list of files and a /references argument
 323   
      *
 324   
      *@return    null or a string of references.
 325   
      */
 326  0
     protected String getReferenceFilesParameter() {
 327   
         //bail on no references
 328  0
         if (references == null) {
 329  0
             return null;
 330   
         }
 331   
         //iterate through the ref list & generate an entry for each
 332   
         //or just rely on the fact that the toString operator does this, but
 333   
         //noting that the separator is ';' on windows, ':' on unix
 334  0
         String refpath = references.toString();
 335   
 
 336   
         //bail on no references listed
 337  0
         if (refpath.length() == 0) {
 338  0
             return null;
 339   
         }
 340   
 
 341  0
         StringBuffer s = new StringBuffer(REFERENCE_OPTION);
 342  0
         s.append(refpath);
 343  0
         return new String(s);
 344   
     }
 345   
 
 346   
 
 347   
     /**
 348   
      *  get default reference list
 349   
      *
 350   
      *@return    null or a string of references.
 351   
      */
 352  0
     protected String getDefaultReferenceParameter() {
 353  0
         if (includeDefaultReferences) {
 354  0
             StringBuffer s = new StringBuffer("/reference:");
 355  0
             s.append(getDefaultReferenceList());
 356  0
             return new String(s);
 357   
         } else {
 358  0
             return null;
 359   
         }
 360   
     }
 361   
 
 362   
 
 363   
     /**
 364   
      * If true, automatically includes the common assemblies
 365   
      * in dotnet, and tells the compiler to link in mscore.dll.
 366   
      *
 367   
      *  set the automatic reference inclusion flag on or off this flag controls
 368   
      *  the string of references and the /nostdlib option in CSC
 369   
      *
 370   
      *@param  f  on/off flag
 371   
      */
 372  0
     public void setIncludeDefaultReferences(boolean f) {
 373  0
         includeDefaultReferences = f;
 374   
     }
 375   
 
 376   
 
 377   
     /**
 378   
      *  query automatic reference inclusion flag
 379   
      *
 380   
      *@return    true if flag is turned on
 381   
      */
 382  0
     public boolean getIncludeDefaultReferences() {
 383  0
         return includeDefaultReferences;
 384   
     }
 385   
 
 386   
 
 387   
     /**
 388   
      *  get the include default references flag or null for no argument needed
 389   
      *
 390   
      *@return    The Parameter to CSC
 391   
      */
 392  0
     protected String getIncludeDefaultReferencesParameter() {
 393  0
         return "/nostdlib" + (includeDefaultReferences ? "-" : "+");
 394   
     }
 395   
 
 396   
 
 397   
 
 398   
     /**
 399   
      * If true, enables optimization flag.
 400   
      *
 401   
      *@param  f  on/off flag
 402   
      */
 403  0
     public void setOptimize(boolean f) {
 404  0
         optimize = f;
 405   
     }
 406   
 
 407   
 
 408   
     /**
 409   
      *  query the optimise flag
 410   
      *
 411   
      *@return    true if optimise is turned on
 412   
      */
 413  0
     public boolean getOptimize() {
 414  0
         return optimize;
 415   
     }
 416   
 
 417   
 
 418   
     /**
 419   
      *  get the optimise flag or null for no argument needed
 420   
      *
 421   
      *@return    The Optimize Parameter to CSC
 422   
      */
 423  0
     protected String getOptimizeParameter() {
 424  0
         return "/optimize" + (optimize ? "+" : "-");
 425   
     }
 426   
 
 427   
 
 428   
     /**
 429   
      *  set the debug flag on or off.
 430   
      *
 431   
      *@param  f  on/off flag
 432   
      */
 433  0
     public void setDebug(boolean f) {
 434  0
         debug = f;
 435   
     }
 436   
 
 437   
 
 438   
     /**
 439   
      *  query the debug flag
 440   
      *
 441   
      *@return    true if debug is turned on
 442   
      */
 443  0
     public boolean getDebug() {
 444  0
         return debug;
 445   
     }
 446   
 
 447   
 
 448   
     /**
 449   
      *  get the debug switch argument
 450   
      *
 451   
      *@return    The Debug Parameter to CSC
 452   
      */
 453  0
     protected String getDebugParameter() {
 454  0
         return "/debug" + (debug ? "+" : "-");
 455   
     }
 456   
 
 457   
 
 458   
     /**
 459   
      * Level of warning currently between 1 and 4
 460   
      * with 4 being the strictest.
 461   
      *
 462   
      *@param  warnLevel  warn level -see .net docs for valid range (probably
 463   
      *      0-4)
 464   
      */
 465  0
     public void setWarnLevel(int warnLevel) {
 466  0
         this.warnLevel = warnLevel;
 467   
     }
 468   
 
 469   
 
 470   
     /**
 471   
      *  query warn level
 472   
      *
 473   
      *@return    current value
 474   
      */
 475  0
     public int getWarnLevel() {
 476  0
         return warnLevel;
 477   
     }
 478   
 
 479   
 
 480   
     /**
 481   
      *  get the warn level switch
 482   
      *
 483   
      *@return    The WarnLevel Parameter to CSC
 484   
      */
 485  0
     protected String getWarnLevelParameter() {
 486  0
         return "/warn:" + warnLevel;
 487   
     }
 488   
 
 489   
 
 490   
     /**
 491   
      *  Sets the name of main class for executables.
 492   
      *
 493   
      *@param  mainClass  The new MainClass value
 494   
      */
 495  0
     public void setMainClass(String mainClass) {
 496  0
         this.mainClass = mainClass;
 497   
     }
 498   
 
 499   
 
 500   
     /**
 501   
      *  Gets the MainClass attribute
 502   
      *
 503   
      *@return    The MainClass value
 504   
      */
 505  0
     public String getMainClass() {
 506  0
         return this.mainClass;
 507   
     }
 508   
 
 509   
 
 510   
     /**
 511   
      *  get the /main argument or null for no argument needed
 512   
      *
 513   
      *@return    The MainClass Parameter to CSC
 514   
      */
 515  0
     protected String getMainClassParameter() {
 516  0
         if (mainClass != null && mainClass.length() != 0) {
 517  0
             return "/main:" + mainClass;
 518   
         } else {
 519  0
             return null;
 520   
         }
 521   
     }
 522   
 
 523   
 
 524   
     /**
 525   
      * Any extra options which are not explicitly supported
 526   
      * by this task.
 527   
      *
 528   
      *@param  extraOptions  The new ExtraOptions value
 529   
      */
 530  0
     public void setExtraOptions(String extraOptions) {
 531  0
         this.extraOptions = extraOptions;
 532   
     }
 533   
 
 534   
 
 535   
     /**
 536   
      *  Gets the ExtraOptions attribute
 537   
      *
 538   
      *@return    The ExtraOptions value
 539   
      */
 540  0
     public String getExtraOptions() {
 541  0
         return this.extraOptions;
 542   
     }
 543   
 
 544   
 
 545   
     /**
 546   
      *  get any extra options or null for no argument needed
 547   
      *
 548   
      *@return    The ExtraOptions Parameter to CSC
 549   
      */
 550  0
     protected String getExtraOptionsParameter() {
 551  0
         if (extraOptions != null && extraOptions.length() != 0) {
 552  0
             return extraOptions;
 553   
         } else {
 554  0
             return null;
 555   
         }
 556   
     }
 557   
 
 558   
 
 559   
     /**
 560   
      * Set the destination directory of files to be compiled.
 561   
      *
 562   
      *@param  dirName  The new DestDir value
 563   
      */
 564  0
     public void setDestDir(File dirName) {
 565  0
         log( "DestDir currently unused", Project.MSG_WARN );
 566   
     }
 567   
 
 568   
 
 569   
     /**
 570   
      * set the target type to one of exe|library|module|winexe
 571   
      * @param targetType
 572   
      */
 573  0
     public void setTargetType(TargetTypes targetType) {
 574  0
         this.targetType=targetType.getValue();
 575   
     }
 576   
     /**
 577   
      * Set the type of target.
 578   
      *
 579   
      *@param  ttype          The new TargetType value
 580   
      *@exception  BuildException  if target is not one of
 581   
      *      exe|library|module|winexe
 582   
      */
 583  0
     public void setTargetType(String ttype)
 584   
              throws BuildException {
 585  0
         ttype = ttype.toLowerCase();
 586  0
         if (ttype.equals("exe") || ttype.equals("library") ||
 587   
                 ttype.equals("module") || ttype.equals("winexe")) {
 588  0
             targetType = ttype;
 589   
         } else {
 590  0
             throw new BuildException("targetType " + ttype
 591   
                     + " is not one of 'exe', 'module', 'winexe' or 'library'" );
 592   
         }
 593   
     }
 594   
 
 595   
 
 596   
     /**
 597   
      *  Gets the TargetType attribute
 598   
      *
 599   
      *@return    The TargetType value
 600   
      */
 601  0
     public String getTargetType() {
 602  0
         return targetType;
 603   
     }
 604   
 
 605   
 
 606   
     /**
 607   
      *  get the argument or null for no argument needed
 608   
      *
 609   
      *@return    The TargetType Parameter to CSC
 610   
      */
 611  0
     protected String getTargetTypeParameter() {
 612  0
         if (notEmpty(targetType)) {
 613  0
             return "/target:" + targetType;
 614   
         } else {
 615  0
             return null;
 616   
         }
 617   
     }
 618   
 
 619   
 
 620   
     /**
 621   
      *  Set the filename of icon to include.
 622   
      *
 623   
      *@param  fileName  path to the file. Can be relative, absolute, whatever.
 624   
      */
 625  0
     public void setWin32Icon(File fileName) {
 626  0
         win32icon = fileName;
 627   
     }
 628   
 
 629   
 
 630   
     /**
 631   
      *  get the argument or null for no argument needed
 632   
      *
 633   
      *@return    The Win32Icon Parameter to CSC
 634   
      */
 635  0
     protected String getWin32IconParameter() {
 636  0
         if (win32icon != null) {
 637  0
             return "/win32icon:" + win32icon.toString();
 638   
         } else {
 639  0
             return null;
 640   
         }
 641   
     }
 642   
 
 643   
 
 644   
     /**
 645   
      * Sets the filename of a win32 resource (.RES) file to include.
 646   
      * This is not a .NET resource, but what Windows is used to.
 647   
      *
 648   
      *@param  fileName  path to the file. Can be relative, absolute, whatever.
 649   
      */
 650  0
     public void setWin32Res(File fileName) {
 651  0
         win32res = fileName;
 652   
     }
 653   
 
 654   
     /**
 655   
      * Gets the file of the win32 .res file to include.
 656   
      * @return path to the file.
 657   
      */
 658  0
     public File getWin32Res() {
 659  0
         return win32res;
 660   
     }
 661   
 
 662   
 
 663   
     /**
 664   
      *  get the argument or null for no argument needed
 665   
      *
 666   
      *@return    The Win32Res Parameter to CSC
 667   
      */
 668  0
     protected String getWin32ResParameter() {
 669  0
         if (win32res != null) {
 670  0
             return "/win32res:" + win32res.toString();
 671   
         } else {
 672  0
             return null;
 673   
         }
 674   
     }
 675   
 
 676   
 
 677   
     /**
 678   
      * If true, require all compiler output to be in UTF8 format.
 679   
      *
 680   
      *@param  enabled  The new utf8Output value
 681   
      */
 682  0
     public void setUtf8Output(boolean enabled) {
 683  0
         utf8output = enabled;
 684   
     }
 685   
 
 686   
 
 687   
     /**
 688   
      *  Gets the utf8OutpuParameter attribute of the CSharp object
 689   
      *
 690   
      *@return    The utf8OutpuParameter value
 691   
      */
 692  0
     protected String getUtf8OutputParameter() {
 693  0
         return utf8output ? "/utf8output" : null;
 694   
     }
 695   
 
 696   
 
 697   
 
 698   
 
 699   
     /**
 700   
      * add a define to the list of definitions
 701   
      * @param define
 702   
      */
 703  0
     public void addDefine(DotnetDefine define) {
 704  0
         definitionList.addElement(define);
 705   
     }
 706   
 
 707   
 
 708   
     /**
 709   
      * get a list of definitions or null
 710   
      * @return a string beginning /D: or null for no definitions
 711   
      */
 712  0
     protected String getDefinitionsParameter() throws BuildException {
 713  0
         StringBuffer defines=new StringBuffer();
 714  0
         Enumeration defEnum=definitionList.elements();
 715  0
         while (defEnum.hasMoreElements()) {
 716   
             //loop through all definitions
 717  0
             DotnetDefine define = (DotnetDefine) defEnum.nextElement();
 718  0
             if(define.isSet(this)) {
 719   
                 //add those that are set, and a delimiter
 720  0
                 defines.append(define.getValue(this));
 721  0
                 defines.append(getDefinitionsDelimiter());
 722   
             }
 723   
         }
 724  0
         if(defines.length()==0) {
 725  0
             return null;
 726   
         } else {
 727  0
             return "/D:"+defines;
 728   
         }
 729   
     }
 730   
 
 731   
 
 732   
     /**
 733   
      * Semicolon separated list of modules to refer to.
 734   
      *
 735   
      *@param  params  The new additionalModules value
 736   
      */
 737  0
     public void setAdditionalModules(String params) {
 738  0
         additionalModules = params;
 739   
     }
 740   
 
 741   
 
 742   
     /**
 743   
      *  get the argument or null for no argument needed
 744   
      *
 745   
      *@return    The AdditionalModules Parameter to CSC
 746   
      */
 747  0
     protected String getAdditionalModulesParameter() {
 748  0
         if (notEmpty(additionalModules)) {
 749  0
             return "/addmodule:" + additionalModules;
 750   
         } else {
 751  0
             return null;
 752   
         }
 753   
     }
 754   
 
 755   
 
 756   
     /**
 757   
      *  get the argument or null for no argument needed
 758   
      *
 759   
      *@return    The OutputFile Parameter to CSC
 760   
      */
 761  0
     protected String getDestFileParameter() {
 762  0
         if (outputFile != null) {
 763  0
             return "/out:" + outputFile.toString();
 764   
         } else {
 765  0
             return null;
 766   
         }
 767   
     }
 768   
 
 769   
 
 770   
     /**
 771   
      * If true, fail on compilation errors.
 772   
      *
 773   
      *@param  b  The new FailOnError value
 774   
      */
 775  0
     public void setFailOnError(boolean b) {
 776  0
         failOnError = b;
 777   
     }
 778   
 
 779   
 
 780   
     /**
 781   
      *  query fail on error flag
 782   
      *
 783   
      *@return    The FailFailOnError value
 784   
      */
 785  0
     public boolean getFailOnError() {
 786  0
         return failOnError;
 787   
     }
 788   
 
 789   
     /**
 790   
      * link or embed a resource
 791   
      * @param resource
 792   
      */
 793  0
     public void addResource(DotnetResource resource) {
 794  0
         resources.add(resource);
 795   
     }
 796   
 
 797   
     /**
 798   
      *  test for a string containing something useful
 799   
      *
 800   
      *@param  s  string in
 801   
      *@return    true if the argument is not null or empty
 802   
      */
 803  0
     protected boolean notEmpty(String s) {
 804  0
         return s != null && s.length() != 0;
 805   
     }
 806   
 
 807   
     /**
 808   
      * validation code
 809   
      * @throws  BuildException  if validation failed
 810   
      */
 811  0
     protected void validate()
 812   
             throws BuildException {
 813  0
         if (outputFile != null && outputFile.isDirectory()) {
 814  0
             throw new BuildException("destFile cannot be a directory");
 815   
         }
 816   
     }
 817   
 
 818   
     /**
 819   
      * Based on DEFAULT_REFERENCE_LIST and getReferenceDelimiter(),
 820   
      * build the appropriate reference string for the compiler.
 821   
      * @return The properly delimited reference list.
 822   
      */
 823  0
     public String getDefaultReferenceList() {
 824  0
         StringBuffer referenceList = new StringBuffer();
 825  0
         for (int index = 0; index < DEFAULT_REFERENCE_LIST_DOTNET_10.length; index++) {
 826  0
             referenceList.append(DEFAULT_REFERENCE_LIST_DOTNET_10[index]);
 827  0
             referenceList.append(getReferenceDelimiter());
 828   
         }
 829  0
         return referenceList.toString();
 830   
     }
 831   
 
 832   
     /**
 833   
      * Get the pattern for files to compile.
 834   
      * @return The compilation file pattern.
 835   
      */
 836  0
     public String getFilePattern() {
 837  0
         return "**/*." + getFileExtension();
 838   
     }
 839   
 
 840   
 
 841   
     /**
 842   
      *  do the work by building the command line and then calling it
 843   
      *
 844   
      *@throws  BuildException  if validation or execution failed
 845   
      */
 846  0
     public void execute()
 847   
              throws BuildException {
 848  0
         validate();
 849  0
         NetCommand command = createNetCommand();
 850   
         //fill in args
 851  0
         fillInSharedParameters(command);
 852  0
         addResources(command);
 853  0
         addCompilerSpecificOptions(command);
 854  0
         int referencesOutOfDate=addReferenceFilesets(command,
 855   
                 getOutputFileTimestamp());
 856   
         //if the refs are out of date, force a build.
 857  0
         boolean forceBuild= referencesOutOfDate > 0;
 858  0
         addFilesAndExecute(command, forceBuild);
 859   
 
 860   
     }
 861   
 
 862   
     /**
 863   
      * Get the delimiter that the compiler uses between references.
 864   
      * For example, c# will return ";"; VB.NET will return ","
 865   
      * @return The string delimiter for the reference string.
 866   
      */
 867   
     public abstract String getReferenceDelimiter();
 868   
 
 869   
     /**
 870   
      * Get the name of the compiler executable.
 871   
      * @return The name of the compiler executable.
 872   
      */
 873   
     public abstract String getCompilerExeName() ;
 874   
 
 875   
     /**
 876   
      * Get the extension of filenames to compile.
 877   
      * @return The string extension of files to compile.
 878   
      */
 879   
     public abstract String getFileExtension();
 880   
 
 881   
 
 882   
     /**
 883   
      * fill in the common information
 884   
      * @param command
 885   
      */
 886  0
     protected void fillInSharedParameters(NetCommand command) {
 887  0
         command.setFailOnError(getFailOnError());
 888   
         //fill in args
 889  0
         command.addArgument("/nologo");
 890  0
         command.addArgument(getAdditionalModulesParameter());
 891  0
         command.addArgument(getDebugParameter());
 892  0
         command.addArgument(getDefaultReferenceParameter());
 893  0
         command.addArgument(getDefinitionsParameter());
 894  0
         command.addArgument(getExtraOptionsParameter());
 895  0
         command.addArgument(getMainClassParameter());
 896  0
         command.addArgument(getOptimizeParameter());
 897  0
         command.addArgument(getDestFileParameter());
 898  0
         command.addArgument(getReferencesParameter());
 899  0
         command.addArgument(getTargetTypeParameter());
 900  0
         command.addArgument(getUtf8OutputParameter());
 901  0
         command.addArgument(getWin32IconParameter());
 902  0
         command.addArgument(getWin32ResParameter());
 903   
     }
 904   
 
 905   
     /**
 906   
      * for every resource declared, we get the (language specific)
 907   
      * resource setting
 908   
      */
 909  0
     protected void addResources(NetCommand command) {
 910  0
         Enumeration e=resources.elements();
 911  0
         while (e.hasMoreElements()) {
 912  0
             DotnetResource resource = (DotnetResource) e.nextElement();
 913  0
             command.addArgument(createResourceParameter(resource));
 914   
         }
 915   
     }
 916   
 
 917   
     /**
 918   
      * from a resource, get the
 919   
      * @param resource
 920   
      * @return a string containing the resource param, or a null string
 921   
      * to conditionally exclude a resource.
 922   
      */
 923   
     protected abstract String createResourceParameter(DotnetResource resource);
 924   
 
 925   
 
 926   
     /**
 927   
      * run through the list of reference files and add them to the command
 928   
      * @param outputTimestamp timestamp to compare against
 929   
      * @return number of files out of date
 930   
      */
 931   
 
 932  0
     protected int addReferenceFilesets(NetCommand command, long outputTimestamp) {
 933  0
         int filesOutOfDate = 0;
 934  0
         Hashtable filesToBuild=new Hashtable();
 935  0
         for (int i = 0; i < referenceFilesets.size(); i++) {
 936  0
             FileSet fs = (FileSet) referenceFilesets.elementAt(i);
 937  0
             filesOutOfDate += command.scanOneFileset(
 938   
                     fs.getDirectoryScanner(getProject()),
 939   
                     filesToBuild,
 940   
                     outputTimestamp);
 941   
         }
 942   
         //bail out early if there were no files
 943  0
         if(filesToBuild.size()==0) {
 944  0
             return 0;
 945   
         }
 946  0
         StringBuffer referenceList= new StringBuffer(REFERENCE_OPTION);
 947   
         //now scan the hashtable and add the files
 948  0
         Enumeration files = filesToBuild.elements();
 949  0
         while (files.hasMoreElements()) {
 950  0
             File file = (File) files.nextElement();
 951  0
             if(isFileManagedBinary(file)) {
 952  0
                 referenceList.append(file.toString());
 953  0
                 referenceList.append(getReferenceDelimiter());
 954   
             } else {
 955  0
                 log("ignoring "+file+" as it is not a managed executable",
 956   
                         Project.MSG_VERBOSE);
 957   
             }
 958   
 
 959   
         }
 960   
         //add it all to an argument
 961  0
         command.addArgument(referenceList.toString());
 962  0
         return filesOutOfDate;
 963   
     }
 964   
 
 965   
     /**
 966   
      * create our helper command
 967   
      * @return a command prefilled with the exe name and task name
 968   
      */
 969  0
     protected NetCommand createNetCommand() {
 970  0
         NetCommand command = new NetCommand(this, getTaskName(), getCompilerExeName());
 971  0
         return command;
 972   
     }
 973   
 
 974   
     /**
 975   
      * add any compiler specifics
 976   
      * @param command
 977   
      */
 978   
     protected abstract void addCompilerSpecificOptions(NetCommand command);
 979   
 
 980   
     /**
 981   
      * override point for delimiting definitions
 982   
      * @return
 983   
      */
 984  0
     public String getDefinitionsDelimiter() {
 985  0
         return ";";
 986   
     }
 987   
 
 988   
 
 989   
     /**
 990   
      * test for a file being managed or not
 991   
      * @return true if we think this is a managed executable, and thus OK
 992   
      * for linking
 993   
      * @todo look at the PE header of the exe and see if it is managed or not.
 994   
      */
 995  0
     protected static boolean isFileManagedBinary(File file) {
 996  0
         String filename= file.toString().toLowerCase();
 997  0
         return filename.endsWith(".exe") || filename.endsWith(".dll")
 998   
                 || filename.endsWith(".netmodule");
 999   
     }
 1000   
 
 1001   
     /**
 1002   
      * Target types to build.
 1003   
      * valid build types are exe|library|module|winexe
 1004   
      */
 1005   
     public static class TargetTypes extends EnumeratedAttribute {
 1006  0
         public String[] getValues() {
 1007  0
             return new String[] {
 1008   
                 "exe",
 1009   
                 "library",
 1010   
                 "module",
 1011   
                 "winexe"
 1012   
             };
 1013   
         }
 1014   
     }
 1015   
 
 1016   
 
 1017   
 }
 1018   
 
 1019   
 
 1020