⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 defaultcompileradapter.java

📁 Use the links below to download a source distribution of Ant from one of our mirrors. It is good pra
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* *  Licensed to the Apache Software Foundation (ASF) under one or more *  contributor license agreements.  See the NOTICE file distributed with *  this work for additional information regarding copyright ownership. *  The ASF licenses this file to You under the Apache License, Version 2.0 *  (the "License"); you may not use this file except in compliance with *  the License.  You may obtain a copy of the License at * *      http://www.apache.org/licenses/LICENSE-2.0 * *  Unless required by applicable law or agreed to in writing, software *  distributed under the License is distributed on an "AS IS" BASIS, *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *  See the License for the specific language governing permissions and *  limitations under the License. * */package org.apache.tools.ant.taskdefs.compilers;//Java5 style//import static org.apache.tools.ant.util.StringUtils.LINE_SEP;import java.io.File;import java.io.FileWriter;import java.io.IOException;import java.io.PrintWriter;import org.apache.tools.ant.BuildException;import org.apache.tools.ant.Location;import org.apache.tools.ant.Project;import org.apache.tools.ant.taskdefs.Execute;import org.apache.tools.ant.taskdefs.Javac;import org.apache.tools.ant.taskdefs.LogStreamHandler;import org.apache.tools.ant.types.Commandline;import org.apache.tools.ant.types.Path;import org.apache.tools.ant.util.FileUtils;import org.apache.tools.ant.util.StringUtils;import org.apache.tools.ant.util.JavaEnvUtils;import org.apache.tools.ant.taskdefs.condition.Os;/** * This is the default implementation for the CompilerAdapter interface. * Currently, this is a cut-and-paste of the original javac task. * * @since Ant 1.3 */public abstract class DefaultCompilerAdapter implements CompilerAdapter {    private static final int COMMAND_LINE_LIMIT = 4096;  // 4K    // CheckStyle:VisibilityModifier OFF - bc    private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();    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 Path compileSourcepath;    protected Project project;    protected Location location;    protected boolean includeAntRuntime;    protected boolean includeJavaRuntime;    protected String memoryInitialSize;    protected String memoryMaximumSize;    protected File[] compileList;    protected Javac attributes;    //must keep for subclass BC, though unused:    // CheckStyle:ConstantNameCheck OFF - bc    protected static final String lSep = StringUtils.LINE_SEP;    // CheckStyle:ConstantNameCheck ON    // CheckStyle:VisibilityModifier ON    /**     * Set the Javac instance which contains the configured compilation     * attributes.     *     * @param attributes a configured Javac task.     */    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();        compileSourcepath = attributes.getSourcepath();        project = attributes.getProject();        location = attributes.getLocation();        includeAntRuntime = attributes.getIncludeantruntime();        includeJavaRuntime = attributes.getIncludejavaruntime();        memoryInitialSize = attributes.getMemoryInitialSize();        memoryMaximumSize = attributes.getMemoryMaximumSize();    }    /**     * Get the Javac task instance associated with this compiler adapter     *     * @return the configured Javac task instance used by this adapter.     */    public Javac getJavac() {        return attributes;    }    /**     * Get the project this compiler adapter was created in.     * @return the owner project     * @since Ant 1.6     */    protected Project getProject() {        return project;    }    /**     * Builds the compilation classpath.     * @return the compilation class path     */    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 && getJavac().isIncludeDestClasses()) {            classpath.setLocation(destDir);        }        // Combine the build classpath with the system classpath, in an        // order determined by the value of build.sysclasspath        Path cp = compileClasspath;        if (cp == null) {            cp = new Path(project);        }        if (includeAntRuntime) {            classpath.addExisting(cp.concatSystemClasspath("last"));        } else {            classpath.addExisting(cp.concatSystemClasspath("ignore"));        }        if (includeJavaRuntime) {            classpath.addJavaRuntime();        }        return classpath;    }    /**     * Get the command line arguments for the switches.     * @param cmd the command line     * @return the command line     */    protected Commandline setupJavacCommandlineSwitches(Commandline cmd) {        return setupJavacCommandlineSwitches(cmd, false);    }    /**     * Does the command line argument processing common to classic and     * modern.  Doesn't add the files to compile.     * @param cmd the command line     * @param useDebugLevel if true set set the debug level with the -g switch     * @return the command line     */    protected Commandline setupJavacCommandlineSwitches(Commandline cmd,                                                        boolean useDebugLevel) {        Path classpath = getCompileClasspath();        // For -sourcepath, use the "sourcepath" value if present.        // Otherwise default to the "srcdir" value.        Path sourcepath = null;        if (compileSourcepath != null) {            sourcepath = compileSourcepath;        } else {            sourcepath = src;        }        String memoryParameterPrefix = assumeJava11() ? "-J-" : "-J-X";        if (memoryInitialSize != null) {            if (!attributes.isForkedJavac()) {                attributes.log("Since fork is false, ignoring "                               + "memoryInitialSize setting.",                               Project.MSG_WARN);            } else {                cmd.createArgument().setValue(memoryParameterPrefix                                              + "ms" + memoryInitialSize);            }        }        if (memoryMaximumSize != null) {            if (!attributes.isForkedJavac()) {                attributes.log("Since fork is false, ignoring "                               + "memoryMaximumSize setting.",                               Project.MSG_WARN);            } else {                cmd.createArgument().setValue(memoryParameterPrefix                                              + "mx" + memoryMaximumSize);            }        }        if (attributes.getNowarn()) {            cmd.createArgument().setValue("-nowarn");        }        if (deprecation) {            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 (assumeJava11()) {            Path cp = new Path(project);            Path bp = getBootClassPath();            if (bp.size() > 0) {                cp.append(bp);            }            if (extdirs != null) {                cp.addExtdirs(extdirs);            }            cp.append(classpath);            cp.append(sourcepath);            cmd.createArgument().setPath(cp);        } else {            cmd.createArgument().setPath(classpath);            // If the buildfile specifies sourcepath="", then don't            // output any sourcepath.            if (sourcepath.size() > 0) {                cmd.createArgument().setValue("-sourcepath");                cmd.createArgument().setPath(sourcepath);            }            if (target != null) {                cmd.createArgument().setValue("-target");                cmd.createArgument().setValue(target);            }            Path bp = getBootClassPath();            if (bp.size() > 0) {                cmd.createArgument().setValue("-bootclasspath");                cmd.createArgument().setPath(bp);            }            if (extdirs != null && extdirs.size() > 0) {                cmd.createArgument().setValue("-extdirs");                cmd.createArgument().setPath(extdirs);            }        }        if (encoding != null) {            cmd.createArgument().setValue("-encoding");            cmd.createArgument().setValue(encoding);        }        if (debug) {            if (useDebugLevel && !assumeJava11()) {                String debugLevel = attributes.getDebugLevel();                if (debugLevel != null) {                    cmd.createArgument().setValue("-g:" + debugLevel);                } else {                    cmd.createArgument().setValue("-g");                }            } else {                cmd.createArgument().setValue("-g");            }        } else if (getNoDebugArgument() != null) {            cmd.createArgument().setValue(getNoDebugArgument());        }        if (optimize) {            cmd.createArgument().setValue("-O");        }        if (depend) {            if (assumeJava11()) {                cmd.createArgument().setValue("-depend");            } else if (assumeJava12()) {                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");        }        addCurrentCompilerArgs(cmd);        return cmd;    }    /**     * Does the command line argument processing for modern.  Doesn't     * add the files to compile.     * @param cmd the command line     * @return the command line     */    protected Commandline setupModernJavacCommandlineSwitches(Commandline cmd) {        setupJavacCommandlineSwitches(cmd, true);        if (attributes.getSource() != null && !assumeJava13()) {            cmd.createArgument().setValue("-source");            String source = attributes.getSource();            if (source.equals("1.1") || source.equals("1.2")) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -