Esempio n. 1
0
  @Override
  protected GocodeServerInstance doCreateServerInstance(IOperationMonitor om)
      throws CommonException, OperationCancellation {
    Path gocodePath = getServerPath();

    ArrayList2<String> commandLine = new ArrayList2<String>();
    commandLine.add(gocodePath.toString());
    commandLine.add("-s");
    if (GocodeCompletionOperation.USE_TCP) {
      commandLine.add("-sock=tcp");
    }

    LangCore.logInfo(
        "Starting gocode server: "
            + DebugPlugin.renderArguments(commandLine.toArray(String.class), null));

    ProcessBuilder pb = new ProcessBuilder(commandLine);

    IToolOperationMonitor opMonitor =
        toolMgr.startNewOperation(ProcessStartKind.ENGINE_SERVER, true, false);
    String prefixText = "==== Starting gocode server ====\n";

    gocodeSetEnableBuiltins(gocodePath, om, opMonitor, prefixText);

    ExternalProcessNotifyingHelper process =
        toolMgr.new RunToolTask(opMonitor, prefixText, null, pb, om).startProcess();

    return new GocodeServerInstance(gocodePath, process);
  }
  private static void execute(String commandLine, String[] expectedArgs, String expectedRendered)
      throws Exception {
    String[] arguments = DebugPlugin.parseArguments(commandLine);
    assertEquals(
        "unexpected parseArguments result;", //$NON-NLS-1$
        Arrays.asList(expectedArgs).toString(),
        Arrays.asList(arguments).toString());

    runCommandLine(commandLine, arguments);

    String rendered = DebugPlugin.renderArguments(arguments, null);
    assertEquals("unexpected renderArguments result;", expectedRendered, rendered); // $NON-NLS-1$

    if (!commandLine.equals(rendered)) {
      String[] arguments2 = DebugPlugin.parseArguments(rendered);
      assertEquals(
          "parsing rendered command line doesn't yield original arguments;", //$NON-NLS-1$
          Arrays.asList(expectedArgs).toString(),
          Arrays.asList(arguments2).toString());
    }

    String[] splitArguments = DebugPlugin.splitArguments(commandLine);
    assertEquals(expectedArgs.length, splitArguments.length);
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < splitArguments.length; i++) {
      if (i > 0) {
        sb.append(" "); // $NON-NLS-1$
      }
      sb.append(splitArguments[i]);
    }
    assertEquals(commandLine, sb.toString());
  }
 public String getProgramArgumentsString() {
   return DebugPlugin.renderArguments(programArguments, null);
 }