Java Code Examples for com.intellij.execution.process.ProcessOutput#checkSuccess()
The following examples show how to use
com.intellij.execution.process.ProcessOutput#checkSuccess() .
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: PantsCompileOptionsExecutor.java From intellij-pants-plugin with Apache License 2.0 | 6 votes |
@NotNull private static String loadProjectStructureFromScript( @NotNull String scriptPath, @NotNull Consumer<String> statusConsumer, @Nullable ProcessAdapter processAdapter ) throws IOException, ExecutionException { final GeneralCommandLine commandLine = PantsUtil.defaultCommandLine(scriptPath); commandLine.setExePath(scriptPath); statusConsumer.consume("Executing " + PathUtil.getFileName(scriptPath)); final ProcessOutput processOutput = PantsUtil.getCmdOutput(commandLine, processAdapter); if (processOutput.checkSuccess(LOG)) { return processOutput.getStdout(); } else { throw new PantsExecutionException("Failed to update the project!", scriptPath, processOutput); } }
Example 2
Source File: PantsCompileOptionsExecutor.java From intellij-pants-plugin with Apache License 2.0 | 6 votes |
@NotNull private String loadProjectStructureFromTargets( @NotNull Consumer<String> statusConsumer, @Nullable ProcessAdapter processAdapter ) throws IOException, ExecutionException { final File outputFile = FileUtil.createTempFile("pants_depmap_run", ".out"); final GeneralCommandLine command = getPantsExportCommand(outputFile, statusConsumer); statusConsumer.consume("Resolving dependencies..."); PantsMetrics.markExportStart(); final ProcessOutput processOutput = getProcessOutput(command); PantsMetrics.markExportEnd(); if (processOutput.getStdout().contains("no such option")) { throw new ExternalSystemException("Pants doesn't have necessary APIs. Please upgrade your pants!"); } if (processOutput.checkSuccess(LOG)) { return FileUtil.loadFile(outputFile); } else { throw new PantsExecutionException("Failed to update the project!", command.getCommandLineString("pants"), processOutput); } }
Example 3
Source File: SimpleExportResult.java From intellij-pants-plugin with Apache License 2.0 | 6 votes |
@NotNull public static SimpleExportResult getExportResult(@NotNull String pantsExecutable) { File pantsExecutableFile = new File(pantsExecutable); SimpleExportResult cache = simpleExportCache.get(pantsExecutableFile); if (cache != null) { return cache; } final GeneralCommandLine commandline = PantsUtil.defaultCommandLine(pantsExecutable); commandline.addParameters("--no-quiet", "export", PantsConstants.PANTS_CLI_OPTION_NO_COLORS); try (TempFile tempFile = TempFile.create("pants_export_run", ".out")) { commandline.addParameter( String.format("%s=%s", PantsConstants.PANTS_CLI_OPTION_EXPORT_OUTPUT_FILE, tempFile.getFile().getPath())); final ProcessOutput processOutput = PantsUtil.getCmdOutput(commandline, null); if (processOutput.checkSuccess(LOG)) { SimpleExportResult result = parse(FileUtil.loadFile(tempFile.getFile())); simpleExportCache.put(pantsExecutableFile, result); return result; } } catch (IOException | ExecutionException e) { // Fall-through to handle outside the block. } throw new PantsException("Failed:" + commandline.getCommandLineString()); }
Example 4
Source File: SourceJarGenerator.java From intellij-pants-plugin with Apache License 2.0 | 4 votes |
private static List<String> getSourcesForTarget(Project project, String targetAddress) { GeneralCommandLine cmd = PantsUtil.defaultCommandLine(project); try { cmd.addParameters("filemap", targetAddress); final ProcessOutput processOutput = PantsUtil.getCmdOutput(cmd, null); if (processOutput.checkSuccess(LOG)) { String stdout = processOutput.getStdout(); return Arrays.stream(stdout.split("\n")) .map(String::trim) .filter(s -> !s.isEmpty()) .map(line -> line.split("\\s+")) .filter(s -> targetAddress.equals(s[1])) .map(s -> s[0]) .collect(Collectors.toList()); } else { List<String> errorLogs = Lists.newArrayList( String.format( "Could not list sources for target: Pants exited with status %d", processOutput.getExitCode() ), String.format("argv: '%s'", cmd.getCommandLineString()), "stdout:", processOutput.getStdout(), "stderr:", processOutput.getStderr() ); final String errorMessage = String.join("\n", errorLogs); LOG.warn(errorMessage); throw new PantsException(errorMessage); } } catch (ExecutionException e) { final String processCreationFailureMessage = String.format( "Could not execute command: '%s' due to error: '%s'", cmd.getCommandLineString(), e.getMessage() ); LOG.warn(processCreationFailureMessage, e); throw new PantsException(processCreationFailureMessage); } }
Example 5
Source File: PantsUtil.java From intellij-pants-plugin with Apache License 2.0 | 4 votes |
public static Collection<String> listAllTargets(@NotNull String projectPath) throws PantsException { if (!PantsUtil.isBUILDFilePath(projectPath)) { return Lists.newArrayList(); } GeneralCommandLine cmd = PantsUtil.defaultCommandLine(projectPath); try (TempFile tempFile = TempFile.create("list", ".out")) { cmd.addParameters( "list", Paths.get(projectPath).getParent().toString() + ':', String.format("%s=%s", PantsConstants.PANTS_CLI_OPTION_LIST_OUTPUT_FILE, tempFile.getFile().getPath() ) ); final ProcessOutput processOutput = PantsUtil.getCmdOutput(cmd, null); if (processOutput.checkSuccess(LOG)) { // output only exists if "list" task succeeds final String output = FileUtil.loadFile(tempFile.getFile()); return Arrays.asList(output.split("\n")); } else { List<String> errorLogs = Lists.newArrayList( String.format( "Could not list targets: Pants exited with status %d", processOutput.getExitCode() ), String.format("argv: '%s'", cmd.getCommandLineString()), "stdout:", processOutput.getStdout(), "stderr:", processOutput.getStderr() ); final String errorMessage = String.join("\n", errorLogs); LOG.warn(errorMessage); throw new PantsException(errorMessage); } } catch (IOException | ExecutionException e) { final String processCreationFailureMessage = String.format( "Could not execute command: '%s' due to error: '%s'", cmd.getCommandLineString(), e.getMessage() ); LOG.warn(processCreationFailureMessage, e); throw new PantsException(processCreationFailureMessage); } }