Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 865   Methods: 73
NCLOC: 406   Classes: 2
 
 Source file Conditionals Statements Methods TOTAL
Javac.java 46.7% 63.5% 65.8% 60.6%
 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   
 
 55   
 package org.apache.tools.ant.taskdefs;
 56   
 
 57   
 import java.io.File;
 58   
 import org.apache.tools.ant.BuildException;
 59   
 import org.apache.tools.ant.DirectoryScanner;
 60   
 import org.apache.tools.ant.Project;
 61   
 import org.apache.tools.ant.taskdefs.compilers.CompilerAdapter;
 62   
 import org.apache.tools.ant.taskdefs.compilers.CompilerAdapterFactory;
 63   
 import org.apache.tools.ant.types.Path;
 64   
 import org.apache.tools.ant.types.Reference;
 65   
 import org.apache.tools.ant.util.GlobPatternMapper;
 66   
 import org.apache.tools.ant.util.JavaEnvUtils;
 67   
 import org.apache.tools.ant.util.SourceFileScanner;
 68   
 import org.apache.tools.ant.util.facade.FacadeTaskHelper;
 69   
 
 70   
 /**
 71   
  * Compiles Java source files. This task can take the following
 72   
  * arguments:
 73   
  * <ul>
 74   
  * <li>sourcedir
 75   
  * <li>destdir
 76   
  * <li>deprecation
 77   
  * <li>classpath
 78   
  * <li>bootclasspath
 79   
  * <li>extdirs
 80   
  * <li>optimize
 81   
  * <li>debug
 82   
  * <li>encoding
 83   
  * <li>target
 84   
  * <li>depend
 85   
  * <li>vebose
 86   
  * <li>failonerror
 87   
  * <li>includeantruntime
 88   
  * <li>includejavaruntime
 89   
  * <li>source
 90   
  * <li>compiler
 91   
  * </ul>
 92   
  * Of these arguments, the <b>sourcedir</b> and <b>destdir</b> are required.
 93   
  * <p>
 94   
  * When this task executes, it will recursively scan the sourcedir and
 95   
  * destdir looking for Java source files to compile. This task makes its
 96   
  * compile decision based on timestamp.
 97   
  *
 98   
  * @author James Davidson <a href="mailto:duncan@x180.com">duncan@x180.com</a>
 99   
  * @author Robin Green
 100   
  *         <a href="mailto:greenrd@hotmail.com">greenrd@hotmail.com</a>
 101   
  * @author Stefan Bodewig
 102   
  * @author <a href="mailto:jayglanville@home.com">J D Glanville</a>
 103   
  *
 104   
  * @version $Revision: 1.110 $
 105   
  *
 106   
  * @since Ant 1.1
 107   
  *
 108   
  * @ant.task category="java"
 109   
  */
 110   
 
 111   
 public class Javac extends MatchingTask {
 112   
 
 113   
     private static final String FAIL_MSG
 114   
         = "Compile failed; see the compiler error output for details.";
 115   
 
 116   
     private Path src;
 117   
     private File destDir;
 118   
     private Path compileClasspath;
 119   
     private Path compileSourcepath;
 120   
     private String encoding;
 121   
     private boolean debug = false;
 122   
     private boolean optimize = false;
 123   
     private boolean deprecation = false;
 124   
     private boolean depend = false;
 125   
     private boolean verbose = false;
 126   
     private String target;
 127   
     private Path bootclasspath;
 128   
     private Path extdirs;
 129   
     private boolean includeAntRuntime = true;
 130   
     private boolean includeJavaRuntime = false;
 131   
     private boolean fork = false;
 132   
     private String forkedExecutable = null;
 133   
     private boolean nowarn = false;
 134   
     private String memoryInitialSize;
 135   
     private String memoryMaximumSize;
 136   
     private FacadeTaskHelper facade = null;
 137   
 
 138   
     protected boolean failOnError = true;
 139   
     protected boolean listFiles = false;
 140   
     protected File[] compileList = new File[0];
 141   
 
 142   
     private String source;
 143   
     private String debugLevel;
 144   
 
 145   
     /**
 146   
      * Javac task for compilation of Java files.
 147   
      */
 148  25
     public Javac() {
 149  25
         if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_1)) {
 150  0
             facade = new FacadeTaskHelper("javac1.1");
 151  25
         } else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_2)) {
 152  0
             facade = new FacadeTaskHelper("javac1.2");
 153  25
         } else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_3)) {
 154  0
             facade = new FacadeTaskHelper("javac1.3");
 155  25
         } else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_4)) {
 156  25
             facade = new FacadeTaskHelper("javac1.4");
 157   
         } else {
 158  0
             facade = new FacadeTaskHelper("classic");
 159   
         }
 160   
     }
 161   
 
 162   
     /**
 163   
      * Get the value of debugLevel.
 164   
      * @return value of debugLevel.
 165   
      */
 166  1
     public String getDebugLevel() {
 167  1
         return debugLevel;
 168   
     }
 169   
 
 170   
     /**
 171   
      * Keyword list to be appended to the -g command-line switch.
 172   
      *
 173   
      * This will be ignored by all implementations except modern
 174   
      * and classic(ver >= 1.2). Legal values are none or a
 175   
      * comma-separated list of the following keywords: lines, vars,
 176   
      * and source. If debuglevel is not specified, by default, :none
 177   
      * will be appended to -g. If debug is not turned on, this attribute
 178   
      * will be ignored.
 179   
      *
 180   
      * @param v  Value to assign to debugLevel.
 181   
      */
 182  0
     public void setDebugLevel(String  v) {
 183  0
         this.debugLevel = v;
 184   
     }
 185   
 
 186   
     /**
 187   
      * Get the value of source.
 188   
      * @return value of source.
 189   
      */
 190  17
     public String getSource() {
 191  17
         return source;
 192   
     }
 193   
 
 194   
     /**
 195   
      * Value of the -source command-line switch; will be ignored
 196   
      * by all implementations except modern and jikes.
 197   
      *
 198   
      * If you use this attribute together with jikes, you must
 199   
      * make sure that your version of jikes supports the -source switch.
 200   
      * Legal values are 1.3 and 1.4 - by default, no -source argument
 201   
      * will be used at all.
 202   
      *
 203   
      * @param v  Value to assign to source.
 204   
      */
 205  0
     public void setSource(String  v) {
 206  0
         this.source = v;
 207   
     }
 208   
 
 209   
     /**
 210   
      * Adds a path for source compilation.
 211   
      *
 212   
      * @return a nested src element.
 213   
      */
 214  0
     public Path createSrc() {
 215  0
         if (src == null) {
 216  0
             src = new Path(getProject());
 217   
         }
 218  0
         return src.createPath();
 219   
     }
 220   
 
 221   
     /**
 222   
      * Recreate src.
 223   
      *
 224   
      * @return a nested src element.
 225   
      */
 226  0
     protected Path recreateSrc() {
 227  0
         src = null;
 228  0
         return createSrc();
 229   
     }
 230   
 
 231   
     /**
 232   
      * Set the source directories to find the source Java files.
 233   
      */
 234  19
     public void setSrcdir(Path srcDir) {
 235  19
         if (src == null) {
 236  19
             src = srcDir;
 237   
         } else {
 238  0
             src.append(srcDir);
 239   
         }
 240   
     }
 241   
 
 242   
     /** Gets the source dirs to find the source java files. */
 243  17
     public Path getSrcdir() {
 244  17
         return src;
 245   
     }
 246   
 
 247   
     /**
 248   
      * Set the destination directory into which the Java source
 249   
      * files should be compiled.
 250   
      */
 251  18
     public void setDestdir(File destDir) {
 252  18
         this.destDir = destDir;
 253   
     }
 254   
 
 255   
     /**
 256   
      * Gets the destination directory into which the java source files
 257   
      * should be compiled.
 258   
      */
 259  17
     public File getDestdir() {
 260  17
         return destDir;
 261   
     }
 262   
 
 263   
     /**
 264   
      * Set the sourcepath to be used for this compilation.
 265   
      */
 266  0
     public void setSourcepath(Path sourcepath) {
 267  0
         if (compileSourcepath == null) {
 268  0
             compileSourcepath = sourcepath;
 269   
         } else {
 270  0
             compileSourcepath.append(sourcepath);
 271   
         }
 272   
     }
 273   
 
 274   
     /** Gets the sourcepath to be used for this compilation. */
 275  17
     public Path getSourcepath() {
 276  17
         return compileSourcepath;
 277   
     }
 278   
 
 279   
     /**
 280   
      * Adds a path to sourcepath.
 281   
      */
 282  0
     public Path createSourcepath() {
 283  0
         if (compileSourcepath == null) {
 284  0
             compileSourcepath = new Path(getProject());
 285   
         }
 286  0
         return compileSourcepath.createPath();
 287   
     }
 288   
 
 289   
     /**
 290   
      * Adds a reference to a source path defined elsewhere.
 291   
      */
 292  0
     public void setSourcepathRef(Reference r) {
 293  0
         createSourcepath().setRefid(r);
 294   
     }
 295   
 
 296   
     /**
 297   
      * Set the classpath to be used for this compilation.
 298   
      *
 299   
      * @param classpath an Ant Path object containing the compilation classpath.
 300   
      */
 301  0
     public void setClasspath(Path classpath) {
 302  0
         if (compileClasspath == null) {
 303  0
             compileClasspath = classpath;
 304   
         } else {
 305  0
             compileClasspath.append(classpath);
 306   
         }
 307   
     }
 308   
 
 309   
     /** Gets the classpath to be used for this compilation. */
 310  17
     public Path getClasspath() {
 311  17
         return compileClasspath;
 312   
     }
 313   
 
 314   
     /**
 315   
      * Adds a path to the classpath.
 316   
      */
 317  3
     public Path createClasspath() {
 318  3
         if (compileClasspath == null) {
 319  3
             compileClasspath = new Path(getProject());
 320   
         }
 321  3
         return compileClasspath.createPath();
 322   
     }
 323   
 
 324   
     /**
 325   
      * Adds a reference to a classpath defined elsewhere.
 326   
      */
 327  1
     public void setClasspathRef(Reference r) {
 328  1
         createClasspath().setRefid(r);
 329   
     }
 330   
 
 331   
     /**
 332   
      * Sets the bootclasspath that will be used to compile the classes
 333   
      * against.
 334   
      */
 335  0
     public void setBootclasspath(Path bootclasspath) {
 336  0
         if (this.bootclasspath == null) {
 337  0
             this.bootclasspath = bootclasspath;
 338   
         } else {
 339  0
             this.bootclasspath.append(bootclasspath);
 340   
         }
 341   
     }
 342   
 
 343   
     /**
 344   
      * Gets the bootclasspath that will be used to compile the classes
 345   
      * against.
 346   
      */
 347  17
     public Path getBootclasspath() {
 348  17
         return bootclasspath;
 349   
     }
 350   
 
 351   
     /**
 352   
      * Adds a path to the bootclasspath.
 353   
      */
 354  0
     public Path createBootclasspath() {
 355  0
         if (bootclasspath == null) {
 356  0
             bootclasspath = new Path(getProject());
 357   
         }
 358  0
         return bootclasspath.createPath();
 359   
     }
 360   
 
 361   
     /**
 362   
      * Adds a reference to a classpath defined elsewhere.
 363   
      */
 364  0
     public void setBootClasspathRef(Reference r) {
 365  0
         createBootclasspath().setRefid(r);
 366   
     }
 367   
 
 368   
     /**
 369   
      * Sets the extension directories that will be used during the
 370   
      * compilation.
 371   
      */
 372  0
     public void setExtdirs(Path extdirs) {
 373  0
         if (this.extdirs == null) {
 374  0
             this.extdirs = extdirs;
 375   
         } else {
 376  0
             this.extdirs.append(extdirs);
 377   
         }
 378   
     }
 379   
 
 380   
     /**
 381   
      * Gets the extension directories that will be used during the
 382   
      * compilation.
 383   
      */
 384  17
     public Path getExtdirs() {
 385  17
         return extdirs;
 386   
     }
 387   
 
 388   
     /**
 389   
      * Adds a path to extdirs.
 390   
      */
 391  0
     public Path createExtdirs() {
 392  0
         if (extdirs == null) {
 393  0
             extdirs = new Path(getProject());
 394   
         }
 395  0
         return extdirs.createPath();
 396   
     }
 397   
 
 398   
     /**
 399   
      * If true, list the source files being handed off to the compiler.
 400   
      */
 401  0
     public void setListfiles(boolean list) {
 402  0
         listFiles = list;
 403   
     }
 404   
 
 405   
     /** Get the listfiles flag. */
 406  0
     public boolean getListfiles() {
 407  0
         return listFiles;
 408   
     }
 409   
 
 410   
     /**
 411   
      * Indicates whether the build will continue
 412   
      * even if there are compilation errors; defaults to true.
 413   
      */
 414  0
     public void setFailonerror(boolean fail) {
 415  0
         failOnError = fail;
 416   
     }
 417   
 
 418   
     /**
 419   
      * @ant.attribute ignore="true"
 420   
      */
 421  0
     public void setProceed(boolean proceed) {
 422  0
         failOnError = !proceed;
 423   
     }
 424   
 
 425   
     /**
 426   
      * Gets the failonerror flag.
 427   
      */
 428  0
     public boolean getFailonerror() {
 429  0
         return failOnError;
 430   
     }
 431   
 
 432   
     /**
 433   
      * Indicates whether source should be
 434   
      * compiled with deprecation information; defaults to off.
 435   
      */
 436  2
     public void setDeprecation(boolean deprecation) {
 437  2
         this.deprecation = deprecation;
 438   
     }
 439   
 
 440   
     /** Gets the deprecation flag. */
 441  17
     public boolean getDeprecation() {
 442  17
         return deprecation;
 443   
     }
 444   
 
 445   
     /**
 446   
      * The initial size of the memory for the underlying VM
 447   
      * if javac is run externally; ignored otherwise.
 448   
      * Defaults to the standard VM memory setting.
 449   
      * (Examples: 83886080, 81920k, or 80m)
 450   
      */
 451  0
     public void setMemoryInitialSize(String memoryInitialSize) {
 452  0
         this.memoryInitialSize = memoryInitialSize;
 453   
     }
 454   
 
 455   
     /** Gets the memoryInitialSize flag. */
 456  17
     public String getMemoryInitialSize() {
 457  17
         return memoryInitialSize;
 458   
     }
 459   
 
 460   
     /**
 461   
      * The maximum size of the memory for the underlying VM
 462   
      * if javac is run externally; ignored otherwise.
 463   
      * Defaults to the standard VM memory setting.
 464   
      * (Examples: 83886080, 81920k, or 80m)
 465   
      */
 466  0
     public void setMemoryMaximumSize(String memoryMaximumSize) {
 467  0
         this.memoryMaximumSize = memoryMaximumSize;
 468   
     }
 469   
 
 470   
     /** Gets the memoryMaximumSize flag. */
 471  17
     public String getMemoryMaximumSize() {
 472  17
         return memoryMaximumSize;
 473   
     }
 474   
 
 475   
     /**
 476   
      * Set the Java source file encoding name.
 477   
      */
 478  0
     public void setEncoding(String encoding) {
 479  0
         this.encoding = encoding;
 480   
     }
 481   
 
 482   
     /** Gets the java source file encoding name. */
 483  17
     public String getEncoding() {
 484  17
         return encoding;
 485   
     }
 486   
 
 487   
     /**
 488   
      * Indicates whether source should be compiled
 489   
      * with debug information; defaults to off.
 490   
      */
 491  3
     public void setDebug(boolean debug) {
 492  3
         this.debug = debug;
 493   
     }
 494   
 
 495   
     /** Gets the debug flag. */
 496  17
     public boolean getDebug() {
 497  17
         return debug;
 498   
     }
 499   
 
 500   
     /**
 501   
      * If true, compiles with optimization enabled.
 502   
      */
 503  1
     public void setOptimize(boolean optimize) {
 504  1
         this.optimize = optimize;
 505   
     }
 506   
 
 507   
     /** Gets the optimize flag. */
 508  17
     public boolean getOptimize() {
 509  17
         return optimize;
 510   
     }
 511   
 
 512   
     /**
 513   
      * Enables dependency-tracking for compilers
 514   
      * that support this (jikes and classic).
 515   
      */
 516  1
     public void setDepend(boolean depend) {
 517  1
         this.depend = depend;
 518   
     }
 519   
 
 520   
     /** Gets the depend flag. */
 521  17
     public boolean getDepend() {
 522  17
         return depend;
 523   
     }
 524   
 
 525   
     /**
 526   
      * If true, asks the compiler for verbose output.
 527   
      */
 528  0
     public void setVerbose(boolean verbose) {
 529  0
         this.verbose = verbose;
 530   
     }
 531   
 
 532   
     /** Gets the verbose flag. */
 533  17
     public boolean getVerbose() {
 534  17
         return verbose;
 535   
     }
 536   
 
 537   
     /**
 538   
      * Sets the target VM that the classes will be compiled for. Valid
 539   
      * strings are "1.1", "1.2", and "1.3".
 540   
      */
 541  2
     public void setTarget(String target) {
 542  2
         this.target = target;
 543   
     }
 544   
 
 545   
     /** Gets the target VM that the classes will be compiled for. */
 546  17
     public String getTarget() {
 547  17
         return target;
 548   
     }
 549   
 
 550   
     /**
 551   
      * If true, includes Ant's own classpath in the classpath.
 552   
      */
 553  0
     public void setIncludeantruntime(boolean include) {
 554  0
         includeAntRuntime = include;
 555   
     }
 556   
 
 557   
     /**
 558   
      * Gets whether or not the ant classpath is to be included in the classpath.
 559   
      */
 560  17
     public boolean getIncludeantruntime() {
 561  17
         return includeAntRuntime;
 562   
     }
 563   
 
 564   
     /**
 565   
      * If true, includes the Java runtime libraries in the classpath.
 566   
      */
 567  0
     public void setIncludejavaruntime(boolean include) {
 568  0
         includeJavaRuntime = include;
 569   
     }
 570   
 
 571   
     /**
 572   
      * Gets whether or not the java runtime should be included in this
 573   
      * task's classpath.
 574   
      */
 575  17
     public boolean getIncludejavaruntime() {
 576  17
         return includeJavaRuntime;
 577   
     }
 578   
 
 579   
     /**
 580   
      * If true, forks the javac compiler.
 581   
      *
 582   
      * @param f "true|false|on|off|yes|no"
 583   
      */
 584  9
     public void setFork(boolean f) {
 585  9
         fork = f;
 586   
     }
 587   
 
 588   
     /**
 589   
      * Sets the the name of the javac executable.
 590   
      *
 591   
      * <p>Ignored unless fork is true or extJavac has been specified
 592   
      * as the compiler.</p>
 593   
      */
 594  1
     public void setExecutable(String forkExec) {
 595  1
         forkedExecutable = forkExec;
 596   
     }
 597   
 
 598   
     /**
 599   
      * Is this a forked invocation of JDK's javac?
 600   
      */
 601  8
     public boolean isForkedJavac() {
 602  8
         return fork || "extJavac".equals(getCompiler());
 603   
     }
 604   
 
 605   
     /**
 606   
      * The name of the javac executable to use in fork-mode.
 607   
      */
 608  8
     public String getJavacExecutable() {
 609  8
         if (forkedExecutable == null && isForkedJavac()) {
 610  1
             forkedExecutable = getSystemJavac();
 611  7
         } else if (forkedExecutable != null && !isForkedJavac()) {
 612  1
             forkedExecutable = null;
 613   
         }
 614  8
         return forkedExecutable;
 615   
     }
 616   
 
 617   
     /**
 618   
      * If true, enables the -nowarn option.
 619   
      */
 620  0
     public void setNowarn(boolean flag) {
 621  0
         this.nowarn = flag;
 622   
     }
 623   
 
 624   
     /**
 625   
      * Should the -nowarn option be used.
 626   
      */
 627  17
     public boolean getNowarn() {
 628  17
         return nowarn;
 629   
     }
 630   
 
 631   
     /**
 632   
      * Adds an implementation specific command-line argument.
 633   
      */
 634  2
     public ImplementationSpecificArgument createCompilerArg() {
 635  2
         ImplementationSpecificArgument arg =
 636   
             new ImplementationSpecificArgument();
 637  2
         facade.addImplementationArgument(arg);
 638  2
         return arg;
 639   
     }
 640   
 
 641   
     /**
 642   
      * Get the additional implementation specific command line arguments.
 643   
      * @return array of command line arguments, guaranteed to be non-null.
 644   
      */
 645  24
     public String[] getCurrentCompilerArgs() {
 646  24
         String chosen = facade.getExplicitChoice();
 647   
         // make sure facade knows about magic properties and fork setting
 648  24
         facade.setImplementation(getCompiler());
 649  24
         try {
 650  24
             return facade.getArgs();
 651   
         } finally {
 652  24
             facade.setImplementation(chosen);
 653   
         }
 654   
     }
 655   
 
 656   
 
 657   
     /**
 658   
      * Executes the task.
 659   
      */
 660  19
     public void execute() throws BuildException {
 661  19
         checkParameters();
 662  19
         resetFileLists();
 663   
 
 664   
         // scan source directories and dest directory to build up
 665   
         // compile lists
 666  19
         String[] list = src.list();
 667  19
         for (int i = 0; i < list.length; i++) {
 668  19
             File srcDir = getProject().resolveFile(list[i]);
 669  19
             if (!srcDir.exists()) {
 670  0
                 throw new BuildException("srcdir \""
 671   
                                          + srcDir.getPath()
 672   
                                          + "\" does not exist!", getLocation());
 673   
             }
 674   
 
 675  19
             DirectoryScanner ds = this.getDirectoryScanner(srcDir);
 676  19
             String[] files = ds.getIncludedFiles();
 677   
 
 678  19
             scanDir(srcDir, destDir != null ? destDir : srcDir, files);
 679   
         }
 680   
 
 681  19
         compile();
 682   
     }
 683   
 
 684   
     /**
 685   
      * Clear the list of files to be compiled and copied..
 686   
      */
 687  19
     protected void resetFileLists() {
 688  19
         compileList = new File[0];
 689   
     }
 690   
 
 691   
     /**
 692   
      * Scans the directory looking for source files to be compiled.
 693   
      * The results are returned in the class variable compileList
 694   
      */
 695  19
     protected void scanDir(File srcDir, File destDir, String[] files) {
 696  19
         GlobPatternMapper m = new GlobPatternMapper();
 697  19
         m.setFrom("*.java");
 698  19
         m.setTo("*.class");
 699  19
         SourceFileScanner sfs = new SourceFileScanner(this);
 700  19
         File[] newFiles = sfs.restrictAsFiles(files, srcDir, destDir, m);
 701   
 
 702  19
         if (newFiles.length > 0) {
 703  17
             File[] newCompileList = new File[compileList.length +
 704   
                 newFiles.length];
 705  17
             System.arraycopy(compileList, 0, newCompileList, 0,
 706   
                     compileList.length);
 707  17
             System.arraycopy(newFiles, 0, newCompileList,
 708   
                     compileList.length, newFiles.length);
 709  17
             compileList = newCompileList;
 710   
         }
 711   
     }
 712   
 
 713   
     /** Gets the list of files to be compiled. */
 714  17
     public File[] getFileList() {
 715  17
         return compileList;
 716   
     }
 717   
 
 718  6
     protected boolean isJdkCompiler(String compilerImpl) {
 719  6
         return "modern".equals(compilerImpl) ||
 720   
             "classic".equals(compilerImpl) ||
 721   
             "javac1.1".equals(compilerImpl) ||
 722   
             "javac1.2".equals(compilerImpl) ||
 723   
             "javac1.3".equals(compilerImpl) ||
 724   
             "javac1.4".equals(compilerImpl);
 725   
     }
 726   
 
 727  1
     protected String getSystemJavac() {
 728  1
         return JavaEnvUtils.getJdkExecutable("javac");
 729   
     }
 730   
 
 731   
     /**
 732   
      * Choose the implementation for this particular task.
 733   
      *
 734   
      * @since Ant 1.5
 735   
      */
 736  2
     public void setCompiler(String compiler) {
 737  2
         facade.setImplementation(compiler);
 738   
     }
 739   
 
 740   
     /**
 741   
      * The implementation for this particular task.
 742   
      *
 743   
      * <p>Defaults to the build.compiler property but can be overriden
 744   
      * via the compiler and fork attributes.</p>
 745   
      *
 746   
      * <p>If fork has been set to true, the result will be extJavac
 747   
      * and not classic or java1.2 - no matter what the compiler
 748   
      * attribute looks like.</p>
 749   
      *
 750   
      * @see #getCompilerVersion
 751   
      *
 752   
      * @since Ant 1.5
 753   
      */
 754  57
     public String getCompiler() {
 755  57
         String compilerImpl = getCompilerVersion();
 756  57
         if (fork) {
 757  6
             if (isJdkCompiler(compilerImpl)) {
 758  4
                 if (facade.hasBeenSet()) {
 759  1
                     log("Since fork is true, ignoring compiler setting.",
 760   
                         Project.MSG_WARN);
 761   
                 }
 762  4
                 compilerImpl = "extJavac";
 763   
             } else {
 764  2
                 log("Since compiler setting isn't classic or modern,"
 765   
                     + "ignoring fork setting.", Project.MSG_WARN);
 766   
             }
 767   
         }
 768  57
         return compilerImpl;
 769   
     }
 770   
 
 771   
     /**
 772   
      * The implementation for this particular task.
 773   
      *
 774   
      * <p>Defaults to the build.compiler property but can be overriden
 775   
      * via the compiler attribute.</p>
 776   
      *
 777   
      * <p>This method does not take the fork attribute into
 778   
      * account.</p>
 779   
      *
 780   
      * @see #getCompiler
 781   
      *
 782   
      * @since Ant 1.5
 783   
      */
 784  211
     public String getCompilerVersion() {
 785  211
         facade.setMagicValue(getProject().getProperty("build.compiler"));
 786  211
         return facade.getImplementation();
 787   
     }
 788   
 
 789   
     /**
 790   
      * Check that all required attributes have been set and nothing
 791   
      * silly has been entered.
 792   
      *
 793   
      * @since Ant 1.5
 794   
      */
 795  19
     protected void checkParameters() throws BuildException {
 796  19
         if (src == null) {
 797  0
             throw new BuildException("srcdir attribute must be set!",
 798   
                                      getLocation());
 799   
         }
 800  19
         if (src.size() == 0) {
 801  0
             throw new BuildException("srcdir attribute must be set!",
 802   
                                      getLocation());
 803   
         }
 804   
 
 805  19
         if (destDir != null && !destDir.isDirectory()) {
 806  0
             throw new BuildException("destination directory \""
 807   
                                      + destDir
 808   
                                      + "\" does not exist "
 809   
                                      + "or is not a directory", getLocation());
 810   
         }
 811   
     }
 812   
 
 813   
     /**
 814   
      * Perform the compilation.
 815   
      *
 816   
      * @since Ant 1.5
 817   
      */
 818  19
     protected void compile() {
 819  19
         String compilerImpl = getCompiler();
 820   
 
 821  19
         if (compileList.length > 0) {
 822  17
             log("Compiling " + compileList.length +
 823   
                 " source file"
 824   
                 + (compileList.length == 1 ? "" : "s")
 825   
                 + (destDir != null ? " to " + destDir : ""));
 826   
 
 827  17
             if (listFiles) {
 828  0
                 for (int i = 0 ; i < compileList.length ; i++) {
 829  0
                   String filename = compileList[i].getAbsolutePath();
 830  0
                   log(filename) ;
 831   
                 }
 832   
             }
 833   
 
 834  17
             CompilerAdapter adapter =
 835   
                 CompilerAdapterFactory.getCompiler(compilerImpl, this);
 836   
 
 837   
             // now we need to populate the compiler adapter
 838  17
             adapter.setJavac(this);
 839   
 
 840   
             // finally, lets execute the compiler!!
 841  17
             if (!adapter.execute()) {
 842  0
                 if (failOnError) {
 843  0
                     throw new BuildException(FAIL_MSG, getLocation());
 844   
                 } else {
 845  0
                     log(FAIL_MSG, Project.MSG_ERR);
 846   
                 }
 847   
             }
 848   
         }
 849   
     }
 850   
 
 851   
     /**
 852   
      * Adds an "compiler" attribute to Commandline$Attribute used to
 853   
      * filter command line attributes based on the current
 854   
      * implementation.
 855   
      */
 856   
     public class ImplementationSpecificArgument extends
 857   
         org.apache.tools.ant.util.facade.ImplementationSpecificArgument {
 858   
 
 859  2
         public void setCompiler(String impl) {
 860  2
             super.setImplementation(impl);
 861   
         }
 862   
     }
 863   
 
 864   
 }
 865