use of com.intellij.execution.configurations.GeneralCommandLine in project jscs-plugin by idok.
the class JscsRunner method lint.
public static LintResult lint(@NotNull JscsSettings settings) {
LintResult result = new LintResult();
try {
GeneralCommandLine commandLine = createCommandLineLint(settings);
ProcessOutput out = execute(commandLine, TIME_OUT);
// if (out.getExitCode() == 0) {
// } else {
result.errorOutput = out.getStderr();
try {
result.jscsLint = JscsLint.read(out.getStdout());
} catch (Exception e) {
//result.errorOutput = out.getStdout();
}
// }
} catch (Exception e) {
e.printStackTrace();
result.errorOutput = e.toString();
}
return result;
}
use of com.intellij.execution.configurations.GeneralCommandLine in project freeline by alibaba.
the class FreelineUtil method build.
public static void build(Project project) {
GeneralCommandLine commandLine = new GeneralCommandLine();
commandLine.setWorkDirectory(project.getBasePath());
commandLine.setExePath("python");
commandLine.addParameter("freeline.py");
// debug
commandLine.addParameter("-d");
// commands process
try {
processCommandline(project, commandLine);
} catch (ExecutionException e) {
e.printStackTrace();
}
}
use of com.intellij.execution.configurations.GeneralCommandLine in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoExecutor method execute.
public boolean execute() {
Logger.getInstance(getClass()).assertTrue(!ApplicationManager.getApplication().isDispatchThread(), "It's bad idea to run external tool on EDT");
Logger.getInstance(getClass()).assertTrue(myProcessHandler == null, "Process has already run with this executor instance");
Ref<Boolean> result = Ref.create(false);
GeneralCommandLine commandLine = null;
try {
commandLine = createCommandLine();
GeneralCommandLine finalCommandLine = commandLine;
myProcessHandler = new KillableColoredProcessHandler(finalCommandLine, true) {
@Override
public void startNotify() {
if (myShowGoEnvVariables) {
GoRunUtil.printGoEnvVariables(finalCommandLine, this);
}
super.startNotify();
}
};
GoHistoryProcessListener historyProcessListener = new GoHistoryProcessListener();
myProcessHandler.addProcessListener(historyProcessListener);
for (ProcessListener listener : myProcessListeners) {
myProcessHandler.addProcessListener(listener);
}
CapturingProcessAdapter processAdapter = new CapturingProcessAdapter(myProcessOutput) {
@Override
public void processTerminated(@NotNull ProcessEvent event) {
super.processTerminated(event);
boolean success = event.getExitCode() == 0 && myProcessOutput.getStderr().isEmpty();
boolean nothingToShow = myProcessOutput.getStdout().isEmpty() && myProcessOutput.getStderr().isEmpty();
boolean cancelledByUser = (event.getExitCode() == -1 || event.getExitCode() == 2) && nothingToShow;
result.set(success);
if (success) {
if (myShowNotificationsOnSuccess) {
showNotification("Finished successfully", NotificationType.INFORMATION);
}
} else if (cancelledByUser) {
if (myShowNotificationsOnError) {
showNotification("Interrupted", NotificationType.WARNING);
}
} else if (myShowOutputOnError) {
ApplicationManager.getApplication().invokeLater(() -> showOutput(myProcessHandler, historyProcessListener));
}
}
};
myProcessHandler.addProcessListener(processAdapter);
myProcessHandler.startNotify();
ExecutionModes.SameThreadMode sameThreadMode = new ExecutionModes.SameThreadMode(getPresentableName());
ExecutionHelper.executeExternalProcess(myProject, myProcessHandler, sameThreadMode, commandLine);
LOGGER.debug("Finished `" + getPresentableName() + "` with result: " + result.get());
return result.get();
} catch (ExecutionException e) {
if (myShowOutputOnError) {
ExecutionHelper.showErrors(myProject, Collections.singletonList(e), getPresentableName(), null);
}
if (myShowNotificationsOnError) {
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;
}
}
use of com.intellij.execution.configurations.GeneralCommandLine in project intellij-elixir by KronicDeth.
the class MixBuilder method runMix.
private static void runMix(@NotNull String elixirPath, @NotNull String mixPath, @Nullable String contentRootPath, boolean addDebugInfo, @NotNull CompileContext context) throws ProjectBuildException {
GeneralCommandLine commandLine = new GeneralCommandLine();
commandLine.withWorkDirectory(contentRootPath);
commandLine.setExePath(elixirPath);
commandLine.addParameter(mixPath);
commandLine.addParameter("compile");
if (!addDebugInfo) {
commandLine.addParameter("--no-debug-info");
}
Process process;
try {
process = commandLine.createProcess();
} catch (ExecutionException e) {
throw new ProjectBuildException("Failed to run mix.", e);
}
BaseOSProcessHandler handler = new BaseOSProcessHandler(process, commandLine.getCommandLineString(), Charset.defaultCharset());
ProcessAdapter adapter = new ElixirCompilerProcessAdapter(context, NAME, commandLine.getWorkDirectory().getPath());
handler.addProcessListener(adapter);
handler.startNotify();
handler.waitFor();
}
use of com.intellij.execution.configurations.GeneralCommandLine in project intellij-elixir by KronicDeth.
the class ExtProcessUtil method execAndGetFirstLine.
@NotNull
public static ExtProcessOutput execAndGetFirstLine(long timeout, @NotNull String... command) {
try {
final Process cmdRunner = new GeneralCommandLine(command).createProcess();
ExecutorService singleTreadExecutor = Executors.newSingleThreadExecutor();
try {
Future<ExtProcessOutput> cmdRunnerFuture = singleTreadExecutor.submit(new Callable<ExtProcessOutput>() {
@Override
public ExtProcessOutput call() throws Exception {
cmdRunner.waitFor();
String stdOut = readLine(cmdRunner.getInputStream());
String stdErr = readLine(cmdRunner.getErrorStream());
return new ExtProcessOutput(stdOut, stdErr);
}
});
try {
return cmdRunnerFuture.get(timeout, TimeUnit.MILLISECONDS);
} catch (Exception e) {
// Suppress
}
cmdRunnerFuture.cancel(true);
} finally {
singleTreadExecutor.shutdown();
}
} catch (ExecutionException e) {
// Suppress
}
return new ExtProcessOutput("", "");
}
Aggregations