compiler.java
来自「MoMEUnit是一个单元测试的J2ME的应用程序xUnit架构实例。这是来自J」· Java 代码 · 共 284 行
JAVA
284 行
package org.momeunit.ant.taskdefs;import java.io.File;import java.util.Iterator;import java.util.Set;import org.apache.tools.ant.BuildException;import org.apache.tools.ant.Project;import org.apache.tools.ant.taskdefs.Copy;import org.apache.tools.ant.taskdefs.Javac;import org.apache.tools.ant.types.FileSet;import org.apache.tools.ant.types.Path;import org.apache.tools.ant.types.Reference;/** * MoMEUnit nested tag intended to specify and configure compiler used to * compile java source files and copy non-java files to destination directory. * Extends {@link Javac} task. Forbids following attributes: * </p> * <ol> * <li> * <p> * <code>classpath</code>, <code>classpathref</code> – classpath of * <code>momeunit</code> is used instead; * </p> * </li> * <li> * <p> * <code>src</code>, <code>sourcepath</code>, <code>sourcepathref</code> - * sources specified by <code>testdir</code> tags and <code>testdir</code> * attribute of <code>momeunit</code> are used instead; * </p> * </li> * </ol> * <p> * and nested tags: * </p> * <ol> * <li> * <p> * <code>classpath</code> – classpath of <code>momeunit</code> is used * instead; * </p> * </li> * <li> * <p> * <code>src</code>, <code>sourcepath</code> - sources specified by * <code>testdir</code> tags and <code>testdir</code> attribute of * <code>momeunit</code> are used instead; * </p> * </ol> * <strong>Note</strong>: <code>target</code> attribute is preset to * <code>1.1</code> and <code>source</code> attribute is preset to * <code>1.3</code>. * </p> * </li> * * @author Sergio Morozov * @version 1.1.2 */public class Compiler extends Javac{ private Copy copy = null; private boolean delOnExit = true; private boolean delOnExitSet = false; /** * Instantiates Compiler tag with owning project. * * @param project * owning project. * @since 1.1 */ public Compiler(Project project) { this(project, null); } /** * Instantiates Compiler tag with owning project and name of owning task. * * @param project * owning project. * @param taskName * name of owning task. * @since 1.1 */ public Compiler(Project project, String taskName) { super(); this.setProject(project); if (taskName != null) this.setTaskName(taskName); this.init(); super.setSource("1.3"); super.setTarget("1.1"); this.setDebug(false); this.setOptimize(false); this.setFailonerror(true); this.copy = new Copy(); this.copy.setProject(project); if (taskName != null) this.copy.setTaskName(taskName); this.copy.init(); } /** * Executes <code>javac</code> task and <code>copy</code> taska. * * @see org.apache.tools.ant.taskdefs.Javac#execute() * @since 1.1 */ public void execute() { if (getSrcdir().size() > 0) super.execute(); this.copy.execute(); } /** * Initializes compiler with sourcepath and classpath. * * @param srcs * {@link Set} of filesets that designate directories under which all * java source files will be compiled and designate non-java files to * be copied to destination directory. * @param classpath * classpath. * @since 1.1 */ public void init(Set srcs, Path classpath) { super.createClasspath().append(classpath); Path srcPath = super.createSrc(); for (Iterator i = srcs.iterator(); i.hasNext();) { FileSet src = (FileSet) i.next(); srcPath.setLocation(src.getDir(getProject())); FileSet fs = (FileSet) src.clone(); fs.setExcludes("**/*.java"); this.copy.addFileset(fs); } } /** * Throws {@link UnsupportedElementException} excpetion; * * @see org.apache.tools.ant.taskdefs.Javac#createClasspath() * @since 1.1 */ public Path createClasspath() { throw new UnsupportedElementException("classpath", getTaskName()); } /** * Throws {@link UnsupportedAttributeException} excpetion; * * @see org.apache.tools.ant.taskdefs.Javac#setClasspathRef(org.apache.tools.ant.types.Reference) * @since 1.1 */ public void setClasspathRef(Reference r) { throw new UnsupportedAttributeException("classpathref", getTaskName()); } /** * Throws {@link UnsupportedAttributeException} excpetion; * * @see org.apache.tools.ant.taskdefs.Javac#setClasspath(org.apache.tools.ant.types.Path) * @since 1.1 */ public void setClasspath(Path classpath) { throw new UnsupportedAttributeException("classpath", getTaskName()); } /* * (non-Javadoc) * * @see org.apache.tools.ant.taskdefs.Javac#setDestdir(java.io.File) */ public void setDestdir(File destDir) { if (!destDir.exists() || !destDir.isDirectory()) throw new BuildException( "destdir=\"" + destDir.getAbsolutePath() + "\" is not a directory."); super.setDestdir(destDir); this.copy.setTodir(destDir); } /** * Throws {@link UnsupportedAttributeException} excpetion; * * @see org.apache.tools.ant.taskdefs.Javac#setSourcepath(org.apache.tools.ant.types.Path) * @since 1.1 */ public void setSourcepath(Path sourcepath) { throw new UnsupportedAttributeException("sourcepath", getTaskName()); } /** * Throws {@link UnsupportedAttributeException} excpetion; * * @see org.apache.tools.ant.taskdefs.Javac#setSourcepathRef(org.apache.tools.ant.types.Reference) * @since 1.1 */ public void setSourcepathRef(Reference r) { throw new UnsupportedAttributeException("sourcepathref", getTaskName()); } /** * Throws {@link UnsupportedAttributeException} excpetion; * * @see org.apache.tools.ant.taskdefs.Javac#setSrcdir(org.apache.tools.ant.types.Path) * @since 1.1 */ public void setSrcdir(Path srcDir) { throw new UnsupportedAttributeException("src", getTaskName()); } /** * Throws {@link UnsupportedElementException} excpetion; * * @see org.apache.tools.ant.taskdefs.Javac#createSourcepath() * @since 1.1 */ public Path createSourcepath() { throw new UnsupportedElementException("sourcepath", getTaskName()); } /** * Throws {@link UnsupportedElementException} excpetion; * * @see org.apache.tools.ant.taskdefs.Javac#createSrc() * @since 1.1 */ public Path createSrc() { throw new UnsupportedElementException("src", getTaskName()); } /** * Should destination directory with it's content be marked for deletion. * * @return <code>true</code> if destination directory with it's content will * be marked for deletion, <code>false</code> otherwise. * @since 1.1 */ public boolean isDelOnExit() { return this.delOnExit; } /** * Sets destination directory with it's content to be marked for deletion * * @param delOnExit * boolean that indicates should destination directory with it's * content be marked for deletion. * @since 1.1 */ public void setDelOnExit(boolean delOnExit) { this.delOnExit = delOnExit; this.delOnExitSet = true; } /** * Checks whether <code>delonexit</code> attribute was set. * * @return <code>true</code> if <code>delonexit</code> attribute was set, * <code>false</code> otherwise. * @since 1.1 */ public boolean wasDelOnExitSet() { return this.delOnExitSet; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?