Package org.apache.tools.ant.types

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


    /**
     * build up a command line
     * @return a command line for jasper
     */
    private CommandlineJava setupJasperCommand() {
        CommandlineJava cmd = new CommandlineJava();
        JspC jspc = getJspc();
        addArg(cmd, "-d", jspc.getDestdir());
        addArg(cmd, "-p", jspc.getPackage());

        if (!isTomcat5x()) {
View Full Code Here


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

        CommandlineJava cmd = null;
        try {
            cmd = (CommandlineJava) getCommandline().clone();
        } catch (CloneNotSupportedException e) {
            throw new BuildException(e);
        }

        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("testsfile=" + casesFile);
        }
       
        cmd.createArgument().setValue("filtertrace=" + test.getFiltertrace());
        cmd.createArgument().setValue("haltOnError=" + test.getHaltonerror());
        cmd.createArgument().setValue("haltOnFailure="
                                      + test.getHaltonfailure());
        if (includeAntRuntime) {
            Vector v = Execute.getProcEnvironment();
            Enumeration e = v.elements();
            while (e.hasMoreElements()) {
                String s = (String) e.nextElement();
                if (s.startsWith("CLASSPATH=")) {
                    cmd.createClasspath(getProject()).createPath()
                        .append(new Path(getProject(),
                                         s.substring(10 // "CLASSPATH=".length()
                                                     )));
                }
            }
            log("Implicitly adding " + antRuntimeClasses + " to CLASSPATH",
                Project.MSG_VERBOSE);
            cmd.createClasspath(getProject()).createPath()
                .append(antRuntimeClasses);
        }

        if (summary) {
            log("Running " + test.getName(), Project.MSG_INFO);
            cmd.createArgument()
                .setValue("formatter"
                          + "=org.apache.tools.ant.taskdefs.optional.junit.SummaryJUnitResultFormatter");
        }

        cmd.createArgument().setValue("showoutput="
                                      + String.valueOf(showOutput));

        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("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 propsFile = createTempPropertiesFile("junit");
        cmd.createArgument().setValue("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 LogStreamHandler(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);
        int retVal;
        try {
            retVal = execute.execute();
        } catch (IOException e) {
            throw new BuildException("Process fork failed.", e, getLocation());
View Full Code Here

    /**
     * @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 IO Exception 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

   */
  @Override
  public void execute() throws BuildException {
    validateOptions();

    CommandlineJava cmd= getJavaCommand();

    cmd.setClassname(m_mainClass);

    List<String> argv= Lists.newArrayList();

    if (null != m_isJUnit) {
      if(m_isJUnit.booleanValue()) {
        argv.add(TestNGCommandLineArgs.JUNIT_DEF_OPT);
      }
    }
   
    if (null != m_skipFailedInvocationCounts) {
      if(m_skipFailedInvocationCounts.booleanValue()) {
        argv.add(TestNGCommandLineArgs.SKIP_FAILED_INVOCATION_COUNT_OPT);
      }
    }
   
    if (m_delegateCommandSystemProperties) {
      delegateCommandSystemProperties();
    }

    if(null != m_verbose) {
      argv.add(TestNGCommandLineArgs.LOG);
      argv.add(m_verbose.toString());
    }

    if(m_assertEnabled) {
      cmd.createVmArgument().setValue("-ea");
    }

    if(m_useDefaultListeners != null) {
      String useDefaultListeners = "false";
      if ("yes".equalsIgnoreCase(m_useDefaultListeners)
          || "true".equalsIgnoreCase(m_useDefaultListeners))
      {
        useDefaultListeners = "true";
      }
      argv.add(TestNGCommandLineArgs.USE_DEFAULT_LISTENERS);
      argv.add(useDefaultListeners);
    }

    if((null != m_outputDir)) {
      if(!m_outputDir.exists()) {
        m_outputDir.mkdirs();
      }
      if(m_outputDir.isDirectory()) {
        argv.add(TestNGCommandLineArgs.OUTDIR_COMMAND_OPT);
        argv.add(m_outputDir.getAbsolutePath());
      }
      else {
        throw new BuildException("Output directory is not a directory: " + m_outputDir);
      }
    }

    if(null != m_target) {
      argv.add(TestNGCommandLineArgs.ANNOTATIONS_COMMAND_OPT);
      argv.add(m_target);
    }

    if((null != m_testjar) && m_testjar.isFile()) {
      argv.add(TestNGCommandLineArgs.TESTJAR_COMMAND_OPT);
      argv.add(m_testjar.getAbsolutePath());
    }

    if(null != m_sourceDirPath) {
      String srcPath= createPathString(m_sourceDirPath, ";");
      argv.add(TestNGCommandLineArgs.SRC_COMMAND_OPT);
      argv.add(srcPath);
    }

    if((null != m_includedGroups) && !"".equals(m_includedGroups)) {
      argv.add(TestNGCommandLineArgs.GROUPS_COMMAND_OPT);
      argv.add(m_includedGroups);
    }

    if((null != m_excludedGroups) && !"".equals(m_excludedGroups)) {
      argv.add(TestNGCommandLineArgs.EXCLUDED_GROUPS_COMMAND_OPT);
      argv.add(m_excludedGroups);
    }

    if(m_classFilesets.size() > 0) {
      argv.add(TestNGCommandLineArgs.TESTCLASS_COMMAND_OPT);
      for(String file : fileset(m_classFilesets)) {
        argv.add(file);
      }
    }

    if(m_listeners != null && m_listeners.size() > 0) {
      argv.add(TestNGCommandLineArgs.LISTENER_COMMAND_OPT);
      StringBuffer listeners= new StringBuffer();
      for(int i= 0; i < m_listeners.size(); i++) {
        listeners.append(m_listeners.get(i));
        if(i < m_listeners.size() - 1) listeners.append(';');
      }
      argv.add(listeners.toString());
    }

    if(m_objectFactory != null) {
      argv.add(TestNGCommandLineArgs.OBJECT_FACTORY_COMMAND_OPT);
      argv.add(m_objectFactory);
    }

    if (m_testRunnerFactory !=null) {
      argv.add(TestNGCommandLineArgs.TESTRUNNER_FACTORY_COMMAND_OPT);
      argv.add(m_testRunnerFactory);
    }

    if(m_parallelMode != null) {
      argv.add(TestNGCommandLineArgs.PARALLEL_MODE);
      argv.add(m_parallelMode);
    }

    if(m_threadCount != null) {
      argv.add(TestNGCommandLineArgs.THREAD_COUNT);
      argv.add(m_threadCount);
    }

    if(m_dataproviderthreadCount != null) {
      argv.add(TestNGCommandLineArgs.DATA_PROVIDER_THREAD_COUNT);
      argv.add(m_dataproviderthreadCount);
    }
   
    if(!"".equals(m_suiteName)) {
      argv.add(TestNGCommandLineArgs.SUITE_NAME_OPT);
      argv.add(m_suiteName);
    }

    if(!"".equals(m_testName)) {
      argv.add(TestNGCommandLineArgs.TEST_NAME_OPT);
      argv.add(m_testName);
    }

    if (!reporterConfigs.isEmpty()) {
      for (ReporterConfig reporterConfig : reporterConfigs) {
        argv.add(TestNGCommandLineArgs.REPORTER);
        argv.add(reporterConfig.serialize());
      }
    }

    if(m_xmlFilesets.size() > 0) {
      for(String file : fileset(m_xmlFilesets)) {
        argv.add(file);
      }
    }

    String fileName= "";
    FileWriter fw= null;
    BufferedWriter bw= null;
    try {
      File f= File.createTempFile("testng", "");
      fileName= f.getAbsolutePath();

      // If the user asked to see the command, preserve the file
      if(!m_dump) {
        f.deleteOnExit();
      }
      fw= new FileWriter(f);
      bw= new BufferedWriter(fw);
      for(String arg : argv) {
        bw.write(arg);
        bw.newLine();
      }
      bw.flush();
    }
    catch(IOException e) {
      e.printStackTrace();
    }
    finally {
      try {
        if(bw != null) {
          bw.close();
        }
        if(fw != null) {
          fw.close();
        }
      }
      catch(IOException e) {
        e.printStackTrace();
      }
    }

    printDebugInfo(fileName);

    createClasspath().setLocation(findJar());

    cmd.createArgument().setValue("@" + fileName);

    ExecuteWatchdog watchdog= createWatchdog();
    boolean wasKilled= false;
    int exitValue= executeAsForked(cmd, watchdog);
    if(null != watchdog) {
View Full Code Here

  /**
   * Creates or returns the already created <CODE>CommandlineJava</CODE>.
   */
  protected CommandlineJava getJavaCommand() {
    if(null == m_javaCommand) {
      m_javaCommand= new CommandlineJava();
    }

    return m_javaCommand;
  }
View Full Code Here

   */
  @Override
  public void execute() throws BuildException {
    validateOptions();

    CommandlineJava cmd= getJavaCommand();

    cmd.setClassname(m_mainClass);

    List<String> argv= Lists.newArrayList();

    if (null != m_isJUnit) {
      if(m_isJUnit.booleanValue()) {
        argv.add(TestNGCommandLineArgs.JUNIT_DEF_OPT);
      }
    }
   
    if (null != m_skipFailedInvocationCounts) {
      if(m_skipFailedInvocationCounts.booleanValue()) {
        argv.add(TestNGCommandLineArgs.SKIP_FAILED_INVOCATION_COUNT_OPT);
      }
    }
   
    if (m_delegateCommandSystemProperties) {
      delegateCommandSystemProperties();
    }

    if(null != m_verbose) {
      argv.add(TestNGCommandLineArgs.LOG);
      argv.add(m_verbose.toString());
    }

    if(m_assertEnabled) {
      cmd.createVmArgument().setValue("-ea");
    }

    if(m_useDefaultListeners != null) {
      String useDefaultListeners = "false";
      if ("yes".equalsIgnoreCase(m_useDefaultListeners)
          || "true".equalsIgnoreCase(m_useDefaultListeners))
      {
        useDefaultListeners = "true";
      }
      argv.add(TestNGCommandLineArgs.USE_DEFAULT_LISTENERS);
      argv.add(useDefaultListeners);
    }

    if((null != m_outputDir)) {
      if(!m_outputDir.exists()) {
        m_outputDir.mkdirs();
      }
      if(m_outputDir.isDirectory()) {
        argv.add(TestNGCommandLineArgs.OUTDIR_COMMAND_OPT);
        argv.add(m_outputDir.getAbsolutePath());
      }
      else {
        throw new BuildException("Output directory is not a directory: " + m_outputDir);
      }
    }

    if(null != m_target) {
      argv.add(TestNGCommandLineArgs.ANNOTATIONS_COMMAND_OPT);
      argv.add(m_target);
    }

    if((null != m_testjar) && m_testjar.isFile()) {
      argv.add(TestNGCommandLineArgs.TESTJAR_COMMAND_OPT);
      argv.add(m_testjar.getAbsolutePath());
    }

    if(null != m_sourceDirPath) {
      String srcPath= createPathString(m_sourceDirPath, ";");
      argv.add(TestNGCommandLineArgs.SRC_COMMAND_OPT);
      argv.add(srcPath);
    }

    if((null != m_includedGroups) && !"".equals(m_includedGroups)) {
      argv.add(TestNGCommandLineArgs.GROUPS_COMMAND_OPT);
      argv.add(m_includedGroups);
    }

    if((null != m_excludedGroups) && !"".equals(m_excludedGroups)) {
      argv.add(TestNGCommandLineArgs.EXCLUDED_GROUPS_COMMAND_OPT);
      argv.add(m_excludedGroups);
    }

    if(m_classFilesets.size() > 0) {
      argv.add(TestNGCommandLineArgs.TESTCLASS_COMMAND_OPT);
      for(String file : fileset(m_classFilesets)) {
        argv.add(file);
      }
    }

    if(m_listeners != null && m_listeners.size() > 0) {
      argv.add(TestNGCommandLineArgs.LISTENER_COMMAND_OPT);
      StringBuffer listeners= new StringBuffer();
      for(int i= 0; i < m_listeners.size(); i++) {
        listeners.append(m_listeners.get(i));
        if(i < m_listeners.size() - 1) listeners.append(';');
      }
      argv.add(listeners.toString());
    }

    if(m_objectFactory != null) {
      argv.add(TestNGCommandLineArgs.OBJECT_FACTORY_COMMAND_OPT);
      argv.add(m_objectFactory);
    }

    if (m_testRunnerFactory !=null) {
      argv.add(TestNGCommandLineArgs.TESTRUNNER_FACTORY_COMMAND_OPT);
      argv.add(m_testRunnerFactory);
    }

    if(m_parallelMode != null) {
      argv.add(TestNGCommandLineArgs.PARALLEL_MODE);
      argv.add(m_parallelMode);
    }

    if(m_threadCount != null) {
      argv.add(TestNGCommandLineArgs.THREAD_COUNT);
      argv.add(m_threadCount);
    }

    if(m_dataproviderthreadCount != null) {
      argv.add(TestNGCommandLineArgs.DATA_PROVIDER_THREAD_COUNT);
      argv.add(m_dataproviderthreadCount);
    }
   
    if(!"".equals(m_suiteName)) {
      argv.add(TestNGCommandLineArgs.SUITE_NAME_OPT);
      argv.add(m_suiteName);
    }

    if(!"".equals(m_testName)) {
      argv.add(TestNGCommandLineArgs.TEST_NAME_OPT);
      argv.add(m_testName);
    }

    if (!reporterConfigs.isEmpty()) {
      for (ReporterConfig reporterConfig : reporterConfigs) {
        argv.add(TestNGCommandLineArgs.REPORTER);
        argv.add(reporterConfig.serialize());
      }
    }

    if(m_xmlFilesets.size() > 0) {
      for(String file : fileset(m_xmlFilesets)) {
        argv.add(file);
      }
    }

    String fileName= "";
    FileWriter fw= null;
    BufferedWriter bw= null;
    try {
      File f= File.createTempFile("testng", "");
      fileName= f.getAbsolutePath();

      // If the user asked to see the command, preserve the file
      if(!m_dump) {
        f.deleteOnExit();
      }
      fw= new FileWriter(f);
      bw= new BufferedWriter(fw);
      for(String arg : argv) {
        bw.write(arg);
        bw.newLine();
      }
      bw.flush();
    }
    catch(IOException e) {
      e.printStackTrace();
    }
    finally {
      try {
        if(bw != null) {
          bw.close();
        }
        if(fw != null) {
          fw.close();
        }
      }
      catch(IOException e) {
        e.printStackTrace();
      }
    }

    printDebugInfo(fileName);

    createClasspath().setLocation(findJar());

    cmd.createArgument().setValue("@" + fileName);

    ExecuteWatchdog watchdog= createWatchdog();
    boolean wasKilled= false;
    int exitValue= executeAsForked(cmd, watchdog);
    if(null != watchdog) {
View Full Code Here

  /**
   * Creates or returns the already created <CODE>CommandlineJava</CODE>.
   */
  protected CommandlineJava getJavaCommand() {
    if(null == m_javaCommand) {
      m_javaCommand= new CommandlineJava();
    }

    return m_javaCommand;
  }
View Full Code Here

     * our execute method
     */
    public boolean execute()
        throws BuildException {
        getJspc().log("Using jasper compiler", Project.MSG_VERBOSE);
        CommandlineJava cmd = setupJasperCommand();
        /*
        Path classpath=cmd.createClasspath(getProject());
        if (getJspc().getClasspath() != null) {
            classpath=getJspc().getClasspath();
        } else {
            classpath.concatSystemClasspath();
        }
        ExecuteJava exec=new ExecuteJava();
        exec.execute(getProject());
        if ((err = executeJava()) != 0) {
            if (failOnError) {
                throw new BuildException("Java returned: " + err, location);
            } else {
                log("Java Result: " + err, Project.MSG_ERR);
            }
        */


        try {
            // Create an instance of the compiler, redirecting output to
            // the project log
            // REVISIT. ugly.
            Java java = (Java) (getProject().createTask("java"));
            if (getJspc().getClasspath() != null) {
                getProject().log("using user supplied classpath: "+getJspc().getClasspath(),
                    Project.MSG_DEBUG);
                java.setClasspath(getJspc().getClasspath());
            } else {
                Path classpath=new Path(getProject());
                classpath=classpath.concatSystemClasspath("only");
                getProject().log("using system classpath: "+classpath, Project.MSG_DEBUG);
                java.setClasspath(classpath);
            }
            java.setDir(getProject().getBaseDir());
            java.setClassname("org.apache.jasper.JspC");
            //this is really irritating; we need a way to set stuff
            String args[] = cmd.getJavaCommand().getArguments();
            for (int i = 0; i < args.length; i++) {
                java.createArg().setValue(args[i]);
            }
            java.setFailonerror(getJspc().getFailonerror());
            //we are forking here to be sure that if JspC calls
View Full Code Here

    /**
     * build up a command line
     * @return a command line for jasper
     */
    private CommandlineJava setupJasperCommand() {
        CommandlineJava cmd = new CommandlineJava();
        JspC jspc = getJspc();
        addArg(cmd, "-d", jspc.getDestdir());
        addArg(cmd, "-p", jspc.getPackage());
        addArg(cmd, "-v" + jspc.getVerbose());
        addArg(cmd, "-uriroot", jspc.getUriroot());
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.