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

📄 groovyc.java

📁 大名鼎鼎的java动态脚本语言。已经通过了sun的认证
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* $Id: Groovyc.java,v 1.15 2005/08/10 09:52:08 hmeling Exp $ Copyright 2003 (C) James Strachan and Bob Mcwhirter. All Rights Reserved. Redistribution and use of this software and associated documentation ("Software"), with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain copyright    statements and notices.  Redistributions must also contain a    copy of this document. 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 name "groovy" must not be used to endorse or promote    products derived from this Software without prior written    permission of The Codehaus.  For written permission,    please contact info@codehaus.org. 4. Products derived from this Software may not be called "groovy"    nor may "groovy" appear in their names without prior written    permission of The Codehaus. "groovy" is a registered    trademark of The Codehaus. 5. Due credit should be given to The Codehaus -    http://groovy.codehaus.org/ THIS SOFTWARE IS PROVIDED BY THE CODEHAUS AND CONTRIBUTORS ``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 CODEHAUS 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. */package org.codehaus.groovy.ant;import groovy.lang.GroovyClassLoader;import java.io.File;import java.io.PrintWriter;import java.io.StringWriter;import java.nio.charset.Charset;import java.util.Iterator;import java.util.List;import org.apache.tools.ant.AntClassLoader;import org.apache.tools.ant.BuildException;import org.apache.tools.ant.DirectoryScanner;import org.apache.tools.ant.Project;import org.apache.tools.ant.listener.AnsiColorLogger;import org.apache.tools.ant.taskdefs.MatchingTask;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.SourceFileScanner;import org.codehaus.groovy.control.CompilationUnit;import org.codehaus.groovy.control.CompilerConfiguration;import org.codehaus.groovy.tools.ErrorReporter;/** * Compiles Groovy source files. This task can take the following * arguments: * <ul> * <li>sourcedir * <li>destdir * <li>classpath * <li>stacktrace * </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 Groovy source files to compile. This task makes its * compile decision based on timestamp. *  * Based heavily on the Javac implementation in Ant * * @author <a href="mailto:james@coredevelopers.net">James Strachan</a> * @author Hein Meling * @version $Revision: 1.15 $  */public class Groovyc extends MatchingTask {    private CompilerConfiguration configuration = new CompilerConfiguration();    private Path src;    private File destDir;    private Path compileClasspath;    private Path compileSourcepath;    private String encoding;    protected boolean failOnError = true;    protected boolean listFiles = false;    protected File[] compileList = new File[0];    public static void main(String[] args) {        String dest = ".";        String src = ".";        boolean listFiles = false;        if (args.length > 0) {            dest = args[0];        }        if (args.length > 1) {            src = args[1];        }        if (args.length > 2) {            String flag = args[2];            if (flag.equalsIgnoreCase("true")) {                listFiles = true;            }        }        Project project = new Project();        project.addBuildListener(new AnsiColorLogger());        Groovyc compiler = new Groovyc();        compiler.setProject(project);        compiler.setSrcdir(new Path(project, src));        compiler.setDestdir(project.resolveFile(dest));        compiler.setListfiles(listFiles);        compiler.execute();    }    public Groovyc() {    }    /**     * 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 directorys 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;    }    /**     * Enable verbose compiling which will display which files     * are being compiled     * @param verbose     */    public void setVerbose(boolean verbose) {        configuration.setVerbose( verbose );    }    /**     * Enable compiler to report stack trace information if a problem occurs     * during compilation.     * @param stacktrace     */    public void setStacktrace(boolean stacktrace) {        configuration.setDebug(stacktrace);    }    /**     * 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.

⌨️ 快捷键说明

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