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);
  }
Exemplo n.º 2
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;
  }
 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());
 }
 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;
 }
  @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());
  }
  @NotNull
  public static TestsOutput getTestsOutput(
      @NotNull final ProcessOutput processOutput, final boolean isAdaptive) {
    String congratulations = CONGRATULATIONS;
    final List<String> lines = processOutput.getStdoutLines();
    for (int i = 0; i < lines.size(); i++) {
      final String line = lines.get(i);
      if (line.startsWith(STUDY_PREFIX)) {
        if (line.contains(TEST_OK)) {
          continue;
        }

        if (line.contains(CONGRATS_MESSAGE)) {
          congratulations =
              line.substring(line.indexOf(CONGRATS_MESSAGE) + CONGRATS_MESSAGE.length());
        }

        if (line.contains(TEST_FAILED)) {
          if (!isAdaptive) {
            return new TestsOutput(
                false, line.substring(line.indexOf(TEST_FAILED) + TEST_FAILED.length()));
          } else {
            final StringBuilder builder =
                new StringBuilder(
                    line.substring(line.indexOf(TEST_FAILED) + TEST_FAILED.length()) + "\n");
            for (int j = i + 1; j < lines.size(); j++) {
              final String failedTextLine = lines.get(j);
              if (!failedTextLine.contains(STUDY_PREFIX)
                  || !failedTextLine.contains(CONGRATS_MESSAGE)) {
                builder.append(failedTextLine);
                builder.append("\n");
              } else {
                break;
              }
            }
            return new TestsOutput(false, builder.toString());
          }
        }
      }
    }

    return new TestsOutput(true, congratulations);
  }
  @NotNull
  @Override
  protected ProcessOutput getPythonProcessOutput(
      @NotNull String helperPath,
      @NotNull List<String> args,
      boolean askForSudo,
      boolean showProgress,
      @Nullable final String workingDir)
      throws ExecutionException {
    final Sdk sdk = getSdk();
    final String homePath = sdk.getHomePath();
    if (homePath == null) {
      throw new ExecutionException("Cannot find Python interpreter for SDK " + sdk.getName());
    }
    final SdkAdditionalData sdkData = sdk.getSdkAdditionalData();
    if (sdkData instanceof PyRemoteSdkAdditionalDataBase) { // remote interpreter
      final PythonRemoteInterpreterManager manager = PythonRemoteInterpreterManager.getInstance();

      RemoteSdkCredentials remoteSdkCredentials;
      if (CaseCollector.useRemoteCredentials((PyRemoteSdkAdditionalDataBase) sdkData)) {
        try {
          remoteSdkCredentials = ((RemoteSdkAdditionalData) sdkData).getRemoteSdkCredentials(false);
        } catch (InterruptedException e) {
          LOG.error(e);
          remoteSdkCredentials = null;
        } catch (ExecutionException e) {
          throw analyzeException(e, helperPath, args);
        }
        if (manager != null && remoteSdkCredentials != null) {
          if (askForSudo) {
            askForSudo =
                !manager.ensureCanWrite(
                    null, remoteSdkCredentials, remoteSdkCredentials.getInterpreterPath());
          }
        } else {
          throw new PyExecutionException(
              PythonRemoteInterpreterManager.WEB_DEPLOYMENT_PLUGIN_IS_DISABLED, helperPath, args);
        }
      }

      if (manager != null) {
        final List<String> cmdline = new ArrayList<String>();
        cmdline.add(homePath);
        cmdline.add(RemoteFile.detectSystemByPath(homePath).createRemoteFile(helperPath).getPath());
        cmdline.addAll(
            Collections2.transform(
                args,
                new Function<String, String>() {
                  @Override
                  public String apply(@Nullable String input) {
                    return quoteIfNeeded(input);
                  }
                }));
        ProcessOutput processOutput;
        do {
          final PyRemoteSdkAdditionalDataBase remoteSdkAdditionalData =
              (PyRemoteSdkAdditionalDataBase) sdkData;
          final PyRemotePathMapper pathMapper =
              manager.setupMappings(null, remoteSdkAdditionalData, null);
          try {
            processOutput =
                PyRemoteProcessStarterManagerUtil.getManager(remoteSdkAdditionalData)
                    .executeRemoteProcess(
                        null,
                        ArrayUtil.toStringArray(cmdline),
                        workingDir,
                        manager,
                        remoteSdkAdditionalData,
                        pathMapper,
                        askForSudo,
                        true);
          } catch (InterruptedException e) {
            throw new ExecutionException(e);
          }
          if (askForSudo
              && processOutput.getStderr().contains("sudo: 3 incorrect password attempts")) {
            continue;
          }
          break;
        } while (true);
        return processOutput;
      } else {
        throw new PyExecutionException(
            PythonRemoteInterpreterManager.WEB_DEPLOYMENT_PLUGIN_IS_DISABLED, helperPath, args);
      }
    } else {
      throw new PyExecutionException("Invalid remote SDK", helperPath, args);
    }
  }
 private int determineNumberOfIncomingChanges(File repo) throws IOException {
   ProcessOutput result = runHg(repo, "-q", "incoming", "--template", "{rev} ");
   String output = result.getStdout();
   return output.length() == 0 ? 0 : output.split(" ").length;
 }
 public int getExitValue() {
   return myProcessOutput.getExitCode();
 }
Exemplo n.º 10
0
 @NotNull
 public String getRawError() {
   return myProcessOutput.getStderr();
 }
Exemplo n.º 11
0
 @NotNull
 public String getRawOutput() {
   return myProcessOutput.getStdout();
 }
Exemplo n.º 12
0
 @NotNull
 public List<String> getErrorLines() {
   return myProcessOutput.getStderrLines();
 }
Exemplo n.º 13
0
 @NotNull
 public List<String> getOutputLines() {
   return myProcessOutput.getStdoutLines();
 }