Search in sources :

Example 41 with GeneralCommandLine

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");
    }
}
Also used : GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) VirtualFile(com.intellij.openapi.vfs.VirtualFile) CapturingProcessHandler(com.intellij.execution.process.CapturingProcessHandler)

Example 42 with GeneralCommandLine

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);
    }
}
Also used : GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) File(java.io.File)

Example 43 with GeneralCommandLine

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;
        }
    };
}
Also used : KotlinReflectionInternalError(kotlin.reflect.KotlinReflectionInternalError) DependencyScope(com.intellij.openapi.roots.DependencyScope) DefaultExecutionResult(com.intellij.execution.DefaultExecutionResult) PlaceHolder(com.intellij.ui.PlaceHolder) SimpleJavaParameters(com.intellij.execution.configurations.SimpleJavaParameters) Unit(kotlin.Unit) TimeUnit(java.util.concurrent.TimeUnit) NotNull(org.jetbrains.annotations.NotNull) ProjectBundle(com.intellij.openapi.project.ProjectBundle) StorageUtilKt(com.intellij.configurationStore.StorageUtilKt) EmptyModuleType(com.intellij.openapi.module.EmptyModuleType) ModuleType(com.intellij.openapi.module.ModuleType) JavaModuleType(com.intellij.openapi.module.JavaModuleType) Executor(com.intellij.execution.Executor) ExtensionPointName(com.intellij.openapi.extensions.ExtensionPointName) LanguageLevel(com.intellij.pom.java.LanguageLevel) DebuggerView(com.intellij.debugger.ui.DebuggerView) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) CommandLineState(com.intellij.execution.configurations.CommandLineState) ProgramRunner(com.intellij.execution.runners.ProgramRunner) EmptyModuleType(com.intellij.openapi.module.EmptyModuleType) JavaModuleType(com.intellij.openapi.module.JavaModuleType) StdModuleTypes(com.intellij.openapi.module.StdModuleTypes) ExternalSystemTaskNotificationListener(com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListener) PsiBundle(com.intellij.psi.PsiBundle) ExternalSystemException(com.intellij.openapi.externalSystem.model.ExternalSystemException) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) Alarm(com.intellij.util.Alarm) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) ProcessHandler(com.intellij.execution.process.ProcessHandler) SimpleJavaSdkType(com.intellij.openapi.projectRoots.SimpleJavaSdkType) ProjectSystemId(com.intellij.openapi.externalSystem.model.ProjectSystemId) File(java.io.File)

Example 44 with GeneralCommandLine

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;
}
Also used : Task(com.intellij.openapi.progress.Task) Macro(com.intellij.ide.macro.Macro) Project(com.intellij.openapi.project.Project) CantRunException(com.intellij.execution.CantRunException) FutureResult(com.intellij.util.concurrency.FutureResult) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) Nullable(org.jetbrains.annotations.Nullable)

Example 45 with GeneralCommandLine

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;
}
Also used : StringTokenizer(java.util.StringTokenizer) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine)

Aggregations

GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)137 ExecutionException (com.intellij.execution.ExecutionException)42 File (java.io.File)35 NotNull (org.jetbrains.annotations.NotNull)35 ProcessOutput (com.intellij.execution.process.ProcessOutput)20 VirtualFile (com.intellij.openapi.vfs.VirtualFile)19 CapturingProcessHandler (com.intellij.execution.process.CapturingProcessHandler)10 Project (com.intellij.openapi.project.Project)10 Key (com.intellij.openapi.util.Key)10 IOException (java.io.IOException)10 Nullable (org.jetbrains.annotations.Nullable)10 OSProcessHandler (com.intellij.execution.process.OSProcessHandler)9 ProcessHandler (com.intellij.execution.process.ProcessHandler)7 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)7 Sdk (com.intellij.openapi.projectRoots.Sdk)7 PsiFile (com.intellij.psi.PsiFile)7 Test (org.junit.Test)6 CapturingAnsiEscapesAwareProcessHandler (com.intellij.execution.process.CapturingAnsiEscapesAwareProcessHandler)5 ArrayList (java.util.ArrayList)5 RunResult (org.jetbrains.kotlin.android.tests.run.RunResult)5