Java Code Examples for com.intellij.execution.runners.ExecutionEnvironment#getRunProfile()

The following examples show how to use com.intellij.execution.runners.ExecutionEnvironment#getRunProfile() . 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: BlazeHotSwapManager.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Nullable
static HotSwappableDebugSession findHotSwappableBlazeDebuggerSession(Project project) {
  DebuggerManagerEx debuggerManager = DebuggerManagerEx.getInstanceEx(project);
  DebuggerSession session = debuggerManager.getContext().getDebuggerSession();
  if (session == null || !session.isAttached()) {
    return null;
  }
  JavaDebugProcess process = session.getProcess().getXdebugProcess();
  if (process == null) {
    return null;
  }
  ExecutionEnvironment env = ((XDebugSessionImpl) process.getSession()).getExecutionEnvironment();
  if (env == null || ClassFileManifestBuilder.getManifest(env) == null) {
    return null;
  }
  RunProfile runProfile = env.getRunProfile();
  if (!(runProfile instanceof BlazeCommandRunConfiguration)) {
    return null;
  }
  return new HotSwappableDebugSession(session, env, (BlazeCommandRunConfiguration) runProfile);
}
 
Example 2
Source File: RoboVmRunner.java    From robovm-idea with GNU General Public License v2.0 6 votes vote down vote up
@Nullable
@Override
protected RunContentDescriptor doExecute(@NotNull RunProfileState state, @NotNull ExecutionEnvironment environment) throws ExecutionException {
    if(DEBUG_EXECUTOR.equals(environment.getExecutor().getId())) {
        RoboVmRunConfiguration runConfig = (RoboVmRunConfiguration)environment.getRunProfile();
        RemoteConnection connection = new RemoteConnection(true, "127.0.0.1", "" + runConfig.getDebugPort(), false);
        connection.setServerMode(true);
        return attachVirtualMachine(state, environment, connection, false);
    } else {
        ExecutionResult executionResult = state.execute(environment.getExecutor(), this);
        if (executionResult == null) {
            return null;
        }
        return new RunContentBuilder(executionResult, environment).showRunContent(environment.getContentToReuse());
    }
}
 
Example 3
Source File: CppBaseDebugRunner.java    From CppTools with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
protected RunContentDescriptor doExecute(Project project, RunProfileState runProfileState, RunContentDescriptor runContentDescriptor, ExecutionEnvironment env) throws ExecutionException {
  FileDocumentManager.getInstance().saveAllDocuments();

  final RunProfile runProfile = env.getRunProfile();

  final XDebugSession debugSession =
      XDebuggerManager.getInstance(project).startSession(this, env, runContentDescriptor, new XDebugProcessStarter() {
        @NotNull
        public XDebugProcess start(@NotNull final XDebugSession session) {
          return new CppDebugProcess(session, CppBaseDebugRunner.this, (BaseCppConfiguration)runProfile);
        }
      });

  return debugSession.getRunContentDescriptor();
}
 
Example 4
Source File: BlazeCoverageProgramRunner.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
protected RunContentDescriptor doExecute(RunProfileState profile, ExecutionEnvironment env)
    throws ExecutionException {
  BlazeInfo blazeInfo = getBlazeInfo(env.getProject());
  if (blazeInfo == null) {
    throw new ExecutionException(
        "Can't run with coverage: no sync data found. Please sync your project and retry.");
  }
  RunContentDescriptor result = super.doExecute(profile, env);
  if (result == null) {
    return null;
  }
  EventLoggingService.getInstance().logEvent(getClass(), "run-with-coverage");
  // remove any old copy of the coverage data

  // retrieve coverage data and copy locally
  BlazeCommandRunConfiguration blazeConfig = (BlazeCommandRunConfiguration) env.getRunProfile();
  BlazeCoverageEnabledConfiguration config =
      (BlazeCoverageEnabledConfiguration) CoverageEnabledConfiguration.getOrCreate(blazeConfig);

  String coverageFilePath = config.getCoverageFilePath();
  File blazeOutputFile = CoverageUtils.getOutputFile(blazeInfo);

  ProcessHandler handler = result.getProcessHandler();
  if (handler != null) {
    ProcessHandler wrappedHandler =
        new ProcessHandlerWrapper(
            handler, exitCode -> copyCoverageOutput(blazeOutputFile, coverageFilePath, exitCode));
    CoverageHelper.attachToProcess(blazeConfig, wrappedHandler, env.getRunnerSettings());
  }
  return result;
}
 
Example 5
Source File: EmbeddedLinuxJVMRunner.java    From embeddedlinux-jvmdebugger-intellij with Apache License 2.0 5 votes vote down vote up
/**
 * Executes the Runner, This only gets called in run mode.
 * It returns null because you want to show only the PI Console
 *
 * @param profileState
 * @param environment
 * @return
 * @throws ExecutionException
 */
@Override
protected RunContentDescriptor doExecute(@NotNull RunProfileState profileState, @NotNull ExecutionEnvironment environment) throws ExecutionException {
    final RunProfile runProfileRaw = environment.getRunProfile();
    if (runProfileRaw instanceof EmbeddedLinuxJVMRunConfiguration) {
        FileDocumentManager.getInstance().saveAllDocuments();
        setupConsole(environment.getProject());
        return super.doExecute(profileState, environment);
    }
    return super.doExecute(profileState, environment);
}
 
Example 6
Source File: EmbeddedLinuxJVMDebugger.java    From embeddedlinux-jvmdebugger-intellij with Apache License 2.0 5 votes vote down vote up
/**
 * Executes the runner
 *
 * @param project
 * @param state
 * @param contentToReuse
 * @param environment
 * @return
 * @throws ExecutionException
 */
@Override
protected RunContentDescriptor doExecute(@NotNull Project project, @NotNull RunProfileState state, RunContentDescriptor contentToReuse, @NotNull ExecutionEnvironment environment) throws ExecutionException {
    final RunProfile runProfileRaw = environment.getRunProfile();
    if (runProfileRaw instanceof EmbeddedLinuxJVMRunConfiguration) {
        FileDocumentManager.getInstance().saveAllDocuments();
        setupConsole(environment.getProject());
        super.doExecute(project, state, contentToReuse, environment);
    }
    return super.doExecute(project, state, contentToReuse, environment);
}
 
Example 7
Source File: TaskRunner.java    From JHelper with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Runs specified TaskConfiguration: generates code and then runs output configuration.
 *
 * @throws ClassCastException if {@code environment.getRunProfile()} is not {@link TaskConfiguration}.
 * @see ExecutionEnvironment#getRunProfile()
 */
@Override
public void execute(@NotNull ExecutionEnvironment environment) {
	Project project = environment.getProject();

	TaskConfiguration taskConfiguration = (TaskConfiguration) environment.getRunProfile();
	CodeGenerationUtils.generateSubmissionFileForTask(project, taskConfiguration);

	generateRunFileForTask(project, taskConfiguration);

	List<RunnerAndConfigurationSettings> allSettings = RunManager.getInstance(project).getAllSettings();
	RunnerAndConfigurationSettings testRunnerSettings = null;
	for (RunnerAndConfigurationSettings configuration : allSettings) {
		if (configuration.getName().equals(RUN_CONFIGURATION_NAME)) {
			testRunnerSettings = configuration;
		}
	}
	if (testRunnerSettings == null) {
		throw new NotificationException(
				"No run configuration found",
				"It should be called (" + RUN_CONFIGURATION_NAME + ")"
		);
	}

	ExecutionTarget originalExecutionTarget = environment.getExecutionTarget();
	ExecutionTarget testRunnerExecutionTarget = ((TaskConfigurationExecutionTarget)originalExecutionTarget).getOriginalTarget();
	RunnerAndConfigurationSettings originalSettings = environment.getRunnerAndConfigurationSettings();

	IDEUtils.chooseConfigurationAndTarget(project, testRunnerSettings, testRunnerExecutionTarget);
	ProgramRunnerUtil.executeConfiguration(testRunnerSettings, environment.getExecutor());

	IDEUtils.chooseConfigurationAndTarget(project, originalSettings, originalExecutionTarget);
}
 
Example 8
Source File: HaxeTestsRunner.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
@Override
protected RunContentDescriptor doExecute(@NotNull final Project project,
                                         @NotNull RunProfileState state,
                                         final RunContentDescriptor descriptor,
                                         @NotNull final ExecutionEnvironment environment) throws ExecutionException {

  final HaxeTestsConfiguration profile = (HaxeTestsConfiguration)environment.getRunProfile();
  final Module module = profile.getConfigurationModule().getModule();

  ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
  VirtualFile[] roots = rootManager.getContentRoots();

  return super.doExecute(project, new CommandLineState(environment) {
    @NotNull
    @Override
    protected ProcessHandler startProcess() throws ExecutionException {
      //actually only neko target is supported for tests
      HaxeTarget currentTarget = HaxeTarget.NEKO;
      final GeneralCommandLine commandLine = new GeneralCommandLine();
      commandLine.setWorkDirectory(PathUtil.getParentPath(module.getModuleFilePath()));
      commandLine.setExePath(currentTarget.getFlag());
      final HaxeModuleSettings settings = HaxeModuleSettings.getInstance(module);
      String folder = settings.getOutputFolder() != null ? (settings.getOutputFolder() + "/release/") : "";
      commandLine.addParameter(getFileNameWithCurrentExtension(currentTarget, folder + settings.getOutputFileName()));

      final TextConsoleBuilder consoleBuilder = TextConsoleBuilderFactory.getInstance().createBuilder(module.getProject());
      consoleBuilder.addFilter(new ErrorFilter(module));
      setConsoleBuilder(consoleBuilder);

      return new OSProcessHandler(commandLine.createProcess(), commandLine.getCommandLineString());
    }

    private String getFileNameWithCurrentExtension(HaxeTarget haxeTarget, String fileName) {
      if (haxeTarget != null) {
        return haxeTarget.getTargetFileNameWithExtension(FileUtil.getNameWithoutExtension(fileName));
      }
      return fileName;
    }
  }, descriptor, environment);
}
 
Example 9
Source File: XDebuggerTree.java    From consulo with Apache License 2.0 5 votes vote down vote up
public boolean isUnderRemoteDebug() {
  DataContext context = DataManager.getInstance().getDataContext(this);
  ExecutionEnvironment env = context.getData(LangDataKeys.EXECUTION_ENVIRONMENT);
  if (env != null && env.getRunProfile() instanceof RemoteRunProfile) {
    return true;
  }
  return false;
}
 
Example 10
Source File: ExecutionManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void compileAndRun(@Nonnull UIAccess uiAccess, @Nonnull Runnable startRunnable, @Nonnull ExecutionEnvironment environment, @Nullable Runnable onCancelRunnable) {
  long id = environment.getExecutionId();
  if (id == 0) {
    id = environment.assignNewExecutionId();
  }

  RunProfile profile = environment.getRunProfile();
  if (!(profile instanceof RunConfiguration)) {
    startRunnable.run();
    return;
  }

  final RunConfiguration runConfiguration = (RunConfiguration)profile;
  final List<BeforeRunTask> beforeRunTasks = RunManagerEx.getInstanceEx(myProject).getBeforeRunTasks(runConfiguration);
  if (beforeRunTasks.isEmpty()) {
    startRunnable.run();
  }
  else {
    DataContext context = environment.getDataContext();
    final DataContext projectContext = context != null ? context : SimpleDataContext.getProjectContext(myProject);

    AsyncResult<Void> result = AsyncResult.undefined();

    runBeforeTask(beforeRunTasks, 0, id, environment, uiAccess, projectContext, runConfiguration, result);

    if (onCancelRunnable != null) {
      result.doWhenRejected(() -> uiAccess.give(onCancelRunnable));
    }

    result.doWhenDone(() -> {
      // important! Do not use DumbService.smartInvokeLater here because it depends on modality state
      // and execution of startRunnable could be skipped if modality state check fails
      uiAccess.give(() -> {
        if (!myProject.isDisposed()) {
          DumbService.getInstance(myProject).runWhenSmart(startRunnable);
        }
      });
    });
  }
}
 
Example 11
Source File: LaunchState.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
protected RunContentDescriptor launch(@NotNull ExecutionEnvironment env) throws ExecutionException {
  FileDocumentManager.getInstance().saveAllDocuments();

  // Set our FlutterLaunchMode up in the ExecutionEnvironment.
  if (RunMode.fromEnv(env).isProfiling()) {
    FlutterLaunchMode.addToEnvironment(env, FlutterLaunchMode.PROFILE);
  }

  final Project project = getEnvironment().getProject();
  @Nullable final FlutterDevice device = DeviceService.getInstance(project).getSelectedDevice();
  if (device == null) {
    showNoDeviceConnectedMessage(project);
    return null;
  }

  final FlutterApp app = myCreateAppCallback.createApp(device);

  // Cache for use in console configuration.
  FlutterApp.addToEnvironment(env, app);

  // Remember the run configuration that started this process.
  app.getProcessHandler().putUserData(FLUTTER_RUN_CONFIG_KEY, runConfig);

  final ExecutionResult result = setUpConsoleAndActions(app);

  // For Bazel run configurations, where the console is not null, and we find the expected
  // process handler type, print the command line command to the console.
  if (runConfig instanceof BazelRunConfig &&
      app.getConsole() != null &&
      app.getProcessHandler() instanceof OSProcessHandler) {
    final String commandLineString = ((OSProcessHandler)app.getProcessHandler()).getCommandLine().trim();
    if (StringUtil.isNotEmpty(commandLineString)) {
      app.getConsole().print(commandLineString + "\n", ConsoleViewContentType.NORMAL_OUTPUT);
    }
  }

  device.bringToFront();

  // Check for and display any analysis errors when we launch an app.
  if (env.getRunProfile() instanceof SdkRunConfig) {
    final Class dartExecutionHelper = classForName("com.jetbrains.lang.dart.ide.runner.DartExecutionHelper");
    if (dartExecutionHelper != null) {
      final String message = ("<a href='open.dart.analysis'>Analysis issues</a> may affect " +
                              "the execution of '" + env.getRunProfile().getName() + "'.");
      final SdkRunConfig config = (SdkRunConfig)env.getRunProfile();
      final SdkFields sdkFields = config.getFields();
      final MainFile mainFile = MainFile.verify(sdkFields.getFilePath(), env.getProject()).get();

      DartExecutionHelper.displayIssues(project, mainFile.getFile(), message, env.getRunProfile().getIcon());
    }
  }

  final FlutterLaunchMode launchMode = FlutterLaunchMode.fromEnv(env);
  if (launchMode.supportsDebugConnection()) {
    return createDebugSession(env, app, result).getRunContentDescriptor();
  }
  else {
    return new RunContentBuilder(result, env).showRunContent(env.getContentToReuse());
  }
}
 
Example 12
Source File: LaunchState.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
protected RunContentDescriptor launch(@NotNull ExecutionEnvironment env) throws ExecutionException {
  FileDocumentManager.getInstance().saveAllDocuments();

  // Set our FlutterLaunchMode up in the ExecutionEnvironment.
  if (RunMode.fromEnv(env).isProfiling()) {
    FlutterLaunchMode.addToEnvironment(env, FlutterLaunchMode.PROFILE);
  }

  final Project project = getEnvironment().getProject();
  @Nullable final FlutterDevice device = DeviceService.getInstance(project).getSelectedDevice();
  if (device == null) {
    showNoDeviceConnectedMessage(project);
    return null;
  }

  final FlutterApp app = myCreateAppCallback.createApp(device);

  // Cache for use in console configuration.
  FlutterApp.addToEnvironment(env, app);

  // Remember the run configuration that started this process.
  app.getProcessHandler().putUserData(FLUTTER_RUN_CONFIG_KEY, runConfig);

  final ExecutionResult result = setUpConsoleAndActions(app);

  // For Bazel run configurations, where the console is not null, and we find the expected
  // process handler type, print the command line command to the console.
  if (runConfig instanceof BazelRunConfig &&
      app.getConsole() != null &&
      app.getProcessHandler() instanceof OSProcessHandler) {
    final String commandLineString = ((OSProcessHandler)app.getProcessHandler()).getCommandLine().trim();
    if (StringUtil.isNotEmpty(commandLineString)) {
      app.getConsole().print(commandLineString + "\n", ConsoleViewContentType.NORMAL_OUTPUT);
    }
  }

  device.bringToFront();

  // Check for and display any analysis errors when we launch an app.
  if (env.getRunProfile() instanceof SdkRunConfig) {
    final Class dartExecutionHelper = classForName("com.jetbrains.lang.dart.ide.runner.DartExecutionHelper");
    if (dartExecutionHelper != null) {
      final String message = ("<a href='open.dart.analysis'>Analysis issues</a> may affect " +
                              "the execution of '" + env.getRunProfile().getName() + "'.");
      final SdkRunConfig config = (SdkRunConfig)env.getRunProfile();
      final SdkFields sdkFields = config.getFields();
      final MainFile mainFile = MainFile.verify(sdkFields.getFilePath(), env.getProject()).get();

      DartExecutionHelper.displayIssues(project, mainFile.getFile(), message, env.getRunProfile().getIcon());
    }
  }

  final FlutterLaunchMode launchMode = FlutterLaunchMode.fromEnv(env);
  if (launchMode.supportsDebugConnection()) {
    return createDebugSession(env, app, result).getRunContentDescriptor();
  }
  else {
    return new RunContentBuilder(result, env).showRunContent(env.getContentToReuse());
  }
}
 
Example 13
Source File: BlazeCommandRunConfigurationRunner.java    From intellij with Apache License 2.0 4 votes vote down vote up
static BlazeCommandRunConfiguration getConfiguration(ExecutionEnvironment environment) {
  RunProfile runProfile = environment.getRunProfile();
  return Preconditions.checkNotNull(getBlazeConfig(runProfile));
}