Java Code Examples for com.intellij.execution.configurations.GeneralCommandLine#createProcess()

The following examples show how to use com.intellij.execution.configurations.GeneralCommandLine#createProcess() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseExternalTool.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void show(DiffRequest request) {
  for (DiffContent diffContent : request.getContents()) {
    Document document = diffContent.getDocument();
    if (document != null) {
      FileDocumentManager.getInstance().saveDocument(document);
    }
  }
  GeneralCommandLine commandLine = new GeneralCommandLine();
  commandLine.setExePath(getToolPath());
  try {
    commandLine.addParameters(getParameters(request));
    commandLine.createProcess();
  }
  catch (Exception e) {
    ExecutionErrorDialog.show(new ExecutionException(e.getMessage()),
                              DiffBundle.message("cant.launch.diff.tool.error.message"), request.getProject());
  }
}
 
Example 2
Source File: FastpassUpdater.java    From intellij-pants-plugin with Apache License 2.0 6 votes vote down vote up
private static boolean runFastpassRefresh(FastpassData data, Project project) {
  try {
    GeneralCommandLine commandLine = PantsUtil.defaultCommandLine(project);
    commandLine.setExePath(FASTPASS_PATH);
    commandLine.addParameters(
      "refresh",
      "--intellij",
      "--intellijLauncher", "echo", // to avoid opening project again
      data.projectName
    );
    Process refresh = commandLine.createProcess();
    refresh.waitFor();
    return refresh.exitValue() == 0;
  }
  catch (Exception e) {
    LOG.warn(e);
    return false;
  }
}
 
Example 3
Source File: OSSPantsJavaExamplesIntegrationTest.java    From intellij-pants-plugin with Apache License 2.0 6 votes vote down vote up
private String[] getModulesNamesFromPantsDependencies(String targetName) throws ProjectBuildException {
  Optional<VirtualFile> pantsExe = PantsUtil.findPantsExecutable(myProject);
  assertTrue(pantsExe.isPresent());
  final GeneralCommandLine commandLine = PantsUtil.defaultCommandLine(pantsExe.get().getPath());
  commandLine.addParameters(PantsConstants.PANTS_CLI_OPTION_NO_COLORS);
  commandLine.addParameters("dependencies");
  commandLine.addParameters(targetName);
  final Process process;
  try {
    process = commandLine.createProcess();
  }
  catch (ExecutionException e) {
    throw new ProjectBuildException(e);
  }

  final CapturingProcessHandler processHandler = new CapturingAnsiEscapesAwareProcessHandler(process, commandLine.getCommandLineString());
  ProcessOutput output = processHandler.runProcess();
  String lines[] = output.getStdout().split("\\r?\\n");
  Set<String> modules = new HashSet<>();
  for (String l : lines) {
    modules.add(PantsUtil.getCanonicalModuleName(l));
  }
  return modules.toArray(new String[modules.size()]);
}
 
Example 4
Source File: GhcModi.java    From intellij-haskforce with Apache License 2.0 6 votes vote down vote up
private void spawnProcess() throws GhcModiError {
    GeneralCommandLine commandLine = new GeneralCommandLine(
        GhcModUtil.changedPathIfStack(module.getProject(), path)
    );
    GhcModUtil.updateEnvironment(module.getProject(), commandLine.getEnvironment());
    ParametersList parametersList = commandLine.getParametersList();
    parametersList.addParametersString(
        GhcModUtil.changedFlagsIfStack(module.getProject(), path, flags)
    );
    // setWorkDirectory is deprecated but is needed to work with IntelliJ 13 which does not have withWorkDirectory.
    commandLine.setWorkDirectory(workingDirectory);
    // Make sure we can actually see the errors.
    commandLine.setRedirectErrorStream(true);
    writeInputToConsole("Using working directory: " + workingDirectory);
    writeInputToConsole("Starting ghc-modi process: " + commandLine.getCommandLineString());
    try {
        process = commandLine.createProcess();
    } catch (ExecutionException e) {
        writeErrorToConsole("Failed to initialize process");
        throw new InitError(e.toString());
    }
    input = new BufferedReader(new InputStreamReader(process.getInputStream()));
    output = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));
    startIdleKillerThread();
}
 
Example 5
Source File: GeneralCommandLineTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static String execAndGetOutput(GeneralCommandLine commandLine, @Nullable String encoding) throws Exception {
  Process process = commandLine.createProcess();
  byte[] bytes = FileUtil.loadBytes(process.getInputStream());
  String output = encoding != null ? new String(bytes, encoding) : new String(bytes);
  int result = process.waitFor();
  assertEquals("Command:\n" + commandLine.getCommandLineString() + "\nOutput:\n" + output, 0, result);
  return output;
}
 
Example 6
Source File: OSProcessHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static Process startProcess(GeneralCommandLine commandLine) throws ExecutionException {
  try {
    return commandLine.createProcess();
  }
  catch (ExecutionException | RuntimeException | Error e) {
    deleteTempFiles(commandLine.getUserData(DELETE_FILES_ON_TERMINATION));
    throw e;
  }
}
 
Example 7
Source File: BrowserLauncherAppless.java    From consulo with Apache License 2.0 5 votes vote down vote up
private boolean doLaunch(@Nullable String url,
                         @Nonnull List<String> command,
                         @Nullable final WebBrowser browser,
                         @Nullable final Project project,
                         @Nonnull String[] additionalParameters,
                         @Nullable Runnable launchTask) {

  if (url != null && url.startsWith("jar:")) {
    String files = extractFiles(url);
    if (files == null) {
      return false;
    }
    url = files;
  }

  List<String> commandWithUrl = new ArrayList<>(command);
  if (url != null) {
    if (browser != null) {
      browser.addOpenUrlParameter(commandWithUrl, url);
    }
    else {
      commandWithUrl.add(url);
    }
  }

  GeneralCommandLine commandLine = new GeneralCommandLine(commandWithUrl);
  addArgs(commandLine, browser == null ? null : browser.getSpecificSettings(), additionalParameters);
  try {
    Process process = commandLine.createProcess();
    checkCreatedProcess(browser, project, commandLine, process, launchTask);
    return true;
  }
  catch (ExecutionException e) {
    doShowError(e.getMessage(), browser, project, null, null);
    return false;
  }
}
 
Example 8
Source File: HaxeTestsRunner.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
@Override
protected RunContentDescriptor doExecute(@NotNull final Project project,
                                         @NotNull RunProfileState state,
                                         final RunContentDescriptor descriptor,
                                         @NotNull final ExecutionEnvironment environment) throws ExecutionException {

  final HaxeTestsConfiguration profile = (HaxeTestsConfiguration)environment.getRunProfile();
  final Module module = profile.getConfigurationModule().getModule();

  ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
  VirtualFile[] roots = rootManager.getContentRoots();

  return super.doExecute(project, new CommandLineState(environment) {
    @NotNull
    @Override
    protected ProcessHandler startProcess() throws ExecutionException {
      //actually only neko target is supported for tests
      HaxeTarget currentTarget = HaxeTarget.NEKO;
      final GeneralCommandLine commandLine = new GeneralCommandLine();
      commandLine.setWorkDirectory(PathUtil.getParentPath(module.getModuleFilePath()));
      commandLine.setExePath(currentTarget.getFlag());
      final HaxeModuleSettings settings = HaxeModuleSettings.getInstance(module);
      String folder = settings.getOutputFolder() != null ? (settings.getOutputFolder() + "/release/") : "";
      commandLine.addParameter(getFileNameWithCurrentExtension(currentTarget, folder + settings.getOutputFileName()));

      final TextConsoleBuilder consoleBuilder = TextConsoleBuilderFactory.getInstance().createBuilder(module.getProject());
      consoleBuilder.addFilter(new ErrorFilter(module));
      setConsoleBuilder(consoleBuilder);

      return new OSProcessHandler(commandLine.createProcess(), commandLine.getCommandLineString());
    }

    private String getFileNameWithCurrentExtension(HaxeTarget haxeTarget, String fileName) {
      if (haxeTarget != null) {
        return haxeTarget.getTargetFileNameWithExtension(FileUtil.getNameWithoutExtension(fileName));
      }
      return fileName;
    }
  }, descriptor, environment);
}
 
Example 9
Source File: NoSqlConfigurable.java    From nosql4idea with Apache License 2.0 5 votes vote down vote up
public ProcessOutput checkShellPath(DatabaseVendor databaseVendor, String shellPath) throws ExecutionException, TimeoutException {
    if (isBlank(shellPath)) {
        return null;
    }

    GeneralCommandLine commandLine = new GeneralCommandLine();
    commandLine.setExePath(shellPath);
    if (testParameter != null) {
        commandLine.addParameter(testParameter);
    }
    CapturingProcessHandler handler = new CapturingProcessHandler(commandLine.createProcess(), CharsetToolkit.getDefaultSystemCharset());
    ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
    ProcessOutput result = indicator == null ?
            handler.runProcess(TIMEOUT_MS) :
            handler.runProcessWithProgressIndicator(indicator);
    if (result.isTimeout()) {
        throw new TimeoutException("Couldn't check " + databaseVendor.name + " CLI executable - stopped by timeout.");
    } else if (result.isCancelled()) {
        throw new ProcessCanceledException();
    } else if (result.getExitCode() != 0 || !result.getStderr().isEmpty()) {
        throw new ExecutionException(String.format("Errors while executing %s. exitCode=%s errors: %s",
                commandLine.toString(),
                result.getExitCode(),
                result.getStderr()));
    }
    return result;
}
 
Example 10
Source File: GaugeRunProcessHandler.java    From Intellij-Plugin with Apache License 2.0 5 votes vote down vote up
public static GaugeRunProcessHandler runCommandLine(final GeneralCommandLine commandLine, GaugeDebugInfo debugInfo, Project project) throws ExecutionException {
    LOG.info(String.format("Running Gauge tests with command : %s", commandLine.getCommandLineString()));
    final GaugeRunProcessHandler gaugeRunProcess = new GaugeRunProcessHandler(commandLine.createProcess(), commandLine.getCommandLineString());
    ProcessTerminatedListener.attach(gaugeRunProcess);
    if (debugInfo.shouldDebug()) {
        launchDebugger(project, debugInfo);
    }
    return gaugeRunProcess;
}
 
Example 11
Source File: PantsUtil.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
public static ProcessOutput getCmdOutput(
  @NotNull GeneralCommandLine command,
  @Nullable ProcessAdapter processAdapter
) throws ExecutionException {
  final CapturingProcessHandler processHandler =
    new CapturingProcessHandler(command.createProcess(), Charset.defaultCharset(), command.getCommandLineString());
  if (processAdapter != null) {
    processHandler.addProcessListener(processAdapter);
  }
  return processHandler.runProcess();
}
 
Example 12
Source File: PantsCompileOptionsExecutor.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
private ProcessOutput getProcessOutput(
  @NotNull GeneralCommandLine command
) throws ExecutionException {
  final Process process = command.createProcess();
  myProcesses.add(process);
  final ProcessOutput processOutput = PantsUtil.getCmdOutput(process, command.getCommandLineString(), null);
  myProcesses.remove(process);
  return processOutput;
}
 
Example 13
Source File: JscsRunner.java    From jscs-plugin with MIT License 5 votes vote down vote up
@NotNull
private static ProcessOutput execute(@NotNull GeneralCommandLine commandLine, int timeoutInMilliseconds) throws ExecutionException {
    LOG.info("Running jscs command: " + commandLine.getCommandLineString());
    Process process = commandLine.createProcess();
    OSProcessHandler processHandler = new ColoredProcessHandler(process, commandLine.getCommandLineString(), Charsets.UTF_8);
    final ProcessOutput output = new ProcessOutput();
    processHandler.addProcessListener(new ProcessAdapter() {
        public void onTextAvailable(ProcessEvent event, Key outputType) {
            if (outputType.equals(ProcessOutputTypes.STDERR)) {
                output.appendStderr(event.getText());
            } else if (!outputType.equals(ProcessOutputTypes.SYSTEM)) {
                output.appendStdout(event.getText());
            }
        }
    });
    processHandler.startNotify();
    if (processHandler.waitFor(timeoutInMilliseconds)) {
        output.setExitCode(process.exitValue());
    } else {
        processHandler.destroyProcess();
        output.setTimeout();
    }
    if (output.isTimeout()) {
        throw new ExecutionException("Command '" + commandLine.getCommandLineString() + "' is timed out.");
    }
    return output;
}
 
Example 14
Source File: BashConsoleRunner.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
@Override
protected Process createProcess() throws ExecutionException {
    String bashLocation = BashInterpreterDetection.instance().findBestLocation();
    if (bashLocation == null) {
        throw new ExecutionException("Could not locate the bash executable");
    }

    GeneralCommandLine commandLine = new GeneralCommandLine().withWorkDirectory(getWorkingDir());
    commandLine.setExePath(bashLocation);
    return commandLine.createProcess();
}
 
Example 15
Source File: NodeRunner.java    From vue-for-idea with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @param commandLine command line to sdk
 * @param timeoutInMilliseconds timeout
 * @return process output
 * @throws ExecutionException
 */
@NotNull
public static ProcessOutput execute(@NotNull GeneralCommandLine commandLine,ProcessListener listener, int timeoutInMilliseconds) throws ExecutionException {
    LOG.info("Running node command: " + commandLine.getCommandLineString());
    Process process = commandLine.createProcess();
    OSProcessHandler processHandler = new ColoredProcessHandler(process, commandLine.getCommandLineString(), Charsets.UTF_8);
    final ProcessOutput output = new ProcessOutput();
    processHandler.addProcessListener(new ProcessAdapter() {
        public void onTextAvailable(ProcessEvent event, Key outputType) {
            if (outputType.equals(ProcessOutputTypes.STDERR)) {
                output.appendStderr(event.getText());
                if(listener!=null){
                    listener.onError(processHandler,event.getText());
                }
            } else if (!outputType.equals(ProcessOutputTypes.SYSTEM)) {
                output.appendStdout(event.getText());
                if(listener!=null){
                    listener.onOutput(processHandler,event.getText());
                }
            }else if(outputType.equals(ProcessOutputTypes.SYSTEM)){
                if(listener!=null){
                    listener.onCommand(processHandler,event.getText());
                }
            }
        }
    });
    processHandler.startNotify();
    if (processHandler.waitFor(timeoutInMilliseconds)) {
        output.setExitCode(process.exitValue());
    } else {
        processHandler.destroyProcess();
        output.setTimeout();
    }
    if (output.isTimeout()) {
        throw new ExecutionException("Command '" + commandLine.getCommandLineString() + "' is timed out.");
    }
    return output;
}
 
Example 16
Source File: CabalJspInterface.java    From intellij-haskforce with Apache License 2.0 4 votes vote down vote up
public Process configure() throws IOException, ExecutionException {
    GeneralCommandLine commandLine = getCommandLine("configure");
    ParametersList parametersList = commandLine.getParametersList();
    parametersList.addParametersString(myBuildOptions.myCabalFlags);
    return commandLine.createProcess();
}
 
Example 17
Source File: MongoConsoleRunner.java    From nosql4idea with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
protected Process createProcess() throws ExecutionException {

    NoSqlConfiguration noSqlConfiguration = NoSqlConfiguration.getInstance(getProject());
    String shellPath = noSqlConfiguration.getShellPath(DatabaseVendor.MONGO);
    final GeneralCommandLine commandLine = new GeneralCommandLine();
    commandLine.setExePath(shellPath);

    commandLine.addParameter(MongoUtils.buildMongoUrl(serverConfiguration, database));

    String shellWorkingDir = serverConfiguration.getShellWorkingDir();
    if (StringUtils.isNotBlank(shellWorkingDir)) {
        commandLine.withWorkDirectory(shellWorkingDir);
    }

    AuthenticationSettings authenticationSettings = serverConfiguration.getAuthenticationSettings();

    String username = authenticationSettings.getUsername();
    if (StringUtils.isNotBlank(username)) {
        commandLine.addParameter("--username");
        commandLine.addParameter(username);
    }

    String password = authenticationSettings.getPassword();
    if (StringUtils.isNotBlank(password)) {
        commandLine.addParameter("--password");
        commandLine.addParameter(password);
    }

    MongoExtraSettings mongoExtraSettings = new MongoExtraSettings(authenticationSettings.getExtras());
    String authenticationDatabase = mongoExtraSettings.getAuthenticationDatabase();
    if (StringUtils.isNotBlank(authenticationDatabase)) {
        commandLine.addParameter("--authenticationDatabase");
        commandLine.addParameter(authenticationDatabase);
    }

    AuthenticationMechanism authenticationMecanism = mongoExtraSettings.getAuthenticationMechanism();
    if (authenticationMecanism != null) {
        commandLine.addParameter("--authenticationMecanism");
        commandLine.addParameter(authenticationMecanism.getMechanismName());
    }

    String shellArgumentsLine = serverConfiguration.getShellArgumentsLine();
    if (StringUtils.isNotBlank(shellArgumentsLine)) {
        commandLine.addParameters(shellArgumentsLine.split(" "));
    }

    return commandLine.createProcess();
}
 
Example 18
Source File: BuckCommandHandler.java    From buck with Apache License 2.0 4 votes vote down vote up
public OSProcessHandler createProcess(GeneralCommandLine commandLine) throws ExecutionException {
  // TODO(t7984081): Use ProcessExecutor to start buck process.
  Process process = commandLine.createProcess();
  return new OSProcessHandler(process, commandLine.getCommandLineString(), charset);
}
 
Example 19
Source File: BuckCommandHandler.java    From Buck-IntelliJ-Plugin with Apache License 2.0 4 votes vote down vote up
public ProcessHandler createProcess(GeneralCommandLine commandLine)
    throws ExecutionException {
  Process process = commandLine.createProcess();
  return new MyOSProcessHandler(process, commandLine, getCharset());
}
 
Example 20
Source File: OCamlApplicationRunningState.java    From reasonml-idea-plugin with MIT License 4 votes vote down vote up
@NotNull
@Override
protected ProcessHandler startProcess() throws ExecutionException {
    GeneralCommandLine commandLine = getCommand();
    return new OSProcessHandler(commandLine.createProcess(), commandLine.getCommandLineString());
}