Java Code Examples for com.intellij.execution.RunManager#getInstance()

The following examples show how to use com.intellij.execution.RunManager#getInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProjectExecutor.java    From tmc-intellij with MIT License 6 votes vote down vote up
public void executeConfiguration(Project project, ModuleBasedConfiguration appCon) {
    if (noProjectsAreOpen()) {
        logger.warn("No open projects found, can't execute the project.");
        return;
    }
    logger.info("Starting to build execution environment.");
    RunManager runManager = RunManager.getInstance(project);
    Executor executor = DefaultRunExecutor.getRunExecutorInstance();
    RunnerAndConfigurationSettingsImpl selectedConfiguration =
            getApplicationRunnerAndConfigurationSettings(runManager, appCon);
    ProgramRunner runner = getRunner(executor, selectedConfiguration);
    logger.info("Creating ExecutionEnvironment.");
    ExecutionEnvironment environment =
            new ExecutionEnvironment(
                    new DefaultRunExecutor(), runner, selectedConfiguration, project);
    try {
        logger.info("Executing project.");
        runner.execute(environment);
    } catch (ExecutionException e1) {
        JavaExecutionUtil.showExecutionErrorMessage(e1, "Error", project);
    }
}
 
Example 2
Source File: BlazeRunConfigurationSyncListener.java    From intellij with Apache License 2.0 6 votes vote down vote up
/**
 * Adds a run configuration for an android_binary target if there is not already a configuration
 * for that target.
 */
private static void maybeAddRunConfiguration(
    Project project, BlazeProjectData blazeProjectData, Label label) {
  RunManager runManager = RunManager.getInstance(project);

  for (BlazeRunConfigurationFactory configurationFactory :
      BlazeRunConfigurationFactory.EP_NAME.getExtensions()) {
    if (configurationFactory.handlesTarget(project, blazeProjectData, label)) {
      final RunnerAndConfigurationSettings settings =
          configurationFactory.createForTarget(project, runManager, label);
      runManager.addConfiguration(settings, /* isShared= */ false);
      if (runManager.getSelectedConfiguration() == null) {
        runManager.setSelectedConfiguration(settings);
      }
      break;
    }
  }
}
 
Example 3
Source File: JavaStatusChecker.java    From embeddedlinux-jvmdebugger-intellij with Apache License 2.0 6 votes vote down vote up
/**
 * Stops the applications via the descriptor of configuration.  This gets called when the application finishes on the client side without maniually closing it.
 *
 * @param javaExitCode
 */
public void stopApplication(@NotNull int javaExitCode) {
    final RunManagerImpl runManager = (RunManagerImpl) RunManager.getInstance(project);
    final Collection<RunnerAndConfigurationSettings> allConfigurations = runManager.getSortedConfigurations();
    List<RunContentDescriptor> allDescriptors = ExecutionManager.getInstance(project).getContentManager().getAllDescriptors();
    boolean exitMsgDisplay = false;
    for (RunnerAndConfigurationSettings runConfiguration : allConfigurations) {
        if (runConfiguration.getConfiguration().getFactory().getType() instanceof EmbeddedLinuxJVMConfigurationType) {
            for (RunContentDescriptor descriptor : allDescriptors) {
                if (runConfiguration.getName().equals(descriptor.getDisplayName())) {
                    try {
                        if (!exitMsgDisplay) {
                            consoleView.print(EmbeddedLinuxJVMBundle.message("exit.code.message", javaExitCode), ConsoleViewContentType.SYSTEM_OUTPUT);
                            exitMsgDisplay = true;
                        }
                        descriptor.setProcessHandler(null);
                    } catch (Exception e) {

                    }
                }
            }

        }

    }
}
 
Example 4
Source File: ProjectUtils.java    From embeddedlinux-jvmdebugger-intellij with Apache License 2.0 6 votes vote down vote up
/**
 * adds run configuration dynamically
 * @param module
 * @param mainClass
 * @param boardName
 */
public static void addProjectConfiguration(final Module module, final String mainClass, final String boardName) {
    final Runnable r = new Runnable() {
        @Override
        public void run() {
            final RunManager runManager = RunManager.getInstance(module.getProject());
            final RunnerAndConfigurationSettings settings = runManager.
                    createRunConfiguration(module.getName(), EmbeddedLinuxJVMConfigurationType.getInstance().getFactory());
            final EmbeddedLinuxJVMRunConfiguration configuration = (EmbeddedLinuxJVMRunConfiguration) settings.getConfiguration();

            configuration.setName(EmbeddedLinuxJVMBundle.message("runner.name", boardName));
            configuration.getRunnerParameters().setRunAsRoot(true);
            configuration.getRunnerParameters().setMainclass(mainClass);

            runManager.addConfiguration(settings, false);
            runManager.setSelectedConfiguration(settings);

            final Notification notification = new Notification(
                    Notifications.GROUPDISPLAY_ID,
                    EmbeddedLinuxJVMBundle.getString("pi.connection.required"), EmbeddedLinuxJVMBundle.message("pi.connection.notsetup", boardName),
                    NotificationType.INFORMATION);
            com.intellij.notification.Notifications.Bus.notify(notification);
        }
    };
    r.run();
}
 
Example 5
Source File: TaskUtils.java    From JHelper with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static void createConfigurationForTask(Project project, TaskData taskData) {
	TaskConfigurationType configurationType = new TaskConfigurationType();
	ConfigurationFactory factory = configurationType.getConfigurationFactories()[0];

	RunManager manager = RunManager.getInstance(project);
	TaskConfiguration taskConfiguration = new TaskConfiguration(
			project,
			factory
	);
	taskConfiguration.setFromTaskData(taskData);
	RunnerAndConfigurationSettings configuration = manager.createConfiguration(
			taskConfiguration,
			factory
	);
	manager.addConfiguration(configuration, true);

	manager.setSelectedConfiguration(configuration);
}
 
Example 6
Source File: PantsIntegrationTestCase.java    From intellij-pants-plugin with Apache License 2.0 6 votes vote down vote up
protected void assertAndRunPantsMake(JUnitConfiguration runConfiguration) {

    RunManager runManager = RunManager.getInstance(myProject);
    assertTrue(runManager instanceof RunManagerImpl);
    RunManagerImpl runManagerImpl = (RunManagerImpl) runManager;

    RunnerAndConfigurationSettings runnerAndConfigurationSettings =
      runManagerImpl.createConfiguration(runConfiguration, JUnitConfigurationType.getInstance().getConfigurationFactories()[0]);
    runManagerImpl.addConfiguration(runnerAndConfigurationSettings, false);

    // Make sure PantsMake is the one and only task before JUnit run.
    List<BeforeRunTask<?>> beforeRunTaskList = runManagerImpl.getBeforeRunTasks(runConfiguration);
    assertEquals(1, beforeRunTaskList.size());
    BeforeRunTask task = beforeRunTaskList.iterator().next();
    assertEquals(PantsMakeBeforeRun.ID, task.getProviderId());

    /*
     * Manually invoke BeforeRunTask as {@link ExecutionManager#compileAndRun} launches another task asynchronously,
     * and there is no way to catch that.
     */
    BeforeRunTaskProvider provider = BeforeRunTaskProvider.getProvider(myProject, task.getProviderId());
    assertNotNull(String.format("Cannot find BeforeRunTaskProvider for id='%s'", task.getProviderId()), provider);
    assertTrue(provider.executeTask(null, runConfiguration, null, task));
  }
 
Example 7
Source File: HaxeModuleBuilder.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
private void createDefaultRunConfiguration(Module module, String buildHxmlPath) {
  HaxeModuleSettings settings = HaxeModuleSettings.getInstance(module);
  settings.setHaxeTarget(HaxeTarget.INTERP);
  settings.setBuildConfig(HaxeConfiguration.HXML.asBuildConfigValue());
  settings.setHxmlPath(buildHxmlPath);
  RunManager manager = RunManager.getInstance(module.getProject());
  HaxeRunConfigurationType configType = HaxeRunConfigurationType.getInstance();
  if(manager.getConfigurationsList(configType).isEmpty()) {
    ConfigurationFactory factory = configType.getConfigurationFactories()[0];
    HaxeApplicationConfiguration config = (HaxeApplicationConfiguration)factory.createTemplateConfiguration(module.getProject());
    config.setName("Execute");
    config.setModule(module);
    RunnerAndConfigurationSettings runSettings = manager.createConfiguration(config, factory);
    manager.addConfiguration(runSettings, false);
    manager.setSelectedConfiguration(runSettings);
  }
}
 
Example 8
Source File: HaxeProjectConfigurationUpdater.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
private void setupHxmlRunConfigurations(Module module) {
  RunManager manager = RunManager.getInstance(module.getProject());
  HaxeRunConfigurationType configType = HaxeRunConfigurationType.getInstance();
  ConfigurationFactory factory = configType.getConfigurationFactories()[0];

  HaxeModuleSettings settings = HaxeModuleSettings.getInstance(module);
  String hxmlPath = settings.getHxmlPath();
  if(hxmlPath != null && !hxmlPath.isEmpty()) {
    HaxeApplicationConfiguration config = (HaxeApplicationConfiguration)factory.createTemplateConfiguration(module.getProject());
    config.setName(module.getName() + " " + new File(hxmlPath).getName());
    config.setModule(module);
    RunnerAndConfigurationSettings runSettings = manager.createConfiguration(config, factory);
    manager.addConfiguration(runSettings, false);
    manager.setSelectedConfiguration(runSettings);
  }
}
 
Example 9
Source File: RunConfigurationProducer.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * Searches the list of existing run configurations to find one created from this context. Returns one if found, or tries to create
 * a new configuration from this context if not found.
 *
 * @param context contains the information about a location in the source code.
 * @return a configuration (new or existing) matching the context, or null if the context is not applicable to this producer.
 */
@javax.annotation.Nullable
public ConfigurationFromContext findOrCreateConfigurationFromContext(ConfigurationContext context) {
  Location location = context.getLocation();
  if (location == null) {
    return null;
  }

  ConfigurationFromContext fromContext = createConfigurationFromContext(context);
  if (fromContext != null) {
    final PsiElement psiElement = fromContext.getSourceElement();
    final Location<PsiElement> _location = PsiLocation.fromPsiElement(psiElement, location.getModule());
    if (_location != null) {
      // replace with existing configuration if any
      final RunManager runManager = RunManager.getInstance(context.getProject());
      final RunnerAndConfigurationSettings settings = findExistingConfiguration(context);
      if (settings != null) {
        fromContext.setConfigurationSettings(settings);
      } else {
        runManager.setUniqueNameIfNeed(fromContext.getConfiguration());
      }
    }
  }

  return fromContext;
}
 
Example 10
Source File: FlutterModuleUtils.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Ensures a Flutter run configuration is selected in the run pull down.
 */
public static void ensureRunConfigSelected(@NotNull Project project) {
  if (project.isDisposed()) return;
  final FlutterRunConfigurationType configType = FlutterRunConfigurationType.getInstance();

  final RunManager runManager = RunManager.getInstance(project);
  if (!runManager.getConfigurationsList(configType).isEmpty()) {
    if (runManager.getSelectedConfiguration() == null) {
      final List<RunnerAndConfigurationSettings> flutterConfigs = runManager.getConfigurationSettingsList(configType);
      if (!flutterConfigs.isEmpty()) {
        runManager.setSelectedConfiguration(flutterConfigs.get(0));
      }
    }
  }
}
 
Example 11
Source File: FlutterModuleUtils.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Ensures a Flutter run configuration is selected in the run pull down.
 */
public static void ensureRunConfigSelected(@NotNull Project project) {
  if (project.isDisposed()) return;
  final FlutterRunConfigurationType configType = FlutterRunConfigurationType.getInstance();

  final RunManager runManager = RunManager.getInstance(project);
  if (!runManager.getConfigurationsList(configType).isEmpty()) {
    if (runManager.getSelectedConfiguration() == null) {
      final List<RunnerAndConfigurationSettings> flutterConfigs = runManager.getConfigurationSettingsList(configType);
      if (!flutterConfigs.isEmpty()) {
        runManager.setSelectedConfiguration(flutterConfigs.get(0));
      }
    }
  }
}
 
Example 12
Source File: RunProjectAction.java    From tmc-intellij with MIT License 5 votes vote down vote up
/**
 * Main run method, readies project module for running. First it finds current module, then
 * checks, whether it has a valid runconfiguration or not. If it does not, it creates one,
 * otherwise current configuration is run as is as long as it has a main class.
 */
private void runProject(Project project) {
    logger.info("Run project action called.");
    logger.info("Getting RunManager.");
    RunManager runManager = RunManager.getInstance(project);
    Module module = getModule(project);
    String configurationType = getConfigurationType();
    logger.info("Creating RunProject object.");
    new RunProject(runManager, module, configurationType);
}
 
Example 13
Source File: OSSPantsIntegrationTest.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
private List<BeforeRunTask<?>> getBeforeRunTask(RunConfiguration configuration) {
  RunManagerImpl runManager = (RunManagerImpl) RunManager.getInstance(myProject);
  RunnerAndConfigurationSettingsImpl configurationSettings = new RunnerAndConfigurationSettingsImpl(runManager, configuration, true);
  runManager.addConfiguration(configurationSettings, true);
  List<BeforeRunTask<?>> tasks = runManager.getBeforeRunTasks(configuration);
  runManager.removeConfiguration(configurationSettings);
  return tasks;
}
 
Example 14
Source File: PantsMakeBeforeRun.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
public static void replaceDefaultMakeWithPantsMake(@NotNull RunConfiguration runConfiguration) {
  if (!PantsUtil.isScalaRelatedTestRunConfiguration(runConfiguration) &&
      !(runConfiguration instanceof CommonProgramRunConfigurationParameters)) {
    return;
  }

  RunManager runManager = RunManager.getInstance(runConfiguration.getProject());
  RunManagerImpl runManagerImpl = (RunManagerImpl) runManager;
  BeforeRunTask pantsMakeTask = new ExternalSystemBeforeRunTask(ID, PantsConstants.SYSTEM_ID);
  pantsMakeTask.setEnabled(true);
  runManagerImpl.setBeforeRunTasks(runConfiguration, Collections.singletonList(pantsMakeTask));
}
 
Example 15
Source File: RunConfigurationProducer.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Searches the list of existing run configurations to find one created from this context. Returns one if found.
 *
 * @param context contains the information about a location in the source code.
 * @return an existing configuration matching the context, or null if no such configuration is found.
 */
@javax.annotation.Nullable
public RunnerAndConfigurationSettings findExistingConfiguration(ConfigurationContext context) {
  final RunManager runManager = RunManager.getInstance(context.getProject());
  final List<RunnerAndConfigurationSettings> configurations = runManager.getConfigurationSettingsList(myConfigurationFactory.getType());
  for (RunnerAndConfigurationSettings configurationSettings : configurations) {
    if (isConfigurationFromContext((T) configurationSettings.getConfiguration(), context)) {
      return configurationSettings;
    }
  }
  return null;
}
 
Example 16
Source File: ConfigurationContext.java    From consulo with Apache License 2.0 4 votes vote down vote up
public RunManager getRunManager() {
  return RunManager.getInstance(getProject());
}