当前位置: 首页>>代码示例>>Java>>正文


Java CapturingProcessHandler.runProcess方法代码示例

本文整理汇总了Java中com.intellij.execution.process.CapturingProcessHandler.runProcess方法的典型用法代码示例。如果您正苦于以下问题:Java CapturingProcessHandler.runProcess方法的具体用法?Java CapturingProcessHandler.runProcess怎么用?Java CapturingProcessHandler.runProcess使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.execution.process.CapturingProcessHandler的用法示例。


在下文中一共展示了CapturingProcessHandler.runProcess方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doCheckExecutable

import com.intellij.execution.process.CapturingProcessHandler; //导入方法依赖的package包/类
protected static boolean doCheckExecutable(@NotNull String executable, @NotNull List<String> processParameters) {
  try {
    GeneralCommandLine commandLine = new GeneralCommandLine();
    commandLine.setExePath(executable);
    commandLine.addParameters(processParameters);
    CapturingProcessHandler handler = new CapturingProcessHandler(commandLine.createProcess(), CharsetToolkit.getDefaultSystemCharset());
    ProcessOutput result = handler.runProcess(TIMEOUT_MS);
    boolean timeout = result.isTimeout();
    int exitCode = result.getExitCode();
    String stderr = result.getStderr();
    if (timeout) {
      LOG.warn("Validation of " + executable + " failed with a timeout");
    }
    if (exitCode != 0) {
      LOG.warn("Validation of " + executable + " failed with a non-zero exit code: " + exitCode);
    }
    if (!stderr.isEmpty()) {
      LOG.warn("Validation of " + executable + " failed with a non-empty error output: " + stderr);
    }
    return !timeout && exitCode == 0 && stderr.isEmpty();
  }
  catch (Throwable t) {
    LOG.warn(t);
    return false;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:ExecutableValidator.java

示例2: addRepository

import com.intellij.execution.process.CapturingProcessHandler; //导入方法依赖的package包/类
@Override
public void addRepository(String repositoryUrl) {
  final String conda = PyCondaPackageService.getCondaExecutable();
  final ArrayList<String> parameters = Lists.newArrayList(conda, "config", "--add", "channels",  repositoryUrl, "--force");
  final GeneralCommandLine commandLine = new GeneralCommandLine(parameters);

  try {
    final Process process = commandLine.createProcess();
    final CapturingProcessHandler handler = new CapturingProcessHandler(process);
    final ProcessOutput result = handler.runProcess();
    final int exitCode = result.getExitCode();
    if (exitCode != 0) {
      final String message = StringUtil.isEmptyOrSpaces(result.getStdout()) && StringUtil.isEmptyOrSpaces(result.getStderr()) ?
                             "Permission denied" : "Non-zero exit code";
      LOG.warn("Failed to add repository " + message);
    }
    PyCondaPackageService.getInstance().addChannel(repositoryUrl);
  }
  catch (ExecutionException e) {
    LOG.warn("Failed to add repository");
  }

}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:PyCondaManagementService.java

示例3: removeRepository

import com.intellij.execution.process.CapturingProcessHandler; //导入方法依赖的package包/类
@Override
public void removeRepository(String repositoryUrl) {
  final String conda = PyCondaPackageService.getCondaExecutable();
  final ArrayList<String> parameters = Lists.newArrayList(conda, "config", "--remove", "channels", repositoryUrl, "--force");
  final GeneralCommandLine commandLine = new GeneralCommandLine(parameters);

  try {
    final Process process = commandLine.createProcess();
    final CapturingProcessHandler handler = new CapturingProcessHandler(process);
    final ProcessOutput result = handler.runProcess();
    final int exitCode = result.getExitCode();
    if (exitCode != 0) {
      final String message = StringUtil.isEmptyOrSpaces(result.getStdout()) && StringUtil.isEmptyOrSpaces(result.getStderr()) ?
                             "Permission denied" : "Non-zero exit code";
      LOG.warn("Failed to remove repository " + message);
    }
    PyCondaPackageService.getInstance().removeChannel(repositoryUrl);
  }
  catch (ExecutionException e) {
    LOG.warn("Failed to remove repository");
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:PyCondaManagementService.java

示例4: runJython

import com.intellij.execution.process.CapturingProcessHandler; //导入方法依赖的package包/类
public static ProcessOutput runJython(String workDir, String pythonPath, String... args) throws ExecutionException {
  final SimpleJavaSdkType sdkType = new SimpleJavaSdkType();
  final Sdk ideaJdk = sdkType.createJdk("tmp", SystemProperties.getJavaHome());
  SimpleJavaParameters parameters = new SimpleJavaParameters();
  parameters.setJdk(ideaJdk);
  parameters.setMainClass("org.python.util.jython");

  File jythonJar = new File(PythonHelpersLocator.getPythonCommunityPath(), "lib/jython.jar");
  parameters.getClassPath().add(jythonJar.getPath());

  parameters.getProgramParametersList().add("-Dpython.path=" + pythonPath + File.pathSeparator + workDir);
  parameters.getProgramParametersList().addAll(args);
  parameters.setWorkingDirectory(workDir);

  final GeneralCommandLine commandLine = JdkUtil.setupJVMCommandLine(sdkType.getVMExecutablePath(ideaJdk), parameters, false);
  final CapturingProcessHandler processHandler = new CapturingProcessHandler(commandLine.createProcess());
  return processHandler.runProcess();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:JythonUnitTestUtil.java

示例5: getModulesNamesFromPantsDependencies

import com.intellij.execution.process.CapturingProcessHandler; //导入方法依赖的package包/类
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()]);
}
 
开发者ID:pantsbuild,项目名称:intellij-pants-plugin,代码行数:25,代码来源:OSSPantsJavaExamplesIntegrationTest.java

示例6: getHelperOutput

import com.intellij.execution.process.CapturingProcessHandler; //导入方法依赖的package包/类
public static String getHelperOutput(String helper) {
  final String path = TheRInterpreterService.getInstance().getInterpreterPath();
  if (StringUtil.isEmptyOrSpaces(path)) {
    LOG.info("Path to interpreter didn't set");
    return null;
  }
  final String helperPath = TheRHelpersLocator.getHelperPath(helper);
  try {
    final Process process = new GeneralCommandLine(path, "--slave", "-f", helperPath).createProcess();
    final CapturingProcessHandler processHandler = new CapturingProcessHandler(process);
    final ProcessOutput output = processHandler.runProcess(5 * TheRPsiUtils.MINUTE);
    if (output.getExitCode() != 0) {
      LOG.error("Failed to run script. Exit code: " + output.getExitCode());
      LOG.error(output.getStderrLines());
    }
    return output.getStdout();
  }
  catch (ExecutionException e) {
    LOG.error(e.getMessage());
  }
  return null;
}
 
开发者ID:ktisha,项目名称:TheRPlugin,代码行数:23,代码来源:TheRPackagesUtil.java

示例7: uninstallPackage

import com.intellij.execution.process.CapturingProcessHandler; //导入方法依赖的package包/类
public static void uninstallPackage(List<InstalledPackage> repoPackage) throws ExecutionException {
  final String path = TheRInterpreterService.getInstance().getInterpreterPath();
  if (StringUtil.isEmptyOrSpaces(path)) {
    throw new ExecutionException("Please, specify path to the R executable.");
  }
  final ArrayList<String> arguments = Lists.newArrayList(path, "CMD", "REMOVE");
  for (InstalledPackage aRepoPackage : repoPackage) {
    arguments.add(aRepoPackage.getName());
  }
  final Process process = new GeneralCommandLine(arguments).createProcess();

  final CapturingProcessHandler processHandler = new CapturingProcessHandler(process);
  final ProcessOutput output = processHandler.runProcess(5 * TheRPsiUtils.MINUTE);
  if (output.getExitCode() != 0) {
    throw new TheRExecutionException("Can't remove package", StringUtil.join(arguments, " "), output.getStdout(),
                                     output.getStderr(), output.getExitCode());
  }
}
 
开发者ID:ktisha,项目名称:TheRPlugin,代码行数:19,代码来源:TheRPackagesUtil.java

示例8: runHelperWithArgs

import com.intellij.execution.process.CapturingProcessHandler; //导入方法依赖的package包/类
@Nullable
private static TheRRunResult runHelperWithArgs(@NotNull final String helper, @NotNull final String... args) {
  final String interpreterPath = TheRInterpreterService.getInstance().getInterpreterPath();
  if (StringUtil.isEmptyOrSpaces(interpreterPath)) {
    LOG.info("Path to interpreter didn't set");
    return null;
  }
  final ArrayList<String> command = Lists.newArrayList(interpreterPath, " --slave", "-f ", TheRHelpersLocator.getHelperPath(helper),
                                                       " --args");
  Collections.addAll(command, args);
  try {
    final Process process = new GeneralCommandLine(command).createProcess();
    final CapturingProcessHandler processHandler = new CapturingProcessHandler(process, null, StringUtil.join(command, " "));
    final ProcessOutput output = processHandler.runProcess(5 * TheRPsiUtils.MINUTE);
    if (output.getExitCode() != 0) {
      LOG.error("Failed to run script. Exit code: " + output.getExitCode());
      LOG.error(output.getStderrLines());
    }
    return new TheRRunResult(StringUtil.join(command, " "), output);
  }
  catch (ExecutionException e) {
    LOG.error(e.getMessage());
  }
  return null;
}
 
开发者ID:ktisha,项目名称:TheRPlugin,代码行数:26,代码来源:TheRPackagesUtil.java

示例9: getProcessOutput

import com.intellij.execution.process.CapturingProcessHandler; //导入方法依赖的package包/类
@Nullable
public static ProcessOutput getProcessOutput(@NotNull final String scriptText, @Nullable final String path) {
  if (path == null) {
    return null;
  }
  try {
    final Process process = Runtime.getRuntime().exec(path + " --slave -e " + scriptText);
    final CapturingProcessHandler processHandler = new CapturingProcessHandler(process);
    return processHandler.runProcess(5000);
  }
  catch (IOException e) {
    LOG.info("Failed to run R executable: \n" +
             "Interpreter path " + path + "\n" +
             "Exception occurred: " + e.getMessage());
  }
  return null;
}
 
开发者ID:ktisha,项目名称:TheRPlugin,代码行数:18,代码来源:TheRUtils.java

示例10: runSkeletonGeneration

import com.intellij.execution.process.CapturingProcessHandler; //导入方法依赖的package包/类
public static void runSkeletonGeneration() {
  final String path = TheRInterpreterService.getInstance().getInterpreterPath();
  if (StringUtil.isEmptyOrSpaces(path)) return;
  final String helperPath = TheRHelpersLocator.getHelperPath(R_GENERATOR);
  try {
    final String skeletonsPath = getSkeletonsPath(path);
    final File skeletonsDir = new File(skeletonsPath);
    if (!skeletonsDir.exists() && !skeletonsDir.mkdirs()) {
      LOG.error("Can't create skeleton dir " + String.valueOf(skeletonsPath));
    }
    final String commandLine = path + " --slave -f " + helperPath + " --args " + skeletonsPath;
    final Process process = Runtime.getRuntime().exec(commandLine);
    final CapturingProcessHandler processHandler = new CapturingProcessHandler(process, null, commandLine);
    final ProcessOutput output = processHandler.runProcess(MINUTE * 5);
    if (output.getExitCode() != 0) {
      LOG.error("Failed to generate skeletons. Exit code: " + output.getExitCode());
      LOG.error(output.getStderrLines());
    }
  }
  catch (IOException e) {
    LOG.error(e);
  }
}
 
开发者ID:ktisha,项目名称:TheRPlugin,代码行数:24,代码来源:TheRSkeletonGenerator.java

示例11: identifyVersion

import com.intellij.execution.process.CapturingProcessHandler; //导入方法依赖的package包/类
@NotNull
public static GitVersion identifyVersion(String gitExecutable) throws TimeoutException, ExecutionException, ParseException {
  GeneralCommandLine commandLine = new GeneralCommandLine();
  commandLine.setExePath(gitExecutable);
  commandLine.addParameter("--version");
  CapturingProcessHandler handler = new CapturingProcessHandler(commandLine.createProcess(), CharsetToolkit.getDefaultSystemCharset());
  ProcessOutput result = handler.runProcess(30 * 1000);
  if (result.isTimeout()) {
    throw new TimeoutException("Couldn't identify the version of Git - stopped by timeout.");
  }
  if (result.getExitCode() != 0 || !result.getStderr().isEmpty()) {
    LOG.info("getVersion exitCode=" + result.getExitCode() + " errors: " + result.getStderr());
    // anyway trying to parse
    try {
      parse(result.getStdout());
    } catch (ParseException pe) {
      throw new ExecutionException("Errors while executing git --version. exitCode=" + result.getExitCode() +
                                   " errors: " + result.getStderr());
    }
  }
  return parse(result.getStdout());
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:23,代码来源:GitVersion.java

示例12: isValid

import com.intellij.execution.process.CapturingProcessHandler; //导入方法依赖的package包/类
public static boolean isValid(@Nullable String executable) {
  try {
    if (StringUtil.isEmptyOrSpaces(executable)) {
      return false;
    }
    GeneralCommandLine commandLine = new GeneralCommandLine();
    //noinspection ConstantConditions
    commandLine.setExePath(executable);
    commandLine.addParameter("--version");
    commandLine.addParameter("-q");
    CapturingProcessHandler handler = new CapturingProcessHandler(commandLine.createProcess(), CharsetToolkit.getDefaultSystemCharset());
    ProcessOutput result = handler.runProcess(30 * 1000);
    return !result.isTimeout() && result.getStderr().isEmpty();
  }
  catch (Throwable e) {
    return false;
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:19,代码来源:HgUtil.java

示例13: runProcess

import com.intellij.execution.process.CapturingProcessHandler; //导入方法依赖的package包/类
private static ProcessOutput runProcess(@NotNull final GeneralCommandLine cl) throws ExecutionException {
  final CapturingProcessHandler handler = new CapturingProcessHandler(cl.createProcess(), Charset.forName("UTF-8"));
  final ProcessOutput result = handler.runProcess(20000);
  if (result.isTimeout()) {
    throw new ExecutionException("Process execution of [" + cl.getCommandLineString() + "] has timed out");
  }
  final String errorOutput = result.getStderr();
  if (!StringUtil.isEmptyOrSpaces(errorOutput)) {
    throw new ExecutionException(errorOutput);
  }
  return result;
}
 
开发者ID:JetBrains,项目名称:teamcity-powershell,代码行数:13,代码来源:DetectionRunner.java

示例14: getTestOutput

import com.intellij.execution.process.CapturingProcessHandler; //导入方法依赖的package包/类
public static StudyTestsOutputParser.TestsOutput getTestOutput(@NotNull Process testProcess,
                                                               @NotNull String commandLine,
                                                               boolean isAdaptive) {
  final CapturingProcessHandler handler = new CapturingProcessHandler(testProcess, null, commandLine);
  final ProcessOutput output = ProgressManager.getInstance().hasProgressIndicator() ? handler
    .runProcessWithProgressIndicator(ProgressManager.getInstance().getProgressIndicator()) :
                               handler.runProcess();
  final StudyTestsOutputParser.TestsOutput testsOutput = StudyTestsOutputParser.getTestsOutput(output, isAdaptive);
  String stderr = output.getStderr();
  if (!stderr.isEmpty() && output.getStdout().isEmpty()) {
    LOG.info("#educational " + stderr);
    return new StudyTestsOutputParser.TestsOutput(false, stderr);
  }
  return testsOutput;
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:16,代码来源:StudyCheckUtils.java

示例15: run

import com.intellij.execution.process.CapturingProcessHandler; //导入方法依赖的package包/类
@NotNull
protected static String run(@NotNull File workingDir, @NotNull List<String> params, boolean ignoreNonZeroExitCode)
  throws ExecutionException
{
  final ProcessBuilder builder = new ProcessBuilder().command(params);
  builder.directory(workingDir);
  builder.redirectErrorStream(true);
  Process clientProcess;
  try {
    clientProcess = builder.start();
  }
  catch (IOException e) {
    throw new RuntimeException(e);
  }

  CapturingProcessHandler handler = new CapturingProcessHandler(clientProcess, CharsetToolkit.getDefaultSystemCharset());
  ProcessOutput result = handler.runProcess(30 * 1000);
  if (result.isTimeout()) {
    throw new RuntimeException("Timeout waiting for the command execution. Command: " + StringUtil.join(params, " "));
  }

  String stdout = result.getStdout().trim();
  if (result.getExitCode() != 0) {
    if (ignoreNonZeroExitCode) {
      debug("{" + result.getExitCode() + "}");
    }
    debug(stdout);
    if (!ignoreNonZeroExitCode) {
      throw new ExecutionException(result.getExitCode(), stdout);
    }
  }
  else {
    debug(stdout);
  }
  return stdout;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:37,代码来源:Executor.java


注:本文中的com.intellij.execution.process.CapturingProcessHandler.runProcess方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。