use of com.intellij.execution.configurations.GeneralCommandLine in project intellij-community by JetBrains.
the class EditExternallyAction method actionPerformed.
public void actionPerformed(AnActionEvent e) {
Project project = e.getData(CommonDataKeys.PROJECT);
VirtualFile[] files = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
Options options = OptionsManager.getInstance().getOptions();
String executablePath = options.getExternalEditorOptions().getExecutablePath();
if (StringUtil.isEmpty(executablePath)) {
Messages.showErrorDialog(project, ImagesBundle.message("error.empty.external.editor.path"), ImagesBundle.message("error.title.empty.external.editor.path"));
ImagesConfigurable.show(project);
} else {
if (files != null) {
Map<String, String> env = EnvironmentUtil.getEnvironmentMap();
for (String varName : env.keySet()) {
if (SystemInfo.isWindows) {
executablePath = StringUtil.replace(executablePath, "%" + varName + "%", env.get(varName), true);
} else {
executablePath = StringUtil.replace(executablePath, "${" + varName + "}", env.get(varName), false);
}
}
executablePath = FileUtil.toSystemDependentName(executablePath);
File executable = new File(executablePath);
GeneralCommandLine commandLine = new GeneralCommandLine();
final String path = executable.exists() ? executable.getAbsolutePath() : executablePath;
if (SystemInfo.isMac) {
commandLine.setExePath(ExecUtil.getOpenCommandPath());
commandLine.addParameter("-a");
commandLine.addParameter(path);
} else {
commandLine.setExePath(path);
}
ImageFileTypeManager typeManager = ImageFileTypeManager.getInstance();
for (VirtualFile file : files) {
if (file.isInLocalFileSystem() && typeManager.isImage(file)) {
commandLine.addParameter(VfsUtilCore.virtualToIoFile(file).getAbsolutePath());
}
}
commandLine.setWorkDirectory(new File(executablePath).getParentFile());
try {
commandLine.createProcess();
} catch (ExecutionException ex) {
Messages.showErrorDialog(project, ex.getLocalizedMessage(), ImagesBundle.message("error.title.launching.external.editor"));
ImagesConfigurable.show(project);
}
}
}
}
use of com.intellij.execution.configurations.GeneralCommandLine in project intellij-elixir by KronicDeth.
the class ElixirSystemUtil method getProcessOutput.
@NotNull
public static ProcessOutput getProcessOutput(int timeout, @Nullable String workDir, @NotNull String exePath, @NotNull String... arguments) throws ExecutionException {
if (workDir == null || !new File(workDir).isDirectory() || !new File(exePath).canExecute()) {
return new ProcessOutput();
}
GeneralCommandLine cmd = new GeneralCommandLine();
cmd.withWorkDirectory(workDir);
cmd.setExePath(exePath);
cmd.addParameters(arguments);
return execute(cmd, timeout);
}
use of com.intellij.execution.configurations.GeneralCommandLine in project intellij-elixir by KronicDeth.
the class MixProjectRootStep method getMixPath.
/**
* private methods
* */
@NotNull
private static String getMixPath(@Nullable String directory) {
if (directory != null) {
File mix = new File(directory, "mix");
if (mix.exists() && mix.canExecute()) {
return mix.getPath();
}
}
String output = "";
GeneralCommandLine generalCommandLine = null;
if (SystemInfo.isWindows) {
generalCommandLine = new GeneralCommandLine("where");
generalCommandLine.addParameter("mix.bat");
} else if (SystemInfo.isMac || SystemInfo.isLinux || SystemInfo.isUnix) {
generalCommandLine = new GeneralCommandLine("which");
generalCommandLine.addParameter("mix");
}
if (generalCommandLine != null) {
try {
output = ScriptRunnerUtil.getProcessOutput(generalCommandLine);
} catch (Exception ignored) {
LOG.warn(ignored);
}
}
return output.trim();
}
use of com.intellij.execution.configurations.GeneralCommandLine in project intellij-elixir by KronicDeth.
the class MixProjectRootStep method fetchDependencies.
private static void fetchDependencies(@NotNull final VirtualFile projectRoot, @NotNull final String mixPath) {
final Project project = ProjectImportBuilder.getCurrentProject();
String sdkPath = project != null ? ElixirSdkType.getSdkPath(project) : null;
final String elixirPath = sdkPath != null ? JpsElixirSdkType.getScriptInterpreterExecutable(sdkPath).getAbsolutePath() : JpsElixirSdkType.getExecutableFileName(JpsElixirSdkType.SCRIPT_INTERPRETER);
ProgressManager.getInstance().run(new Task.Modal(project, "Fetching dependencies", true) {
@Override
public void run(@NotNull final ProgressIndicator indicator) {
indicator.setIndeterminate(true);
GeneralCommandLine commandLine = new GeneralCommandLine();
commandLine.withWorkDirectory(projectRoot.getCanonicalPath());
commandLine.setExePath(elixirPath);
commandLine.addParameter(mixPath);
commandLine.addParameter("deps.get");
try {
OSProcessHandler handler = new OSProcessHandler(commandLine.createProcess(), commandLine.getPreparedCommandLine(Platform.current()));
handler.addProcessListener(new ProcessAdapter() {
@Override
public void onTextAvailable(ProcessEvent event, Key outputType) {
String text = event.getText();
indicator.setText2(text);
}
});
ProcessTerminatedListener.attach(handler);
handler.startNotify();
handler.waitFor();
indicator.setText2("Refreshing");
} catch (ExecutionException e) {
LOG.warn(e);
}
}
});
}
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