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

📄 javac.java

📁 java ant的源码!非常值得看的源码
💻 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;import java.io.File;import org.apache.tools.ant.BuildException;import org.apache.tools.ant.DirectoryScanner;import org.apache.tools.ant.MagicNames;import org.apache.tools.ant.Project;import org.apache.tools.ant.taskdefs.compilers.CompilerAdapter;import org.apache.tools.ant.taskdefs.compilers.CompilerAdapterFactory;import org.apache.tools.ant.types.Path;import org.apache.tools.ant.types.Reference;import org.apache.tools.ant.util.GlobPatternMapper;import org.apache.tools.ant.util.JavaEnvUtils;import org.apache.tools.ant.util.SourceFileScanner;import org.apache.tools.ant.util.facade.FacadeTaskHelper;/** * Compiles 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>verbose * <li>failonerror * <li>includeantruntime * <li>includejavaruntime * <li>source * <li>compiler * </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. * * * @since Ant 1.1 * * @ant.task category="java" */public class Javac extends MatchingTask {    private static final String FAIL_MSG        = "Compile failed; see the compiler error output for details.";    private static final String JAVAC16 = "javac1.6";    private static final String JAVAC15 = "javac1.5";    private static final String JAVAC14 = "javac1.4";    private static final String JAVAC13 = "javac1.3";    private static final String JAVAC12 = "javac1.2";    private static final String JAVAC11 = "javac1.1";    private static final String MODERN = "modern";    private static final String CLASSIC = "classic";    private static final String EXTJAVAC = "extJavac";    private Path src;    private File destDir;    private Path compileClasspath;    private Path compileSourcepath;    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 targetAttribute;    private Path bootclasspath;    private Path extdirs;    private boolean includeAntRuntime = true;    private boolean includeJavaRuntime = false;    private boolean fork = false;    private String forkedExecutable = null;    private boolean nowarn = false;    private String memoryInitialSize;    private String memoryMaximumSize;    private FacadeTaskHelper facade = null;    // CheckStyle:VisibilityModifier OFF - bc    protected boolean failOnError = true;    protected boolean listFiles = false;    protected File[] compileList = new File[0];    // CheckStyle:VisibilityModifier ON    private String source;    private String debugLevel;    private File tmpDir;    /**     * Javac task for compilation of Java files.     */    public Javac() {        facade = new FacadeTaskHelper(assumedJavaVersion());    }    private String assumedJavaVersion() {        if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_2)) {            return JAVAC12;        } else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_3)) {            return JAVAC13;        } else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_4)) {            return JAVAC14;        } else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_5)) {            return JAVAC15;        } else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_6)) {            return JAVAC16;        } else {            return CLASSIC;        }    }    /**     * Get the value of debugLevel.     * @return value of debugLevel.     */    public String getDebugLevel() {        return debugLevel;    }    /**     * Keyword list to be appended to the -g command-line switch.     *     * This will be ignored by all implementations except modern     * and classic(ver >= 1.2). Legal values are none or a     * comma-separated list of the following keywords: lines, vars,     * and source. If debuglevel is not specified, by default, :none     * will be appended to -g. If debug is not turned on, this attribute     * will be ignored.     *     * @param v  Value to assign to debugLevel.     */    public void setDebugLevel(String  v) {        this.debugLevel = v;    }    /**     * Get the value of source.     * @return value of source.     */    public String getSource() {        return source != null            ? source : getProject().getProperty(MagicNames.BUILD_JAVAC_SOURCE);    }    /**     * Value of the -source command-line switch; will be ignored     * by all implementations except modern and jikes.     *     * If you use this attribute together with jikes, you must make     * sure that your version of jikes supports the -source switch.     * Legal values are 1.3, 1.4, 1.5, and 5 - by default, no     * -source argument will be used at all.     *     * @param v  Value to assign to source.     */    public void setSource(String  v) {        this.source = v;    }    /**     * Adds a path for source compilation.     *     * @return a nested src element.     */    public Path createSrc() {        if (src == null) {            src = new Path(getProject());        }        return src.createPath();    }    /**     * Recreate src.     *     * @return a nested src element.     */    protected Path recreateSrc() {        src = null;        return createSrc();    }    /**     * Set the source directories to find the source Java files.     * @param srcDir the source directories as a path     */    public void setSrcdir(Path srcDir) {        if (src == null) {            src = srcDir;        } else {            src.append(srcDir);        }    }    /**     * Gets the source dirs to find the source java files.     * @return the source directories as a path     */    public Path getSrcdir() {        return src;    }    /**     * Set the destination directory into which the Java source     * files should be compiled.     * @param destDir the destination director     */    public void setDestdir(File destDir) {        this.destDir = destDir;    }    /**     * Gets the destination directory into which the java source files     * should be compiled.     * @return the destination directory     */    public File getDestdir() {        return destDir;    }    /**     * Set the sourcepath to be used for this compilation.     * @param sourcepath the source path     */    public void setSourcepath(Path sourcepath) {        if (compileSourcepath == null) {            compileSourcepath = sourcepath;        } else {            compileSourcepath.append(sourcepath);        }    }    /**     * Gets the sourcepath to be used for this compilation.     * @return the source path     */    public Path getSourcepath() {        return compileSourcepath;    }    /**     * Adds a path to sourcepath.     * @return a sourcepath to be configured     */    public Path createSourcepath() {        if (compileSourcepath == null) {            compileSourcepath = new Path(getProject());        }        return compileSourcepath.createPath();    }    /**     * Adds a reference to a source path defined elsewhere.     * @param r a reference to a source path     */    public void setSourcepathRef(Reference r) {        createSourcepath().setRefid(r);    }    /**     * Set the classpath to be used for this compilation.     *     * @param classpath an Ant Path object containing the compilation classpath.     */    public void setClasspath(Path classpath) {        if (compileClasspath == null) {            compileClasspath = classpath;        } else {            compileClasspath.append(classpath);        }    }    /**     * Gets the classpath to be used for this compilation.     * @return the class path     */    public Path getClasspath() {        return compileClasspath;    }    /**     * Adds a path to the classpath.     * @return a class path to be configured     */    public Path createClasspath() {        if (compileClasspath == null) {            compileClasspath = new Path(getProject());        }        return compileClasspath.createPath();    }    /**     * Adds a reference to a classpath defined elsewhere.     * @param r a reference to a classpath     */    public void setClasspathRef(Reference r) {        createClasspath().setRefid(r);    }    /**     * Sets the bootclasspath that will be used to compile the classes     * against.     * @param bootclasspath a path to use as a boot class path (may be more     *                      than one)     */    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.     * @return the boot path     */    public Path getBootclasspath() {        return bootclasspath;    }    /**     * Adds a path to the bootclasspath.     * @return a path to be configured     */    public Path createBootclasspath() {        if (bootclasspath == null) {            bootclasspath = new Path(getProject());        }        return bootclasspath.createPath();    }    /**     * Adds a reference to a classpath defined elsewhere.     * @param r a reference to a classpath     */    public void setBootClasspathRef(Reference r) {        createBootclasspath().setRefid(r);    }    /**     * Sets the extension directories that will be used during the     * compilation.     * @param extdirs a path     */    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.     * @return the extension directories as a path     */    public Path getExtdirs() {        return extdirs;    }    /**     * Adds a path to extdirs.     * @return a path to be configured     */    public Path createExtdirs() {        if (extdirs == null) {            extdirs = new Path(getProject());        }        return extdirs.createPath();    }    /**     * If true, list the source files being handed off to the compiler.     * @param list if true list the source files     */    public void setListfiles(boolean list) {        listFiles = list;    }    /**     * Get the listfiles flag.     * @return the listfiles flag     */    public boolean getListfiles() {        return listFiles;    }    /**     * Indicates whether the build will continue     * even if there are compilation errors; defaults to true.     * @param fail if true halt the build on failure     */    public void setFailonerror(boolean fail) {        failOnError = fail;    }    /**     * @ant.attribute ignore="true"     * @param proceed inverse of failoferror     */    public void setProceed(boolean proceed) {        failOnError = !proceed;    }    /**     * Gets the failonerror flag.     * @return the failonerror flag     */    public boolean getFailonerror() {        return failOnError;    }    /**     * Indicates whether source should be     * compiled with deprecation information; defaults to off.     * @param deprecation if true turn on deprecation information     */    public void setDeprecation(boolean deprecation) {        this.deprecation = deprecation;    }    /**     * Gets the deprecation flag.     * @return the deprecation flag     */    public boolean getDeprecation() {        return deprecation;    }    /**     * The initial size of the memory for the underlying VM     * if javac is run externally; ignored otherwise.     * Defaults to the standard VM memory setting.     * (Examples: 83886080, 81920k, or 80m)     * @param memoryInitialSize string to pass to VM     */    public void setMemoryInitialSize(String memoryInitialSize) {        this.memoryInitialSize = memoryInitialSize;    }    /**     * Gets the memoryInitialSize flag.     * @return the memoryInitialSize flag     */    public String getMemoryInitialSize() {        return memoryInitialSize;    }    /**     * The maximum size of the memory for the underlying VM     * if javac is run externally; ignored otherwise.     * Defaults to the standard VM memory setting.     * (Examples: 83886080, 81920k, or 80m)     * @param memoryMaximumSize string to pass to VM     */    public void setMemoryMaximumSize(String memoryMaximumSize) {        this.memoryMaximumSize = memoryMaximumSize;    }    /**     * Gets the memoryMaximumSize flag.     * @return the memoryMaximumSize flag     */    public String getMemoryMaximumSize() {        return memoryMaximumSize;    }    /**     * Set the Java source file encoding name.     * @param encoding the source file encoding     */    public void setEncoding(String encoding) {        this.encoding = encoding;    }    /**     * Gets the java source file encoding name.     * @return the source file encoding name     */    public String getEncoding() {        return encoding;    }

⌨️ 快捷键说明

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