Search in sources :

Example 56 with RunnerAndConfigurationSettings

use of com.intellij.execution.RunnerAndConfigurationSettings 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 57 with RunnerAndConfigurationSettings

use of com.intellij.execution.RunnerAndConfigurationSettings 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 58 with RunnerAndConfigurationSettings

use of com.intellij.execution.RunnerAndConfigurationSettings in project android by JetBrains.

the class AndroidRunConfigurations method addRunConfiguration.

public void addRunConfiguration(@NotNull AndroidFacet facet, @Nullable String activityClass, @Nullable TargetSelectionMode targetSelectionMode, @Nullable String preferredAvdName) {
    Module module = facet.getModule();
    RunManager runManager = RunManager.getInstance(module.getProject());
    AndroidRunConfigurationType runConfigurationType = AndroidRunConfigurationType.getInstance();
    RunnerAndConfigurationSettings settings = runManager.createRunConfiguration(module.getName(), runConfigurationType.getFactory());
    AndroidRunConfiguration configuration = (AndroidRunConfiguration) settings.getConfiguration();
    configuration.setModule(module);
    if (activityClass != null) {
        configuration.setLaunchActivity(activityClass);
    } else if (facet.getProjectType() == PROJECT_TYPE_INSTANTAPP) {
        configuration.setLaunchUrl(getDefaultRunConfigurationUrl(facet));
    } else if (isWatchFaceApp(facet)) {
        // In case of a watch face app, there is only a service and no default activity that can be launched
        // Eventually, we'd need to support launching a service, but currently you cannot launch a watch face service as well.
        // See https://code.google.com/p/android/issues/detail?id=151353
        configuration.MODE = DO_NOTHING;
    } else {
        configuration.MODE = LAUNCH_DEFAULT_ACTIVITY;
    }
    if (targetSelectionMode != null) {
        configuration.getDeployTargetContext().setTargetSelectionMode(targetSelectionMode);
    }
    if (preferredAvdName != null) {
        configuration.PREFERRED_AVD = preferredAvdName;
    }
    runManager.addConfiguration(settings, false);
    runManager.setSelectedConfiguration(settings);
}
Also used : AndroidRunConfigurationType(com.android.tools.idea.run.AndroidRunConfigurationType) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) AndroidRunConfiguration(com.android.tools.idea.run.AndroidRunConfiguration) Module(com.intellij.openapi.module.Module) RunManager(com.intellij.execution.RunManager)

Example 59 with RunnerAndConfigurationSettings

use of com.intellij.execution.RunnerAndConfigurationSettings in project android by JetBrains.

the class PostSyncProjectSetup method setMakeStepInJunitRunConfigurations.

private void setMakeStepInJunitRunConfigurations(@NotNull String makeTaskName) {
    ConfigurationType junitConfigurationType = AndroidJUnitConfigurationType.getInstance();
    BeforeRunTaskProvider<BeforeRunTask>[] taskProviders = Extensions.getExtensions(BeforeRunTaskProvider.EXTENSION_POINT_NAME, myProject);
    BeforeRunTaskProvider targetProvider = null;
    for (BeforeRunTaskProvider<? extends BeforeRunTask> provider : taskProviders) {
        if (makeTaskName.equals(provider.getName())) {
            targetProvider = provider;
            break;
        }
    }
    if (targetProvider != null) {
        RunManagerImpl runManager = RunManagerImpl.getInstanceImpl(myProject);
        // Set the correct "Make step" in the "JUnit Run Configuration" template.
        for (ConfigurationFactory configurationFactory : junitConfigurationType.getConfigurationFactories()) {
            RunnerAndConfigurationSettings template = runManager.getConfigurationTemplate(configurationFactory);
            RunConfiguration runConfiguration = template.getConfiguration();
            setMakeStepInJUnitConfiguration(targetProvider, runConfiguration);
        }
        // Set the correct "Make step" in existing JUnit Configurations.
        for (RunConfiguration runConfiguration : runManager.getConfigurationsList(junitConfigurationType)) {
            setMakeStepInJUnitConfiguration(targetProvider, runConfiguration);
        }
    }
}
Also used : ConfigurationType(com.intellij.execution.configurations.ConfigurationType) AndroidJUnitConfigurationType(com.android.tools.idea.testartifacts.junit.AndroidJUnitConfigurationType) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) ConfigurationFactory(com.intellij.execution.configurations.ConfigurationFactory) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) BeforeRunTaskProvider(com.intellij.execution.BeforeRunTaskProvider) MakeBeforeRunTaskProvider(com.android.tools.idea.gradle.run.MakeBeforeRunTaskProvider) RunManagerImpl(com.intellij.execution.impl.RunManagerImpl)

Example 60 with RunnerAndConfigurationSettings

use of com.intellij.execution.RunnerAndConfigurationSettings in project android by JetBrains.

the class AndroidJUnitConfigurations method isFromContext.

// Copy of JUnitConfigurationProducer#isConfigurationFromContext using AndroidJUnitConfigurationType instead of JUnitConfigurationType
public static boolean isFromContext(@NotNull JUnitConfiguration unitConfiguration, @NotNull ConfigurationContext context, @NotNull ConfigurationFactory configurationFactory) {
    if (RunConfigurationProducer.getInstance(PatternConfigurationProducer.class).isMultipleElementsSelected(context)) {
        return false;
    }
    RunConfiguration predefinedConfiguration = context.getOriginalConfiguration(AndroidJUnitConfigurationType.getInstance());
    Location contextLocation = context.getLocation();
    String paramSetName = contextLocation instanceof PsiMemberParameterizedLocation ? ((PsiMemberParameterizedLocation) contextLocation).getParamSetName() : null;
    assert contextLocation != null;
    Location location = JavaExecutionUtil.stepIntoSingleClass(contextLocation);
    if (location == null) {
        return false;
    }
    PsiElement element = location.getPsiElement();
    PsiClass testClass = getTestClass(element);
    PsiMethod testMethod = getTestMethod(element, false);
    PsiPackage testPackage;
    if (element instanceof PsiPackage) {
        testPackage = (PsiPackage) element;
    } else {
        if (element instanceof PsiDirectory) {
            testPackage = JavaDirectoryService.getInstance().getPackage(((PsiDirectory) element));
        } else {
            testPackage = null;
        }
    }
    PsiDirectory testDir = element instanceof PsiDirectory ? (PsiDirectory) element : null;
    RunnerAndConfigurationSettings template = RunManager.getInstance(location.getProject()).getConfigurationTemplate(configurationFactory);
    Module predefinedModule = ((JUnitConfiguration) template.getConfiguration()).getConfigurationModule().getModule();
    String vmParameters = predefinedConfiguration instanceof JUnitConfiguration ? ((JUnitConfiguration) predefinedConfiguration).getVMParameters() : null;
    if (vmParameters != null && !Comparing.strEqual(vmParameters, unitConfiguration.getVMParameters())) {
        return false;
    }
    if (paramSetName != null && !Comparing.strEqual(paramSetName, unitConfiguration.getProgramParameters())) {
        return false;
    }
    TestObject testobject = unitConfiguration.getTestObject();
    if (testobject != null) {
        if (testobject.isConfiguredByElement(unitConfiguration, testClass, testMethod, testPackage, testDir)) {
            Module configurationModule = unitConfiguration.getConfigurationModule().getModule();
            if (Comparing.equal(location.getModule(), configurationModule)) {
                return true;
            }
            if (Comparing.equal(predefinedModule, configurationModule)) {
                return true;
            }
        }
    }
    return false;
}
Also used : PatternConfigurationProducer(com.intellij.execution.junit.PatternConfigurationProducer) JUnitConfiguration(com.intellij.execution.junit.JUnitConfiguration) TestObject(com.intellij.execution.junit.TestObject) PsiMemberParameterizedLocation(com.intellij.execution.junit2.PsiMemberParameterizedLocation) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) Module(com.intellij.openapi.module.Module) PsiMemberParameterizedLocation(com.intellij.execution.junit2.PsiMemberParameterizedLocation) Location(com.intellij.execution.Location)

Aggregations

RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)104 Project (com.intellij.openapi.project.Project)24 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)16 RunManagerEx (com.intellij.execution.RunManagerEx)14 Nullable (org.jetbrains.annotations.Nullable)14 RunManager (com.intellij.execution.RunManager)12 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 Module (com.intellij.openapi.module.Module)10 NotNull (org.jetbrains.annotations.NotNull)9 ConfigurationFactory (com.intellij.execution.configurations.ConfigurationFactory)7 ConfigurationType (com.intellij.execution.configurations.ConfigurationType)7 ExternalSystemRunConfiguration (com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration)7 ExternalSystemTaskExecutionSettings (com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings)6 Executor (com.intellij.execution.Executor)4 RunManagerImpl (com.intellij.execution.impl.RunManagerImpl)4 AbstractExternalSystemTaskConfigurationType (com.intellij.openapi.externalSystem.service.execution.AbstractExternalSystemTaskConfigurationType)4 ExternalSystemNode (com.intellij.openapi.externalSystem.view.ExternalSystemNode)4 RunConfigurationNode (com.intellij.openapi.externalSystem.view.RunConfigurationNode)4 PsiElement (com.intellij.psi.PsiElement)4 ConfigurationContext (com.intellij.execution.actions.ConfigurationContext)3