Package org.apache.tools.ant.types

Examples of org.apache.tools.ant.types.CommandlineJava


    verbose = false;
    timers = false;
    xweaveDir = null;
    xdoneSignal = null;
    logCommand = false;
    javaCmd = new CommandlineJava();
  }
View Full Code Here


        if (perm != null) {
            log("Permissions ignored when running in forked mode!",
                Project.MSG_WARN);
        }

        CommandlineJava cmd;
        try {
            cmd = (CommandlineJava) (getCommandline().clone());
        } catch (CloneNotSupportedException e) {
            throw new BuildException("This shouldn't happen", e, getLocation());
        }
        if (casesFile == null) {
            cmd.createArgument().setValue(test.getName());
            if (test.getMethods() != null) {
                cmd.createArgument().setValue(Constants.METHOD_NAMES + test.getMethodsString());
            }
        } else {
            log("Running multiple tests in the same VM", Project.MSG_VERBOSE);
            cmd.createArgument().setValue(Constants.TESTSFILE + casesFile);
        }

        cmd.createArgument().setValue(Constants.FILTERTRACE + test.getFiltertrace());
        cmd.createArgument().setValue(Constants.HALT_ON_ERROR + test.getHaltonerror());
        cmd.createArgument().setValue(Constants.HALT_ON_FAILURE
                                      + test.getHaltonfailure());
        checkIncludeAntRuntime(cmd);

        checkIncludeSummary(cmd);

        cmd.createArgument().setValue(Constants.SHOWOUTPUT
                                      + String.valueOf(showOutput));
        cmd.createArgument().setValue(Constants.OUTPUT_TO_FORMATTERS
                                      + String.valueOf(outputToFormatters));
        cmd.createArgument().setValue(Constants.LOG_FAILED_TESTS
                                      + String.valueOf(logFailedTests));

        // #31885
        cmd.createArgument().setValue(Constants.LOGTESTLISTENEREVENTS
                                      + String.valueOf(getEnableTestListenerEvents()));

        StringBuffer formatterArg = new StringBuffer(STRING_BUFFER_SIZE);
        final FormatterElement[] feArray = mergeFormatters(test);
        for (int i = 0; i < feArray.length; i++) {
            FormatterElement fe = feArray[i];
            if (fe.shouldUse(this)) {
                formatterArg.append(Constants.FORMATTER);
                formatterArg.append(fe.getClassname());
                File outFile = getOutput(fe, test);
                if (outFile != null) {
                    formatterArg.append(",");
                    formatterArg.append(outFile);
                }
                cmd.createArgument().setValue(formatterArg.toString());
                formatterArg = new StringBuffer();
            }
        }

        File vmWatcher = createTempPropertiesFile("junitvmwatcher");
        cmd.createArgument().setValue(Constants.CRASHFILE
                                      + vmWatcher.getAbsolutePath());
        File propsFile = createTempPropertiesFile("junit");
        cmd.createArgument().setValue(Constants.PROPSFILE
                                      + propsFile.getAbsolutePath());
        Hashtable p = getProject().getProperties();
        Properties props = new Properties();
        for (Enumeration e = p.keys(); e.hasMoreElements();) {
            Object key = e.nextElement();
            props.put(key, p.get(key));
        }
        try {
            FileOutputStream outstream = new FileOutputStream(propsFile);
            props.store(outstream, "Ant JUnitTask generated properties file");
            outstream.close();
        } catch (java.io.IOException e) {
            FILE_UTILS.tryHardToDelete(propsFile);
            throw new BuildException("Error creating temporary properties "
                                     + "file.", e, getLocation());
        }

        Execute execute = new Execute(
            new JUnitLogStreamHandler(
                this,
                Project.MSG_INFO,
                Project.MSG_WARN),
            watchdog);
        execute.setCommandline(cmd.getCommandline());
        execute.setAntRun(getProject());
        if (dir != null) {
            execute.setWorkingDirectory(dir);
        }

        String[] environment = env.getVariables();
        if (environment != null) {
            for (int i = 0; i < environment.length; i++) {
                log("Setting environment variable: " + environment[i],
                    Project.MSG_VERBOSE);
            }
        }
        execute.setNewenvironment(newEnvironment);
        execute.setEnvironment(environment);

        log(cmd.describeCommand(), Project.MSG_VERBOSE);

        checkForkedPath(cmd);

        TestResultHolder result = new TestResultHolder();
        try {
View Full Code Here

     * @return the command line.
     * @since Ant 1.6.2
     */
    protected CommandlineJava getCommandline() {
        if (commandline == null) {
            commandline = new CommandlineJava();
            commandline.setClassname("org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner");
        }
        return commandline;
    }
View Full Code Here

     */
    private void executeTestPlan(File testPlanFile, File resultLogFile) {
        log("Executing test plan: " + testPlanFile + " ==> " + resultLogFile, Project.MSG_INFO);
        resultLogFiles.add(resultLogFile);

        CommandlineJava cmd = new CommandlineJava();

        cmd.setJar(jmeterJar.getAbsolutePath());

        // Set the JVM args
        Iterator<Object> jvmArgIterator = jvmArgs.iterator();
        while (jvmArgIterator.hasNext()) {
            Arg jvmArg = (Arg)jvmArgIterator.next();
            cmd.createVmArgument().setValue(jvmArg.getValue());
        }

        // Set the JMeter args
        Iterator<Object> jmeterArgIterator = jmeterArgs.iterator();
        while (jmeterArgIterator.hasNext()) {
            Arg jmeterArg = (Arg)jmeterArgIterator.next();
            cmd.createArgument().setValue(jmeterArg.getValue());
        }

        // non-gui mode
        cmd.createArgument().setValue("-n");
        // the properties file
        if (jmeterProperties != null) {
            cmd.createArgument().setValue("-p");
            cmd.createArgument().setValue(jmeterProperties.getAbsolutePath());
        }
        // the test plan file
        cmd.createArgument().setValue("-t");
        cmd.createArgument().setValue(testPlanFile.getAbsolutePath());
        // the result log file
        cmd.createArgument().setValue("-l");
        cmd.createArgument().setValue(resultLogFile.getAbsolutePath());
        // run remote servers?
        if (runRemote) {
            cmd.createArgument().setValue("-r");
        }

        // the proxy host
        if ((proxyHost != null) && (proxyHost.length() > 0)) {
            cmd.createArgument().setValue("-H");
            cmd.createArgument().setValue(proxyHost);
        }
        // the proxy port
        if ((proxyPort != null) && (proxyPort.length() > 0)) {
            cmd.createArgument().setValue("-P");
            cmd.createArgument().setValue(proxyPort);
        }
        // the proxy user
        if ((proxyUser != null) && (proxyUser.length() > 0)) {
            cmd.createArgument().setValue("-u");
            cmd.createArgument().setValue(proxyUser);
        }
        // the proxy password
        if ((proxyPass != null) && (proxyPass.length() > 0)) {
            cmd.createArgument().setValue("-a");
            cmd.createArgument().setValue(proxyPass);
        }

        // the JMeter runtime properties
        Iterator<Object> jmPropertyIterator = jmProperties.iterator();
        while (jmPropertyIterator.hasNext()) {
            Property jmProperty = (Property)jmPropertyIterator.next();
            if (jmProperty.isValid()) {
                cmd.createArgument().setValue("-J" + jmProperty.toString());
            }
        }

        Execute execute = new Execute(new LogStreamHandler(this, Project.MSG_INFO, Project.MSG_WARN));
        execute.setCommandline(cmd.getCommandline());
        execute.setAntRun(getProject());

        execute.setWorkingDirectory(new File(jmeterHome.getAbsolutePath() + File.separator + "bin"));
        log(cmd.describeCommand(), Project.MSG_VERBOSE);

        try {
            execute.execute();
        }
        catch (IOException e) {
View Full Code Here

        if (perm != null) {
            log("Permissions ignored when running in forked mode!",
                Project.MSG_WARN);
        }

        CommandlineJava cmd;
        try {
            cmd = (CommandlineJava) (getCommandline().clone());
        } catch (CloneNotSupportedException e) {
            throw new BuildException("This shouldn't happen", e, getLocation());
        }
        cmd.setClassname("org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner");
        if (casesFile == null) {
            cmd.createArgument().setValue(test.getName());
        } else {
            log("Running multiple tests in the same VM", Project.MSG_VERBOSE);
            cmd.createArgument().setValue(Constants.TESTSFILE + casesFile);
        }

        cmd.createArgument().setValue(Constants.FILTERTRACE + test.getFiltertrace());
        cmd.createArgument().setValue(Constants.HALT_ON_ERROR + test.getHaltonerror());
        cmd.createArgument().setValue(Constants.HALT_ON_FAILURE
                                      + test.getHaltonfailure());
        checkIncludeAntRuntime(cmd);

        checkIncludeSummary(cmd);

        cmd.createArgument().setValue(Constants.SHOWOUTPUT
                                      + String.valueOf(showOutput));
        cmd.createArgument().setValue(Constants.OUTPUT_TO_FORMATTERS
                                      + String.valueOf(outputToFormatters));

        cmd.createArgument().setValue(
            Constants.LOGTESTLISTENEREVENTS + "true"); // #31885

        StringBuffer formatterArg = new StringBuffer(STRING_BUFFER_SIZE);
        final FormatterElement[] feArray = mergeFormatters(test);
        for (int i = 0; i < feArray.length; i++) {
            FormatterElement fe = feArray[i];
            if (fe.shouldUse(this)) {
                formatterArg.append(Constants.FORMATTER);
                formatterArg.append(fe.getClassname());
                File outFile = getOutput(fe, test);
                if (outFile != null) {
                    formatterArg.append(",");
                    formatterArg.append(outFile);
                }
                cmd.createArgument().setValue(formatterArg.toString());
                formatterArg = new StringBuffer();
            }
        }

        File vmWatcher = createTempPropertiesFile("junitvmwatcher");
        cmd.createArgument().setValue(Constants.CRASHFILE
                                      + vmWatcher.getAbsolutePath());
        File propsFile = createTempPropertiesFile("junit");
        cmd.createArgument().setValue(Constants.PROPSFILE
                                      + propsFile.getAbsolutePath());
        Hashtable p = getProject().getProperties();
        Properties props = new Properties();
        for (Enumeration e = p.keys(); e.hasMoreElements();) {
            Object key = e.nextElement();
            props.put(key, p.get(key));
        }
        try {
            FileOutputStream outstream = new FileOutputStream(propsFile);
            props.store(outstream, "Ant JUnitTask generated properties file");
            outstream.close();
        } catch (java.io.IOException e) {
            propsFile.delete();
            throw new BuildException("Error creating temporary properties "
                                     + "file.", e, getLocation());
        }

        Execute execute = new Execute(
            new JUnitLogStreamHandler(
                this,
                Project.MSG_INFO,
                Project.MSG_WARN),
            watchdog);
        execute.setCommandline(cmd.getCommandline());
        execute.setAntRun(getProject());
        if (dir != null) {
            execute.setWorkingDirectory(dir);
        }

        String[] environment = env.getVariables();
        if (environment != null) {
            for (int i = 0; i < environment.length; i++) {
                log("Setting environment variable: " + environment[i],
                    Project.MSG_VERBOSE);
            }
        }
        execute.setNewenvironment(newEnvironment);
        execute.setEnvironment(environment);

        log(cmd.describeCommand(), Project.MSG_VERBOSE);

        checkForkedPath(cmd);

        TestResultHolder result = new TestResultHolder();
        try {
View Full Code Here

     * @return the command line.
     * @since Ant 1.6.2
     */
    protected CommandlineJava getCommandline() {
        if (commandline == null) {
            commandline = new CommandlineJava();
        }
        return commandline;
    }
View Full Code Here

     * @param classname the name of the class to run.
     * @param args  arguments for the class.
     * @throws BuildException in case of IOException in the execution.
     */
    protected void run(String classname, Vector args) throws BuildException {
        CommandlineJava cmdj = new CommandlineJava();
        cmdj.setClassname(classname);
        for (int i = 0; i < args.size(); i++) {
            cmdj.createArgument().setValue((String) args.elementAt(i));
        }
        run(cmdj);
    }
View Full Code Here

     *
     * @exception BuildException if an error occurs
     */
    public void execute() throws BuildException {

        CommandlineJava commandline = new CommandlineJava();

        if ("text".equals(format)) {
            commandline.setClassname("jdepend.textui.JDepend");
        } else
            if ("xml".equals(format)) {
                commandline.setClassname("jdepend.xmlui.JDepend");
            }

        if (jvm != null) {
            commandline.setVm(jvm);
        }
        if (getSourcespath() == null && getClassespath() == null) {
            throw new BuildException("Missing classespath required argument");
        } else if (getClassespath() == null) {
            String msg =
View Full Code Here

     * @param classname the name of the class to run.
     * @param args  arguments for the class.
     * @throws BuildException in case of IOException in the execution.
     */
    protected void run(String classname, Vector<String> args) throws BuildException {
        CommandlineJava cmdj = new CommandlineJava();
        cmdj.setClassname(classname);
        final int size = args.size();
        for (int i = 0; i < size; i++) {
            cmdj.createArgument().setValue(args.elementAt(i));
        }
        run(cmdj);
    }
View Full Code Here

    }

    private boolean dependencyCheck() throws BuildException {
        // using "antlr -o <OutputDirectory> -lib <LibDirectory> -depend <T>"
        // to get the list of dependencies
        CommandlineJava cmdline;
        try {
            cmdline = (CommandlineJava) commandline.clone();
        } catch (java.lang.CloneNotSupportedException e) {
            throw new BuildException("Clone of commandline failed: " + e);
        }

        cmdline.createArgument().setValue("-depend");
        cmdline.createArgument().setValue("-o");
        cmdline.createArgument().setValue(outputDirectory.toString());
        cmdline.createArgument().setValue("-lib");
        cmdline.createArgument().setValue(libDirectory.toString());
        cmdline.createArgument().setValue(target.toString());

        log(cmdline.describeCommand(), Project.MSG_VERBOSE);

        // redirect output generated by ANTLR to temporary file
        Redirector r = new Redirector(this);
        File f;
        try {
            f = File.createTempFile("depend", null, getOutputdirectory());
            f.deleteOnExit();
            log("Write dependencies for '" + target.toString() + "' to file '" + f.getCanonicalPath() + "'", Project.MSG_VERBOSE);
            r.setOutput(f);
            r.setAlwaysLog(false);
            r.createStreams();
        } catch (IOException e) {
            throw new BuildException("Redirection of output failed: " + e);
        }

        // execute antlr -depend ...
        int err = 0;
        try {
            err = run(cmdline.getCommandline(), r.getOutputStream(), null);
        } catch (IOException e) {
            try {
                r.complete();
                log("Redirection of output terminated.", Project.MSG_VERBOSE);
            } catch (IOException ex) {
                log("Termination of output redirection failed: " + ex, Project.MSG_ERR);
            }
            throw new BuildException(e, getLocation());
        } finally {
            try {
                bos.close();
            } catch (IOException e) {
                // ignore
            }
        }

        try {
            r.complete();
            log("Redirection of output terminated.", Project.MSG_VERBOSE);
        } catch (IOException e) {
            log("Termination of output redirection failed: " + e, Project.MSG_ERR);
        }

        if (err != 0) {
            if (f.exists()) {
                f.delete();
            }
            if (cmdline.getClasspath() == null) {
                log("Antlr libraries not found in external classpath or embedded classpath statement ", Project.MSG_ERR);
            }
            log("Dependency check failed. ANTLR returned: " + err, Project.MSG_ERR);
            return true;
        } else {
View Full Code Here

TOP

Related Classes of org.apache.tools.ant.types.CommandlineJava

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.