com.intellij.execution.impl.RunManagerImpl Java Examples

The following examples show how to use com.intellij.execution.impl.RunManagerImpl. 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: RunConfigurationSerializer.java    From intellij with Apache License 2.0 6 votes vote down vote up
/**
 * Parses a RunConfiguration from the given XML element, and adds it to the project, if there's
 * not already a run configuration with the same name and type,
 */
@VisibleForTesting
static void loadFromXmlElementIgnoreExisting(Project project, Element element)
    throws InvalidDataException {
  if (!shouldLoadConfiguration(project, element)) {
    return;
  }
  runWithPathVariableSet(
      project,
      () -> {
        RunnerAndConfigurationSettings settings =
            RunManagerImpl.getInstanceImpl(project).loadConfiguration(element, false);
        RunConfiguration config = settings != null ? settings.getConfiguration() : null;
        if (config instanceof BlazeRunConfiguration) {
          ((BlazeRunConfiguration) config).setKeepInSync(true);
        }
      });
}
 
Example #2
Source File: AbstractAutoTestManager.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static List<RunConfiguration> loadConfigurations(State state, Project project) {
  List<RunConfiguration> configurations = ContainerUtil.newArrayList();
  RunManagerImpl runManager = RunManagerImpl.getInstanceImpl(project);
  List<RunConfigurationDescriptor> descriptors = ContainerUtil.notNullize(state.myEnabledRunConfigurations);
  for (RunConfigurationDescriptor descriptor : descriptors) {
    if (descriptor.myType != null && descriptor.myName != null) {
      RunnerAndConfigurationSettings settings = runManager.findConfigurationByTypeAndName(descriptor.myType,
                                                                                          descriptor.myName);
      RunConfiguration configuration = settings != null ? settings.getConfiguration() : null;
      if (configuration != null) {
        configurations.add(configuration);
      }
    }
  }
  return configurations;
}
 
Example #3
Source File: AbstractImportTestsAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
public ExecutionTarget getTarget() {
  if (myTargetId != null) {
    if (DefaultExecutionTarget.INSTANCE.getId().equals(myTargetId)) {
      return DefaultExecutionTarget.INSTANCE;
    }
    final RunnerAndConfigurationSettingsImpl settings =
            new RunnerAndConfigurationSettingsImpl(RunManagerImpl.getInstanceImpl(myProject), myConfiguration, false);
    for (ExecutionTargetProvider provider : ExecutionTargetProvider.EXTENSION_NAME.getExtensionList()) {
      for (ExecutionTarget target : provider.getTargets(myProject, settings)) {
        if (myTargetId.equals(target.getId())) {
          return target;
        }
      }
    }
    return null;
  }
  return DefaultExecutionTarget.INSTANCE;
}
 
Example #4
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 #5
Source File: EditTestsAction.java    From JHelper with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void performAction(AnActionEvent e) {
	Project project = e.getProject();
	RunnerAndConfigurationSettings selectedConfiguration =
			RunManagerImpl.getInstanceImpl(project).getSelectedConfiguration();
	if (selectedConfiguration == null) {
		return;
	}
	RunConfiguration configuration = selectedConfiguration.getConfiguration();
	if (configuration instanceof TaskConfiguration) {
		TaskConfiguration taskConfiguration = (TaskConfiguration) configuration;
		Test[] originalTests = taskConfiguration.getTests();
		EditTestsDialog dialog = new EditTestsDialog(originalTests, project);
		dialog.show();
		if (!dialog.isOK()) {
			return;
		}
		Test[] newTests = dialog.getTests();
		taskConfiguration.setTests(newTests);

		// @todo: save configuration
	}
}
 
Example #6
Source File: AutoSwitcher.java    From JHelper with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void addSelectedConfigurationListener() {
	RunManagerImpl.getInstanceImpl(project).addRunManagerListener(new RunManagerListener() {
		@Override
		public void runConfigurationSelected(RunnerAndConfigurationSettings selectedConfiguration) {
			if (selectedConfiguration == null) {
				return;
			}
			RunConfiguration configuration = selectedConfiguration.getConfiguration();
			if (busy || !(configuration instanceof TaskConfiguration)) {
				return;
			}
			busy = true;
			String pathToClassFile = ((TaskConfiguration) configuration).getCppPath();
			VirtualFile toOpen = project.getBaseDir().findFileByRelativePath(pathToClassFile);
			if (toOpen != null) {
				TransactionGuard.getInstance().submitTransactionAndWait(() -> FileEditorManager.getInstance(project).openFile(
						toOpen,
						true
				));
			}
			busy = false;
		}
	});
}
 
Example #7
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 #8
Source File: AndroidSyncTest.java    From intellij with Apache License 2.0 5 votes vote down vote up
public TestProjectArguments createTestProjectArguments() {
  Sdk android25 = MockSdkUtil.registerSdk(workspace, "25");

  RunManager runManager = RunManagerImpl.getInstanceImpl(getProject());
  RunnerAndConfigurationSettings runnerAndConfigurationSettings =
      runManager.createConfiguration(
          "Blaze Android Binary Run Configuration",
          BlazeCommandRunConfigurationType.getInstance().getFactory());
  runManager.addConfiguration(runnerAndConfigurationSettings, false);
  BlazeCommandRunConfiguration configuration =
      (BlazeCommandRunConfiguration) runnerAndConfigurationSettings.getConfiguration();
  TargetInfo target =
      TargetInfo.builder(
              Label.create("//java/com/android:app"), ANDROID_BINARY.getKind().getKindString())
          .build();
  configuration.setTargetInfo(target);

  workspace.createFile(
      new WorkspacePath("java/com/google/Source.java"),
      "package com.google;",
      "public class Source {}");
  workspace.createFile(
      new WorkspacePath("java/com/google/Other.java"),
      "package com.google;",
      "public class Other {}");
  VirtualFile javaRoot = workspace.createDirectory(new WorkspacePath("java/com/google"));
  TargetMap targetMap =
      targetMap(
          android_library("//java/com/google:lib")
              .java_toolchain_version("8")
              .res("res/values/strings.xml")
              .src("Source.java", "Other.java"),
          android_binary("//java/com/android:app"));
  return new TestProjectArguments(android25, targetMap, javaRoot);
}
 
Example #9
Source File: CreateAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void perform(final ConfigurationContext context) {
  final RunnerAndConfigurationSettings configuration = context.getConfiguration();
  if (RunDialog.editConfiguration(context.getProject(), configuration, ExecutionBundle.message("create.run.configuration.for.item.dialog.title", configuration.getName()))) {
    final RunManagerImpl runManager = (RunManagerImpl)context.getRunManager();
    runManager.addConfiguration(configuration,
                                runManager.isConfigurationShared(configuration),
                                runManager.getBeforeRunTasks(configuration.getConfiguration()), false);
    runManager.setSelectedConfiguration(configuration);
  }
}
 
Example #10
Source File: CreateAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void perform(final ConfigurationContext context) {
  final RunManagerImpl runManager = (RunManagerImpl)context.getRunManager();
  final RunnerAndConfigurationSettings configuration = context.getConfiguration();
  final RunnerAndConfigurationSettings template = runManager.getConfigurationTemplate(configuration.getFactory());
  final RunConfiguration templateConfiguration = template.getConfiguration();
  runManager.addConfiguration(configuration,
                              runManager.isConfigurationShared(template),
                              runManager.getBeforeRunTasks(templateConfiguration),
                              false);
  runManager.setSelectedConfiguration(configuration);
}
 
Example #11
Source File: ChooseRunConfigurationPopup.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static List<ItemWrapper> createFlatSettingsList(@Nonnull Project project) {
  return RunManagerImpl.getInstanceImpl(project)
          .getConfigurationsGroupedByTypeAndFolder(false)
          .values()
          .stream()
          .flatMap(map -> map.values().stream().flatMap(Collection::stream))
          .map(settings -> ItemWrapper.wrap(project, settings))
          .collect(Collectors.toList());
}
 
Example #12
Source File: ExecutorAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private static ConfigurationFromContext createConfiguration(RunConfigurationProducer<?> producer,
                                                            ConfigurationContext context) {
  RunConfiguration configuration = producer.createLightConfiguration(context);
  if (configuration == null) return null;
  RunnerAndConfigurationSettingsImpl
          settings = new RunnerAndConfigurationSettingsImpl(RunManagerImpl.getInstanceImpl(context.getProject()), configuration, false);
  return new ConfigurationFromContextImpl(producer, settings, context.getPsiLocation());
}
 
Example #13
Source File: CompoundRunConfiguration.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void initIfNeed() {
  if (myInitialized) return;
  mySetToRun.clear();
  RunManagerImpl manager = RunManagerImpl.getInstanceImpl(getProject());
  for (Pair<String, String> pair : myPairs) {
    RunnerAndConfigurationSettings settings = manager.findConfigurationByTypeAndName(pair.first, pair.second);
    if (settings != null && settings.getConfiguration() != this) {
      mySetToRun.add(settings.getConfiguration());
    }
  }
  myInitialized = true;
}
 
Example #14
Source File: CompoundRunConfigurationSettingsEditor.java    From consulo with Apache License 2.0 5 votes vote down vote up
public CompoundRunConfigurationSettingsEditor(@Nonnull Project project) {
  myRunManager = RunManagerImpl.getInstanceImpl(project);
  myModel = new SortedListModel<>(CompoundRunConfiguration.COMPARATOR);
  myList = new JBList(myModel);
  myList.setCellRenderer(new ColoredListCellRenderer() {
    @Override
    protected void customizeCellRenderer(@Nonnull JList list, Object value, int index, boolean selected, boolean hasFocus) {
      RunConfiguration configuration = myModel.get(index);
      setIcon(configuration.getType().getIcon());
      append(configuration.getType().getDisplayName() + " '" + configuration.getName() + "'");
    }
  });
  myList.setVisibleRowCount(15);
}
 
Example #15
Source File: GaugeRunProcessHandler.java    From Intellij-Plugin with Apache License 2.0 5 votes vote down vote up
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());
                LOG.debug(e);
            }
        }
    };

    ApplicationManager.getApplication().invokeAndWait(runnable, ModalityState.any());
}
 
Example #16
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 #17
Source File: PantsClasspathRunConfigurationExtension.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * The goal of this function is to find classpath for IntelliJ JUnit/Scala runner.
 * <p/>
 * This function will fail if the projects' Pants doesn't support `--export-classpath-manifest-jar-only`.
 * It also assumes that Pants has created a manifest jar that contains all the classpath links for the
 * particular test that's being run.
 */
@Override
public <T extends RunConfigurationBase> void updateJavaParameters(
  T configuration,
  @NotNull JavaParameters params,
  RunnerSettings runnerSettings
) throws ExecutionException {
  List<BeforeRunTask<?>> tasks = ((RunManagerImpl) RunManager.getInstance(configuration.getProject())).getBeforeRunTasks(configuration);
  boolean builtByPants = tasks.stream().anyMatch(s -> s.getProviderId().equals(PantsMakeBeforeRun.ID));
  // Not built by Pants means it was built by IntelliJ, in which case we don't need to change the classpath.
  if (!builtByPants) {
    return;
  }

  final Module module = findPantsModule(configuration);
  if (module == null) {
    return;
  }

  Set<String> pathsAllowed = calculatePathsAllowed(params);

  final PathsList classpath = params.getClassPath();
  List<String> classpathToKeep = classpath.getPathList().stream()
    .filter(cp -> pathsAllowed.stream().anyMatch(cp::contains)).collect(Collectors.toList());
  classpath.clear();
  classpath.addAll(classpathToKeep);

  VirtualFile manifestJar = PantsUtil.findProjectManifestJar(configuration.getProject())
    .orElseThrow(() -> new ExecutionException("manifest.jar is not found. It should be generated by `./pants export-classpath ...`"));
  classpath.add(manifestJar.getPath());

  PantsExternalMetricsListenerManager.getInstance().logTestRunner(configuration);
}
 
Example #18
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 #19
Source File: ServerConnectionManager.java    From aem-ide-tooling-4-intellij with Apache License 2.0 5 votes vote down vote up
public void connectInDebugMode(RunManagerEx runManager) {
    ServerConfiguration serverConfiguration = selectionHandler.getCurrentConfiguration();
    // Create Remote Connection to Server using the IntelliJ Run / Debug Connection
    //AS TODO: It is working but the configuration is listed and made persistent. That is not too bad because
    //AS TODO: after changes a reconnect will update the configuration.
    RemoteConfigurationType remoteConfigurationType = new RemoteConfigurationType();
    RunConfiguration runConfiguration = remoteConfigurationType.getFactory().createTemplateConfiguration(myProject);
    RemoteConfiguration remoteConfiguration = (RemoteConfiguration) runConfiguration;
    // Server means if you are listening. If not you are attaching.
    remoteConfiguration.SERVER_MODE = false;
    remoteConfiguration.USE_SOCKET_TRANSPORT = true;
    remoteConfiguration.HOST = serverConfiguration.getHost();
    remoteConfiguration.PORT = serverConfiguration.getConnectionDebugPort() + "";
    // Set a Name of the Configuration so that it is properly listed.
    remoteConfiguration.setName(serverConfiguration.getName());
    RunnerAndConfigurationSettings configuration = new RunnerAndConfigurationSettingsImpl(
        (RunManagerImpl) runManager,
        runConfiguration,
        false
    );
    runManager.setTemporaryConfiguration(configuration);
    //AS TODO: Make sure that this is the proper way to obtain the DEBUG Executor
    Executor executor = ExecutorRegistry.getInstance().getExecutorById(ToolWindowId.DEBUG);
    ExecutionUtil.runConfiguration(configuration, executor);
    // Update the Modules with the Remote Sling Server
    OsgiClient osgiClient = obtainOSGiClient();
    if(osgiClient != null) {
        BundleStatus status = checkAndUpdateSupportBundle(false);
        if(status != BundleStatus.failed) {
            checkModules(osgiClient);
        }
    }
}
 
Example #20
Source File: RunConfigurationSerializerTest.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Before
public final void doSetup() {
  runManager = RunManagerImpl.getInstanceImpl(getProject());
  // Without BlazeProjectData, the configuration editor is always disabled.
  BlazeProjectDataManager mockProjectDataManager =
      new MockBlazeProjectDataManager(MockBlazeProjectDataBuilder.builder(workspaceRoot).build());
  registerProjectService(BlazeProjectDataManager.class, mockProjectDataManager);

  RunnerAndConfigurationSettings runnerAndConfigurationSettings =
      runManager.createConfiguration(
          "Bazel Configuration", BlazeCommandRunConfigurationType.getInstance().getFactory());
  runManager.addConfiguration(runnerAndConfigurationSettings, false);
  configuration =
      (BlazeCommandRunConfiguration) runnerAndConfigurationSettings.getConfiguration();
}
 
Example #21
Source File: BlazeCommandRunConfigurationRunManagerImplTest.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Before
public final void doSetup() {
  runManager = RunManagerImpl.getInstanceImpl(getProject());
  // Without BlazeProjectData, the configuration editor is always disabled.
  BlazeProjectDataManager mockProjectDataManager =
      new MockBlazeProjectDataManager(MockBlazeProjectDataBuilder.builder(workspaceRoot).build());
  registerProjectService(BlazeProjectDataManager.class, mockProjectDataManager);
  type = BlazeCommandRunConfigurationType.getInstance();

  RunnerAndConfigurationSettings runnerAndConfigurationSettings =
      runManager.createConfiguration("Blaze Configuration", type.getFactory());
  runManager.addConfiguration(runnerAndConfigurationSettings, false);
  configuration =
      (BlazeCommandRunConfiguration) runnerAndConfigurationSettings.getConfiguration();
}
 
Example #22
Source File: BlazeRunConfigurationSyncListener.java    From intellij with Apache License 2.0 5 votes vote down vote up
/**
 * On each sync, re-calculate target kind for all existing run configurations, in case the target
 * map has changed since the last sync. Also force-enable our before-run task on all
 * configurations.
 */
private static void updateExistingRunConfigurations(Project project) {
  RunManagerImpl manager = RunManagerImpl.getInstanceImpl(project);
  boolean beforeRunTasksChanged = false;
  for (RunConfiguration config :
      manager.getConfigurationsList(BlazeCommandRunConfigurationType.getInstance())) {
    if (config instanceof BlazeCommandRunConfiguration) {
      ((BlazeCommandRunConfiguration) config).updateTargetKindAsync(null);
      beforeRunTasksChanged |= enableBlazeBeforeRunTask((BlazeCommandRunConfiguration) config);
    }
  }
  if (beforeRunTasksChanged) {
    manager.fireBeforeRunTasksUpdated();
  }
}
 
Example #23
Source File: BlazeRunConfigurationSyncListener.java    From intellij with Apache License 2.0 5 votes vote down vote up
private static void removeInvalidRunConfigurations(Project project) {
  RunManagerImpl manager = RunManagerImpl.getInstanceImpl(project);
  List<RunnerAndConfigurationSettings> toRemove =
      manager
          .getConfigurationSettingsList(BlazeCommandRunConfigurationType.getInstance())
          .stream()
          .filter(s -> isInvalidRunConfig(s.getConfiguration()))
          .collect(Collectors.toList());
  if (!toRemove.isEmpty()) {
    manager.removeConfigurations(toRemove);
  }
}
 
Example #24
Source File: RunConfigurationSerializer.java    From intellij with Apache License 2.0 5 votes vote down vote up
/**
 * Deserializes the configuration represented by the given XML element, then searches for an
 * existing run configuration in the project with the same name and type.
 */
@Nullable
@VisibleForTesting
static RunnerAndConfigurationSettings findExisting(Project project, Element element)
    throws InvalidDataException {
  RunManagerImpl manager = RunManagerImpl.getInstanceImpl(project);
  RunnerAndConfigurationSettingsImpl settings = new RunnerAndConfigurationSettingsImpl(manager);
  settings.readExternal(element, /* isShared= */ false);
  RunConfiguration config = settings.getConfiguration();
  if (config == null) {
    return null;
  }
  return manager.findConfigurationByTypeAndName(config.getType().getId(), config.getName());
}
 
Example #25
Source File: RunConfigurationSerializer.java    From intellij with Apache License 2.0 5 votes vote down vote up
public static Element writeToXml(RunConfiguration configuration) {
  RunnerAndConfigurationSettings settings =
      RunManagerImpl.getInstanceImpl(configuration.getProject()).getSettings(configuration);
  Element element = new Element("configuration");
  try {
    runWithPathVariableSet(
        configuration.getProject(),
        () -> ((RunnerAndConfigurationSettingsImpl) settings).writeExternal(element));
  } catch (WriteExternalException e) {
    logger.warn("Error serializing run configuration to XML", e);
  }
  return element;
}
 
Example #26
Source File: CleanProjectTargetsSyncAction.java    From intellij with Apache License 2.0 5 votes vote down vote up
private static void removeInvalidRunConfigurations(Project project, ImmutableSet<Label> deleted) {
  RunManagerImpl manager = RunManagerImpl.getInstanceImpl(project);
  List<RunnerAndConfigurationSettings> toRemove =
      manager
          .getConfigurationSettingsList(BlazeCommandRunConfigurationType.getInstance())
          .stream()
          .filter(s -> isDeletedTarget(s.getConfiguration(), deleted))
          .collect(Collectors.toList());
  if (!toRemove.isEmpty()) {
    manager.removeConfigurations(toRemove);
  }
}
 
Example #27
Source File: ProjectExecutor.java    From tmc-intellij with MIT License 5 votes vote down vote up
@NotNull
private RunnerAndConfigurationSettingsImpl getApplicationRunnerAndConfigurationSettings(
        RunManager runManager, ModuleBasedConfiguration appCon) {
    logger.info("Getting RunnerAndConfigurationSettings implementation.");
    return new RunnerAndConfigurationSettingsImpl(
            (RunManagerImpl) runManager,
            appCon,
            runManager.getSelectedConfiguration().isTemplate());
}
 
Example #28
Source File: ProgramRunnerUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static void executeConfiguration(@Nonnull ExecutionEnvironment environment, boolean showSettings, boolean assignNewId) {
  if (ExecutorRegistry.getInstance().isStarting(environment)) {
    return;
  }

  RunnerAndConfigurationSettings runnerAndConfigurationSettings = environment.getRunnerAndConfigurationSettings();
  if (runnerAndConfigurationSettings != null) {
    if (!ExecutionTargetManager.canRun(environment)) {
      ExecutionUtil.handleExecutionError(environment, new ExecutionException(
              StringUtil.escapeXml("Cannot run '" + environment.getRunProfile().getName() + "' on '" + environment.getExecutionTarget().getDisplayName() + "'")));
      return;
    }

    if (!RunManagerImpl.canRunConfiguration(environment) || (showSettings && runnerAndConfigurationSettings.isEditBeforeRun())) {
      if (!RunDialog.editConfiguration(environment, "Edit configuration")) {
        return;
      }

      while (!RunManagerImpl.canRunConfiguration(environment)) {
        if (Messages.YES ==
            Messages.showYesNoDialog(environment.getProject(), "Configuration is still incorrect. Do you want to edit it again?", "Change Configuration Settings", "Edit", "Continue Anyway",
                                     Messages.getErrorIcon())) {
          if (!RunDialog.editConfiguration(environment, "Edit configuration")) {
            return;
          }
        }
        else {
          break;
        }
      }
    }

    ConfigurationType configurationType = runnerAndConfigurationSettings.getType();
    if (configurationType != null) {
      UsageTrigger.trigger("execute." + ConvertUsagesUtil.ensureProperKey(configurationType.getId()) + "." + environment.getExecutor().getId());
    }
  }

  try {
    if (assignNewId) {
      environment.assignNewExecutionId();
    }
    environment.getRunner().execute(environment);
  }
  catch (ExecutionException e) {
    String name = runnerAndConfigurationSettings != null ? runnerAndConfigurationSettings.getName() : null;
    if (name == null) {
      name = environment.getRunProfile().getName();
    }
    if (name == null && environment.getContentToReuse() != null) {
      name = environment.getContentToReuse().getDisplayName();
    }
    if (name == null) {
      name = "<Unknown>";
    }
    ExecutionUtil.handleExecutionError(environment.getProject(), environment.getExecutor().getToolWindowId(), name, e);
  }
}