showNotification(StringUtil.notNullize(e.getMessage(), "Unknown error, see logs for details"), NotificationType.ERROR); String commandLineInfo = commandLine != null ? commandLine.getCommandLineString() : "not constructed"; LOGGER.debug("Finished `" + getPresentableName() + "` with an exception. Commandline: " + commandLineInfo, e); return false;
NotificationType.ERROR); String commandLineInfo = commandLine != null ? commandLine.getCommandLineString() : "not constructed"; LOGGER.debug("Finished `" + getPresentableName() + "` with an exception. Commandline: " + commandLineInfo, e);
@Nullable @Override protected Process createProcess() throws ExecutionException { String shellPath = MongoConfiguration.getInstance(getProject()).getShellPath(); GeneralCommandLine commandLine = MongoUtils.buildCommandLine(shellPath, serverConfiguration, database); notifier.notifyInfo("Running " + commandLine.getCommandLineString()); return commandLine.createProcess(); }
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(), commandLine.getCommandLineString()); ProcessOutput result = handler.runProcess(15 * 1000); return result.getExitCode() == 0; }
@Test public void buildCommandeLine() { ServerConfiguration serverConfiguration = ServerConfiguration.byDefault(); serverConfiguration.setUsername("john.doe"); serverConfiguration.setPassword("secretPassword"); serverConfiguration.setAuthenticationDatabase("users"); serverConfiguration.setAuthenticationMechanism(AuthenticationMechanism.SCRAM_SHA_1); serverConfiguration.setShellWorkingDir("/tmp"); serverConfiguration.setShellArgumentsLine("--quiet --ipv6"); GeneralCommandLine commandLine = MongoUtils.buildCommandLine("/usr/bin/mongo", serverConfiguration, new MongoDatabase("mydatabase", new MongoServer(serverConfiguration))); assertThat(commandLine.getCommandLineString()) .isEqualTo("/usr/bin/mongo localhost:27017/mydatabase " + "--username john.doe --password secretPassword " + "--authenticationDatabase users --authenticationMechanism SCRAM-SHA-1 " + "--quiet --ipv6"); }
/** * Executes commandLine, optionally piping input to stdin, and return stdout. */ @Nullable public static String readCommandLine(@NotNull final GeneralCommandLine commandLine, @Nullable final String input) { String output = null; try { final Process process = commandLine.createProcess(); if (input != null) { final BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(process.getOutputStream())); writer.write(input); writer.flush(); writer.close(); } output = new CapturingProcessHandler(process, Charset.defaultCharset(), commandLine.getCommandLineString() ).runProcess().getStdout(); } catch (final ExecutionException e) { LOG.debug(e); } catch (final IOException e) { LOG.debug(e); } return output; }
private static void runBuildProcess(@NotNull CompileContext context, @NotNull GeneralCommandLine commandLine, @NotNull String path) throws ProjectBuildException { try { LOG.debug(commandLine.getCommandLineString()); final Process process = commandLine.createProcess(); BaseOSProcessHandler handler = new BaseOSProcessHandler(process, commandLine.getCommandLineString(), Charset.defaultCharset()); handler.addProcessListener(new ProcessAdapter() { @Override public void onTextAvailable(ProcessEvent event, Key outputType) { final String text = event.getText(); if (!StringUtil.isEmptyOrSpaces(text)) { CompilerMessage compilerMessage = compilerMessageFromOutputLine(text.trim()); context.processMessage(compilerMessage); } } }); handler.startNotify(); handler.waitFor(); } catch (ExecutionException e) { throw new ProjectBuildException(e.getMessage()); } }
cmd.createProcess(), Charset.defaultCharset(), cmd.getCommandLineString() ).runProcess();
@NotNull @Override protected ProcessHandler startProcess() throws ExecutionException { try { final GeneralCommandLine dubCommandLine = getExecutableCommandLine(config); return new OSProcessHandler(dubCommandLine.createProcess(), dubCommandLine.getCommandLineString()); } catch (final ExecutionException e) { final String message = e.getMessage(); final Project project = config.getProject(); final boolean isEmpty = message.equals("DUB executable is not specified"); final boolean notCorrect = message.startsWith("Cannot run program"); if (isEmpty || notCorrect) { Notifications.Bus.notify( new Notification("DUB run configuration", "DUB settings", "DUB executable is " + (isEmpty ? "not specified" : "not specified correctly") + "<br/><a href='configureDLanguageTools'>Configure</a> executable", NotificationType.ERROR, new DToolsNotificationListener(project)), project); } throw e; } }
@NotNull @Override public ProcessHandler startProcess() throws ExecutionException { try { final GeneralCommandLine appCommandLine = getExecutableCommandLine(config); return new OSProcessHandler(appCommandLine.createProcess(), appCommandLine.getCommandLineString()); } catch (final NoValidDlangSdkFound e) { throw new ExecutionException("No valid DMD SDK found!"); } catch (final ModuleNotFoundException e) { throw new ExecutionException("Run configuration has no module selected."); } catch (final ExecutionException e) { final String message = e.getMessage(); final boolean isEmpty = message.equals("Executable is not specified"); final boolean notCorrect = message.startsWith("Cannot run program"); if (isEmpty || notCorrect) { Notifications.Bus.notify( new Notification("D App run configuration", "D App settings", "D application executable path is " + (isEmpty ? "empty" : "not specified correctly") + "<br/><a href='configure'>Configure</a> output folder", NotificationType.ERROR), config.getProject()); } throw e; } }
public static Boolean isKnownGdb(String path) { try { GeneralCommandLine command = new GeneralCommandLine(); command.setExePath(path); command.addParameter("--version"); ProcessOutput output = new CapturingProcessHandler( command.createProcess(), Charset.defaultCharset(), command.getCommandLineString()).runProcess(); if (output.getExitCode() != 0) { LOG.error("gdb exited with invalid exit code: " + output.getExitCode()); return false; } String cmdOutput = output.getStdout(); return cmdOutput.contains("(GDB) 7.6") || cmdOutput.contains("(GDB) 7.4"); } catch (Exception e) { LOG.error("Exception while executing the process:", e); return false; } }
try { output = new CapturingProcessHandler(commandLine.createProcess(), Charset.defaultCharset(), commandLine.getCommandLineString()).runProcess(); } catch (final ExecutionException e) { LOG.info("Failed executing " + command);
public static Boolean isValidGdbPath(String path) { try { GeneralCommandLine command = new GeneralCommandLine(); command.setExePath(path); command.addParameter("--version"); ProcessOutput output = new CapturingProcessHandler( command.createProcess(), Charset.defaultCharset(), command.getCommandLineString()).runProcess(); if (output.getExitCode() != 0) { LOG.error("gdb exited with invalid exit code: " + output.getExitCode()); return false; } // TODO maybe we should warn the user that his GDB version is not the latest at time of writing (7.6.2) return output.getStdout().contains("GDB"); } catch (Exception e) { // LOG.error("Exception while executing the process:", e); return false; } } }
@NotNull @Override protected ProcessHandler startProcess() throws ExecutionException { try { final GeneralCommandLine cmd = getDmdCommandLine(config); final OSProcessHandler handler = new OSProcessHandler(cmd.createProcess(), cmd.getCommandLineString()); handler.addProcessListener(this); return handler; } catch (final NoValidDlangSdkFound e) { throw new ExecutionException("No valid DMD SDK found!"); } catch (final NoSourcesException e) { throw new ExecutionException("No D Language source files found in directory: " + e.getSourcesRoot()); } catch (final ModuleNotFoundException e) { throw new ExecutionException("Run configuration has no module selected."); } catch (final ExecutionException e) { final String message = e.getMessage(); final boolean isEmpty = message.equals("Executable is not specified"); final boolean notCorrect = message.startsWith("Cannot run program"); if (isEmpty || notCorrect) { Notifications.Bus.notify( new Notification("DMD run configuration", "DMD settings", "DMD executable path is " + (isEmpty ? "empty" : "not specified correctly") + "<br/><a href='configure'>Configure</a>", NotificationType.ERROR), config.getProject()); } throw e; } }
.withParameters(dmdParameters); LOG.debug(String.format("dmd command: %s", cmd.getCommandLineString())); return cmd; } else {
final OSProcessHandler process = new OSProcessHandler(cmd.createProcess(), cmd.getCommandLineString()); final DubInitListener listener = new DubInitListener(); process.addProcessListener(listener);
final OSProcessHandler process = new OSProcessHandler(commandLine.createProcess(), commandLine.getCommandLineString()); process.addProcessListener(new ProcessAdapter() { @Override
@NotNull private String processFile(final PsiFile file, final String dubPath) { final GeneralCommandLine cmd = new GeneralCommandLine() .withWorkDirectory(file.getProject().getBasePath()) .withExePath(dubPath) .withEnvironment("DFLAGS", "-o-") .withParameters("build", "--combined", "-q"); try { final String dubCommand = cmd.getCommandLineString(); final DubProcessListener listener = new DubProcessListener(); final OSProcessHandler process = new OSProcessHandler(cmd.createProcess(), dubCommand); process.addProcessListener(listener); process.startNotify(); process.waitFor(); return listener.getOutput(); } catch (final ExecutionException e) { LOG.warn("There was a problem running 'dub build --combined -q'", e); } return ""; }
final OSProcessHandler process = new OSProcessHandler(cmd.createProcess(), cmd.getCommandLineString()); process.addProcessListener(new ProcessAdapter() { @Override
GeneralCommandLine cmd = createCommandLine(); if (LOG.isDebugEnabled()) { LOG.debug("Running login sso command `" + cmd.getCommandLineString() + "`");