Package org.apache.tools.ant.types

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


      log("Test class names:\n" + testClassPerLine, Project.MSG_VERBOSE);
 
      Files.write(testClassPerLine, classNamesFile, Charsets.UTF_8);
 
      // Prepare command line for java execution.
      CommandlineJava commandline;
      commandline = (CommandlineJava) getCommandline().clone();
      commandline.createClasspath(getProject()).add(addSlaveClasspath());
      commandline.setClassname(SlaveMainSafe.class.getName());
      commandline.createArgument().setValue("@" + classNamesFile.getAbsolutePath());
      if (slave.slaves == 1) {
        commandline.createArgument().setValue(SlaveMain.OPTION_FREQUENT_FLUSH);
      }
 
      String [] commandLineArgs = commandline.getCommandline();
 
      log("Slave process command line:\n" +
          Joiner.on(" ").join(commandLineArgs), Project.MSG_VERBOSE);
 
      final EventBus eventBus = new EventBus("slave");
View Full Code Here


    log("Test class names:\n" + testClassPerLine, Project.MSG_VERBOSE);

    Files.write(testClassPerLine, classNamesFile, Charsets.UTF_8);

    // Prepare command line for java execution.
    CommandlineJava commandline;
    commandline = (CommandlineJava) getCommandline().clone();
    commandline.createClasspath(getProject()).add(addSlaveClasspath());
    commandline.setClassname(SlaveMainSafe.class.getName());
    if (slave.slaves == 1) {
      commandline.createArgument().setValue(SlaveMain.OPTION_FREQUENT_FLUSH);
    }

    // Set up full output files.
    File sysoutFile = tempFile(uniqueSeed,
        "junit4-J" + slave.id, ".sysout", getTempDir());
    File syserrFile = tempFile(uniqueSeed,
        "junit4-J" + slave.id, ".syserr", getTempDir());

    // Set up communication channel.
    File eventFile = tempFile(uniqueSeed,
        "junit4-J" + slave.id, ".events", getTempDir());
    temporaryFiles.add(eventFile);
    commandline.createArgument().setValue(SlaveMain.OPTION_EVENTSFILE);
    commandline.createArgument().setFile(eventFile);
   
    if (sysouts) {
      commandline.createArgument().setValue(SlaveMain.OPTION_SYSOUTS);
    }

    InputStream eventStream = new TailInputStream(eventFile);

    // Set up input suites file.
    commandline.createArgument().setValue("@" + classNamesFile.getAbsolutePath());

    // Emit command line before -stdin to avoid confusion.
    slave.slaveCommandLine = escapeAndJoin(commandline.getCommandline());
    log("Forked JVM process command line (may need escape sequences for your shell):\n" +
        slave.slaveCommandLine, Project.MSG_VERBOSE);

    commandline.createArgument().setValue(SlaveMain.OPTION_STDIN);

    final EventBus eventBus = new EventBus("slave-" + slave.id);
    final DiagnosticsListener diagnosticsListener = new DiagnosticsListener(slave, this);
    eventBus.register(diagnosticsListener);
    eventBus.register(new AggregatingListener(aggregatedBus, slave));
View Full Code Here

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

    CommandlineJava cmd= getJavaCommand();

    cmd.setClassname(m_mainClass);

    List<String> argv= new ArrayList<String>();

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

    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_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(!"".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

   }

   public void execute()
           throws BuildException
   {
      CommandlineJava cmd = new CommandlineJava();

      if (output != null)
      {
         cmd.createArgument().setValue("-o");
         cmd.createArgument().setValue(output.toString());
      }
      if (xml)
      {
         cmd.createArgument().setValue("-xml");
      }
      if (bytecode)
      {
         cmd.createArgument().setValue("-bytecode");
      }
      logAndAddFilesToCompile(cmd);
      try
      {
         // Create an instance of the compiler, redirecting output to
         // the project log
         classpath.append(compilerClasspath);
         Java java = (Java) (getProject().createTask("java"));
         if (getClasspath() != null)
         {
            getProject().log("using user supplied classpath: "
                    + getClasspath(), Project.MSG_DEBUG);
            java.setClasspath(getClasspath()
                    .concatSystemClasspath("ignore"));
         }
         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.jboss.aop.annotation.compiler.AnnotationCompiler");
         //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(getFailonerror());
View Full Code Here

   }

   public void execute()
           throws BuildException
   {
      CommandlineJava cmd = new CommandlineJava();
      if (compileSourcepath == null)
      {
         throw new BuildException(MSG_PREFIX + "'src' path element not found");
      }
     
      if (classpath == null)
      {
         throw new BuildException(MSG_PREFIX + "classpath undefined (use 'classpath' path elements and/or the 'classpathref' attribute)");
      }
     
      if (verbose)
         cmd.createArgument().setValue("-verbose");
      if (suppress)
         cmd.createArgument().setValue("-suppress");
      if (!optimized)
         cmd.createArgument().setValue("-noopt");
      if (report)
         cmd.createArgument().setValue("-report");
      if (aoppath != null && aoppath.size() > 0)
      {
         cmd.createArgument().setValue("-aoppath");
         cmd.createArgument().setValue(aoppath.toString());
      }
      if (aopclasspath != null && aopclasspath.size() > 0)
      {
         cmd.createArgument().setValue("-aopclasspath");
         cmd.createArgument().setValue(aopclasspath.toString());
      }
      logAndAddFilesToCompile(cmd);
     
      try
      {
         // Create an instance of the compiler, redirecting output to
         // the project log
         classpath.append(compilerClasspath);
         Java java = (Java) (getProject().createTask("java"));
         if (jvm != null && jvm.length() > 0)
         {
            java.setJvm(jvm);
         }
         if (getClasspath() != null)
         {
            getProject().log("using user supplied classpath: "
                    + getClasspath(), Project.MSG_DEBUG);
            java.setClasspath(getClasspath()
                    .concatSystemClasspath("ignore"));
         }
         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.jboss.aop.standalone.Compiler");
         //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(getFailonerror());
View Full Code Here

      }
    }
  }

  private int executeRunnerClassAsForked() throws BuildException {
    CommandlineJava cmd = initializeJavaCommand();

    Execute execute = new Execute(new LogStreamHandler(this, Project.MSG_INFO, Project.MSG_WARN));
    String[] commandLine = cmd.getCommandline();
    log("Executing: " + StringUtils.join(Arrays.asList(commandLine), " "));
    execute.setCommandline(commandLine);
    execute.setNewenvironment(false);
    execute.setAntRun(getProject());

    log(cmd.describeCommand(), Project.MSG_VERBOSE);
    int retVal;
    try {
      retVal = execute.execute();
    }
    catch (IOException e) {
View Full Code Here

    return retVal;
  }

  private CommandlineJava initializeJavaCommand() {
    CommandlineJava cmd = new CommandlineJava();
    cmd.setClassname(testRunnerClass);
    appendDebugArgument(cmd);
    appendVerboseArgument(cmd);
    appendHtmlResultPage(cmd);
    appendXmlResultPage(cmd);
    appendSuiteFilter(cmd);
    cmd.createArgument().setValue(fitnesseHost);
    cmd.createArgument().setValue(String.valueOf(fitnessePort));
    cmd.createArgument().setValue(suitePage);
    cmd.createClasspath(getProject()).createPath().append(classpath);
    return cmd;
  }
View Full Code Here

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

    CommandlineJava cmd = getJavaCommand();
    cmd.setClassname(m_mainClass);
    if(m_assertEnabled) {
      cmd.createVmArgument().setValue("-ea");
    }
    if (m_delegateCommandSystemProperties) {
      delegateCommandSystemProperties();
    }
    setListeners(VerboseReporter.class.getName());
    List<String> argv = createArguments();

    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

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.