use of com.intellij.execution.configurations.GeneralCommandLine in project intellij-community by JetBrains.
the class ShowFilePathAction method doOpen.
private static void doOpen(@NotNull File _dir, @Nullable File _toSelect) throws IOException, ExecutionException {
String dir = FileUtil.toSystemDependentName(FileUtil.toCanonicalPath(_dir.getPath()));
String toSelect = _toSelect != null ? FileUtil.toSystemDependentName(FileUtil.toCanonicalPath(_toSelect.getPath())) : null;
if (SystemInfo.isWindows) {
String cmd = toSelect != null ? "explorer /select," + toSelect : "explorer /root," + dir;
// no quoting/escaping is needed
Process process = Runtime.getRuntime().exec(cmd);
new CapturingProcessHandler(process, null, cmd).runProcess().checkSuccess(LOG);
} else if (SystemInfo.isMac) {
GeneralCommandLine cmd = toSelect != null ? new GeneralCommandLine("open", "-R", toSelect) : new GeneralCommandLine("open", dir);
ExecUtil.execAndGetOutput(cmd).checkSuccess(LOG);
} else if (fileManagerApp.getValue() != null) {
schedule(new GeneralCommandLine(fileManagerApp.getValue(), toSelect != null ? toSelect : dir));
} else if (SystemInfo.hasXdgOpen()) {
schedule(new GeneralCommandLine("xdg-open", dir));
} else if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.OPEN)) {
Desktop.getDesktop().open(new File(dir));
} else {
Messages.showErrorDialog("This action isn't supported on the current platform", "Cannot Open File");
}
}
use of com.intellij.execution.configurations.GeneralCommandLine in project intellij-community by JetBrains.
the class CreateDesktopEntryAction method install.
private static void install(File entryFile, boolean globalEntry) throws IOException, ExecutionException {
if (globalEntry) {
File script = ExecUtil.createTempExecutableScript("create_desktop_entry_", ".sh", "#!/bin/sh\n" + "xdg-desktop-menu install --mode system '" + entryFile.getAbsolutePath() + "' && xdg-desktop-menu forceupdate --mode system\n");
try {
exec(new GeneralCommandLine(script.getPath()), ApplicationBundle.message("desktop.entry.sudo.prompt"));
} finally {
FileUtil.delete(script);
}
} else {
exec(new GeneralCommandLine("xdg-desktop-menu", "install", "--mode", "user", entryFile.getAbsolutePath()), null);
exec(new GeneralCommandLine("xdg-desktop-menu", "forceupdate", "--mode", "user"), null);
}
}
use of com.intellij.execution.configurations.GeneralCommandLine in project intellij-community by JetBrains.
the class RemoteExternalSystemCommunicationManager method createRunProfileState.
private RunProfileState createRunProfileState(final String configuration) {
return new CommandLineState(null) {
private SimpleJavaParameters createJavaParameters() throws ExecutionException {
final SimpleJavaParameters params = new SimpleJavaParameters();
params.setJdk(new SimpleJavaSdkType().createJdk("tmp", SystemProperties.getJavaHome()));
File myWorkingDirectory = new File(configuration);
params.setWorkingDirectory(myWorkingDirectory.isDirectory() ? myWorkingDirectory.getPath() : PathManager.getBinPath());
final List<String> classPath = ContainerUtilRt.newArrayList();
// IDE jars.
classPath.addAll(PathManager.getUtilClassPath());
ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(ProjectBundle.class));
ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(PlaceHolder.class));
ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(DebuggerView.class));
ExternalSystemApiUtil.addBundle(params.getClassPath(), "messages.ProjectBundle", ProjectBundle.class);
ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(PsiBundle.class));
ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(Alarm.class));
ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(DependencyScope.class));
ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(ExtensionPointName.class));
ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(StorageUtilKt.class));
ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(ExternalSystemTaskNotificationListener.class));
ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(StdModuleTypes.class));
ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(JavaModuleType.class));
ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(ModuleType.class));
ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(EmptyModuleType.class));
ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(LanguageLevel.class));
// add Kotlin runtime
ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(Unit.class));
ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(KotlinReflectionInternalError.class));
// External system module jars
ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(getClass()));
// external-system-rt.jar
ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(ExternalSystemException.class));
ExternalSystemApiUtil.addBundle(params.getClassPath(), "messages.CommonBundle", CommonBundle.class);
params.getClassPath().addAll(classPath);
params.setMainClass(MAIN_CLASS_NAME);
params.getVMParametersList().addParametersString("-Djava.awt.headless=true");
// It may take a while for external system api to resolve external dependencies. Default RMI timeout
// is 15 seconds (http://download.oracle.com/javase/6/docs/technotes/guides/rmi/sunrmiproperties.html#connectionTimeout),
// we don't want to get EOFException because of that.
params.getVMParametersList().addParametersString("-Dsun.rmi.transport.connectionTimeout=" + String.valueOf(TimeUnit.HOURS.toMillis(1)));
final String debugPort = System.getProperty(ExternalSystemConstants.EXTERNAL_SYSTEM_REMOTE_COMMUNICATION_MANAGER_DEBUG_PORT);
if (debugPort != null) {
params.getVMParametersList().addParametersString("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=" + debugPort);
}
ProjectSystemId externalSystemId = myTargetExternalSystemId.get();
if (externalSystemId != null) {
ExternalSystemManager<?, ?, ?, ?, ?> manager = ExternalSystemApiUtil.getManager(externalSystemId);
if (manager != null) {
params.getClassPath().add(PathUtil.getJarPathForClass(manager.getProjectResolverClass()));
params.getProgramParametersList().add(manager.getProjectResolverClass().getName());
params.getProgramParametersList().add(manager.getTaskManagerClass().getName());
manager.enhanceRemoteProcessing(params);
}
}
return params;
}
@Override
@NotNull
public ExecutionResult execute(@NotNull Executor executor, @NotNull ProgramRunner runner) throws ExecutionException {
ProcessHandler processHandler = startProcess();
return new DefaultExecutionResult(processHandler);
}
@Override
@NotNull
protected OSProcessHandler startProcess() throws ExecutionException {
SimpleJavaParameters params = createJavaParameters();
GeneralCommandLine commandLine = params.toCommandLine();
OSProcessHandler processHandler = new OSProcessHandler(commandLine);
ProcessTerminatedListener.attach(processHandler);
return processHandler;
}
};
}
use of com.intellij.execution.configurations.GeneralCommandLine in project intellij-community by JetBrains.
the class ExecutionHandler method runBuildImpl.
/**
* @param antBuildListener should not be null. Use {@link com.intellij.lang.ant.config.AntBuildListener#NULL}
*/
@Nullable
private static FutureResult<ProcessHandler> runBuildImpl(final AntBuildFileBase buildFile, String[] targets, @Nullable final AntBuildMessageView buildMessageViewToReuse, final DataContext dataContext, List<BuildFileProperty> additionalProperties, @NotNull final AntBuildListener antBuildListener, final boolean waitFor) {
final AntBuildMessageView messageView;
final GeneralCommandLine commandLine;
final Project project = buildFile.getProject();
try {
FileDocumentManager.getInstance().saveAllDocuments();
final AntCommandLineBuilder builder = new AntCommandLineBuilder();
builder.setBuildFile(buildFile.getAllOptions(), VfsUtilCore.virtualToIoFile(buildFile.getVirtualFile()));
builder.calculateProperties(dataContext, buildFile.getProject(), additionalProperties);
builder.addTargets(targets);
builder.getCommandLine().setCharset(EncodingProjectManager.getInstance(buildFile.getProject()).getDefaultCharset());
messageView = prepareMessageView(buildMessageViewToReuse, buildFile, targets, additionalProperties);
commandLine = builder.getCommandLine().toCommandLine();
messageView.setBuildCommandLine(commandLine.getCommandLineString());
} catch (RunCanceledException e) {
e.showMessage(project, AntBundle.message("run.ant.error.dialog.title"));
antBuildListener.buildFinished(AntBuildListener.FAILED_TO_RUN, 0);
return null;
} catch (CantRunException e) {
ExecutionErrorDialog.show(e, AntBundle.message("cant.run.ant.error.dialog.title"), project);
antBuildListener.buildFinished(AntBuildListener.FAILED_TO_RUN, 0);
return null;
} catch (Macro.ExecutionCancelledException e) {
antBuildListener.buildFinished(AntBuildListener.ABORTED, 0);
return null;
} catch (Throwable e) {
antBuildListener.buildFinished(AntBuildListener.FAILED_TO_RUN, 0);
LOG.error(e);
return null;
}
final FutureResult<ProcessHandler> future = new FutureResult<>();
new Task.Backgroundable(buildFile.getProject(), AntBundle.message("ant.build.progress.dialog.title"), true) {
public boolean shouldStartInBackground() {
return true;
}
public void onCancel() {
antBuildListener.buildFinished(AntBuildListener.ABORTED, 0);
}
public void run(@NotNull final ProgressIndicator indicator) {
try {
ProcessHandler handler = runBuild(indicator, messageView, buildFile, antBuildListener, commandLine);
future.set(handler);
if (waitFor && handler != null) {
handler.waitFor();
}
} catch (Throwable e) {
LOG.error(e);
antBuildListener.buildFinished(AntBuildListener.FAILED_TO_RUN, 0);
}
}
}.queue();
return future;
}
use of com.intellij.execution.configurations.GeneralCommandLine in project intellij-community by JetBrains.
the class ExtConnection method createRshCommand.
private static GeneralCommandLine createRshCommand(String host, String userName, ExtConfiguration config) {
GeneralCommandLine command = new GeneralCommandLine();
command.setExePath(config.CVS_RSH);
command.addParameter(host);
command.addParameter("-l");
command.addParameter(userName);
if (!config.PRIVATE_KEY_FILE.isEmpty()) {
command.addParameter("-i");
command.addParameter(config.PRIVATE_KEY_FILE);
}
if (!config.ADDITIONAL_PARAMETERS.isEmpty()) {
StringTokenizer parameters = new StringTokenizer(config.ADDITIONAL_PARAMETERS, " ");
while (parameters.hasMoreTokens()) command.addParameter(parameters.nextToken());
}
return command;
}
Aggregations