use of com.intellij.execution.configurations.GeneralCommandLine in project intellij-community by JetBrains.
the class Tool method execute.
public void execute(AnActionEvent event, DataContext dataContext, long executionId, @Nullable final ProcessListener processListener) {
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
if (project == null) {
return;
}
FileDocumentManager.getInstance().saveAllDocuments();
try {
if (isUseConsole()) {
ExecutionEnvironment environment = ExecutionEnvironmentBuilder.create(project, DefaultRunExecutor.getRunExecutorInstance(), new ToolRunProfile(this, dataContext)).build();
environment.setExecutionId(executionId);
environment.getRunner().execute(environment, new ProgramRunner.Callback() {
@Override
public void processStarted(RunContentDescriptor descriptor) {
ProcessHandler processHandler = descriptor.getProcessHandler();
if (processHandler != null && processListener != null) {
LOG.assertTrue(!processHandler.isStartNotified(), "ProcessHandler is already startNotified, the listener won't be correctly notified");
processHandler.addProcessListener(processListener);
}
}
});
} else {
GeneralCommandLine commandLine = createCommandLine(dataContext);
if (commandLine == null) {
return;
}
OSProcessHandler handler = new OSProcessHandler(commandLine);
handler.addProcessListener(new ToolProcessAdapter(project, synchronizeAfterExecution(), getName()));
if (processListener != null) {
handler.addProcessListener(processListener);
}
handler.startNotify();
}
} catch (ExecutionException ex) {
ExecutionErrorDialog.show(ex, ToolsBundle.message("tools.process.start.error"), project);
}
}
use of com.intellij.execution.configurations.GeneralCommandLine in project intellij-community by JetBrains.
the class ToolRunProfile method getState.
@Override
public RunProfileState getState(@NotNull final Executor executor, @NotNull final ExecutionEnvironment env) {
final Project project = env.getProject();
if (myCommandLine == null) {
// can return null if creation of cmd line has been cancelled
return null;
}
final CommandLineState commandLineState = new CommandLineState(env) {
GeneralCommandLine createCommandLine() {
return myCommandLine;
}
@Override
@NotNull
protected OSProcessHandler startProcess() throws ExecutionException {
final GeneralCommandLine commandLine = createCommandLine();
final OSProcessHandler processHandler = new ColoredProcessHandler(commandLine);
ProcessTerminatedListener.attach(processHandler);
return processHandler;
}
@Override
@NotNull
public ExecutionResult execute(@NotNull final Executor executor, @NotNull ProgramRunner runner) throws ExecutionException {
final ExecutionResult result = super.execute(executor, runner);
final ProcessHandler processHandler = result.getProcessHandler();
if (processHandler != null) {
processHandler.addProcessListener(new ToolProcessAdapter(project, myTool.synchronizeAfterExecution(), getName()));
processHandler.addProcessListener(new ProcessAdapter() {
@Override
public void onTextAvailable(ProcessEvent event, Key outputType) {
if ((outputType == ProcessOutputTypes.STDOUT && myTool.isShowConsoleOnStdOut()) || (outputType == ProcessOutputTypes.STDERR && myTool.isShowConsoleOnStdErr())) {
ExecutionManager.getInstance(project).getContentManager().toFrontRunContent(executor, processHandler);
}
}
});
}
return result;
}
};
TextConsoleBuilder builder = TextConsoleBuilderFactory.getInstance().createBuilder(project);
final FilterInfo[] outputFilters = myTool.getOutputFilters();
for (FilterInfo outputFilter : outputFilters) {
builder.addFilter(new RegexpFilter(project, outputFilter.getRegExp()));
}
commandLineState.setConsoleBuilder(builder);
return commandLineState;
}
use of com.intellij.execution.configurations.GeneralCommandLine in project intellij-community by JetBrains.
the class BrowserLauncherAppless method doLaunch.
private boolean doLaunch(@Nullable String url, @NotNull List<String> command, @Nullable WebBrowser browser, @Nullable Project project, @NotNull String[] additionalParameters, @Nullable Runnable launchTask) {
GeneralCommandLine commandLine = new GeneralCommandLine(command);
if (url != null && url.startsWith("jar:")) {
return false;
}
if (url != null) {
commandLine.addParameter(url);
}
final BrowserSpecificSettings browserSpecificSettings = browser == null ? null : browser.getSpecificSettings();
if (browserSpecificSettings != null) {
commandLine.getEnvironment().putAll(browserSpecificSettings.getEnvironmentVariables());
}
addArgs(commandLine, browserSpecificSettings, additionalParameters);
try {
Process process = commandLine.createProcess();
checkCreatedProcess(browser, project, commandLine, process, launchTask);
return true;
} catch (ExecutionException e) {
showError(e.getMessage(), browser, project, null, null);
return false;
}
}
use of com.intellij.execution.configurations.GeneralCommandLine in project intellij-community by JetBrains.
the class EnvironmentVariablesTextFieldWithBrowseButton method showParentEnvironmentDialog.
public static void showParentEnvironmentDialog(@NotNull Component parent) {
EnvVariablesTable table = new EnvVariablesTable();
table.setValues(convertToVariables(new TreeMap<>(new GeneralCommandLine().getParentEnvironment()), true));
table.getActionsPanel().setVisible(false);
DialogBuilder builder = new DialogBuilder(parent);
builder.setTitle(ExecutionBundle.message("environment.variables.system.dialog.title"));
builder.centerPanel(table.getComponent());
builder.addCloseButton();
builder.show();
}
use of com.intellij.execution.configurations.GeneralCommandLine in project intellij-community by JetBrains.
the class ExecUtil method sudoCommand.
@NotNull
private static GeneralCommandLine sudoCommand(@NotNull GeneralCommandLine commandLine, @NotNull String prompt) throws ExecutionException, IOException {
if (SystemInfo.isUnix && "root".equals(System.getenv("USER"))) {
return commandLine;
}
List<String> command = ContainerUtil.newArrayList();
command.add(commandLine.getExePath());
command.addAll(commandLine.getParametersList().getList());
GeneralCommandLine sudoCommandLine;
if (SystemInfo.isMac) {
String escapedCommandLine = StringUtil.join(command, ExecUtil::escapeAppleScriptArgument, " & \" \" & ");
String escapedScript = "tell current application\n" + " activate\n" + " do shell script " + escapedCommandLine + " with administrator privileges without altering line endings\n" + "end tell";
sudoCommandLine = new GeneralCommandLine(getOsascriptPath(), "-e", escapedScript);
} else if (hasGkSudo.getValue()) {
List<String> sudoCommand = ContainerUtil.newArrayList();
sudoCommand.addAll(Arrays.asList("gksudo", "--message", prompt, "--"));
sudoCommand.addAll(command);
sudoCommandLine = new GeneralCommandLine(sudoCommand);
} else if (hasKdeSudo.getValue()) {
List<String> sudoCommand = ContainerUtil.newArrayList();
sudoCommand.addAll(Arrays.asList("kdesudo", "--comment", prompt, "--"));
sudoCommand.addAll(command);
sudoCommandLine = new GeneralCommandLine(sudoCommand);
} else if (hasPkExec.getValue()) {
command.add(0, "pkexec");
sudoCommandLine = new GeneralCommandLine(command);
} else if (SystemInfo.isUnix && hasTerminalApp()) {
String escapedCommandLine = StringUtil.join(command, ExecUtil::escapeUnixShellArgument, " ");
File script = createTempExecutableScript("sudo", ".sh", "#!/bin/sh\n" + "echo " + escapeUnixShellArgument(prompt) + "\n" + "echo\n" + "sudo -- " + escapedCommandLine + "\n" + "STATUS=$?\n" + "echo\n" + "read -p \"Press Enter to close this window...\" TEMP\n" + "exit $STATUS\n");
sudoCommandLine = new GeneralCommandLine(getTerminalCommand("Install", script.getAbsolutePath()));
} else {
throw new UnsupportedOperationException("Unsupported OS/desktop: " + SystemInfo.OS_NAME + '/' + SystemInfo.SUN_DESKTOP);
}
return sudoCommandLine.withWorkDirectory(commandLine.getWorkDirectory()).withEnvironment(commandLine.getEnvironment()).withParentEnvironmentType(commandLine.getParentEnvironmentType()).withRedirectErrorStream(commandLine.isRedirectErrorStream());
}
Aggregations