Search in sources :

Example 6 with ConfigurationFactory

use of com.intellij.execution.configurations.ConfigurationFactory in project android by JetBrains.

the class AndroidJavaDebugger method attachToClient.

@Override
public void attachToClient(@NotNull Project project, @NotNull Client client) {
    String debugPort = getClientDebugPort(client);
    String runConfigName = String.format(RUN_CONFIGURATION_NAME_PATTERN, debugPort);
    // Try to find existing debug session
    if (hasExistingDebugSession(project, debugPort, runConfigName)) {
        return;
    }
    // Create run configuration
    RemoteConfigurationType remoteConfigurationType = RemoteConfigurationType.getInstance();
    ConfigurationFactory factory = remoteConfigurationType.getFactory();
    RunnerAndConfigurationSettings runSettings = RunManager.getInstance(project).createRunConfiguration(runConfigName, factory);
    RemoteConfiguration configuration = (RemoteConfiguration) runSettings.getConfiguration();
    configuration.HOST = "localhost";
    configuration.PORT = debugPort;
    configuration.USE_SOCKET_TRANSPORT = true;
    configuration.SERVER_MODE = false;
    ProgramRunnerUtil.executeConfiguration(project, runSettings, DefaultDebugExecutor.getDebugExecutorInstance());
}
Also used : RemoteConfiguration(com.intellij.execution.remote.RemoteConfiguration) ConfigurationFactory(com.intellij.execution.configurations.ConfigurationFactory) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) RemoteConfigurationType(com.intellij.execution.remote.RemoteConfigurationType)

Example 7 with ConfigurationFactory

use of com.intellij.execution.configurations.ConfigurationFactory in project Intellij-Plugin by getgauge.

the class GaugeRunProcessHandler method launchDebugger.

private static void launchDebugger(final Project project, final GaugeDebugInfo debugInfo) {
    Runnable runnable = () -> {
        final long startTime = System.currentTimeMillis();
        GenericDebuggerRunner basicProgramRunner = new GenericDebuggerRunner();
        RunManagerImpl manager = new RunManagerImpl(project);
        ConfigurationFactory configFactory = RemoteConfigurationType.getInstance().getConfigurationFactories()[0];
        RemoteConfiguration remoteConfig = new RemoteConfiguration(project, configFactory);
        remoteConfig.PORT = debugInfo.getPort();
        remoteConfig.HOST = debugInfo.getHost();
        remoteConfig.USE_SOCKET_TRANSPORT = true;
        remoteConfig.SERVER_MODE = false;
        RunnerAndConfigurationSettingsImpl configuration = new RunnerAndConfigurationSettingsImpl(manager, remoteConfig, false);
        ExecutionEnvironment environment = new ExecutionEnvironment(new DefaultDebugExecutor(), basicProgramRunner, configuration, project);
        boolean debuggerConnected = false;
        // Trying to connect to gauge java for 25 secs. The sleep is because it may take a few seconds for gauge to launch the java process and the jvm to load after that
        while (!debuggerConnected && ((System.currentTimeMillis() - startTime) < 25000)) {
            try {
                Thread.sleep(5000);
                basicProgramRunner.execute(environment);
                debuggerConnected = true;
            } catch (Exception e) {
                System.err.println("Failed to connect debugger. Retrying... : " + e.getMessage());
            }
        }
    };
    ApplicationManager.getApplication().invokeAndWait(runnable, ModalityState.any());
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) DefaultDebugExecutor(com.intellij.execution.executors.DefaultDebugExecutor) RemoteConfiguration(com.intellij.execution.remote.RemoteConfiguration) ConfigurationFactory(com.intellij.execution.configurations.ConfigurationFactory) RunnerAndConfigurationSettingsImpl(com.intellij.execution.impl.RunnerAndConfigurationSettingsImpl) GenericDebuggerRunner(com.intellij.debugger.impl.GenericDebuggerRunner) ExecutionException(com.intellij.execution.ExecutionException) RunManagerImpl(com.intellij.execution.impl.RunManagerImpl)

Example 8 with ConfigurationFactory

use of com.intellij.execution.configurations.ConfigurationFactory in project buck by facebook.

the class TestExecutionState method attachDebugger.

private void attachDebugger(String title, String port) {
    final RemoteConnection remoteConnection = new RemoteConnection(/* useSockets */
    true, "localhost", port, /* serverMode */
    false);
    final RemoteStateState state = new RemoteStateState(mProject, remoteConnection);
    final String name = title + " debugger (" + port + ")";
    final ConfigurationFactory cfgFactory = ConfigurationTypeUtil.findConfigurationType("Remote").getConfigurationFactories()[0];
    RunnerAndConfigurationSettings runSettings = RunManager.getInstance(mProject).createRunConfiguration(name, cfgFactory);
    final Executor debugExecutor = DefaultDebugExecutor.getDebugExecutorInstance();
    final ExecutionEnvironment env = new ExecutionEnvironmentBuilder(mProject, debugExecutor).runProfile(runSettings.getConfiguration()).build();
    final int pollTimeout = 3000;
    final DebugEnvironment environment = new DefaultDebugEnvironment(env, state, remoteConnection, pollTimeout);
    ApplicationManager.getApplication().invokeLater(() -> {
        try {
            final DebuggerSession debuggerSession = DebuggerManagerEx.getInstanceEx(mProject).attachVirtualMachine(environment);
            if (debuggerSession == null) {
                return;
            }
            XDebuggerManager.getInstance(mProject).startSessionAndShowTab(name, null, new XDebugProcessStarter() {

                @Override
                @NotNull
                public XDebugProcess start(@NotNull XDebugSession session) {
                    return JavaDebugProcess.create(session, debuggerSession);
                }
            });
        } catch (ExecutionException e) {
            LOG.error("failed to attach to debugger on port " + port + " with polling timeout " + pollTimeout);
        }
    });
}
Also used : XDebugSession(com.intellij.xdebugger.XDebugSession) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) XDebugProcess(com.intellij.xdebugger.XDebugProcess) NotNull(org.jetbrains.annotations.NotNull) DefaultDebugEnvironment(com.intellij.debugger.DefaultDebugEnvironment) DefaultDebugExecutor(com.intellij.execution.executors.DefaultDebugExecutor) Executor(com.intellij.execution.Executor) DebuggerSession(com.intellij.debugger.impl.DebuggerSession) XDebugProcessStarter(com.intellij.xdebugger.XDebugProcessStarter) ConfigurationFactory(com.intellij.execution.configurations.ConfigurationFactory) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) RemoteConnection(com.intellij.execution.configurations.RemoteConnection) RemoteStateState(com.intellij.debugger.engine.RemoteStateState) ExecutionEnvironmentBuilder(com.intellij.execution.runners.ExecutionEnvironmentBuilder) ExecutionException(com.intellij.execution.ExecutionException) DefaultDebugEnvironment(com.intellij.debugger.DefaultDebugEnvironment) DebugEnvironment(com.intellij.debugger.DebugEnvironment)

Example 9 with ConfigurationFactory

use of com.intellij.execution.configurations.ConfigurationFactory in project buck by facebook.

the class AndroidDebugger method createRunConfiguration.

private static RunnerAndConfigurationSettings createRunConfiguration(Project project, String debugPort) {
    final RemoteConfigurationType remoteConfigurationType = RemoteConfigurationType.getInstance();
    final ConfigurationFactory factory = remoteConfigurationType.getFactory();
    final RunnerAndConfigurationSettings runSettings = RunManager.getInstance(project).createRunConfiguration(getRunConfigurationName(debugPort), factory);
    final RemoteConfiguration configuration = (RemoteConfiguration) runSettings.getConfiguration();
    configuration.HOST = "localhost";
    configuration.PORT = debugPort;
    configuration.USE_SOCKET_TRANSPORT = true;
    configuration.SERVER_MODE = false;
    return runSettings;
}
Also used : RemoteConfiguration(com.intellij.execution.remote.RemoteConfiguration) ConfigurationFactory(com.intellij.execution.configurations.ConfigurationFactory) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) RemoteConfigurationType(com.intellij.execution.remote.RemoteConfigurationType)

Example 10 with ConfigurationFactory

use of com.intellij.execution.configurations.ConfigurationFactory in project buck by facebook.

the class TestConfigurationTest method testPersistency.

public void testPersistency() throws Exception {
    final ConfigurationFactory factory = TestConfigurationType.getInstance().getConfigurationFactories()[0];
    final TestConfiguration cfg = new TestConfiguration(getProject(), factory, "test serialization");
    cfg.data.target = "//src/com/facebook/buck:test";
    cfg.data.testSelectors = "com.facebook.buck.Test";
    cfg.data.additionalParams = "--num-threads 239";
    final Element testElement = new Element("test_element");
    cfg.writeExternal(testElement);
    final TestConfiguration cfg2 = new TestConfiguration(getProject(), factory, "test serialization");
    cfg2.readExternal(testElement);
    Assert.assertEquals("//src/com/facebook/buck:test", cfg2.data.target);
    Assert.assertEquals("com.facebook.buck.Test", cfg2.data.testSelectors);
    Assert.assertEquals("--num-threads 239", cfg2.data.additionalParams);
}
Also used : Element(org.jdom.Element) ConfigurationFactory(com.intellij.execution.configurations.ConfigurationFactory)

Aggregations

ConfigurationFactory (com.intellij.execution.configurations.ConfigurationFactory)19 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)7 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)6 Project (com.intellij.openapi.project.Project)6 NotNull (org.jetbrains.annotations.NotNull)6 ConfigurationType (com.intellij.execution.configurations.ConfigurationType)4 RunManagerImpl (com.intellij.execution.impl.RunManagerImpl)4 DefaultDebugExecutor (com.intellij.execution.executors.DefaultDebugExecutor)3 RemoteConfiguration (com.intellij.execution.remote.RemoteConfiguration)3 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)3 MakeBeforeRunTaskProvider (com.android.tools.idea.gradle.run.MakeBeforeRunTaskProvider)2 ExecutionException (com.intellij.execution.ExecutionException)2 RunManagerEx (com.intellij.execution.RunManagerEx)2 ConfigurationFactoryEx (com.intellij.execution.configuration.ConfigurationFactoryEx)2 RunnerAndConfigurationSettingsImpl (com.intellij.execution.impl.RunnerAndConfigurationSettingsImpl)2 RemoteConfigurationType (com.intellij.execution.remote.RemoteConfigurationType)2 AndroidRunConfiguration (com.android.tools.idea.run.AndroidRunConfiguration)1 AndroidJUnitConfiguration (com.android.tools.idea.testartifacts.junit.AndroidJUnitConfiguration)1 AndroidJUnitConfigurationType (com.android.tools.idea.testartifacts.junit.AndroidJUnitConfigurationType)1 DebugEnvironment (com.intellij.debugger.DebugEnvironment)1