public void testPantsIdeaPluginGoal() throws Throwable {
    assertEmpty(ModuleManager.getInstance(myProject).getModules());

    /** Check whether Pants supports `idea-plugin` goal. */
    PantsUtil.findPantsExecutable(getProjectFolder().getPath());
    final GeneralCommandLine commandLinePantsGoals =
        PantsUtil.defaultCommandLine(getProjectFolder().getPath());
    commandLinePantsGoals.addParameter("goals");
    final ProcessOutput cmdOutputGoals =
        PantsUtil.getCmdOutput(commandLinePantsGoals.withWorkDirectory(getProjectFolder()), null);
    assertEquals(commandLinePantsGoals.toString() + " failed", 0, cmdOutputGoals.getExitCode());
    if (!cmdOutputGoals.getStdout().contains("idea-plugin")) {
      return;
    }

    /** Generate idea project via `idea-plugin` goal. */
    final GeneralCommandLine commandLine =
        PantsUtil.defaultCommandLine(getProjectFolder().getPath());
    final File outputFile = FileUtil.createTempFile("project_dir_location", ".out");
    commandLine.addParameters(
        "idea-plugin",
        "--no-open",
        "--output-file=" + outputFile.getPath(),
        "testprojects/tests/java/org/pantsbuild/testproject/::");
    final ProcessOutput cmdOutput =
        PantsUtil.getCmdOutput(commandLine.withWorkDirectory(getProjectFolder()), null);
    assertEquals(commandLine.toString() + " failed", 0, cmdOutput.getExitCode());
    String projectDir = FileUtil.loadFile(outputFile);

    myProject = ProjectUtil.openProject(projectDir + "/project.ipr", myProject, false);
    // Invoke post startup activities.
    UIUtil.dispatchAllInvocationEvents();
    /**
     * Under unit test mode, {@link com.intellij.ide.impl.ProjectUtil#openProject} will force open a
     * project in a new window, so Project SDK has to be reset. In practice, this is not needed.
     */
    ApplicationManager.getApplication()
        .runWriteAction(
            new Runnable() {
              @Override
              public void run() {
                final JavaSdk javaSdk = JavaSdk.getInstance();
                ProjectRootManager.getInstance(myProject)
                    .setProjectSdk(
                        ProjectJdkTable.getInstance().getSdksOfType(javaSdk).iterator().next());
              }
            });

    JUnitConfiguration runConfiguration =
        generateJUnitConfiguration(
            "testprojects_tests_java_org_pantsbuild_testproject_matcher_matcher",
            "org.pantsbuild.testproject.matcher.MatcherTest",
            null);

    assertAndRunPantsMake(runConfiguration);
    assertSuccessfulJUnitTest(runConfiguration);
  }
  @NotNull
  private static Version parseVersion(@NotNull ProcessOutput output) throws VcsException {
    if (output.isTimeout() || (output.getExitCode() != 0) || !output.getStderr().isEmpty()) {
      throw new VcsException(
          String.format(
              "Exit code: %d, Error: %s, Timeout: %b",
              output.getExitCode(), output.getStderr(), output.isTimeout()));
    }

    return parseVersion(output.getStdout());
  }
 public PyExecutionException(
     @NotNull String message,
     @NotNull String command,
     @NotNull List<String> args,
     @NotNull ProcessOutput output) {
   this(
       message,
       command,
       args,
       output.getStdout(),
       output.getStderr(),
       output.getExitCode(),
       Collections.<PyExecutionFix>emptyList());
 }
Exemplo n.º 4
0
  public static boolean checkMongoShellPath(String mongoShellPath) throws ExecutionException {
    if (isBlank(mongoShellPath)) {
      return false;
    }

    GeneralCommandLine commandLine = new GeneralCommandLine();
    commandLine.setExePath(mongoShellPath);
    commandLine.addParameter("--version");
    CapturingProcessHandler handler =
        new CapturingProcessHandler(
            commandLine.createProcess(), CharsetToolkit.getDefaultSystemCharset());
    ProcessOutput result = handler.runProcess(15 * 1000);
    return result.getExitCode() == 0;
  }
 private boolean generateSkeletonsForList(
     @NotNull final PySkeletonRefresher refresher,
     ProgressIndicator indicator,
     @Nullable final String currentBinaryFilesPath)
     throws InvalidSdkException {
   final PySkeletonGenerator generator =
       new PySkeletonGenerator(refresher.getSkeletonsPath(), mySdk, currentBinaryFilesPath);
   indicator.setIndeterminate(false);
   final String homePath = mySdk.getHomePath();
   if (homePath == null) return false;
   final ProcessOutput runResult =
       PySdkUtil.getProcessOutput(
           new File(homePath).getParent(),
           new String[] {
             homePath, PythonHelpersLocator.getHelperPath("extra_syspath.py"), myQualifiedName
           },
           PythonSdkType.getVirtualEnvExtraEnv(homePath),
           5000);
   if (runResult.getExitCode() == 0 && !runResult.isTimeout()) {
     final String extraPath = runResult.getStdout();
     final PySkeletonGenerator.ListBinariesResult binaries =
         generator.listBinaries(mySdk, extraPath);
     final List<String> names = Lists.newArrayList(binaries.modules.keySet());
     Collections.sort(names);
     final int size = names.size();
     for (int i = 0; i != size; ++i) {
       final String name = names.get(i);
       indicator.setFraction((double) i / size);
       if (needBinaryList(name)) {
         indicator.setText2(name);
         final PySkeletonRefresher.PyBinaryItem item = binaries.modules.get(name);
         final String modulePath = item != null ? item.getPath() : "";
         //noinspection unchecked
         refresher.generateSkeleton(
             name, modulePath, new ArrayList<String>(), Consumer.EMPTY_CONSUMER);
       }
     }
   }
   return true;
 }
 public int getExitValue() {
   return myProcessOutput.getExitCode();
 }