/**
   * Get the classpath to use for running the fitnesse tests. The classpath is found using the
   * fitnesse <code>path</code> property or using Maven dependancies, according to the POM
   * configuration. The classpath is adapted to the local server configuration depending on the
   * local folders.
   *
   * @param tServer The FitNesse configuration.
   * @return The ClassPath to use.
   * @throws MojoExecutionException If the classpath can't be found.
   */
  private String getClassPath(Fitnesse tServer) throws MojoExecutionException {
    String tResult;
    if ("fitnesse".equals(classPathProvider)) {
      StringBuffer tBuffer = new StringBuffer();
      ClassPathBuilder tBuilder =
          new ClassPathBuilder(
              tServer.getHostName(), tServer.getPort(), tServer.getPageName(), getLog());
      tBuffer.append(tBuilder.getPath(classPathSubstitutions, getLog()));
      Artifact curArt;
      for (Iterator tIt = pluginArtifacts.iterator(); tIt.hasNext(); ) {
        curArt = (Artifact) tIt.next();
        if (!curArt.getScope().equals(Artifact.SCOPE_PROVIDED)
            && !curArt.getScope().equals(Artifact.SCOPE_TEST)) {
          tBuffer.append(File.pathSeparatorChar).append(curArt.getFile().getAbsolutePath());
        }
      }
      tBuffer.append(File.pathSeparatorChar).append(resolvePlugin().getFile().getAbsolutePath());
      getLog().info("Try to download classpath from FitNesse server...");
      tResult = tBuffer.toString();
    } else {
      tResult = getMavenClassPath();
    }
    if (copyDependencies) {
      tResult = copyDependenciesLocally(tResult);
    }

    return tResult;
  }
  /**
   * Create the Command object fot running the tests locally.
   *
   * @param pServer The fitnesse configuration.
   * @param pClassPath The classpath.
   * @return A ready to use command object.
   */
  FCommandline prepareCommandLine(Fitnesse pServer, String pClassPath) {
    mCmd.clear();

    mCmd.setExecutable(jdk);
    if (jdkOpts != null && jdkOpts.length() > 0) {
      StringTokenizer tTok = new StringTokenizer(jdkOpts, " ");
      while (tTok.hasMoreTokens()) {
        mCmd.createArgument().setValue(tTok.nextToken());
      }
    }
    mCmd.createArgument().setValue("-cp");
    mCmd.createArgument().setValue(pClassPath);
    mCmd.createArgument().setValue(fitnesseRunnerClass);
    mCmd.createArgument().setValue("-v");
    if (debug) {
      mCmd.createArgument().setValue("-debug");
    }
    mCmd.createArgument().setValue("-html");
    String tFileName = getTmpFileName(pServer);
    File tFile = new File(tFileName);
    if (tFile.exists()) {
      tFile.delete();
    }
    mCmd.createArgument().setValue(tFileName);
    if (generateXml) {
      mCmd.createArgument().setValue("-xml");
      String tXmlFileName = getResultFileName(pServer, "", "xml");
      File tXmlFile = new File(tXmlFileName);
      if (tXmlFile.exists()) {
        tXmlFile.delete();
      }
      mCmd.createArgument().setValue(tXmlFileName);
    }
    mCmd.createArgument().setValue("-nopath");
    if (pServer.getSuiteFilter() != null && pServer.getSuiteFilter().length() > 0) {
      mCmd.createArgument().setValue("-suiteFilter");
      mCmd.createArgument().setValue(pServer.getSuiteFilter());
    }

    mCmd.createArgument().setValue(pServer.getHostName());

    mCmd.createArgument().setValue("" + pServer.getPort());
    mCmd.createArgument().setValue(pServer.getPageName());
    mCmd.setWorkingDirectory(workingDir);
    getLog().info("Execute =" + mCmd.toString());
    getLog().info("From =" + mCmd.getWorkingDirectory());
    return mCmd;
  }