Search in sources :

Example 26 with RunContentDescriptor

use of com.intellij.execution.ui.RunContentDescriptor in project android by JetBrains.

the class RestartActivityAction method findDevices.

/**
   * Finds the devices associated with all run configurations for the given project
   */
@NotNull
private static List<IDevice> findDevices(@Nullable Project project) {
    if (project == null) {
        return Collections.emptyList();
    }
    List<RunContentDescriptor> runningProcesses = ExecutionManager.getInstance(project).getContentManager().getAllDescriptors();
    if (runningProcesses.isEmpty()) {
        return Collections.emptyList();
    }
    List<IDevice> devices = Lists.newArrayList();
    for (RunContentDescriptor descriptor : runningProcesses) {
        ProcessHandler processHandler = descriptor.getProcessHandler();
        if (processHandler == null || processHandler.isProcessTerminated() || processHandler.isProcessTerminating()) {
            continue;
        }
        devices.addAll(getConnectedDevices(processHandler));
    }
    return devices;
}
Also used : RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) IDevice(com.android.ddmlib.IDevice) AndroidProcessHandler(com.android.tools.idea.run.AndroidProcessHandler) ProcessHandler(com.intellij.execution.process.ProcessHandler) NotNull(org.jetbrains.annotations.NotNull)

Example 27 with RunContentDescriptor

use of com.intellij.execution.ui.RunContentDescriptor in project android by JetBrains.

the class AndroidProgramRunner method doExecute.

@Override
protected RunContentDescriptor doExecute(@NotNull final RunProfileState state, @NotNull final ExecutionEnvironment env) throws ExecutionException {
    boolean showRunContent = env.getRunProfile() instanceof AndroidTestRunConfiguration;
    RunnerAndConfigurationSettings runnerAndConfigurationSettings = env.getRunnerAndConfigurationSettings();
    if (runnerAndConfigurationSettings != null) {
        runnerAndConfigurationSettings.setActivateToolWindowBeforeRun(showRunContent);
    }
    RunContentDescriptor descriptor = super.doExecute(state, env);
    if (descriptor != null) {
        ProcessHandler processHandler = descriptor.getProcessHandler();
        assert processHandler != null;
        RunProfile runProfile = env.getRunProfile();
        int uniqueId = runProfile instanceof RunConfigurationBase ? ((RunConfigurationBase) runProfile).getUniqueID() : -1;
        AndroidSessionInfo sessionInfo = new AndroidSessionInfo(processHandler, descriptor, uniqueId, env.getExecutor().getId(), InstantRunUtils.isInstantRunEnabled(env));
        processHandler.putUserData(AndroidSessionInfo.KEY, sessionInfo);
    }
    return descriptor;
}
Also used : RunConfigurationBase(com.intellij.execution.configurations.RunConfigurationBase) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) AndroidTestRunConfiguration(com.android.tools.idea.testartifacts.instrumented.AndroidTestRunConfiguration) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) ProcessHandler(com.intellij.execution.process.ProcessHandler) RunProfile(com.intellij.execution.configurations.RunProfile)

Example 28 with RunContentDescriptor

use of com.intellij.execution.ui.RunContentDescriptor in project android by JetBrains.

the class AndroidJavaDebugger method hasExistingDebugSession.

private static boolean hasExistingDebugSession(@NotNull Project project, @NotNull final String debugPort, @NotNull final String runConfigName) {
    Collection<RunContentDescriptor> descriptors = null;
    Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
    Project targetProject = null;
    // Scan through open project to find if this port has been opened in any session.
    for (Project openProject : openProjects) {
        targetProject = openProject;
        // First check the titles of the run configurations.
        descriptors = ExecutionHelper.findRunningConsoleByTitle(targetProject, new NotNullFunction<String, Boolean>() {

            @NotNull
            @Override
            public Boolean fun(String title) {
                return runConfigName.equals(title);
            }
        });
        // If it can't find a matching title, check the debugger sessions.
        if (descriptors.isEmpty()) {
            DebuggerSession debuggerSession = findJdwpDebuggerSession(targetProject, debugPort);
            if (debuggerSession != null) {
                XDebugSession session = debuggerSession.getXDebugSession();
                if (session != null) {
                    descriptors = Collections.singletonList(session.getRunContentDescriptor());
                } else {
                    // Detach existing session.
                    debuggerSession.getProcess().stop(false);
                }
            }
        }
        if (!descriptors.isEmpty()) {
            break;
        }
    }
    if (descriptors != null && !descriptors.isEmpty()) {
        return activateDebugSessionWindow(project, descriptors.iterator().next());
    }
    return false;
}
Also used : Project(com.intellij.openapi.project.Project) XDebugSession(com.intellij.xdebugger.XDebugSession) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) DebuggerSession(com.intellij.debugger.impl.DebuggerSession) NotNullFunction(com.intellij.util.NotNullFunction)

Example 29 with RunContentDescriptor

use of com.intellij.execution.ui.RunContentDescriptor in project intellij-plugins by JetBrains.

the class JstdCoverageProgramRunner method start.

@Nullable
private static RunContentDescriptor start(@Nullable JstdServer server, @NotNull ExecutionEnvironment environment) throws ExecutionException {
    FileDocumentManager.getInstance().saveAllDocuments();
    JstdRunConfiguration runConfiguration = (JstdRunConfiguration) environment.getRunProfile();
    CoverageEnabledConfiguration coverageEnabledConfiguration = CoverageEnabledConfiguration.getOrCreate(runConfiguration);
    String coverageFilePath = coverageEnabledConfiguration.getCoverageFilePath();
    JstdRunProfileState jstdState = new JstdRunProfileState(environment, runConfiguration.getRunSettings(), coverageFilePath);
    ExecutionResult executionResult = jstdState.executeWithServer(server);
    RunContentBuilder contentBuilder = new RunContentBuilder(executionResult, environment);
    final RunContentDescriptor descriptor = contentBuilder.showRunContent(environment.getContentToReuse());
    ProcessHandler processHandler = executionResult.getProcessHandler();
    if (processHandler instanceof NopProcessHandler) {
        if (server != null) {
            server.addLifeCycleListener(new JstdServerLifeCycleAdapter() {

                @Override
                public void onBrowserCaptured(@NotNull JstdBrowserInfo info) {
                    ExecutionUtil.restartIfActive(descriptor);
                    server.removeLifeCycleListener(this);
                }
            }, contentBuilder);
        }
    } else {
        CoverageHelper.attachToProcess(runConfiguration, processHandler, environment.getRunnerSettings());
    }
    return descriptor;
}
Also used : JstdRunConfiguration(com.google.jstestdriver.idea.execution.JstdRunConfiguration) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) CoverageEnabledConfiguration(com.intellij.execution.configurations.coverage.CoverageEnabledConfiguration) JstdRunProfileState(com.google.jstestdriver.idea.execution.JstdRunProfileState) NopProcessHandler(com.intellij.execution.process.NopProcessHandler) ProcessHandler(com.intellij.execution.process.ProcessHandler) ExecutionResult(com.intellij.execution.ExecutionResult) NopProcessHandler(com.intellij.execution.process.NopProcessHandler) RunContentBuilder(com.intellij.execution.runners.RunContentBuilder) JstdServerLifeCycleAdapter(com.google.jstestdriver.idea.server.JstdServerLifeCycleAdapter) JstdBrowserInfo(com.google.jstestdriver.idea.server.JstdBrowserInfo) Nullable(org.jetbrains.annotations.Nullable)

Example 30 with RunContentDescriptor

use of com.intellij.execution.ui.RunContentDescriptor in project intellij-plugins by JetBrains.

the class JstdRunProgramRunner method start.

public static RunContentDescriptor start(@Nullable JstdServer server, boolean fromDebug, @NotNull RunProfileState state, @NotNull ExecutionEnvironment environment) throws ExecutionException {
    FileDocumentManager.getInstance().saveAllDocuments();
    JstdRunProfileState jstdState = JstdRunProfileState.cast(state);
    ExecutionResult executionResult = jstdState.executeWithServer(server);
    RunContentBuilder contentBuilder = new RunContentBuilder(executionResult, environment);
    final RunContentDescriptor descriptor = contentBuilder.showRunContent(environment.getContentToReuse());
    if (server != null && executionResult.getProcessHandler() instanceof NopProcessHandler) {
        server.addLifeCycleListener(new JstdServerLifeCycleAdapter() {

            @Override
            public void onBrowserCaptured(@NotNull JstdBrowserInfo info) {
                if (fromDebug) {
                    final Alarm alarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD, descriptor);
                    alarm.addRequest(() -> ExecutionUtil.restartIfActive(descriptor), 1000);
                } else {
                    ExecutionUtil.restartIfActive(descriptor);
                }
                server.removeLifeCycleListener(this);
            }
        }, contentBuilder);
    }
    return descriptor;
}
Also used : RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) Alarm(com.intellij.util.Alarm) ExecutionResult(com.intellij.execution.ExecutionResult) NopProcessHandler(com.intellij.execution.process.NopProcessHandler) RunContentBuilder(com.intellij.execution.runners.RunContentBuilder) JstdServerLifeCycleAdapter(com.google.jstestdriver.idea.server.JstdServerLifeCycleAdapter) JstdBrowserInfo(com.google.jstestdriver.idea.server.JstdBrowserInfo)

Aggregations

RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)70 ProcessHandler (com.intellij.execution.process.ProcessHandler)26 Project (com.intellij.openapi.project.Project)18 NotNull (org.jetbrains.annotations.NotNull)14 Nullable (org.jetbrains.annotations.Nullable)13 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)11 Executor (com.intellij.execution.Executor)10 DefaultRunExecutor (com.intellij.execution.executors.DefaultRunExecutor)9 ProcessEvent (com.intellij.execution.process.ProcessEvent)8 ExecutionException (com.intellij.execution.ExecutionException)7 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)7 ArrayList (java.util.ArrayList)7 ProgramRunner (com.intellij.execution.runners.ProgramRunner)6 ExecutionResult (com.intellij.execution.ExecutionResult)5 RunProfile (com.intellij.execution.configurations.RunProfile)5 CloseAction (com.intellij.execution.ui.actions.CloseAction)5 Pair (com.intellij.openapi.util.Pair)5 IOException (java.io.IOException)5 RunContentManager (com.intellij.execution.ui.RunContentManager)4 ApplicationManager (com.intellij.openapi.application.ApplicationManager)4