ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From co...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs/compilers DefaultCompilerAdapter.java
Date Mon, 27 Aug 2001 12:30:53 GMT
conor       01/08/27 05:30:53

  Modified:    src/main/org/apache/tools/ant/taskdefs Tag: ANT_14_BRANCH
                        Javac.java
               src/main/org/apache/tools/ant/taskdefs/compilers Tag:
                        ANT_14_BRANCH DefaultCompilerAdapter.java
  Log:
  Allow memory size of forked JAvac to be specified
  
  Submitted by:	Eric Lefevre <eric.lefevre@valtech.co.uk>
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.67.2.2  +584 -558  jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Javac.java
  
  Index: Javac.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Javac.java,v
  retrieving revision 1.67.2.1
  retrieving revision 1.67.2.2
  diff -u -r1.67.2.1 -r1.67.2.2
  --- Javac.java	2001/08/13 06:32:02	1.67.2.1
  +++ Javac.java	2001/08/27 12:30:53	1.67.2.2
  @@ -1,558 +1,584 @@
  -/*
  - * The Apache Software License, Version 1.1
  - *
  - * Copyright (c) 1999 The Apache Software Foundation.  All rights
  - * reserved.
  - *
  - * Redistribution and use in source and binary forms, with or without
  - * modification, are permitted provided that the following conditions
  - * are met:
  - *
  - * 1. Redistributions of source code must retain the above copyright
  - *    notice, this list of conditions and the following disclaimer.
  - *
  - * 2. Redistributions in binary form must reproduce the above copyright
  - *    notice, this list of conditions and the following disclaimer in
  - *    the documentation and/or other materials provided with the
  - *    distribution.
  - *
  - * 3. The end-user documentation included with the redistribution, if
  - *    any, must include the following acknowlegement:
  - *       "This product includes software developed by the
  - *        Apache Software Foundation (http://www.apache.org/)."
  - *    Alternately, this acknowlegement may appear in the software itself,
  - *    if and wherever such third-party acknowlegements normally appear.
  - *
  - * 4. The names "The Jakarta Project", "Ant", and "Apache Software
  - *    Foundation" must not be used to endorse or promote products derived
  - *    from this software without prior written permission. For written
  - *    permission, please contact apache@apache.org.
  - *
  - * 5. Products derived from this software may not be called "Apache"
  - *    nor may "Apache" appear in their names without prior written
  - *    permission of the Apache Group.
  - *
  - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  - * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  - * SUCH DAMAGE.
  - * ====================================================================
  - *
  - * This software consists of voluntary contributions made by many
  - * individuals on behalf of the Apache Software Foundation.  For more
  - * information on the Apache Software Foundation, please see
  - * <http://www.apache.org/>.
  - */
  -
  -package org.apache.tools.ant.taskdefs;
  -
  -import org.apache.tools.ant.BuildException;
  -import org.apache.tools.ant.DirectoryScanner;
  -import org.apache.tools.ant.Project;
  -import org.apache.tools.ant.types.*;
  -import org.apache.tools.ant.util.*;
  -import org.apache.tools.ant.taskdefs.compilers.*;
  -
  -import java.io.File;
  -
  -/**
  - * Task to compile Java source files. This task can take the following
  - * arguments:
  - * <ul>
  - * <li>sourcedir
  - * <li>destdir
  - * <li>deprecation
  - * <li>classpath
  - * <li>bootclasspath
  - * <li>extdirs
  - * <li>optimize
  - * <li>debug
  - * <li>encoding
  - * <li>target
  - * <li>depend
  - * <li>vebose
  - * <li>failonerror
  - * <li>includeantruntime
  - * <li>includejavaruntime
  - * </ul>
  - * Of these arguments, the <b>sourcedir</b> and <b>destdir</b> are required.
  - * <p>
  - * When this task executes, it will recursively scan the sourcedir and
  - * destdir looking for Java source files to compile. This task makes its
  - * compile decision based on timestamp. 
  - *
  - * @author James Davidson <a href="mailto:duncan@x180.com">duncan@x180.com</a>
  - * @author Robin Green <a href="mailto:greenrd@hotmail.com">greenrd@hotmail.com</a>
  - * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> 
  - * @author <a href="mailto:jayglanville@home.com">J D Glanville</a>
  - */
  -
  -public class Javac extends MatchingTask {
  -
  -    private static final String FAIL_MSG 
  -        = "Compile failed, messages should have been provided.";
  -
  -    private Path src;
  -    private File destDir;
  -    private Path compileClasspath;
  -    private String encoding;
  -    private boolean debug = false;
  -    private boolean optimize = false;
  -    private boolean deprecation = false;
  -    private boolean depend = false;
  -    private boolean verbose = false;
  -    private String target;
  -    private Path bootclasspath;
  -    private Path extdirs;
  -    private boolean includeAntRuntime = true;
  -    private boolean includeJavaRuntime = false;
  -    private boolean fork = false;
  -    private boolean nowarn = false;
  -
  -    protected boolean failOnError = true;
  -    protected File[] compileList = new File[0];
  -
  -    /**
  -     * Create a nested <src ...> element for multiple source path
  -     * support.
  -     *
  -     * @return a nexted src element.
  -     */
  -    public Path createSrc() {
  -        if (src == null) {
  -            src = new Path(project);
  -        }
  -        return src.createPath();
  -    }
  -
  -    /**
  -     * Set the source dirs to find the source Java files.
  -     */
  -    public void setSrcdir(Path srcDir) {
  -        if (src == null) {
  -            src = srcDir;
  -        } else {
  -            src.append(srcDir);
  -        }
  -    }
  -
  -    /** Gets the source dirs to find the source java files. */
  -    public Path getSrcdir() {
  -        return src;
  -    }
  -
  -    /**
  -     * Set the destination directory into which the Java source
  -     * files should be compiled.
  -     */
  -    public void setDestdir(File destDir) {
  -        this.destDir = destDir;
  -    }
  -
  -    /** 
  -     * Gets the destination directory into which the java source files
  -     * should be compiled.
  -     */
  -    public File getDestdir() {
  -        return destDir;
  -    }
  -
  -    /**
  -     * Set the classpath to be used for this compilation.
  -     */
  -    public void setClasspath(Path classpath) {
  -        if (compileClasspath == null) {
  -            compileClasspath = classpath;
  -        } else {
  -            compileClasspath.append(classpath);
  -        }
  -    }
  -
  -    /** Gets the classpath to be used for this compilation. */
  -    public Path getClasspath() {
  -        return compileClasspath;
  -    }
  -
  -    /**
  -     * Maybe creates a nested classpath element.
  -     */
  -    public Path createClasspath() {
  -        if (compileClasspath == null) {
  -            compileClasspath = new Path(project);
  -        }
  -        return compileClasspath.createPath();
  -    }
  -
  -    /**
  -     * Adds a reference to a CLASSPATH defined elsewhere.
  -     */
  -    public void setClasspathRef(Reference r) {
  -        createClasspath().setRefid(r);
  -    }
  -
  -    /**
  -     * Sets the bootclasspath that will be used to compile the classes
  -     * against.
  -     */
  -    public void setBootclasspath(Path bootclasspath) {
  -        if (this.bootclasspath == null) {
  -            this.bootclasspath = bootclasspath;
  -        } else {
  -            this.bootclasspath.append(bootclasspath);
  -        }
  -    }
  -
  -    /**
  -     * Gets the bootclasspath that will be used to compile the classes
  -     * against.
  -     */
  -    public Path getBootclasspath() {
  -        return bootclasspath;
  -    }
  -
  -    /**
  -     * Maybe creates a nested classpath element.
  -     */
  -    public Path createBootclasspath() {
  -        if (bootclasspath == null) {
  -            bootclasspath = new Path(project);
  -        }
  -        return bootclasspath.createPath();
  -    }
  -
  -    /**
  -     * Adds a reference to a CLASSPATH defined elsewhere.
  -     */
  -    public void setBootClasspathRef(Reference r) {
  -        createBootclasspath().setRefid(r);
  -    }
  -
  -    /**
  -     * Sets the extension directories that will be used during the
  -     * compilation.
  -     */
  -    public void setExtdirs(Path extdirs) {
  -        if (this.extdirs == null) {
  -            this.extdirs = extdirs;
  -        } else {
  -            this.extdirs.append(extdirs);
  -        }
  -    }
  -
  -    /**
  -     * Gets the extension directories that will be used during the
  -     * compilation.
  -     */
  -    public Path getExtdirs() {
  -        return extdirs;
  -    }
  -
  -    /**
  -     * Maybe creates a nested classpath element.
  -     */
  -    public Path createExtdirs() {
  -        if (extdirs == null) {
  -            extdirs = new Path(project);
  -        }
  -        return extdirs.createPath();
  -    }
  -
  -    /**
  -     * Throw a BuildException if compilation fails
  -     */
  -    public void setFailonerror(boolean fail) {
  -        failOnError = fail;
  -    }
  -
  -    /**
  -     * Proceed if compilation fails
  -     */
  -    public void setProceed(boolean proceed) {
  -        failOnError = !proceed;
  -    }
  -
  -    /**
  -     * Gets the failonerror flag.
  -     */
  -    public boolean getFailonerror() {
  -        return failOnError;
  -    }
  -
  -    /**
  -     * Set the deprecation flag.
  -     */
  -    public void setDeprecation(boolean deprecation) {
  -        this.deprecation = deprecation;
  -    }
  -
  -    /** Gets the deprecation flag. */
  -    public boolean getDeprecation() {
  -        return deprecation;
  -    }
  -
  -    /**
  -     * Set the Java source file encoding name.
  -     */
  -    public void setEncoding(String encoding) {
  -        this.encoding = encoding;
  -    }
  -
  -    /** Gets the java source file encoding name. */
  -    public String getEncoding() {
  -        return encoding;
  -    }
  -
  -    /**
  -     * Set the debug flag.
  -     */
  -    public void setDebug(boolean debug) {
  -        this.debug = debug;
  -    }
  -
  -    /** Gets the debug flag. */
  -    public boolean getDebug() {
  -        return debug;
  -    }
  -
  -    /**
  -     * Set the optimize flag.
  -     */
  -    public void setOptimize(boolean optimize) {
  -        this.optimize = optimize;
  -    }
  -
  -    /** Gets the optimize flag. */
  -    public boolean getOptimize() {
  -        return optimize;
  -    }
  -
  -    /** 
  -     * Set the depend flag.
  -     */ 
  -    public void setDepend(boolean depend) {
  -        this.depend = depend;
  -    }  
  -
  -    /** Gets the depend flag. */
  -    public boolean getDepend() {
  -        return depend;
  -    }
  -
  -    /** 
  -     * Set the verbose flag.
  -     */ 
  -    public void setVerbose(boolean verbose) {
  -        this.verbose = verbose;
  -    }
  -
  -    /** Gets the verbose flag. */
  -    public boolean getVerbose() {
  -        return verbose;
  -    }
  -
  -    /**
  -     * Sets the target VM that the classes will be compiled for. Valid
  -     * strings are "1.1", "1.2", and "1.3".
  -     */
  -    public void setTarget(String target) {
  -        this.target = target;
  -    }
  -
  -    /** Gets the target VM that the classes will be compiled for. */
  -    public String getTarget() {
  -        return target;
  -    }
  -
  -    /**
  -     * Include ant's own classpath in this task's classpath?
  -     */
  -    public void setIncludeantruntime( boolean include ) {
  -        includeAntRuntime = include;
  -    }
  -
  -    /**
  -     * Gets whether or not the ant classpath is to be included in the
  -     * task's classpath.
  -     */
  -    public boolean getIncludeantruntime() {
  -        return includeAntRuntime;
  -    }
  -
  -    /**
  -     * Sets whether or not to include the java runtime libraries to this
  -     * task's classpath.
  -     */
  -    public void setIncludejavaruntime( boolean include ) {
  -        includeJavaRuntime = include;
  -    }
  -
  -    /**
  -     * Gets whether or not the java runtime should be included in this
  -     * task's classpath.
  -     */
  -    public boolean getIncludejavaruntime() {
  -        return includeJavaRuntime;
  -    }
  -
  -    /**
  -     * Sets whether to fork the javac compiler.
  -     */    
  -    public void setFork(boolean fork) 
  -    {
  -	this.fork = fork;
  -    }
  -	
  -
  -    /**
  -     * Sets whether the -nowarn option should be used.
  -     */
  -    public void setNowarn(boolean flag) {
  -        this.nowarn = flag;
  -    }
  -
  -    /**
  -     * Should the -nowarn option be used.
  -     */
  -    public boolean getNowarn() {
  -        return nowarn;
  -    }
  -
  -    /**
  -     * Executes the task.
  -     */
  -    public void execute() throws BuildException {
  -        // first off, make sure that we've got a srcdir
  -
  -        if (src == null) {
  -            throw new BuildException("srcdir attribute must be set!", location);
  -        }
  -        String [] list = src.list();
  -        if (list.length == 0) {
  -            throw new BuildException("srcdir attribute must be set!", location);
  -        }
  -        
  -        if (destDir != null && !destDir.isDirectory()) {
  -            throw new BuildException("destination directory \"" + destDir + "\" does not exist or is not a directory", location);
  -        }
  -
  -        // scan source directories and dest directory to build up 
  -        // compile lists
  -        resetFileLists();
  -        for (int i=0; i<list.length; i++) {
  -            File srcDir = (File)project.resolveFile(list[i]);
  -            if (!srcDir.exists()) {
  -                throw new BuildException("srcdir \"" + srcDir.getPath() + "\" does not exist!", location);
  -            }
  -
  -            DirectoryScanner ds = this.getDirectoryScanner(srcDir);
  -
  -            String[] files = ds.getIncludedFiles();
  -
  -            scanDir(srcDir, destDir != null ? destDir : srcDir, files);
  -        }
  -        
  -        // compile the source files
  -
  -        String compiler = project.getProperty("build.compiler");
  -	
  -	if (fork) {
  -	    if (compiler != null) {
  -                if (isJdkCompiler(compiler)) {
  -                    log("Since fork is true, ignoring build.compiler setting.",
  -                        Project.MSG_WARN);
  -                    compiler = "extJavac";
  -                }
  -                else {
  -                    log("Since build.compiler setting isn't classic or modern, ignoring fork setting.", Project.MSG_WARN);
  -                }
  -	    }
  -            else {
  -                compiler = "extJavac";
  -            }
  -	} 
  -
  -	if (compiler == null) {
  -            if (Project.getJavaVersion() != Project.JAVA_1_1 &&
  -                Project.getJavaVersion() != Project.JAVA_1_2) {
  -                compiler = "modern";
  -            } else {
  -                compiler = "classic";
  -            }
  -        }
  -
  -        if (compileList.length > 0) {
  -
  -            CompilerAdapter adapter = CompilerAdapterFactory.getCompiler(
  -              compiler, this );
  -            log("Compiling " + compileList.length + 
  -                " source file"
  -                + (compileList.length == 1 ? "" : "s")
  -                + (destDir != null ? " to " + destDir : ""));
  -
  -            // now we need to populate the compiler adapter
  -            adapter.setJavac( this );
  -            
  -            // finally, lets execute the compiler!!
  -            if (!adapter.execute()) {
  -                if (failOnError) {
  -                    throw new BuildException(FAIL_MSG, location);
  -                }
  -                else {
  -                    log(FAIL_MSG, Project.MSG_ERR);
  -                }
  -            }
  -        }
  -    }
  -
  -    /**
  -     * Clear the list of files to be compiled and copied.. 
  -     */
  -    protected void resetFileLists() {
  -        compileList = new File[0];
  -    }
  -
  -    /**
  -     * Scans the directory looking for source files to be compiled.  
  -     * The results are returned in the class variable compileList
  -     */
  -    protected void scanDir(File srcDir, File destDir, String files[]) {
  -        GlobPatternMapper m = new GlobPatternMapper();
  -        m.setFrom("*.java");
  -        m.setTo("*.class");
  -        SourceFileScanner sfs = new SourceFileScanner(this);
  -        File[] newFiles = sfs.restrictAsFiles(files, srcDir, destDir, m);
  -        
  -        if (newFiles.length > 0) {
  -            File[] newCompileList = new File[compileList.length +
  -                newFiles.length];
  -            System.arraycopy(compileList, 0, newCompileList, 0,
  -                    compileList.length);
  -            System.arraycopy(newFiles, 0, newCompileList,
  -                    compileList.length, newFiles.length);
  -            compileList = newCompileList;
  -        }
  -    }
  -
  -    /** Gets the list of files to be compiled. */
  -    public File[] getFileList() {
  -        return compileList;
  -    }
  -
  -    protected boolean isJdkCompiler(String compiler) {
  -        return "modern".equals(compiler) ||
  -            "classic".equals(compiler) ||
  -            "javac1.1".equals(compiler) ||
  -            "javac1.2".equals(compiler) ||
  -            "javac1.3".equals(compiler) ||
  -            "javac1.4".equals(compiler);
  -    }
  -
  -}
  +/*
  + * The Apache Software License, Version 1.1
  + *
  + * Copyright (c) 1999 The Apache Software Foundation.  All rights
  + * reserved.
  + *
  + * Redistribution and use in source and binary forms, with or without
  + * modification, are permitted provided that the following conditions
  + * are met:
  + *
  + * 1. Redistributions of source code must retain the above copyright
  + *    notice, this list of conditions and the following disclaimer.
  + *
  + * 2. Redistributions in binary form must reproduce the above copyright
  + *    notice, this list of conditions and the following disclaimer in
  + *    the documentation and/or other materials provided with the
  + *    distribution.
  + *
  + * 3. The end-user documentation included with the redistribution, if
  + *    any, must include the following acknowlegement:
  + *       "This product includes software developed by the
  + *        Apache Software Foundation (http://www.apache.org/)."
  + *    Alternately, this acknowlegement may appear in the software itself,
  + *    if and wherever such third-party acknowlegements normally appear.
  + *
  + * 4. The names "The Jakarta Project", "Ant", and "Apache Software
  + *    Foundation" must not be used to endorse or promote products derived
  + *    from this software without prior written permission. For written
  + *    permission, please contact apache@apache.org.
  + *
  + * 5. Products derived from this software may not be called "Apache"
  + *    nor may "Apache" appear in their names without prior written
  + *    permission of the Apache Group.
  + *
  + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  + * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  + * SUCH DAMAGE.
  + * ====================================================================
  + *
  + * This software consists of voluntary contributions made by many
  + * individuals on behalf of the Apache Software Foundation.  For more
  + * information on the Apache Software Foundation, please see
  + * <http://www.apache.org/>.
  + */
  +
  +package org.apache.tools.ant.taskdefs;
  +
  +import org.apache.tools.ant.BuildException;
  +import org.apache.tools.ant.DirectoryScanner;
  +import org.apache.tools.ant.Project;
  +import org.apache.tools.ant.types.*;
  +import org.apache.tools.ant.util.*;
  +import org.apache.tools.ant.taskdefs.compilers.*;
  +
  +import java.io.File;
  +
  +/**
  + * Task to compile Java source files. This task can take the following
  + * arguments:
  + * <ul>
  + * <li>sourcedir
  + * <li>destdir
  + * <li>deprecation
  + * <li>classpath
  + * <li>bootclasspath
  + * <li>extdirs
  + * <li>optimize
  + * <li>debug
  + * <li>encoding
  + * <li>target
  + * <li>depend
  + * <li>vebose
  + * <li>failonerror
  + * <li>includeantruntime
  + * <li>includejavaruntime
  + * </ul>
  + * Of these arguments, the <b>sourcedir</b> and <b>destdir</b> are required.
  + * <p>
  + * When this task executes, it will recursively scan the sourcedir and
  + * destdir looking for Java source files to compile. This task makes its
  + * compile decision based on timestamp.
  + *
  + * @author James Davidson <a href="mailto:duncan@x180.com">duncan@x180.com</a>
  + * @author Robin Green <a href="mailto:greenrd@hotmail.com">greenrd@hotmail.com</a>
  + * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
  + * @author <a href="mailto:jayglanville@home.com">J D Glanville</a>
  + */
  +
  +public class Javac extends MatchingTask {
  +
  +    private static final String FAIL_MSG
  +        = "Compile failed, messages should have been provided.";
  +
  +    private Path src;
  +    private File destDir;
  +    private Path compileClasspath;
  +    private String encoding;
  +    private boolean debug = false;
  +    private boolean optimize = false;
  +    private boolean deprecation = false;
  +    private boolean depend = false;
  +    private boolean verbose = false;
  +    private String target;
  +    private Path bootclasspath;
  +    private Path extdirs;
  +    private boolean includeAntRuntime = true;
  +    private boolean includeJavaRuntime = false;
  +    private boolean fork = false;
  +    private boolean nowarn = false;
  +    private String memoryInitialSize;
  +    private String memoryMaximumSize;
  +
  +    protected boolean failOnError = true;
  +    protected File[] compileList = new File[0];
  +
  +    /**
  +     * Create a nested <src ...> element for multiple source path
  +     * support.
  +     *
  +     * @return a nexted src element.
  +     */
  +    public Path createSrc() {
  +        if (src == null) {
  +            src = new Path(project);
  +        }
  +        return src.createPath();
  +    }
  +
  +    /**
  +     * Set the source dirs to find the source Java files.
  +     */
  +    public void setSrcdir(Path srcDir) {
  +        if (src == null) {
  +            src = srcDir;
  +        } else {
  +            src.append(srcDir);
  +        }
  +    }
  +
  +    /** Gets the source dirs to find the source java files. */
  +    public Path getSrcdir() {
  +        return src;
  +    }
  +
  +    /**
  +     * Set the destination directory into which the Java source
  +     * files should be compiled.
  +     */
  +    public void setDestdir(File destDir) {
  +        this.destDir = destDir;
  +    }
  +
  +    /**
  +     * Gets the destination directory into which the java source files
  +     * should be compiled.
  +     */
  +    public File getDestdir() {
  +        return destDir;
  +    }
  +
  +    /**
  +     * Set the classpath to be used for this compilation.
  +     */
  +    public void setClasspath(Path classpath) {
  +        if (compileClasspath == null) {
  +            compileClasspath = classpath;
  +        } else {
  +            compileClasspath.append(classpath);
  +        }
  +    }
  +
  +    /** Gets the classpath to be used for this compilation. */
  +    public Path getClasspath() {
  +        return compileClasspath;
  +    }
  +
  +    /**
  +     * Maybe creates a nested classpath element.
  +     */
  +    public Path createClasspath() {
  +        if (compileClasspath == null) {
  +            compileClasspath = new Path(project);
  +        }
  +        return compileClasspath.createPath();
  +    }
  +
  +    /**
  +     * Adds a reference to a CLASSPATH defined elsewhere.
  +     */
  +    public void setClasspathRef(Reference r) {
  +        createClasspath().setRefid(r);
  +    }
  +
  +    /**
  +     * Sets the bootclasspath that will be used to compile the classes
  +     * against.
  +     */
  +    public void setBootclasspath(Path bootclasspath) {
  +        if (this.bootclasspath == null) {
  +            this.bootclasspath = bootclasspath;
  +        } else {
  +            this.bootclasspath.append(bootclasspath);
  +        }
  +    }
  +
  +    /**
  +     * Gets the bootclasspath that will be used to compile the classes
  +     * against.
  +     */
  +    public Path getBootclasspath() {
  +        return bootclasspath;
  +    }
  +
  +    /**
  +     * Maybe creates a nested classpath element.
  +     */
  +    public Path createBootclasspath() {
  +        if (bootclasspath == null) {
  +            bootclasspath = new Path(project);
  +        }
  +        return bootclasspath.createPath();
  +    }
  +
  +    /**
  +     * Adds a reference to a CLASSPATH defined elsewhere.
  +     */
  +    public void setBootClasspathRef(Reference r) {
  +        createBootclasspath().setRefid(r);
  +    }
  +
  +    /**
  +     * Sets the extension directories that will be used during the
  +     * compilation.
  +     */
  +    public void setExtdirs(Path extdirs) {
  +        if (this.extdirs == null) {
  +            this.extdirs = extdirs;
  +        } else {
  +            this.extdirs.append(extdirs);
  +        }
  +    }
  +
  +    /**
  +     * Gets the extension directories that will be used during the
  +     * compilation.
  +     */
  +    public Path getExtdirs() {
  +        return extdirs;
  +    }
  +
  +    /**
  +     * Maybe creates a nested classpath element.
  +     */
  +    public Path createExtdirs() {
  +        if (extdirs == null) {
  +            extdirs = new Path(project);
  +        }
  +        return extdirs.createPath();
  +    }
  +
  +    /**
  +     * Throw a BuildException if compilation fails
  +     */
  +    public void setFailonerror(boolean fail) {
  +        failOnError = fail;
  +    }
  +
  +    /**
  +     * Proceed if compilation fails
  +     */
  +    public void setProceed(boolean proceed) {
  +        failOnError = !proceed;
  +    }
  +
  +    /**
  +     * Gets the failonerror flag.
  +     */
  +    public boolean getFailonerror() {
  +        return failOnError;
  +    }
  +
  +    /**
  +     * Set the deprecation flag.
  +     */
  +    public void setDeprecation(boolean deprecation) {
  +        this.deprecation = deprecation;
  +    }
  +
  +    /** Gets the deprecation flag. */
  +    public boolean getDeprecation() {
  +        return deprecation;
  +    }
  +
  +    /**
  +     * Set the memoryInitialSize flag.
  +     */
  +    public void setMemoryInitialSize(String memoryInitialSize) {
  +        this.memoryInitialSize = memoryInitialSize;
  +    }
  +
  +    /** Gets the memoryInitialSize flag. */
  +    public String getMemoryInitialSize() {
  +        return memoryInitialSize;
  +    }
  +
  +    /**
  +     * Set the memoryMaximumSize flag.
  +     */
  +    public void setMemoryMaximumSize(String memoryMaximumSize) {
  +        this.memoryMaximumSize = memoryMaximumSize;
  +    }
  +
  +    /** Gets the memoryMaximumSize flag. */
  +    public String getMemoryMaximumSize() {
  +        return memoryMaximumSize;
  +    }
  +
  +    /**
  +     * Set the Java source file encoding name.
  +     */
  +    public void setEncoding(String encoding) {
  +        this.encoding = encoding;
  +    }
  +
  +    /** Gets the java source file encoding name. */
  +    public String getEncoding() {
  +        return encoding;
  +    }
  +
  +    /**
  +     * Set the debug flag.
  +     */
  +    public void setDebug(boolean debug) {
  +        this.debug = debug;
  +    }
  +
  +    /** Gets the debug flag. */
  +    public boolean getDebug() {
  +        return debug;
  +    }
  +
  +    /**
  +     * Set the optimize flag.
  +     */
  +    public void setOptimize(boolean optimize) {
  +        this.optimize = optimize;
  +    }
  +
  +    /** Gets the optimize flag. */
  +    public boolean getOptimize() {
  +        return optimize;
  +    }
  +
  +    /**
  +     * Set the depend flag.
  +     */
  +    public void setDepend(boolean depend) {
  +        this.depend = depend;
  +    }
  +
  +    /** Gets the depend flag. */
  +    public boolean getDepend() {
  +        return depend;
  +    }
  +
  +    /**
  +     * Set the verbose flag.
  +     */
  +    public void setVerbose(boolean verbose) {
  +        this.verbose = verbose;
  +    }
  +
  +    /** Gets the verbose flag. */
  +    public boolean getVerbose() {
  +        return verbose;
  +    }
  +
  +    /**
  +     * Sets the target VM that the classes will be compiled for. Valid
  +     * strings are "1.1", "1.2", and "1.3".
  +     */
  +    public void setTarget(String target) {
  +        this.target = target;
  +    }
  +
  +    /** Gets the target VM that the classes will be compiled for. */
  +    public String getTarget() {
  +        return target;
  +    }
  +
  +    /**
  +     * Include ant's own classpath in this task's classpath?
  +     */
  +    public void setIncludeantruntime( boolean include ) {
  +        includeAntRuntime = include;
  +    }
  +
  +    /**
  +     * Gets whether or not the ant classpath is to be included in the
  +     * task's classpath.
  +     */
  +    public boolean getIncludeantruntime() {
  +        return includeAntRuntime;
  +    }
  +
  +    /**
  +     * Sets whether or not to include the java runtime libraries to this
  +     * task's classpath.
  +     */
  +    public void setIncludejavaruntime( boolean include ) {
  +        includeJavaRuntime = include;
  +    }
  +
  +    /**
  +     * Gets whether or not the java runtime should be included in this
  +     * task's classpath.
  +     */
  +    public boolean getIncludejavaruntime() {
  +        return includeJavaRuntime;
  +    }
  +
  +    /**
  +     * Sets whether to fork the javac compiler.
  +     */
  +    public void setFork(boolean fork)
  +    {
  +  this.fork = fork;
  +    }
  +
  +
  +    /**
  +     * Sets whether the -nowarn option should be used.
  +     */
  +    public void setNowarn(boolean flag) {
  +        this.nowarn = flag;
  +    }
  +
  +    /**
  +     * Should the -nowarn option be used.
  +     */
  +    public boolean getNowarn() {
  +        return nowarn;
  +    }
  +
  +    /**
  +     * Executes the task.
  +     */
  +    public void execute() throws BuildException {
  +        // first off, make sure that we've got a srcdir
  +
  +        if (src == null) {
  +            throw new BuildException("srcdir attribute must be set!", location);
  +        }
  +        String [] list = src.list();
  +        if (list.length == 0) {
  +            throw new BuildException("srcdir attribute must be set!", location);
  +        }
  +
  +        if (destDir != null && !destDir.isDirectory()) {
  +            throw new BuildException("destination directory \"" + destDir + "\" does not exist or is not a directory", location);
  +        }
  +
  +        // scan source directories and dest directory to build up
  +        // compile lists
  +        resetFileLists();
  +        for (int i=0; i<list.length; i++) {
  +            File srcDir = (File)project.resolveFile(list[i]);
  +            if (!srcDir.exists()) {
  +                throw new BuildException("srcdir \"" + srcDir.getPath() + "\" does not exist!", location);
  +            }
  +
  +            DirectoryScanner ds = this.getDirectoryScanner(srcDir);
  +
  +            String[] files = ds.getIncludedFiles();
  +
  +            scanDir(srcDir, destDir != null ? destDir : srcDir, files);
  +        }
  +
  +        // compile the source files
  +
  +        String compiler = project.getProperty("build.compiler");
  +
  +  if (fork) {
  +      if (compiler != null) {
  +                if (isJdkCompiler(compiler)) {
  +                    log("Since fork is true, ignoring build.compiler setting.",
  +                        Project.MSG_WARN);
  +                    compiler = "extJavac";
  +                }
  +                else {
  +                    log("Since build.compiler setting isn't classic or modern, ignoring fork setting.", Project.MSG_WARN);
  +                }
  +      }
  +            else {
  +                compiler = "extJavac";
  +            }
  +  }
  +
  +  if (compiler == null) {
  +            if (Project.getJavaVersion() != Project.JAVA_1_1 &&
  +                Project.getJavaVersion() != Project.JAVA_1_2) {
  +                compiler = "modern";
  +            } else {
  +                compiler = "classic";
  +            }
  +        }
  +
  +        if (compileList.length > 0) {
  +
  +            CompilerAdapter adapter = CompilerAdapterFactory.getCompiler(
  +              compiler, this );
  +            log("Compiling " + compileList.length +
  +                " source file"
  +                + (compileList.length == 1 ? "" : "s")
  +                + (destDir != null ? " to " + destDir : ""));
  +
  +            // now we need to populate the compiler adapter
  +            adapter.setJavac( this );
  +
  +            // finally, lets execute the compiler!!
  +            if (!adapter.execute()) {
  +                if (failOnError) {
  +                    throw new BuildException(FAIL_MSG, location);
  +                }
  +                else {
  +                    log(FAIL_MSG, Project.MSG_ERR);
  +                }
  +            }
  +        }
  +    }
  +
  +    /**
  +     * Clear the list of files to be compiled and copied..
  +     */
  +    protected void resetFileLists() {
  +        compileList = new File[0];
  +    }
  +
  +    /**
  +     * Scans the directory looking for source files to be compiled.
  +     * The results are returned in the class variable compileList
  +     */
  +    protected void scanDir(File srcDir, File destDir, String files[]) {
  +        GlobPatternMapper m = new GlobPatternMapper();
  +        m.setFrom("*.java");
  +        m.setTo("*.class");
  +        SourceFileScanner sfs = new SourceFileScanner(this);
  +        File[] newFiles = sfs.restrictAsFiles(files, srcDir, destDir, m);
  +
  +        if (newFiles.length > 0) {
  +            File[] newCompileList = new File[compileList.length +
  +                newFiles.length];
  +            System.arraycopy(compileList, 0, newCompileList, 0,
  +                    compileList.length);
  +            System.arraycopy(newFiles, 0, newCompileList,
  +                    compileList.length, newFiles.length);
  +            compileList = newCompileList;
  +        }
  +    }
  +
  +    /** Gets the list of files to be compiled. */
  +    public File[] getFileList() {
  +        return compileList;
  +    }
  +
  +    protected boolean isJdkCompiler(String compiler) {
  +        return "modern".equals(compiler) ||
  +            "classic".equals(compiler) ||
  +            "javac1.1".equals(compiler) ||
  +            "javac1.2".equals(compiler) ||
  +            "javac1.3".equals(compiler) ||
  +            "javac1.4".equals(compiler);
  +    }
  +
  +}
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.6.2.2   +433 -416  jakarta-ant/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java
  
  Index: DefaultCompilerAdapter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java,v
  retrieving revision 1.6.2.1
  retrieving revision 1.6.2.2
  diff -u -r1.6.2.1 -r1.6.2.2
  --- DefaultCompilerAdapter.java	2001/08/13 06:32:02	1.6.2.1
  +++ DefaultCompilerAdapter.java	2001/08/27 12:30:53	1.6.2.2
  @@ -1,416 +1,433 @@
  -/*
  - * The Apache Software License, Version 1.1
  - *
  - * Copyright (c) 2001 The Apache Software Foundation.  All rights
  - * reserved.
  - *
  - * Redistribution and use in source and binary forms, with or without
  - * modification, are permitted provided that the following conditions
  - * are met:
  - *
  - * 1. Redistributions of source code must retain the above copyright
  - *    notice, this list of conditions and the following disclaimer.
  - *
  - * 2. Redistributions in binary form must reproduce the above copyright
  - *    notice, this list of conditions and the following disclaimer in
  - *    the documentation and/or other materials provided with the
  - *    distribution.
  - *
  - * 3. The end-user documentation included with the redistribution, if
  - *    any, must include the following acknowlegement:
  - *       "This product includes software developed by the
  - *        Apache Software Foundation (http://www.apache.org/)."
  - *    Alternately, this acknowlegement may appear in the software itself,
  - *    if and wherever such third-party acknowlegements normally appear.
  - *
  - * 4. The names "The Jakarta Project", "Ant", and "Apache Software
  - *    Foundation" must not be used to endorse or promote products derived
  - *    from this software without prior written permission. For written
  - *    permission, please contact apache@apache.org.
  - *
  - * 5. Products derived from this software may not be called "Apache"
  - *    nor may "Apache" appear in their names without prior written
  - *    permission of the Apache Group.
  - *
  - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  - * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  - * SUCH DAMAGE.
  - * ====================================================================
  - *
  - * This software consists of voluntary contributions made by many
  - * individuals on behalf of the Apache Software Foundation.  For more
  - * information on the Apache Software Foundation, please see
  - * <http://www.apache.org/>.
  - */
  -
  -package org.apache.tools.ant.taskdefs.compilers;
  -
  -import org.apache.tools.ant.*;
  -import org.apache.tools.ant.taskdefs.*;
  -import org.apache.tools.ant.types.*;
  -
  -import java.io.*;
  -import java.util.Random;
  -
  -/**
  - * This is the default implementation for the CompilerAdapter interface.
  - * Currently, this is a cut-and-paste of the original javac task.
  - *
  - * @author James Davidson <a href="mailto:duncan@x180.com">duncan@x180.com</a>
  - * @author Robin Green <a href="mailto:greenrd@hotmail.com">greenrd@hotmail.com</a>
  - * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> 
  - * @author <a href="mailto:jayglanville@home.com">J D Glanville</a>
  - */
  -public abstract class DefaultCompilerAdapter implements CompilerAdapter {
  -
  -    /* jdg - TODO - all these attributes are currently protected, but they
  -     * should probably be private in the near future.
  -     */
  -
  -    protected Path src;
  -    protected File destDir;
  -    protected String encoding;
  -    protected boolean debug = false;
  -    protected boolean optimize = false;
  -    protected boolean deprecation = false;
  -    protected boolean depend = false;
  -    protected boolean verbose = false;
  -    protected String target;
  -    protected Path bootclasspath;
  -    protected Path extdirs;
  -    protected Path compileClasspath;
  -    protected Project project;
  -    protected Location location;
  -    protected boolean includeAntRuntime;
  -    protected boolean includeJavaRuntime;
  -
  -    protected File[] compileList;
  -    protected static String lSep = System.getProperty("line.separator");
  -    protected Javac attributes;
  -
  -    public void setJavac( Javac attributes ) {
  -        this.attributes = attributes;
  -        src = attributes.getSrcdir();
  -        destDir = attributes.getDestdir();
  -        encoding = attributes.getEncoding();
  -        debug = attributes.getDebug();
  -        optimize = attributes.getOptimize();
  -        deprecation = attributes.getDeprecation();
  -        depend = attributes.getDepend();
  -        verbose = attributes.getVerbose();
  -        target = attributes.getTarget();
  -        bootclasspath = attributes.getBootclasspath();
  -        extdirs = attributes.getExtdirs();
  -        compileList = attributes.getFileList();
  -        compileClasspath = attributes.getClasspath();
  -        project = attributes.getProject();
  -        location = attributes.getLocation();
  -        includeAntRuntime = attributes.getIncludeantruntime();
  -        includeJavaRuntime = attributes.getIncludejavaruntime();
  -    }
  -
  -    public Javac getJavac() {
  -        return attributes;
  -    }
  -
  -    /**
  -     * Builds the compilation classpath.
  -     *
  -     */
  -    protected Path getCompileClasspath() {
  -        Path classpath = new Path(project);
  -
  -        // add dest dir to classpath so that previously compiled and
  -        // untouched classes are on classpath
  -
  -        if (destDir != null) {
  -            classpath.setLocation(destDir);
  -        }
  -
  -        // Combine the build classpath with the system classpath, in an 
  -        // order determined by the value of build.classpath
  -
  -        if (compileClasspath == null) {
  -            if ( includeAntRuntime ) {
  -                classpath.addExisting(Path.systemClasspath);
  -            }
  -        } else {
  -            if ( includeAntRuntime ) {
  -                classpath.addExisting(compileClasspath.concatSystemClasspath("last"));
  -            } else {
  -                classpath.addExisting(compileClasspath.concatSystemClasspath("ignore"));
  -            }
  -        }
  -
  -        if (includeJavaRuntime) {
  -            // XXX move this stuff to a separate class, code is identical to
  -            //     code in ../rmic/DefaultRmicAdapter
  -
  -            if (System.getProperty("java.vendor").toLowerCase().indexOf("microsoft") >= 0) {
  -                // Pull in *.zip from packages directory
  -                FileSet msZipFiles = new FileSet();
  -                msZipFiles.setDir(new File(System.getProperty("java.home") + File.separator + "Packages"));
  -                msZipFiles.setIncludes("*.ZIP");
  -                classpath.addFileset(msZipFiles);
  -            }
  -            else if (Project.getJavaVersion() == Project.JAVA_1_1) {
  -                classpath.addExisting(new Path(null,
  -                                                System.getProperty("java.home")
  -                                                + File.separator + "lib"
  -                                                + File.separator 
  -                                                + "classes.zip"));
  -            } else {
  -                // JDK > 1.1 seems to set java.home to the JRE directory.
  -                classpath.addExisting(new Path(null,
  -                                                System.getProperty("java.home")
  -                                                + File.separator + "lib"
  -                                                + File.separator + "rt.jar"));
  -                // Just keep the old version as well and let addExistingToPath
  -                // sort it out.
  -                classpath.addExisting(new Path(null,
  -                                                System.getProperty("java.home")
  -                                                + File.separator +"jre"
  -                                                + File.separator + "lib"
  -                                                + File.separator + "rt.jar"));
  -
  -                // Added for MacOS X
  -                classpath.addExisting(new Path(null,
  -                                               System.getProperty("java.home")
  -                                               + File.separator + ".."
  -                                               + File.separator + "Classes"
  -                                               + File.separator + "classes.jar"));
  -                classpath.addExisting(new Path(null,
  -                                               System.getProperty("java.home")
  -                                               + File.separator + ".."
  -                                               + File.separator + "Classes"
  -                                               + File.separator + "ui.jar"));
  -            }
  -        }
  -            
  -        return classpath;
  -    }
  -
  -    /**
  -     * Does the command line argument processing common to classic and
  -     * modern.  Doesn't add the files to compile.
  -     */
  -    protected Commandline setupJavacCommandlineSwitches(Commandline cmd) {
  -        Path classpath = getCompileClasspath();
  -
  -        if (attributes.getNowarn()) {
  -            cmd.createArgument().setValue("-nowarn");
  -        }
  -        
  -        if (deprecation == true) {
  -            cmd.createArgument().setValue("-deprecation");
  -        }
  -
  -        if (destDir != null) {
  -            cmd.createArgument().setValue("-d");
  -            cmd.createArgument().setFile(destDir);
  -        }
  -        
  -        cmd.createArgument().setValue("-classpath");
  -
  -        // Just add "sourcepath" to classpath ( for JDK1.1 )
  -        // as well as "bootclasspath" and "extdirs"
  -        if (Project.getJavaVersion().startsWith("1.1")) {
  -            Path cp = new Path(project);
  -            /*
  -             * XXX - This doesn't mix very well with build.systemclasspath,
  -             */
  -            if (bootclasspath != null) {
  -                cp.append(bootclasspath);
  -            }
  -            if (extdirs != null) {
  -                addExtdirsToClasspath(cp);
  -            }
  -            cp.append(classpath);
  -            cp.append(src);
  -            cmd.createArgument().setPath(cp);
  -        } else {
  -            cmd.createArgument().setPath(classpath);
  -            cmd.createArgument().setValue("-sourcepath");
  -            cmd.createArgument().setPath(src);
  -            if (target != null) {
  -                cmd.createArgument().setValue("-target");
  -                cmd.createArgument().setValue(target);
  -            }
  -            if (bootclasspath != null) {
  -                cmd.createArgument().setValue("-bootclasspath");
  -                cmd.createArgument().setPath(bootclasspath);
  -            }
  -            if (extdirs != null) {
  -                cmd.createArgument().setValue("-extdirs");
  -                cmd.createArgument().setPath(extdirs);
  -            }
  -        }
  -
  -        if (encoding != null) {
  -            cmd.createArgument().setValue("-encoding");
  -            cmd.createArgument().setValue(encoding);
  -        }
  -        if (debug) {
  -            cmd.createArgument().setValue("-g");
  -        } else if (Project.getJavaVersion() != Project.JAVA_1_0 &&
  -                   Project.getJavaVersion() != Project.JAVA_1_1) {
  -            cmd.createArgument().setValue("-g:none");
  -        }
  -        if (optimize) {
  -            cmd.createArgument().setValue("-O");
  -        }
  -
  -        if (depend) {
  -            if (Project.getJavaVersion().startsWith("1.1")) {
  -                cmd.createArgument().setValue("-depend");
  -            } else if (Project.getJavaVersion().startsWith("1.2")) {
  -                cmd.createArgument().setValue("-Xdepend");
  -            } else {
  -                attributes.log("depend attribute is not supported by the modern compiler",
  -                    Project.MSG_WARN);
  -            }
  -        }
  -
  -        if (verbose) {
  -            cmd.createArgument().setValue("-verbose");
  -        }
  -        return cmd;
  -    }
  -
  -    /**
  -     * Does the command line argument processing common to classic and
  -     * modern and adds the files to compile as well.
  -     */
  -    protected Commandline setupJavacCommand() {
  -        Commandline cmd = new Commandline();
  -        setupJavacCommandlineSwitches(cmd);
  -        logAndAddFilesToCompile(cmd);
  -        return cmd;
  -    }
  -
  -    /**
  -     * Logs the compilation parameters, adds the files to compile and logs the 
  -     * &qout;niceSourceList&quot;
  -     */
  -    protected void logAndAddFilesToCompile(Commandline cmd) {
  -        attributes.log("Compilation args: " + cmd.toString(),
  -            Project.MSG_VERBOSE);
  -
  -        StringBuffer niceSourceList = new StringBuffer("File");
  -        if (compileList.length != 1) {
  -            niceSourceList.append("s");
  -        }
  -        niceSourceList.append(" to be compiled:");
  -
  -        niceSourceList.append(lSep);
  -
  -        for (int i=0; i < compileList.length; i++) {
  -            String arg = compileList[i].getAbsolutePath();
  -            cmd.createArgument().setValue(arg);
  -            niceSourceList.append("    " + arg + lSep);
  -        }
  -
  -        attributes.log(niceSourceList.toString(), Project.MSG_VERBOSE);
  -    }
  -
  -    /**
  -     * Do the compile with the specified arguments.
  -     * @param args - arguments to pass to process on command line
  -     * @param firstFileName - index of the first source file in args
  -     */
  -    protected int executeExternalCompile(String[] args, int firstFileName) {
  -        String[] commandArray = null;
  -        File tmpFile = null;
  -
  -        try {
  -            /*
  -             * Many system have been reported to get into trouble with 
  -             * long command lines - no, not only Windows ;-).
  -             *
  -             * POSIX seems to define a lower limit of 4k, so use a temporary 
  -             * file if the total length of the command line exceeds this limit.
  -             */
  -            if (Commandline.toString(args).length() > 4096) {
  -                PrintWriter out = null;
  -                try {
  -                    tmpFile = new File("jikes"+(new Random(System.currentTimeMillis())).nextLong());
  -                    out = new PrintWriter(new FileWriter(tmpFile));
  -                    for (int i = firstFileName; i < args.length; i++) {
  -                        out.println(args[i]);
  -                    }
  -                    out.flush();
  -                    commandArray = new String[firstFileName+1];
  -                    System.arraycopy(args, 0, commandArray, 0, firstFileName);
  -                    commandArray[firstFileName] = "@" + tmpFile.getAbsolutePath();
  -                } catch (IOException e) {
  -                    throw new BuildException("Error creating temporary file", e, location);
  -                } finally {
  -                    if (out != null) {
  -                        try {out.close();} catch (Throwable t) {}
  -                    }
  -                }
  -            } else {
  -                commandArray = args;
  -            }
  -            
  -            try {
  -                Execute exe = new Execute(new LogStreamHandler(attributes, 
  -                                                               Project.MSG_INFO,
  -                                                               Project.MSG_WARN));
  -                exe.setAntRun(project);
  -                exe.setWorkingDirectory(project.getBaseDir());
  -                exe.setCommandline(commandArray);
  -                exe.execute();
  -                return exe.getExitValue();
  -            } catch (IOException e) {
  -                throw new BuildException("Error running " + args[0] 
  -                        + " compiler", e, location);
  -            }
  -        } finally {
  -            if (tmpFile != null) {
  -                tmpFile.delete();
  -            }
  -        }
  -    }
  -
  -    /**
  -     * Emulation of extdirs feature in java >= 1.2.
  -     * This method adds all files in the given
  -     * directories (but not in sub-directories!) to the classpath,
  -     * so that you don't have to specify them all one by one.
  -     * @param classpath - Path to append files to
  -     */
  -    protected void addExtdirsToClasspath(Path classpath) {
  -        if (extdirs == null) {
  -            String extProp = System.getProperty("java.ext.dirs");
  -            if (extProp != null) {
  -                extdirs = new Path(project, extProp);
  -            } else {
  -                return;
  -            }
  -        }
  -
  -        String[] dirs = extdirs.list();
  -        for (int i=0; i<dirs.length; i++) {
  -            if (!dirs[i].endsWith(File.separator)) {
  -                dirs[i] += File.separator;
  -            }
  -            File dir = project.resolveFile(dirs[i]);
  -            FileSet fs = new FileSet();
  -            fs.setDir(dir);
  -            fs.setIncludes("*");
  -            classpath.addFileset(fs);
  -        }
  -    }
  -
  -}
  -
  +/*
  + * The Apache Software License, Version 1.1
  + *
  + * Copyright (c) 2001 The Apache Software Foundation.  All rights
  + * reserved.
  + *
  + * Redistribution and use in source and binary forms, with or without
  + * modification, are permitted provided that the following conditions
  + * are met:
  + *
  + * 1. Redistributions of source code must retain the above copyright
  + *    notice, this list of conditions and the following disclaimer.
  + *
  + * 2. Redistributions in binary form must reproduce the above copyright
  + *    notice, this list of conditions and the following disclaimer in
  + *    the documentation and/or other materials provided with the
  + *    distribution.
  + *
  + * 3. The end-user documentation included with the redistribution, if
  + *    any, must include the following acknowlegement:
  + *       "This product includes software developed by the
  + *        Apache Software Foundation (http://www.apache.org/)."
  + *    Alternately, this acknowlegement may appear in the software itself,
  + *    if and wherever such third-party acknowlegements normally appear.
  + *
  + * 4. The names "The Jakarta Project", "Ant", and "Apache Software
  + *    Foundation" must not be used to endorse or promote products derived
  + *    from this software without prior written permission. For written
  + *    permission, please contact apache@apache.org.
  + *
  + * 5. Products derived from this software may not be called "Apache"
  + *    nor may "Apache" appear in their names without prior written
  + *    permission of the Apache Group.
  + *
  + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  + * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  + * SUCH DAMAGE.
  + * ====================================================================
  + *
  + * This software consists of voluntary contributions made by many
  + * individuals on behalf of the Apache Software Foundation.  For more
  + * information on the Apache Software Foundation, please see
  + * <http://www.apache.org/>.
  + */
  +
  +package org.apache.tools.ant.taskdefs.compilers;
  +
  +import org.apache.tools.ant.*;
  +import org.apache.tools.ant.taskdefs.*;
  +import org.apache.tools.ant.types.*;
  +
  +import java.io.*;
  +import java.util.Random;
  +
  +/**
  + * This is the default implementation for the CompilerAdapter interface.
  + * Currently, this is a cut-and-paste of the original javac task.
  + *
  + * @author James Davidson <a href="mailto:duncan@x180.com">duncan@x180.com</a>
  + * @author Robin Green <a href="mailto:greenrd@hotmail.com">greenrd@hotmail.com</a>
  + * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
  + * @author <a href="mailto:jayglanville@home.com">J D Glanville</a>
  + */
  +public abstract class DefaultCompilerAdapter implements CompilerAdapter {
  +
  +    /* jdg - TODO - all these attributes are currently protected, but they
  +     * should probably be private in the near future.
  +     */
  +
  +    protected Path src;
  +    protected File destDir;
  +    protected String encoding;
  +    protected boolean debug = false;
  +    protected boolean optimize = false;
  +    protected boolean deprecation = false;
  +    protected boolean depend = false;
  +    protected boolean verbose = false;
  +    protected String target;
  +    protected Path bootclasspath;
  +    protected Path extdirs;
  +    protected Path compileClasspath;
  +    protected Project project;
  +    protected Location location;
  +    protected boolean includeAntRuntime;
  +    protected boolean includeJavaRuntime;
  +    protected String memoryInitialSize;
  +    protected String memoryMaximumSize;
  +
  +    protected File[] compileList;
  +    protected static String lSep = System.getProperty("line.separator");
  +    protected Javac attributes;
  +
  +    public void setJavac( Javac attributes ) {
  +        this.attributes = attributes;
  +        src = attributes.getSrcdir();
  +        destDir = attributes.getDestdir();
  +        encoding = attributes.getEncoding();
  +        debug = attributes.getDebug();
  +        optimize = attributes.getOptimize();
  +        deprecation = attributes.getDeprecation();
  +        depend = attributes.getDepend();
  +        verbose = attributes.getVerbose();
  +        target = attributes.getTarget();
  +        bootclasspath = attributes.getBootclasspath();
  +        extdirs = attributes.getExtdirs();
  +        compileList = attributes.getFileList();
  +        compileClasspath = attributes.getClasspath();
  +        project = attributes.getProject();
  +        location = attributes.getLocation();
  +        includeAntRuntime = attributes.getIncludeantruntime();
  +        includeJavaRuntime = attributes.getIncludejavaruntime();
  +        memoryInitialSize = attributes.getMemoryInitialSize();
  +        memoryMaximumSize = attributes.getMemoryMaximumSize();
  +    }
  +
  +    public Javac getJavac() {
  +        return attributes;
  +    }
  +
  +    /**
  +     * Builds the compilation classpath.
  +     *
  +     */
  +    protected Path getCompileClasspath() {
  +        Path classpath = new Path(project);
  +
  +        // add dest dir to classpath so that previously compiled and
  +        // untouched classes are on classpath
  +
  +        if (destDir != null) {
  +            classpath.setLocation(destDir);
  +        }
  +
  +        // Combine the build classpath with the system classpath, in an
  +        // order determined by the value of build.classpath
  +
  +        if (compileClasspath == null) {
  +            if ( includeAntRuntime ) {
  +                classpath.addExisting(Path.systemClasspath);
  +            }
  +        } else {
  +            if ( includeAntRuntime ) {
  +                classpath.addExisting(compileClasspath.concatSystemClasspath("last"));
  +            } else {
  +                classpath.addExisting(compileClasspath.concatSystemClasspath("ignore"));
  +            }
  +        }
  +
  +        if (includeJavaRuntime) {
  +            // XXX move this stuff to a separate class, code is identical to
  +            //     code in ../rmic/DefaultRmicAdapter
  +
  +            if (System.getProperty("java.vendor").toLowerCase().indexOf("microsoft") >= 0) {
  +                // Pull in *.zip from packages directory
  +                FileSet msZipFiles = new FileSet();
  +                msZipFiles.setDir(new File(System.getProperty("java.home") + File.separator + "Packages"));
  +                msZipFiles.setIncludes("*.ZIP");
  +                classpath.addFileset(msZipFiles);
  +            }
  +            else if (Project.getJavaVersion() == Project.JAVA_1_1) {
  +                classpath.addExisting(new Path(null,
  +                                                System.getProperty("java.home")
  +                                                + File.separator + "lib"
  +                                                + File.separator
  +                                                + "classes.zip"));
  +            } else {
  +                // JDK > 1.1 seems to set java.home to the JRE directory.
  +                classpath.addExisting(new Path(null,
  +                                                System.getProperty("java.home")
  +                                                + File.separator + "lib"
  +                                                + File.separator + "rt.jar"));
  +                // Just keep the old version as well and let addExistingToPath
  +                // sort it out.
  +                classpath.addExisting(new Path(null,
  +                                                System.getProperty("java.home")
  +                                                + File.separator +"jre"
  +                                                + File.separator + "lib"
  +                                                + File.separator + "rt.jar"));
  +
  +                // Added for MacOS X
  +                classpath.addExisting(new Path(null,
  +                                               System.getProperty("java.home")
  +                                               + File.separator + ".."
  +                                               + File.separator + "Classes"
  +                                               + File.separator + "classes.jar"));
  +                classpath.addExisting(new Path(null,
  +                                               System.getProperty("java.home")
  +                                               + File.separator + ".."
  +                                               + File.separator + "Classes"
  +                                               + File.separator + "ui.jar"));
  +            }
  +        }
  +
  +        return classpath;
  +    }
  +
  +    /**
  +     * Does the command line argument processing common to classic and
  +     * modern.  Doesn't add the files to compile.
  +     */
  +    protected Commandline setupJavacCommandlineSwitches(Commandline cmd) {
  +        Path classpath = getCompileClasspath();
  +
  +        // we cannot be using Java 1.0 when forking, so we only have to
  +        // distinguish between Java 1.1, and Java 1.2 and higher, as Java 1.1
  +        // has its own parameter format
  +        boolean usingJava1_1 = Project.getJavaVersion().equals(Project.JAVA_1_1);
  +        String memoryParameterPrefix = usingJava1_1 ? "-J-" : "-J-X";
  +        if (memoryInitialSize != null) {
  +            cmd.createArgument().setValue(memoryParameterPrefix+"ms"+memoryInitialSize);
  +        }
  +
  +        if (memoryMaximumSize != null) {
  +            cmd.createArgument().setValue(memoryParameterPrefix+"mx"+memoryMaximumSize);
  +        }
  +
  +        if (attributes.getNowarn()) {
  +            cmd.createArgument().setValue("-nowarn");
  +        }
  +
  +        if (deprecation == true) {
  +            cmd.createArgument().setValue("-deprecation");
  +        }
  +
  +        if (destDir != null) {
  +            cmd.createArgument().setValue("-d");
  +            cmd.createArgument().setFile(destDir);
  +        }
  +
  +        cmd.createArgument().setValue("-classpath");
  +
  +        // Just add "sourcepath" to classpath ( for JDK1.1 )
  +        // as well as "bootclasspath" and "extdirs"
  +        if (Project.getJavaVersion().startsWith("1.1")) {
  +            Path cp = new Path(project);
  +            /*
  +             * XXX - This doesn't mix very well with build.systemclasspath,
  +             */
  +            if (bootclasspath != null) {
  +                cp.append(bootclasspath);
  +            }
  +            if (extdirs != null) {
  +                addExtdirsToClasspath(cp);
  +            }
  +            cp.append(classpath);
  +            cp.append(src);
  +            cmd.createArgument().setPath(cp);
  +        } else {
  +            cmd.createArgument().setPath(classpath);
  +            cmd.createArgument().setValue("-sourcepath");
  +            cmd.createArgument().setPath(src);
  +            if (target != null) {
  +                cmd.createArgument().setValue("-target");
  +                cmd.createArgument().setValue(target);
  +            }
  +            if (bootclasspath != null) {
  +                cmd.createArgument().setValue("-bootclasspath");
  +                cmd.createArgument().setPath(bootclasspath);
  +            }
  +            if (extdirs != null) {
  +                cmd.createArgument().setValue("-extdirs");
  +                cmd.createArgument().setPath(extdirs);
  +            }
  +        }
  +
  +        if (encoding != null) {
  +            cmd.createArgument().setValue("-encoding");
  +            cmd.createArgument().setValue(encoding);
  +        }
  +        if (debug) {
  +            cmd.createArgument().setValue("-g");
  +        } else if (Project.getJavaVersion() != Project.JAVA_1_0 &&
  +                   Project.getJavaVersion() != Project.JAVA_1_1) {
  +            cmd.createArgument().setValue("-g:none");
  +        }
  +        if (optimize) {
  +            cmd.createArgument().setValue("-O");
  +        }
  +
  +        if (depend) {
  +            if (Project.getJavaVersion().startsWith("1.1")) {
  +                cmd.createArgument().setValue("-depend");
  +            } else if (Project.getJavaVersion().startsWith("1.2")) {
  +                cmd.createArgument().setValue("-Xdepend");
  +            } else {
  +                attributes.log("depend attribute is not supported by the modern compiler",
  +                    Project.MSG_WARN);
  +            }
  +        }
  +
  +        if (verbose) {
  +            cmd.createArgument().setValue("-verbose");
  +        }
  +        return cmd;
  +    }
  +
  +    /**
  +     * Does the command line argument processing common to classic and
  +     * modern and adds the files to compile as well.
  +     */
  +    protected Commandline setupJavacCommand() {
  +        Commandline cmd = new Commandline();
  +        setupJavacCommandlineSwitches(cmd);
  +        logAndAddFilesToCompile(cmd);
  +        return cmd;
  +    }
  +
  +    /**
  +     * Logs the compilation parameters, adds the files to compile and logs the
  +     * &qout;niceSourceList&quot;
  +     */
  +    protected void logAndAddFilesToCompile(Commandline cmd) {
  +        attributes.log("Compilation args: " + cmd.toString(),
  +            Project.MSG_VERBOSE);
  +
  +        StringBuffer niceSourceList = new StringBuffer("File");
  +        if (compileList.length != 1) {
  +            niceSourceList.append("s");
  +        }
  +        niceSourceList.append(" to be compiled:");
  +
  +        niceSourceList.append(lSep);
  +
  +        for (int i=0; i < compileList.length; i++) {
  +            String arg = compileList[i].getAbsolutePath();
  +            cmd.createArgument().setValue(arg);
  +            niceSourceList.append("    " + arg + lSep);
  +        }
  +
  +        attributes.log(niceSourceList.toString(), Project.MSG_VERBOSE);
  +    }
  +
  +    /**
  +     * Do the compile with the specified arguments.
  +     * @param args - arguments to pass to process on command line
  +     * @param firstFileName - index of the first source file in args
  +     */
  +    protected int executeExternalCompile(String[] args, int firstFileName) {
  +        String[] commandArray = null;
  +        File tmpFile = null;
  +
  +        try {
  +            /*
  +             * Many system have been reported to get into trouble with
  +             * long command lines - no, not only Windows ;-).
  +             *
  +             * POSIX seems to define a lower limit of 4k, so use a temporary
  +             * file if the total length of the command line exceeds this limit.
  +             */
  +            if (Commandline.toString(args).length() > 4096) {
  +                PrintWriter out = null;
  +                try {
  +                    tmpFile = new File("jikes"+(new Random(System.currentTimeMillis())).nextLong());
  +                    out = new PrintWriter(new FileWriter(tmpFile));
  +                    for (int i = firstFileName; i < args.length; i++) {
  +                        out.println(args[i]);
  +                    }
  +                    out.flush();
  +                    commandArray = new String[firstFileName+1];
  +                    System.arraycopy(args, 0, commandArray, 0, firstFileName);
  +                    commandArray[firstFileName] = "@" + tmpFile.getAbsolutePath();
  +                } catch (IOException e) {
  +                    throw new BuildException("Error creating temporary file", e, location);
  +                } finally {
  +                    if (out != null) {
  +                        try {out.close();} catch (Throwable t) {}
  +                    }
  +                }
  +            } else {
  +                commandArray = args;
  +            }
  +
  +            try {
  +                Execute exe = new Execute(new LogStreamHandler(attributes,
  +                                                               Project.MSG_INFO,
  +                                                               Project.MSG_WARN));
  +                exe.setAntRun(project);
  +                exe.setWorkingDirectory(project.getBaseDir());
  +                exe.setCommandline(commandArray);
  +                exe.execute();
  +                return exe.getExitValue();
  +            } catch (IOException e) {
  +                throw new BuildException("Error running " + args[0]
  +                        + " compiler", e, location);
  +            }
  +        } finally {
  +            if (tmpFile != null) {
  +                tmpFile.delete();
  +            }
  +        }
  +    }
  +
  +    /**
  +     * Emulation of extdirs feature in java >= 1.2.
  +     * This method adds all files in the given
  +     * directories (but not in sub-directories!) to the classpath,
  +     * so that you don't have to specify them all one by one.
  +     * @param classpath - Path to append files to
  +     */
  +    protected void addExtdirsToClasspath(Path classpath) {
  +        if (extdirs == null) {
  +            String extProp = System.getProperty("java.ext.dirs");
  +            if (extProp != null) {
  +                extdirs = new Path(project, extProp);
  +            } else {
  +                return;
  +            }
  +        }
  +
  +        String[] dirs = extdirs.list();
  +        for (int i=0; i<dirs.length; i++) {
  +            if (!dirs[i].endsWith(File.separator)) {
  +                dirs[i] += File.separator;
  +            }
  +            File dir = project.resolveFile(dirs[i]);
  +            FileSet fs = new FileSet();
  +            fs.setDir(dir);
  +            fs.setIncludes("*");
  +            classpath.addFileset(fs);
  +        }
  +    }
  +
  +}
  +
  
  
  

Mime
View raw message