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

📄 junittask.java

📁 Use the links below to download a source distribution of Ant from one of our mirrors. It is good pra
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        getCommandline().setMaxmemory(max);    }    /**     * The command used to invoke the Java Virtual Machine,     * default is 'java'. The command is resolved by     * java.lang.Runtime.exec(). Ignored if fork is disabled.     *     * @param   value   the new VM to use instead of <tt>java</tt>     * @see #setFork(boolean)     *     * @since Ant 1.2     */    public void setJvm(String value) {        getCommandline().setVm(value);    }    /**     * Adds a JVM argument; ignored if not forking.     *     * @return create a new JVM argument so that any argument can be     * passed to the JVM.     * @see #setFork(boolean)     *     * @since Ant 1.2     */    public Commandline.Argument createJvmarg() {        return getCommandline().createVmArgument();    }    /**     * The directory to invoke the VM in. Ignored if no JVM is forked.     * @param   dir     the directory to invoke the JVM from.     * @see #setFork(boolean)     *     * @since Ant 1.2     */    public void setDir(File dir) {        this.dir = dir;    }    /**     * Adds a system property that tests can access.     * This might be useful to tranfer Ant properties to the     * testcases when JVM forking is not enabled.     *     * @since Ant 1.3     * @deprecated since ant 1.6     * @param sysp environment variable to add     */    public void addSysproperty(Environment.Variable sysp) {        getCommandline().addSysproperty(sysp);    }    /**     * Adds a system property that tests can access.     * This might be useful to tranfer Ant properties to the     * testcases when JVM forking is not enabled.     * @param sysp new environment variable to add     * @since Ant 1.6     */    public void addConfiguredSysproperty(Environment.Variable sysp) {        // get a build exception if there is a missing key or value        // see bugzilla report 21684        String testString = sysp.getContent();        getProject().log("sysproperty added : " + testString, Project.MSG_DEBUG);        getCommandline().addSysproperty(sysp);    }    /**     * Adds a set of properties that will be used as system properties     * that tests can access.     *     * This might be useful to tranfer Ant properties to the     * testcases when JVM forking is not enabled.     *     * @param sysp set of properties to be added     * @since Ant 1.6     */    public void addSyspropertyset(PropertySet sysp) {        getCommandline().addSyspropertyset(sysp);    }    /**     * Adds path to classpath used for tests.     *     * @return reference to the classpath in the embedded java command line     * @since Ant 1.2     */    public Path createClasspath() {        return getCommandline().createClasspath(getProject()).createPath();    }    /**     * Adds a path to the bootclasspath.     * @return reference to the bootclasspath in the embedded java command line     * @since Ant 1.6     */    public Path createBootclasspath() {        return getCommandline().createBootclasspath(getProject()).createPath();    }    /**     * Adds an environment variable; used when forking.     *     * <p>Will be ignored if we are not forking a new VM.</p>     * @param var environment variable to be added     * @since Ant 1.5     */    public void addEnv(Environment.Variable var) {        env.addVariable(var);    }    /**     * If true, use a new environment when forked.     *     * <p>Will be ignored if we are not forking a new VM.</p>     *     * @param newenv boolean indicating if setting a new environment is wished     * @since Ant 1.5     */    public void setNewenvironment(boolean newenv) {        newEnvironment = newenv;    }    /**     * Preset the attributes of the test     * before configuration in the build     * script.     * This allows attributes in the <junit> task     * be be defaults for the tests, but allows     * individual tests to override the defaults.     */    private void preConfigure(BaseTest test) {        test.setFiltertrace(filterTrace);        test.setHaltonerror(haltOnError);        if (errorProperty != null) {            test.setErrorProperty(errorProperty);        }        test.setHaltonfailure(haltOnFail);        if (failureProperty != null) {            test.setFailureProperty(failureProperty);        }        test.setFork(fork);    }    /**     * Add a new single testcase.     * @param   test    a new single testcase     * @see JUnitTest     *     * @since Ant 1.2     */    public void addTest(JUnitTest test) {        tests.addElement(test);        preConfigure(test);    }    /**     * Adds a set of tests based on pattern matching.     *     * @return  a new instance of a batch test.     * @see BatchTest     *     * @since Ant 1.2     */    public BatchTest createBatchTest() {        BatchTest test = new BatchTest(getProject());        batchTests.addElement(test);        preConfigure(test);        return test;    }    /**     * Add a new formatter to all tests of this task.     *     * @param fe formatter element     * @since Ant 1.2     */    public void addFormatter(FormatterElement fe) {        formatters.addElement(fe);    }    /**     * If true, include ant.jar, optional.jar and junit.jar in the forked VM.     *     * @param b include ant run time yes or no     * @since Ant 1.5     */    public void setIncludeantruntime(boolean b) {        includeAntRuntime = b;    }    /**     * If true, send any output generated by tests to Ant's logging system     * as well as to the formatters.     * By default only the formatters receive the output.     *     * <p>Output will always be passed to the formatters and not by     * shown by default.  This option should for example be set for     * tests that are interactive and prompt the user to do     * something.</p>     *     * @param showOutput if true, send output to Ant's logging system too     * @since Ant 1.5     */    public void setShowOutput(boolean showOutput) {        this.showOutput = showOutput;    }    /**     * If true, send any output generated by tests to the formatters.     *     * @param outputToFormatters if true, send output to formatters (Default     *                           is true).     * @since Ant 1.7.0     */    public void setOutputToFormatters(boolean outputToFormatters) {        this.outputToFormatters = outputToFormatters;    }    /**     * Assertions to enable in this program (if fork=true)     * @since Ant 1.6     * @param asserts assertion set     */    public void addAssertions(Assertions asserts) {        if (getCommandline().getAssertions() != null) {            throw new BuildException("Only one assertion declaration is allowed");        }        getCommandline().setAssertions(asserts);    }    /**     * Sets the permissions for the application run inside the same JVM.     * @since Ant 1.6     * @return .     */    public Permissions createPermissions() {        if (perm == null) {            perm = new Permissions();        }        return perm;    }    /**     * If set, system properties will be copied to the cloned VM - as     * well as the bootclasspath unless you have explicitly specified     * a bootclaspath.     *     * <p>Doesn't have any effect unless fork is true.</p>     * @param cloneVm a <code>boolean</code> value.     * @since Ant 1.7     */    public void setCloneVm(boolean cloneVm) {        getCommandline().setCloneVm(cloneVm);    }    /**     * Creates a new JUnitRunner and enables fork of a new Java VM.     *     * @throws Exception under ??? circumstances     * @since Ant 1.2     */    public JUnitTask() throws Exception {        getCommandline()            .setClassname("org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner");    }    /**     * Where Ant should place temporary files.     *     * @param tmpDir location where temporary files should go to     * @since Ant 1.6     */    public void setTempdir(File tmpDir) {        if (tmpDir != null) {            if (!tmpDir.exists() || !tmpDir.isDirectory()) {                throw new BuildException(tmpDir.toString()                                         + " is not a valid temp directory");            }        }        this.tmpDir = tmpDir;    }    /**     * Adds the jars or directories containing Ant, this task and     * JUnit to the classpath - this should make the forked JVM work     * without having to specify them directly.     *     * @since Ant 1.4     */    public void init() {        antRuntimeClasses = new Path(getProject());        splitJunit = !addClasspathResource("/junit/framework/TestCase.class");        addClasspathEntry("/org/apache/tools/ant/launch/AntMain.class");        addClasspathEntry("/org/apache/tools/ant/Task.class");        addClasspathEntry("/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.class");    }    private static JUnitTaskMirror createMirror(JUnitTask task, ClassLoader loader) {        try {            loader.loadClass("junit.framework.Test"); // sanity check        } catch (ClassNotFoundException e) {            throw new BuildException(                    "The <classpath> for <junit> must include junit.jar "                    + "if not in Ant's own classpath",                    e, task.getLocation());        }        try {            Class c = loader.loadClass(JUnitTaskMirror.class.getName() + "Impl");            if (c.getClassLoader() != loader) {                throw new BuildException("Overdelegating loader", task.getLocation());            }            Constructor cons = c.getConstructor(new Class[] {JUnitTask.class});            return (JUnitTaskMirror) cons.newInstance(new Object[] {task});        } catch (Exception e) {            throw new BuildException(e, task.getLocation());        }    }    private final class SplitLoader extends AntClassLoader {        public SplitLoader(ClassLoader parent, Path path) {            super(parent, getProject(), path, true);        }        // forceLoadClass is not convenient here since it would not        // properly deal with inner classes of these classes.        protected synchronized Class loadClass(String classname, boolean resolve)        throws ClassNotFoundException {            Class theClass = findLoadedClass(classname);            if (theClass != null) {                return theClass;            }            if (isSplit(classname)) {                theClass = findClass(classname);                if (resolve) {                    resolveClass(theClass);                }                return theClass;            } else {                return super.loadClass(classname, resolve);            }        }        private final String[] splitClasses = {            "BriefJUnitResultFormatter",            "JUnitResultFormatter",            "JUnitTaskMirrorImpl",            "JUnitTestRunner",            "JUnitVersionHelper",            "OutErrSummaryJUnitResultFormatter",            "PlainJUnitResultFormatter",            "SummaryJUnitResultFormatter",            "XMLJUnitResultFormatter",        };        private boolean isSplit(String classname) {            String simplename = classname.substring(classname.lastIndexOf('.') + 1);            for (int i = 0; i < splitClasses.length; i++) {                if (simplename.equals(splitClasses[i])                        || simplename.startsWith(splitClasses[i] + '$')) {                    return true;                }            }            return false;        }    }    /**     * Sets up the delegate that will actually run the tests.     *     * <p>Will be invoked implicitly once the delegate is needed.</p>

⌨️ 快捷键说明

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