Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 929   Methods: 47
NCLOC: 476   Classes: 3
 
 Source file Conditionals Statements Methods TOTAL
NetRexxC.java 0% 0% 0% 0%
 1   
 /*
 2   
  * The Apache Software License, Version 1.1
 3   
  *
 4   
  * Copyright (c) 2000-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;
 55   
 
 56   
 import java.io.BufferedReader;
 57   
 import java.io.File;
 58   
 import java.io.IOException;
 59   
 import java.io.PrintWriter;
 60   
 import java.io.StringReader;
 61   
 import java.io.StringWriter;
 62   
 import java.util.Enumeration;
 63   
 import java.util.Hashtable;
 64   
 import java.util.Properties;
 65   
 import java.util.StringTokenizer;
 66   
 import java.util.Vector;
 67   
 import netrexx.lang.Rexx;
 68   
 import org.apache.tools.ant.BuildException;
 69   
 import org.apache.tools.ant.DirectoryScanner;
 70   
 import org.apache.tools.ant.Project;
 71   
 import org.apache.tools.ant.taskdefs.MatchingTask;
 72   
 import org.apache.tools.ant.types.EnumeratedAttribute;
 73   
 
 74   
 /**
 75   
  * Compiles NetRexx source files.
 76   
  * This task can take the following
 77   
  * arguments:
 78   
  * <ul>
 79   
  * <li>binary</li>
 80   
  * <li>classpath</li>
 81   
  * <li>comments</li>
 82   
  * <li>compile</li>
 83   
  * <li>console</li>
 84   
  * <li>crossref</li>
 85   
  * <li>decimal</li>
 86   
  * <li>destdir</li>
 87   
  * <li>diag</li>
 88   
  * <li>explicit</li>
 89   
  * <li>format</li>
 90   
  * <li>keep</li>
 91   
  * <li>logo</li>
 92   
  * <li>replace</li>
 93   
  * <li>savelog</li>
 94   
  * <li>srcdir</li>
 95   
  * <li>sourcedir</li>
 96   
  * <li>strictargs</li>
 97   
  * <li>strictassign</li>
 98   
  * <li>strictcase</li>
 99   
  * <li>strictimport</li>
 100   
  * <li>symbols</li>
 101   
  * <li>time</li>
 102   
  * <li>trace</li>
 103   
  * <li>utf8</li>
 104   
  * <li>verbose</li>
 105   
  * <li>suppressMethodArgumentNotUsed</li>
 106   
  * <li>suppressPrivatePropertyNotUsed</li>
 107   
  * <li>suppressVariableNotUsed</li>
 108   
  * <li>suppressExceptionNotSignalled</li>
 109   
  * <li>suppressDeprecation</li>
 110   
  * </ul>
 111   
  * Of these arguments, the <b>srcdir</b> argument is required.
 112   
  *
 113   
  * <p>When this task executes, it will recursively scan the srcdir
 114   
  * looking for NetRexx source files to compile. This task makes its
 115   
  * compile decision based on timestamp.
 116   
  * <p>Before files are compiled they and any other file in the
 117   
  * srcdir will be copied to the destdir allowing support files to be
 118   
  * located properly in the classpath. The reason for copying the source files
 119   
  * before the compile is that NetRexxC has only two destinations for classfiles:
 120   
  * <ol>
 121   
  * <li>The current directory, and,</li>
 122   
  * <li>The directory the source is in (see sourcedir option)
 123   
  * </ol>
 124   
  *
 125   
  * @author dIon Gillard <a href="mailto:dion@multitask.com.au">dion@multitask.com.au</a>
 126   
  */
 127   
 public class NetRexxC extends MatchingTask {
 128   
 
 129   
     // variables to hold arguments
 130   
     private boolean binary;
 131   
     private String classpath;
 132   
     private boolean comments;
 133   
     private boolean compact = true;// should be the default, as it integrates better in ant.
 134   
     private boolean compile = true;
 135   
     private boolean console;
 136   
     private boolean crossref;
 137   
     private boolean decimal = true;
 138   
     private File destDir;
 139   
     private boolean diag;
 140   
     private boolean explicit;
 141   
     private boolean format;
 142   
     private boolean keep;
 143   
     private boolean logo = true;
 144   
     private boolean replace;
 145   
     private boolean savelog;
 146   
     private File srcDir;
 147   
     private boolean sourcedir = true;// ?? Should this be the default for ant?
 148   
     private boolean strictargs;
 149   
     private boolean strictassign;
 150   
     private boolean strictcase;
 151   
     private boolean strictimport;
 152   
     private boolean strictprops;
 153   
     private boolean strictsignal;
 154   
     private boolean symbols;
 155   
     private boolean time;
 156   
     private String trace = "trace2";
 157   
     private boolean utf8;
 158   
     private String verbose = "verbose3";
 159   
     private boolean suppressMethodArgumentNotUsed = false;
 160   
     private boolean suppressPrivatePropertyNotUsed = false;
 161   
     private boolean suppressVariableNotUsed = false;
 162   
     private boolean suppressExceptionNotSignalled = false;
 163   
     private boolean suppressDeprecation = false;
 164   
 
 165   
     // constants for the messages to suppress by flags and their corresponding properties
 166   
     static final String MSG_METHOD_ARGUMENT_NOT_USED = "Warning: Method argument is not used";
 167   
     static final String MSG_PRIVATE_PROPERTY_NOT_USED = "Warning: Private property is defined but not used";
 168   
     static final String MSG_VARIABLE_NOT_USED = "Warning: Variable is set but not used";
 169   
     static final String MSG_EXCEPTION_NOT_SIGNALLED = "is in SIGNALS list but is not signalled within the method";
 170   
     static final String MSG_DEPRECATION = "has been deprecated";
 171   
 
 172   
     // other implementation variables
 173   
     private Vector compileList = new Vector();
 174   
     private Hashtable filecopyList = new Hashtable();
 175   
 
 176   
     /**
 177   
      * Set whether literals are treated as binary, rather than NetRexx types
 178   
      */
 179  0
     public void setBinary(boolean binary) {
 180  0
         this.binary = binary;
 181   
     }
 182   
 
 183   
 
 184   
     /** Set the classpath used for NetRexx compilation  */
 185  0
     public void setClasspath(String classpath) {
 186  0
         this.classpath = classpath;
 187   
     }
 188   
 
 189   
 
 190   
     /**
 191   
      * Set whether comments are passed through to the generated java source.
 192   
      * Valid true values are "on" or "true". Anything else sets the flag to
 193   
      * false. The default value is false
 194   
      */
 195  0
     public void setComments(boolean comments) {
 196  0
         this.comments = comments;
 197   
     }
 198   
 
 199   
 
 200   
     /**
 201   
      * Set whether error messages come out in compact or verbose format. Valid
 202   
      * true values are "on" or "true". Anything else sets the flag to false.
 203   
      * The default value is false
 204   
      */
 205  0
     public void setCompact(boolean compact) {
 206  0
         this.compact = compact;
 207   
     }
 208   
 
 209   
 
 210   
     /**
 211   
      * Set whether the NetRexx compiler should compile the generated java code
 212   
      * Valid true values are "on" or "true". Anything else sets the flag to
 213   
      * false. The default value is true. Setting this flag to false, will
 214   
      * automatically set the keep flag to true.
 215   
      */
 216  0
     public void setCompile(boolean compile) {
 217  0
         this.compile = compile;
 218  0
         if (!this.compile && !this.keep) {
 219  0
             this.keep = true;
 220   
         }
 221   
     }
 222   
 
 223   
 
 224   
     /**
 225   
      * Set whether or not messages should be displayed on the 'console' Valid
 226   
      * true values are "on" or "true". Anything else sets the flag to false.
 227   
      * The default value is true.
 228   
      */
 229  0
     public void setConsole(boolean console) {
 230  0
         this.console = console;
 231   
     }
 232   
 
 233   
 
 234   
     /** Whether variable cross references are generated  */
 235  0
     public void setCrossref(boolean crossref) {
 236  0
         this.crossref = crossref;
 237   
     }
 238   
 
 239   
 
 240   
     /**
 241   
      * Set whether decimal arithmetic should be used for the netrexx code.
 242   
      * Binary arithmetic is used when this flag is turned off. Valid true
 243   
      * values are "on" or "true". Anything else sets the flag to false. The
 244   
      * default value is true.
 245   
      */
 246  0
     public void setDecimal(boolean decimal) {
 247  0
         this.decimal = decimal;
 248   
     }
 249   
 
 250   
 
 251   
     /**
 252   
      * Set the destination directory into which the NetRexx source files
 253   
      * should be copied and then compiled.
 254   
      */
 255  0
     public void setDestDir(File destDirName) {
 256  0
         destDir = destDirName;
 257   
     }
 258   
 
 259   
 
 260   
     /**
 261   
      * Whether diagnostic information about the compile is generated
 262   
      */
 263  0
     public void setDiag(boolean diag) {
 264  0
         this.diag = diag;
 265   
     }
 266   
 
 267   
 
 268   
     /**
 269   
      * Sets whether variables must be declared explicitly before use. Valid
 270   
      * true values are "on" or "true". Anything else sets the flag to false.
 271   
      * The default value is false.
 272   
      */
 273  0
     public void setExplicit(boolean explicit) {
 274  0
         this.explicit = explicit;
 275   
     }
 276   
 
 277   
 
 278   
     /**
 279   
      * Whether the generated java code is formatted nicely or left to match
 280   
      * NetRexx line numbers for call stack debugging
 281   
      */
 282  0
     public void setFormat(boolean format) {
 283  0
         this.format = format;
 284   
     }
 285   
 
 286   
 
 287   
     /**
 288   
      * Whether the generated java code is produced Valid true values are "on"
 289   
      * or "true". Anything else sets the flag to false. The default value is
 290   
      * false.
 291   
      */
 292  0
     public void setJava(boolean java) {
 293  0
         log( "The attribute java is currently unused.", Project.MSG_WARN );
 294   
     }
 295   
 
 296   
 
 297   
     /**
 298   
      * Sets whether the generated java source file should be kept after
 299   
      * compilation. The generated files will have an extension of .java.keep,
 300   
      * <b>not</b> .java Valid true values are "on" or "true". Anything else
 301   
      * sets the flag to false. The default value is false.
 302   
      */
 303  0
     public void setKeep(boolean keep) {
 304  0
         this.keep = keep;
 305   
     }
 306   
 
 307   
 
 308   
     /** Whether the compiler text logo is displayed when compiling  */
 309  0
     public void setLogo(boolean logo) {
 310  0
         this.logo = logo;
 311   
     }
 312   
 
 313   
 
 314   
     /**
 315   
      * Whether the generated .java file should be replaced when compiling
 316   
      * Valid true values are "on" or "true". Anything else sets the flag to
 317   
      * false. The default value is false.
 318   
      */
 319  0
     public void setReplace(boolean replace) {
 320  0
         this.replace = replace;
 321   
     }
 322   
 
 323   
 
 324   
     /**
 325   
      * Sets whether the compiler messages will be written to NetRexxC.log as
 326   
      * well as to the console Valid true values are "on" or "true". Anything
 327   
      * else sets the flag to false. The default value is false.
 328   
      */
 329  0
     public void setSavelog(boolean savelog) {
 330  0
         this.savelog = savelog;
 331   
     }
 332   
 
 333   
 
 334   
     /**
 335   
      * Tells the NetRexx compiler to store the class files in the same
 336   
      * directory as the source files. The alternative is the working directory
 337   
      * Valid true values are "on" or "true". Anything else sets the flag to
 338   
      * false. The default value is true.
 339   
      */
 340  0
     public void setSourcedir(boolean sourcedir) {
 341  0
         this.sourcedir = sourcedir;
 342   
     }
 343   
 
 344   
 
 345   
     /** Set the source dir to find the source Java files.  */
 346  0
     public void setSrcDir(File srcDirName) {
 347  0
         srcDir = srcDirName;
 348   
     }
 349   
 
 350   
 
 351   
     /**
 352   
      * Tells the NetRexx compiler that method calls always need parentheses,
 353   
      * even if no arguments are needed, e.g. <code>aStringVar.getBytes</code>
 354   
      * vs. <code>aStringVar.getBytes()</code> Valid true values are "on" or
 355   
      * "true". Anything else sets the flag to false. The default value is
 356   
      * false.
 357   
      */
 358  0
     public void setStrictargs(boolean strictargs) {
 359  0
         this.strictargs = strictargs;
 360   
     }
 361   
 
 362   
 
 363   
     /**
 364   
      * Tells the NetRexx compile that assignments must match exactly on type
 365   
      */
 366  0
     public void setStrictassign(boolean strictassign) {
 367  0
         this.strictassign = strictassign;
 368   
     }
 369   
 
 370   
 
 371   
     /**
 372   
      * Specifies whether the NetRexx compiler should be case sensitive or not
 373   
      */
 374  0
     public void setStrictcase(boolean strictcase) {
 375  0
         this.strictcase = strictcase;
 376   
     }
 377   
 
 378   
 
 379   
     /**
 380   
      * Sets whether classes need to be imported explicitly using an <code>import</code>
 381   
      * statement. By default the NetRexx compiler will import certain packages
 382   
      * automatically Valid true values are "on" or "true". Anything else sets
 383   
      * the flag to false. The default value is false.
 384   
      */
 385  0
     public void setStrictimport(boolean strictimport) {
 386  0
         this.strictimport = strictimport;
 387   
     }
 388   
 
 389   
 
 390   
     /**
 391   
      * Sets whether local properties need to be qualified explicitly using
 392   
      * <code>this</code> Valid true values are "on" or "true". Anything else
 393   
      * sets the flag to false. The default value is false.
 394   
      */
 395  0
     public void setStrictprops(boolean strictprops) {
 396  0
         this.strictprops = strictprops;
 397   
     }
 398   
 
 399   
 
 400   
     /**
 401   
      * Whether the compiler should force catching of exceptions by explicitly
 402   
      * named types
 403   
      */
 404  0
     public void setStrictsignal(boolean strictsignal) {
 405  0
         this.strictsignal = strictsignal;
 406   
     }
 407   
 
 408   
 
 409   
     /**
 410   
      * Sets whether debug symbols should be generated into the class file
 411   
      * Valid true values are "on" or "true". Anything else sets the flag to
 412   
      * false. The default value is false.
 413   
      */
 414  0
     public void setSymbols(boolean symbols) {
 415  0
         this.symbols = symbols;
 416   
     }
 417   
 
 418   
 
 419   
     /**
 420   
      * Asks the NetRexx compiler to print compilation times to the console
 421   
      * Valid true values are "on" or "true". Anything else sets the flag to
 422   
      * false. The default value is false.
 423   
      */
 424  0
     public void setTime(boolean time) {
 425  0
         this.time = time;
 426   
     }
 427   
 
 428   
 
 429  0
     public void setTrace(TraceAttr trace) {
 430  0
         this.trace = trace.getValue();
 431   
     }
 432   
 
 433   
 
 434   
     /**
 435   
      * Turns on or off tracing and directs the resultant trace output Valid
 436   
      * values are: "trace", "trace1", "trace2" and "notrace". "trace" and
 437   
      * "trace2"
 438   
      */
 439  0
     public void setTrace(String trace) {
 440  0
         TraceAttr t = new TraceAttr();
 441   
 
 442  0
         t.setValue(trace);
 443  0
         setTrace(t);
 444   
     }
 445   
 
 446   
 
 447   
     /**
 448   
      * Tells the NetRexx compiler that the source is in UTF8 Valid true values
 449   
      * are "on" or "true". Anything else sets the flag to false. The default
 450   
      * value is false.
 451   
      */
 452  0
     public void setUtf8(boolean utf8) {
 453  0
         this.utf8 = utf8;
 454   
     }
 455   
 
 456   
 
 457   
     /**
 458   
      * Whether lots of warnings and error messages should be generated
 459   
      */
 460  0
     public void setVerbose(VerboseAttr verbose) {
 461  0
         this.verbose = verbose.getValue();
 462   
     }
 463   
 
 464   
 
 465   
     /**
 466   
      * Whether lots of warnings and error messages should be generated
 467   
      */
 468  0
     public void setVerbose(String verbose) {
 469  0
         VerboseAttr v = new VerboseAttr();
 470   
 
 471  0
         v.setValue(verbose);
 472  0
         setVerbose(v);
 473   
     }
 474   
 
 475   
 
 476   
     /**
 477   
      * Whether the task should suppress the "Method argument is not used" in
 478   
      * strictargs-Mode, which can not be suppressed by the compiler itself.
 479   
      * The warning is logged as verbose message, though.
 480   
      */
 481  0
     public void setSuppressMethodArgumentNotUsed(boolean suppressMethodArgumentNotUsed) {
 482  0
         this.suppressMethodArgumentNotUsed = suppressMethodArgumentNotUsed;
 483   
     }
 484   
 
 485   
 
 486   
     /**
 487   
      * Whether the task should suppress the "Private property is defined but
 488   
      * not used" in strictargs-Mode, which can be quite annoying while
 489   
      * developing. The warning is logged as verbose message, though.
 490   
      */
 491  0
     public void setSuppressPrivatePropertyNotUsed(boolean suppressPrivatePropertyNotUsed) {
 492  0
         this.suppressPrivatePropertyNotUsed = suppressPrivatePropertyNotUsed;
 493   
     }
 494   
 
 495   
 
 496   
     /**
 497   
      * Whether the task should suppress the "Variable is set but not used" in
 498   
      * strictargs-Mode. Be careful with this one! The warning is logged as
 499   
      * verbose message, though.
 500   
      */
 501  0
     public void setSuppressVariableNotUsed(boolean suppressVariableNotUsed) {
 502  0
         this.suppressVariableNotUsed = suppressVariableNotUsed;
 503   
     }
 504   
 
 505   
 
 506   
     /**
 507   
      * Whether the task should suppress the "FooException is in SIGNALS list
 508   
      * but is not signalled within the method", which is sometimes rather
 509   
      * useless. The warning is logged as verbose message, though.
 510   
      */
 511  0
     public void setSuppressExceptionNotSignalled(boolean suppressExceptionNotSignalled) {
 512  0
         this.suppressExceptionNotSignalled = suppressExceptionNotSignalled;
 513   
     }
 514   
 
 515   
 
 516   
     /**
 517   
      * Tells whether we should filter out any deprecation-messages
 518   
      * of the compiler out.
 519   
      */
 520  0
     public void setSuppressDeprecation(boolean suppressDeprecation) {
 521  0
         this.suppressDeprecation = suppressDeprecation;
 522   
     }
 523   
 
 524   
 
 525   
     /**
 526   
      * init-Method sets defaults from Properties. That way, when ant is called
 527   
      * with arguments like -Dant.netrexxc.verbose=verbose5 one can easily take
 528   
      * control of all netrexxc-tasks.
 529   
      */
 530   
     // Sorry for the formatting, but that way it's easier to keep in sync with the private properties (line by line).
 531  0
     public void init() {
 532  0
         String p;
 533   
 
 534  0
         if ((p = getProject().getProperty("ant.netrexxc.binary")) != null) {
 535  0
             this.binary = Project.toBoolean(p);
 536   
         }
 537   
         // classpath makes no sense
 538  0
         if ((p = getProject().getProperty("ant.netrexxc.comments")) != null) {
 539  0
             this.comments = Project.toBoolean(p);
 540   
         }
 541  0
         if ((p = getProject().getProperty("ant.netrexxc.compact")) != null) {
 542  0
             this.compact = Project.toBoolean(p);
 543   
         }
 544  0
         if ((p = getProject().getProperty("ant.netrexxc.compile")) != null) {
 545  0
             this.compile = Project.toBoolean(p);
 546   
         }
 547  0
         if ((p = getProject().getProperty("ant.netrexxc.console")) != null) {
 548  0
             this.console = Project.toBoolean(p);
 549   
         }
 550  0
         if ((p = getProject().getProperty("ant.netrexxc.crossref")) != null) {
 551  0
             this.crossref = Project.toBoolean(p);
 552   
         }
 553  0
         if ((p = getProject().getProperty("ant.netrexxc.decimal")) != null) {
 554  0
             this.decimal = Project.toBoolean(p);
 555   
             // destDir
 556   
         }
 557  0
         if ((p = getProject().getProperty("ant.netrexxc.diag")) != null) {
 558  0
             this.diag = Project.toBoolean(p);
 559   
         }
 560  0
         if ((p = getProject().getProperty("ant.netrexxc.explicit")) != null) {
 561  0
             this.explicit = Project.toBoolean(p);
 562   
         }
 563  0
         if ((p = getProject().getProperty("ant.netrexxc.format")) != null) {
 564  0
             this.format = Project.toBoolean(p);
 565   
         }
 566  0
         if ((p = getProject().getProperty("ant.netrexxc.keep")) != null) {
 567  0
             this.keep = Project.toBoolean(p);
 568   
         }
 569  0
         if ((p = getProject().getProperty("ant.netrexxc.logo")) != null) {
 570  0
             this.logo = Project.toBoolean(p);
 571   
         }
 572  0
         if ((p = getProject().getProperty("ant.netrexxc.replace")) != null) {
 573  0
             this.replace = Project.toBoolean(p);
 574   
         }
 575  0
         if ((p = getProject().getProperty("ant.netrexxc.savelog")) != null) {
 576  0
             this.savelog = Project.toBoolean(p);
 577   
             // srcDir
 578   
         }
 579  0
         if ((p = getProject().getProperty("ant.netrexxc.sourcedir")) != null) {
 580  0
             this.sourcedir = Project.toBoolean(p);
 581   
         }
 582  0
         if ((p = getProject().getProperty("ant.netrexxc.strictargs")) != null) {
 583  0
             this.strictargs = Project.toBoolean(p);
 584   
         }
 585  0
         if ((p = getProject().getProperty("ant.netrexxc.strictassign")) != null) {
 586  0
             this.strictassign = Project.toBoolean(p);
 587   
         }
 588  0
         if ((p = getProject().getProperty("ant.netrexxc.strictcase")) != null) {
 589  0
             this.strictcase = Project.toBoolean(p);
 590   
         }
 591  0
         if ((p = getProject().getProperty("ant.netrexxc.strictimport")) != null) {
 592  0
             this.strictimport = Project.toBoolean(p);
 593   
         }
 594  0
         if ((p = getProject().getProperty("ant.netrexxc.strictprops")) != null) {
 595  0
             this.strictprops = Project.toBoolean(p);
 596   
         }
 597  0
         if ((p = getProject().getProperty("ant.netrexxc.strictsignal")) != null) {
 598  0
             this.strictsignal = Project.toBoolean(p);
 599   
         }
 600  0
         if ((p = getProject().getProperty("ant.netrexxc.symbols")) != null) {
 601  0
             this.symbols = Project.toBoolean(p);
 602   
         }
 603  0
         if ((p = getProject().getProperty("ant.netrexxc.time")) != null) {
 604  0
             this.time = Project.toBoolean(p);
 605   
         }
 606  0
         if ((p = getProject().getProperty("ant.netrexxc.trace")) != null) {
 607  0
             setTrace(p);
 608   
         }
 609  0
         if ((p = getProject().getProperty("ant.netrexxc.utf8")) != null) {
 610  0
             this.utf8 = Project.toBoolean(p);
 611   
         }
 612  0
         if ((p = getProject().getProperty("ant.netrexxc.verbose")) != null) {
 613  0
             setVerbose(p);
 614   
         }
 615  0
         if ((p = getProject().getProperty("ant.netrexxc.suppressMethodArgumentNotUsed")) != null) {
 616  0
             this.suppressMethodArgumentNotUsed = Project.toBoolean(p);
 617   
         }
 618  0
         if ((p = getProject().getProperty("ant.netrexxc.suppressPrivatePropertyNotUsed")) != null) {
 619  0
             this.suppressPrivatePropertyNotUsed = Project.toBoolean(p);
 620   
         }
 621  0
         if ((p = getProject().getProperty("ant.netrexxc.suppressVariableNotUsed")) != null) {
 622  0
             this.suppressVariableNotUsed = Project.toBoolean(p);
 623   
         }
 624  0
         if ((p = getProject().getProperty("ant.netrexxc.suppressExceptionNotSignalled")) != null) {
 625  0
             this.suppressExceptionNotSignalled = Project.toBoolean(p);
 626   
         }
 627  0
         if ((p = getProject().getProperty("ant.netrexxc.suppressDeprecation")) != null) {
 628  0
             this.suppressDeprecation = Project.toBoolean(p);
 629   
         }
 630   
     }
 631   
 
 632   
 
 633   
     /** Executes the task - performs the actual compiler call.  */
 634  0
     public void execute() throws BuildException {
 635   
 
 636   
         // first off, make sure that we've got a srcdir and destdir
 637  0
         if (srcDir == null || destDir == null) {
 638  0
             throw new BuildException("srcDir and destDir attributes must be set!");
 639   
         }
 640   
 
 641   
         // scan source and dest dirs to build up both copy lists and
 642   
         // compile lists
 643   
         //        scanDir(srcDir, destDir);
 644  0
         DirectoryScanner ds = getDirectoryScanner(srcDir);
 645   
 
 646  0
         String[] files = ds.getIncludedFiles();
 647   
 
 648  0
         scanDir(srcDir, destDir, files);
 649   
 
 650   
         // copy the source and support files
 651  0
         copyFilesToDestination();
 652   
 
 653   
         // compile the source files
 654  0
         if (compileList.size() > 0) {
 655  0
             log("Compiling " + compileList.size() + " source file"
 656   
                  + (compileList.size() == 1 ? "" : "s")
 657   
                  + " to " + destDir);
 658  0
             doNetRexxCompile();
 659   
         }
 660   
     }
 661   
 
 662   
 
 663   
     /**
 664   
      * Scans the directory looking for source files to be compiled and support
 665   
      * files to be copied.
 666   
      */
 667  0
     private void scanDir(File srcDir, File destDir, String[] files) {
 668  0
         for (int i = 0; i < files.length; i++) {
 669  0
             File srcFile = new File(srcDir, files[i]);
 670  0
             File destFile = new File(destDir, files[i]);
 671  0
             String filename = files[i];
 672   
             // if it's a non source file, copy it if a later date than the
 673   
             // dest
 674   
             // if it's a source file, see if the destination class file
 675   
             // needs to be recreated via compilation
 676  0
             if (filename.toLowerCase().endsWith(".nrx")) {
 677  0
                 File classFile =
 678   
                     new File(destDir,
 679   
                     filename.substring(0, filename.lastIndexOf('.')) + ".class");
 680   
 
 681  0
                 if (!compile || srcFile.lastModified() > classFile.lastModified()) {
 682  0
                     filecopyList.put(srcFile.getAbsolutePath(), destFile.getAbsolutePath());
 683  0
                     compileList.addElement(destFile.getAbsolutePath());
 684   
                 }
 685   
             } else {
 686  0
                 if (srcFile.lastModified() > destFile.lastModified()) {
 687  0
                     filecopyList.put(srcFile.getAbsolutePath(), destFile.getAbsolutePath());
 688   
                 }
 689   
             }
 690   
         }
 691   
     }
 692   
 
 693   
 
 694   
     /** Copy eligible files from the srcDir to destDir  */
 695  0
     private void copyFilesToDestination() {
 696  0
         if (filecopyList.size() > 0) {
 697  0
             log("Copying " + filecopyList.size() + " file"
 698   
                  + (filecopyList.size() == 1 ? "" : "s")
 699   
                  + " to " + destDir.getAbsolutePath());
 700   
 
 701  0
             Enumeration enum = filecopyList.keys();
 702   
 
 703  0
             while (enum.hasMoreElements()) {
 704  0
                 String fromFile = (String) enum.nextElement();
 705  0
                 String toFile = (String) filecopyList.get(fromFile);
 706   
 
 707  0
                 try {
 708  0
                     getProject().copyFile(fromFile, toFile);
 709   
                 } catch (IOException ioe) {
 710  0
                     String msg = "Failed to copy " + fromFile + " to " + toFile
 711   
                          + " due to " + ioe.getMessage();
 712   
 
 713  0
                     throw new BuildException(msg, ioe);
 714   
                 }
 715   
             }
 716   
         }
 717   
     }
 718   
 
 719   
 
 720   
     /** Peforms a copmile using the NetRexx 1.1.x compiler  */
 721  0
     private void doNetRexxCompile() throws BuildException {
 722  0
         log("Using NetRexx compiler", Project.MSG_VERBOSE);
 723   
 
 724  0
         String classpath = getCompileClasspath();
 725  0
         StringBuffer compileOptions = new StringBuffer();
 726   
 
 727   
         // create an array of strings for input to the compiler: one array
 728   
         // comes from the compile options, the other from the compileList
 729  0
         String[] compileOptionsArray = getCompileOptionsAsArray();
 730  0
         String[] fileListArray = new String[compileList.size()];
 731  0
         Enumeration e = compileList.elements();
 732  0
         int j = 0;
 733   
 
 734  0
         while (e.hasMoreElements()) {
 735  0
             fileListArray[j] = (String) e.nextElement();
 736  0
             j++;
 737   
         }
 738   
         // create a single array of arguments for the compiler
 739  0
         String compileArgs[] = new String[compileOptionsArray.length + fileListArray.length];
 740   
 
 741  0
         for (int i = 0; i < compileOptionsArray.length; i++) {
 742  0
             compileArgs[i] = compileOptionsArray[i];
 743   
         }
 744  0
         for (int i = 0; i < fileListArray.length; i++) {
 745  0
             compileArgs[i + compileOptionsArray.length] = fileListArray[i];
 746   
         }
 747   
 
 748   
         // print nice output about what we are doing for the log
 749  0
         compileOptions.append("Compilation args: ");
 750  0
         for (int i = 0; i < compileOptionsArray.length; i++) {
 751  0
             compileOptions.append(compileOptionsArray[i]);
 752  0
             compileOptions.append(" ");
 753   
         }
 754  0
         log(compileOptions.toString(), Project.MSG_VERBOSE);
 755   
 
 756  0
         String eol = System.getProperty("line.separator");
 757  0
         StringBuffer niceSourceList = new StringBuffer("Files to be compiled:" + eol);
 758   
 
 759  0
         for (int i = 0; i < compileList.size(); i++) {
 760  0
             niceSourceList.append("    ");
 761  0
             niceSourceList.append(compileList.elementAt(i).toString());
 762  0
             niceSourceList.append(eol);
 763   
         }
 764   
 
 765  0
         log(niceSourceList.toString(), Project.MSG_VERBOSE);
 766   
 
 767   
         // need to set java.class.path property and restore it later
 768   
         // since the NetRexx compiler has no option for the classpath
 769  0
         String currentClassPath = System.getProperty("java.class.path");
 770  0
         Properties currentProperties = System.getProperties();
 771   
 
 772  0
         currentProperties.put("java.class.path", classpath);
 773   
 
 774  0
         try {
 775  0
             StringWriter out = new StringWriter();
 776  0
             int rc =
 777   
                 COM.ibm.netrexx.process.NetRexxC.main(new Rexx(compileArgs), new PrintWriter(out));
 778  0
             String sdir = srcDir.getAbsolutePath();
 779  0
             String ddir = destDir.getAbsolutePath();
 780  0
             boolean doReplace = !(sdir.equals(ddir));
 781  0
             int dlen = ddir.length();
 782  0
             String l;
 783  0
             BufferedReader in = new BufferedReader(new StringReader(out.toString()));
 784   
 
 785  0
             log("replacing destdir '" + ddir + "' through sourcedir '" + sdir + "'", Project.MSG_VERBOSE);
 786  0
             while ((l = in.readLine()) != null) {
 787  0
                 int idx;
 788   
 
 789  0
                 while (doReplace && ((idx = l.indexOf(ddir)) != -1)) {// path is mentioned in the message
 790  0
                     l = (new StringBuffer(l)).replace(idx, idx + dlen, sdir).toString();
 791   
                 }
 792   
                 // verbose level logging for suppressed messages
 793  0
                 if (suppressMethodArgumentNotUsed && l.indexOf(MSG_METHOD_ARGUMENT_NOT_USED) != -1) {
 794  0
                     log(l, Project.MSG_VERBOSE);
 795  0
                 } else if (suppressPrivatePropertyNotUsed && l.indexOf(MSG_PRIVATE_PROPERTY_NOT_USED) != -1) {
 796  0
                     log(l, Project.MSG_VERBOSE);
 797  0
                 } else if (suppressVariableNotUsed && l.indexOf(MSG_VARIABLE_NOT_USED) != -1) {
 798  0
                     log(l, Project.MSG_VERBOSE);
 799  0
                 } else if (suppressExceptionNotSignalled && l.indexOf(MSG_EXCEPTION_NOT_SIGNALLED) != -1) {
 800  0
                     log(l, Project.MSG_VERBOSE);
 801  0
                 } else if (suppressDeprecation && l.indexOf(MSG_DEPRECATION) != -1) {
 802  0
                     log(l, Project.MSG_VERBOSE);
 803  0
                 } else if (l.indexOf("Error:") != -1) {// error level logging for compiler errors
 804  0
                     log(l, Project.MSG_ERR);
 805  0
                 } else if (l.indexOf("Warning:") != -1) {// warning for all warning messages
 806  0
                     log(l, Project.MSG_WARN);
 807   
                 } else {
 808  0
                     log(l, Project.MSG_INFO);// info level for the rest.
 809   
                 }
 810   
             }
 811  0
             if (rc > 1) {
 812  0
                 throw new BuildException("Compile failed, messages should have been provided.");
 813   
             }
 814   
         } catch (IOException ioe) {
 815  0
             throw new BuildException("Unexpected IOException while playing with Strings",
 816   
                 ioe);
 817   
         } finally {
 818   
             // need to reset java.class.path property
 819   
             // since the NetRexx compiler has no option for the classpath
 820  0
             currentProperties = System.getProperties();
 821  0
             currentProperties.put("java.class.path", currentClassPath);
 822   
         }
 823   
 
 824   
     }
 825   
 
 826   
 
 827   
     /** Builds the compilation classpath.  */
 828  0
     private String getCompileClasspath() {
 829  0
         StringBuffer classpath = new StringBuffer();
 830   
 
 831   
         // add dest dir to classpath so that previously compiled and
 832   
         // untouched classes are on classpath
 833  0
         classpath.append(destDir.getAbsolutePath());
 834   
 
 835   
         // add our classpath to the mix
 836  0
         if (this.classpath != null) {
 837  0
             addExistingToClasspath(classpath, this.classpath);
 838   
         }
 839   
 
 840   
         // add the system classpath
 841   
         // addExistingToClasspath(classpath,System.getProperty("java.class.path"));
 842  0
         return classpath.toString();
 843   
     }
 844   
 
 845   
 
 846   
     /** This  */
 847  0
     private String[] getCompileOptionsAsArray() {
 848  0
         Vector options = new Vector();
 849   
 
 850  0
         options.addElement(binary ? "-binary" : "-nobinary");
 851  0
         options.addElement(comments ? "-comments" : "-nocomments");
 852  0
         options.addElement(compile ? "-compile" : "-nocompile");
 853  0
         options.addElement(compact ? "-compact" : "-nocompact");
 854  0
         options.addElement(console ? "-console" : "-noconsole");
 855  0
         options.addElement(crossref ? "-crossref" : "-nocrossref");
 856  0
         options.addElement(decimal ? "-decimal" : "-nodecimal");
 857  0
         options.addElement(diag ? "-diag" : "-nodiag");
 858  0
         options.addElement(explicit ? "-explicit" : "-noexplicit");
 859  0
         options.addElement(format ? "-format" : "-noformat");
 860  0
         options.addElement(keep ? "-keep" : "-nokeep");
 861  0
         options.addElement(logo ? "-logo" : "-nologo");
 862  0
         options.addElement(replace ? "-replace" : "-noreplace");
 863  0
         options.addElement(savelog ? "-savelog" : "-nosavelog");
 864  0
         options.addElement(sourcedir ? "-sourcedir" : "-nosourcedir");
 865  0
         options.addElement(strictargs ? "-strictargs" : "-nostrictargs");
 866  0
         options.addElement(strictassign ? "-strictassign" : "-nostrictassign");
 867  0
         options.addElement(strictcase ? "-strictcase" : "-nostrictcase");
 868  0
         options.addElement(strictimport ? "-strictimport" : "-nostrictimport");
 869  0
         options.addElement(strictprops ? "-strictprops" : "-nostrictprops");
 870  0
         options.addElement(strictsignal ? "-strictsignal" : "-nostrictsignal");
 871  0
         options.addElement(symbols ? "-symbols" : "-nosymbols");
 872  0
         options.addElement(time ? "-time" : "-notime");
 873  0
         options.addElement("-" + trace);
 874  0
         options.addElement(utf8 ? "-utf8" : "-noutf8");
 875  0
         options.addElement("-" + verbose);
 876   
 
 877  0
         String[] results = new String[options.size()];
 878   
 
 879  0
         options.copyInto(results);
 880  0
         return results;
 881   
     }
 882   
 
 883   
 
 884   
     /**
 885   
      * Takes a classpath-like string, and adds each element of this string to
 886   
      * a new classpath, if the components exist. Components that don't exist,
 887   
      * aren't added. We do this, because jikes issues warnings for
 888   
      * non-existant files/dirs in his classpath, and these warnings are pretty
 889   
      * annoying.
 890   
      *
 891   
      * @param target - target classpath
 892   
      * @param source - source classpath to get file objects.
 893   
      */
 894  0
     private void addExistingToClasspath(StringBuffer target, String source) {
 895  0
         StringTokenizer tok = new StringTokenizer(source,
 896   
             System.getProperty("path.separator"), false);
 897   
 
 898  0
         while (tok.hasMoreTokens()) {
 899  0
             File f = getProject().resolveFile(tok.nextToken());
 900   
 
 901  0
             if (f.exists()) {
 902  0
                 target.append(File.pathSeparator);
 903  0
                 target.append(f.getAbsolutePath());
 904   
             } else {
 905  0
                 log("Dropping from classpath: " +
 906   
                     f.getAbsolutePath(), Project.MSG_VERBOSE);
 907   
             }
 908   
         }
 909   
 
 910   
     }
 911   
 
 912   
 
 913   
     public static class TraceAttr extends EnumeratedAttribute {
 914  0
         public String[] getValues() {
 915  0
             return new String[]{"trace", "trace1", "trace2", "notrace"};
 916   
         }
 917   
     }
 918   
 
 919   
 
 920   
     public static class VerboseAttr extends EnumeratedAttribute {
 921  0
         public String[] getValues() {
 922  0
             return new String[]{"verbose", "verbose0", "verbose1",
 923   
                 "verbose2", "verbose3", "verbose4",
 924   
                 "verbose5", "noverbose"};
 925   
         }
 926   
     }
 927   
 }
 928   
 
 929