Search in sources :

Example 1 with CommandLineState

use of com.intellij.execution.configurations.CommandLineState 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;
}
Also used : RegexpFilter(com.intellij.execution.filters.RegexpFilter) ExecutionResult(com.intellij.execution.ExecutionResult) NotNull(org.jetbrains.annotations.NotNull) Project(com.intellij.openapi.project.Project) Executor(com.intellij.execution.Executor) TextConsoleBuilder(com.intellij.execution.filters.TextConsoleBuilder) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) CommandLineState(com.intellij.execution.configurations.CommandLineState) ProgramRunner(com.intellij.execution.runners.ProgramRunner) Key(com.intellij.openapi.util.Key)

Example 2 with CommandLineState

use of com.intellij.execution.configurations.CommandLineState 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)

Aggregations

Executor (com.intellij.execution.Executor)2 CommandLineState (com.intellij.execution.configurations.CommandLineState)2 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)2 ProgramRunner (com.intellij.execution.runners.ProgramRunner)2 NotNull (org.jetbrains.annotations.NotNull)2 StorageUtilKt (com.intellij.configurationStore.StorageUtilKt)1 DebuggerView (com.intellij.debugger.ui.DebuggerView)1 DefaultExecutionResult (com.intellij.execution.DefaultExecutionResult)1 ExecutionResult (com.intellij.execution.ExecutionResult)1 SimpleJavaParameters (com.intellij.execution.configurations.SimpleJavaParameters)1 RegexpFilter (com.intellij.execution.filters.RegexpFilter)1 TextConsoleBuilder (com.intellij.execution.filters.TextConsoleBuilder)1 OSProcessHandler (com.intellij.execution.process.OSProcessHandler)1 ProcessHandler (com.intellij.execution.process.ProcessHandler)1 ExtensionPointName (com.intellij.openapi.extensions.ExtensionPointName)1 ExternalSystemException (com.intellij.openapi.externalSystem.model.ExternalSystemException)1 ProjectSystemId (com.intellij.openapi.externalSystem.model.ProjectSystemId)1 ExternalSystemTaskNotificationListener (com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListener)1 EmptyModuleType (com.intellij.openapi.module.EmptyModuleType)1 JavaModuleType (com.intellij.openapi.module.JavaModuleType)1