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

The following examples show how to use com.intellij.execution.runners.ExecutionEnvironment#getProject() . 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: DaemonConsoleView.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Sets up a launcher to use a DaemonConsoleView.
 */
public static void install(@NotNull CommandLineState launcher, @NotNull ExecutionEnvironment env, @NotNull VirtualFile workDir) {
  // Create our own console builder.
  //
  // We need to filter input to this console without affecting other consoles, so we cannot use
  // a consoleFilterInputProvider.
  final GlobalSearchScope searchScope = SearchScopeProvider.createSearchScope(env.getProject(), env.getRunProfile());
  final TextConsoleBuilder builder = new TextConsoleBuilderImpl(env.getProject(), searchScope) {
    @NotNull
    @Override
    protected ConsoleView createConsole() {
      return new DaemonConsoleView(env.getProject(), searchScope);
    }
  };

  // Set up basic console filters. (More may be added later.)
  // TODO(devoncarew): Do we need this filter? What about DartConsoleFilter (for package: uris)?
  builder.addFilter(new DartRelativePathsConsoleFilter(env.getProject(), workDir.getPath()));
  launcher.setConsoleBuilder(builder);
}
 
Example 2
Source File: LaunchState.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@NotNull
private FlutterPositionMapper createPositionMapper(@NotNull ExecutionEnvironment env,
                                                   @NotNull FlutterApp app,
                                                   @NotNull DartUrlResolver resolver) {
  final FlutterPositionMapper.Analyzer analyzer;
  if (app.getMode() == RunMode.DEBUG) {
    analyzer = FlutterPositionMapper.Analyzer.create(env.getProject(), sourceLocation);
  }
  else {
    analyzer = null; // Don't need analysis server just to run.
  }

  // Choose source root containing the Dart application.
  // TODO(skybrian) for bazel, we probably should pass in three source roots here (for bazel-bin, bazel-genfiles, etc).
  final VirtualFile pubspec = resolver.getPubspecYamlFile();
  final VirtualFile sourceRoot = pubspec != null ? pubspec.getParent() : workDir;

  return new FlutterPositionMapper(env.getProject(), sourceRoot, resolver, analyzer);
}
 
Example 3
Source File: DaemonConsoleView.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Sets up a launcher to use a DaemonConsoleView.
 */
public static void install(@NotNull CommandLineState launcher, @NotNull ExecutionEnvironment env, @NotNull VirtualFile workDir) {
  // Create our own console builder.
  //
  // We need to filter input to this console without affecting other consoles, so we cannot use
  // a consoleFilterInputProvider.
  final GlobalSearchScope searchScope = SearchScopeProvider.createSearchScope(env.getProject(), env.getRunProfile());
  final TextConsoleBuilder builder = new TextConsoleBuilderImpl(env.getProject(), searchScope) {
    @NotNull
    @Override
    protected ConsoleView createConsole() {
      return new DaemonConsoleView(env.getProject(), searchScope);
    }
  };

  // Set up basic console filters. (More may be added later.)
  // TODO(devoncarew): Do we need this filter? What about DartConsoleFilter (for package: uris)?
  builder.addFilter(new DartRelativePathsConsoleFilter(env.getProject(), workDir.getPath()));
  launcher.setConsoleBuilder(builder);
}
 
Example 4
Source File: LaunchState.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@NotNull
private FlutterPositionMapper createPositionMapper(@NotNull ExecutionEnvironment env,
                                                   @NotNull FlutterApp app,
                                                   @NotNull DartUrlResolver resolver) {
  final FlutterPositionMapper.Analyzer analyzer;
  if (app.getMode() == RunMode.DEBUG) {
    analyzer = FlutterPositionMapper.Analyzer.create(env.getProject(), sourceLocation);
  }
  else {
    analyzer = null; // Don't need analysis server just to run.
  }

  // Choose source root containing the Dart application.
  // TODO(skybrian) for bazel, we probably should pass in three source roots here (for bazel-bin, bazel-genfiles, etc).
  final VirtualFile pubspec = resolver.getPubspecYamlFile();
  final VirtualFile sourceRoot = pubspec != null ? pubspec.getParent() : workDir;

  return new FlutterPositionMapper(env.getProject(), sourceRoot, resolver, analyzer);
}
 
Example 5
Source File: BlazeCommandGenericRunConfigurationRunner.java    From intellij with Apache License 2.0 6 votes vote down vote up
public BlazeCommandRunProfileState(ExecutionEnvironment environment) {
  super(environment);
  this.configuration = getConfiguration(environment);
  this.handlerState =
      (BlazeCommandRunConfigurationCommonState) configuration.getHandler().getState();
  Project project = environment.getProject();
  this.consoleFilters =
      ImmutableList.<Filter>builder()
          .add(
              new BlazeTargetFilter(true),
              new UrlFilter(),
              new IssueOutputFilter(
                  project,
                  WorkspaceRoot.fromProject(project),
                  BlazeInvocationContext.ContextType.RunConfiguration,
                  false))
          .build();
}
 
Example 6
Source File: SdkRunConfig.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@NotNull
@Override
public GeneralCommandLine getCommand(@NotNull ExecutionEnvironment env, @Nullable FlutterDevice device) throws ExecutionException {
  final SdkFields launchFields = fields.copy();
  final Project project = env.getProject();
  final RunMode mode = RunMode.fromEnv(env);
  return fields.createFlutterSdkRunCommand(project, mode, FlutterLaunchMode.fromEnv(env), device);
}
 
Example 7
Source File: SdkRunConfig.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@NotNull
@Override
public GeneralCommandLine getCommand(@NotNull ExecutionEnvironment env, @Nullable FlutterDevice device) throws ExecutionException {
  final SdkFields launchFields = fields.copy();
  final Project project = env.getProject();
  final RunMode mode = RunMode.fromEnv(env);
  return fields.createFlutterSdkRunCommand(project, mode, FlutterLaunchMode.fromEnv(env), device);
}
 
Example 8
Source File: BlazeAndroidRunConfigurationDeployTargetManager.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
DeployTarget getDeployTarget(
    Executor executor, ExecutionEnvironment env, AndroidFacet facet, int runConfigId)
    throws ExecutionException {
  DeployTargetProvider currentTargetProvider = getCurrentDeployTargetProvider();
  Project project = env.getProject();

  DeployTarget deployTarget;

  if (currentTargetProvider.requiresRuntimePrompt(project)) {
    deployTarget =
        currentTargetProvider.showPrompt(
            executor,
            env,
            facet,
            getDeviceCount(),
            isAndroidTest,
            deployTargetStates,
            runConfigId,
            (device) -> LaunchCompatibility.YES);
    if (deployTarget == null) {
      return null;
    }
  } else {
    deployTarget = currentTargetProvider.getDeployTarget(env.getProject());
  }

  return deployTarget;
}
 
Example 9
Source File: AppCommandLineState.java    From embeddedlinux-jvmdebugger-intellij with Apache License 2.0 5 votes vote down vote up
/**
 * Command line state when runner is launch
 *
 * @param environment
 * @param configuration
 */
public AppCommandLineState(@NotNull ExecutionEnvironment environment, @NotNull EmbeddedLinuxJVMRunConfiguration configuration) {
    super(environment);
    this.configuration = configuration;
    this.runnerSettings = environment.getRunnerSettings();
    this.project = environment.getProject();
    this.isDebugMode = runnerSettings instanceof DebuggingRunnerData;
    this.outputForwarder = new EmbeddedLinuxJVMOutputForwarder(EmbeddedLinuxJVMConsoleView.getInstance(project));
    this.outputForwarder.attachTo(null);
}
 
Example 10
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 11
Source File: MuleBeforeRunTasksProvider.java    From mule-intellij-plugins with Apache License 2.0 4 votes vote down vote up
@Override
public boolean executeTask(DataContext dataContext, RunConfiguration runConfiguration, ExecutionEnvironment executionEnvironment, MuleBeforeRunTask muleBeforeRunTask)
{
    final Semaphore targetDone = new Semaphore();
    final List<Boolean> results = new ArrayList<>();

    final Project project = executionEnvironment.getProject();

    MuleConfiguration muleConfiguration = (MuleConfiguration) runConfiguration;

    Module[] modules = muleConfiguration.getModules();

    for (Module nextModule : modules) {
        //final MavenProject mavenProject = getMavenProject(runConfiguration, project);
        final MavenProject mavenProject = getMavenProject(nextModule);
        try {
            ApplicationManager.getApplication().invokeAndWait(new Runnable() {
                public void run() {
                    if (!project.isDisposed() && mavenProject != null) {
                        FileDocumentManager.getInstance().saveAllDocuments();
                        final MavenExplicitProfiles explicitProfiles = MavenProjectsManager.getInstance(project).getExplicitProfiles();
                        final MavenRunner mavenRunner = MavenRunner.getInstance(project);
                        targetDone.down();
                        (new Task.Backgroundable(project, TasksBundle.message("maven.tasks.executing"), true) {
                            public void run(@NotNull ProgressIndicator indicator) {
                                try {
                                    MavenRunnerParameters params =
                                            new MavenRunnerParameters(true, mavenProject.getDirectory(), ParametersListUtil.parse("package"), explicitProfiles.getEnabledProfiles(),
                                                    explicitProfiles.getDisabledProfiles());
                                    boolean result = mavenRunner.runBatch(Collections.singletonList(params), null, null, TasksBundle.message("maven.tasks.executing"), indicator);
                                    results.add(result);
                                } finally {
                                    targetDone.up();
                                }
                            }

                            public boolean shouldStartInBackground() {
                                return MavenRunner.getInstance(project).getSettings().isRunMavenInBackground();
                            }

                            public void processSentToBackground() {
                                MavenRunner.getInstance(project).getSettings().setRunMavenInBackground(true);
                            }
                        }).queue();
                    }
                }
            }, ModalityState.NON_MODAL);
        } catch (Exception exeception) {
            return false;
        }
        targetDone.waitFor();
    }

    boolean endResult = true;

    for (Boolean nextResult : results) {
        endResult = endResult && nextResult;
    }

    return endResult;
}
 
Example 12
Source File: SdkAttachConfig.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@NotNull
@Override
public LaunchState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment env) throws ExecutionException {
  try {
    checkRunnable(env.getProject());
  }
  catch (RuntimeConfigurationError e) {
    throw new ExecutionException(e);
  }

  final SdkFields launchFields = getFields();
  final MainFile mainFile = MainFile.verify(launchFields.getFilePath(), env.getProject()).get();
  final Project project = env.getProject();
  final RunMode mode = RunMode.fromEnv(env);
  final Module module = ModuleUtilCore.findModuleForFile(mainFile.getFile(), env.getProject());
  final LaunchState.CreateAppCallback createAppCallback = (@Nullable FlutterDevice device) -> {
    if (device == null) return null;

    final GeneralCommandLine command = getCommand(env, device);

    final FlutterApp app = FlutterApp.start(env, project, module, mode, device, command,
                                            StringUtil.capitalize(mode.mode()) + "App",
                                            "StopApp");

    // Stop the app if the Flutter SDK changes.
    final FlutterSdkManager.Listener sdkListener = new FlutterSdkManager.Listener() {
      @Override
      public void flutterSdkRemoved() {
        app.shutdownAsync();
      }
    };
    FlutterSdkManager.getInstance(project).addListener(sdkListener);
    Disposer.register(project, () -> FlutterSdkManager.getInstance(project).removeListener(sdkListener));

    return app;
  };

  final LaunchState launcher = new AttachState(env, mainFile.getAppDir(), mainFile.getFile(), this, createAppCallback);
  addConsoleFilters(launcher, env, mainFile, module);
  return launcher;
}
 
Example 13
Source File: SdkAttachConfig.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@NotNull
@Override
public LaunchState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment env) throws ExecutionException {
  try {
    checkRunnable(env.getProject());
  }
  catch (RuntimeConfigurationError e) {
    throw new ExecutionException(e);
  }

  final SdkFields launchFields = getFields();
  final MainFile mainFile = MainFile.verify(launchFields.getFilePath(), env.getProject()).get();
  final Project project = env.getProject();
  final RunMode mode = RunMode.fromEnv(env);
  final Module module = ModuleUtilCore.findModuleForFile(mainFile.getFile(), env.getProject());
  final LaunchState.CreateAppCallback createAppCallback = (@Nullable FlutterDevice device) -> {
    if (device == null) return null;

    final GeneralCommandLine command = getCommand(env, device);

    final FlutterApp app = FlutterApp.start(env, project, module, mode, device, command,
                                            StringUtil.capitalize(mode.mode()) + "App",
                                            "StopApp");

    // Stop the app if the Flutter SDK changes.
    final FlutterSdkManager.Listener sdkListener = new FlutterSdkManager.Listener() {
      @Override
      public void flutterSdkRemoved() {
        app.shutdownAsync();
      }
    };
    FlutterSdkManager.getInstance(project).addListener(sdkListener);
    Disposer.register(project, () -> FlutterSdkManager.getInstance(project).removeListener(sdkListener));

    return app;
  };

  final LaunchState launcher = new AttachState(env, mainFile.getAppDir(), mainFile.getFile(), this, createAppCallback);
  addConsoleFilters(launcher, env, mainFile, module);
  return launcher;
}
 
Example 14
Source File: BlazeAndroidBinaryRunConfigurationHandler.java    From intellij with Apache License 2.0 4 votes vote down vote up
@Override
public BlazeCommandRunConfigurationRunner createRunner(
    Executor executor, ExecutionEnvironment env) throws ExecutionException {
  Project project = env.getProject();

  // This is a workaround for b/134587683
  // Due to the way blaze run configuration editors update the underlying configuration state,
  // it's possible for the configuration referenced in this handler to be out of date. This can
  // cause tricky side-effects such as incorrect build target and target validation settings.
  // Fortunately, the only field that can come out of sync is the target label and it's target
  // kind. The handlers are designed to only handle their supported target kinds, so we can
  // safely ignore all fields other than target label itself and extract an up to date target
  // label from the execution environment.
  // Validation of the updated target label is not needed here because:
  // 1. The target kind is guaranteed to be an android instrumentation test kind or else this
  //    specific handler will not be used.
  // 2. Any other validation is done during edit-time of the run configuration before saving.
  BlazeCommandRunConfiguration configFromEnv =
      BlazeAndroidRunConfigurationHandler.getCommandConfig(env);
  configuration.setTarget(configFromEnv.getSingleTarget());

  Module module = getModule();
  AndroidFacet facet = module != null ? AndroidFacet.getInstance(module) : null;
  ProjectViewSet projectViewSet = ProjectViewManager.getInstance(project).getProjectViewSet();
  BlazeAndroidRunConfigurationValidationUtil.validateExecution(module, facet, projectViewSet);

  ImmutableList<String> blazeFlags =
      configState
          .getCommonState()
          .getExpandedBuildFlags(
              project,
              projectViewSet,
              BlazeCommandName.RUN,
              BlazeInvocationContext.runConfigContext(
                  ExecutorType.fromExecutor(env.getExecutor()), configuration.getType(), false));
  ImmutableList<String> exeFlags =
      ImmutableList.copyOf(
          configState.getCommonState().getExeFlagsState().getFlagsForExternalProcesses());
  BlazeAndroidRunContext runContext = createRunContext(project, facet, env, blazeFlags, exeFlags);

  EventLoggingService.getInstance()
      .logEvent(
          BlazeAndroidBinaryRunConfigurationHandler.class,
          "BlazeAndroidBinaryRun",
          ImmutableMap.of(
              "launchMethod",
              configState.getLaunchMethod().name(),
              "executorId",
              env.getExecutor().getId(),
              "targetLabel",
              configuration.getSingleTarget().toString(),
              "nativeDebuggingEnabled",
              Boolean.toString(configState.getCommonState().isNativeDebuggingEnabled())));
  return new BlazeAndroidRunConfigurationRunner(
      module,
      runContext,
      getCommonState().getDeployTargetManager(),
      getCommonState().getDebuggerManager(),
      configuration);
}
 
Example 15
Source File: BlazeAndroidTestRunConfigurationHandler.java    From intellij with Apache License 2.0 4 votes vote down vote up
@Override
public BlazeCommandRunConfigurationRunner createRunner(
    Executor executor, ExecutionEnvironment env) throws ExecutionException {
  Project project = env.getProject();

  // This is a workaround for b/134587683
  // Due to the way blaze run configuration editors update the underlying configuration state,
  // it's possible for the configuration referenced in this handler to be out of date. This can
  // cause tricky side-effects such as incorrect build target and target validation settings.
  // Fortunately, the only field that can come out of sync is the target label and it's target
  // kind. The handlers are designed to only handle their supported target kinds, so we can
  // safely ignore all fields other than target label itself and extract an up to date target
  // label from the execution environment.
  // Validation of the updated target label is not needed here because:
  // 1. The target kind is guaranteed to be an android binary kind or else this
  //    specific handler will not be used.
  // 2. Any other validation is done during edit-time of the run configuration before saving.
  BlazeCommandRunConfiguration configFromEnv =
      BlazeAndroidRunConfigurationHandler.getCommandConfig(env);
  configuration.setTarget(configFromEnv.getSingleTarget());

  Module module = getModule();
  AndroidFacet facet = module != null ? AndroidFacet.getInstance(module) : null;
  ProjectViewSet projectViewSet = ProjectViewManager.getInstance(project).getProjectViewSet();
  BlazeAndroidRunConfigurationValidationUtil.validateExecution(module, facet, projectViewSet);

  ImmutableList<String> blazeFlags =
      configState
          .getCommonState()
          .getExpandedBuildFlags(
              project,
              projectViewSet,
              BlazeCommandName.TEST,
              BlazeInvocationContext.runConfigContext(
                  ExecutorType.fromExecutor(env.getExecutor()), configuration.getType(), false));
  ImmutableList<String> exeFlags =
      ImmutableList.copyOf(
          configState.getCommonState().getExeFlagsState().getFlagsForExternalProcesses());
  BlazeAndroidRunContext runContext = createRunContext(project, facet, env, blazeFlags, exeFlags);

  EventLoggingService.getInstance()
      .logEvent(
          BlazeAndroidTestRunConfigurationHandler.class,
          "BlazeAndroidTestRun",
          ImmutableMap.of(
              "launchMethod",
              configState.getLaunchMethod().name(),
              "executorId",
              env.getExecutor().getId()));

  return new BlazeAndroidRunConfigurationRunner(
      module,
      runContext,
      getCommonState().getDeployTargetManager(),
      getCommonState().getDebuggerManager(),
      configuration);
}
 
Example 16
Source File: BlazeGoRunConfigurationRunner.java    From intellij with Apache License 2.0 4 votes vote down vote up
GoApplicationRunningState toNativeState(ExecutionEnvironment env) throws ExecutionException {
  ExecutableInfo executable = getExecutableInfo(env);
  if (executable == null || StringUtil.isEmptyOrSpaces(executable.binary.getPath())) {
    throw new ExecutionException("Blaze output binary not found");
  }
  Project project = env.getProject();
  BlazeProjectData projectData =
      BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
  if (projectData == null) {
    throw new ExecutionException("Project data not found. Please run blaze sync.");
  }
  GoApplicationConfiguration nativeConfig =
      (GoApplicationConfiguration)
          GoApplicationRunConfigurationType.getInstance()
              .getConfigurationFactories()[0]
              .createTemplateConfiguration(project, RunManager.getInstance(project));
  nativeConfig.setKind(Kind.PACKAGE);
  // prevents binary from being deleted by
  // GoBuildingRunningState$ProcessHandler#processTerminated
  nativeConfig.setOutputDirectory(executable.binary.getParent());
  nativeConfig.setParams(ParametersListUtil.join(getParameters(executable)));
  nativeConfig.setWorkingDirectory(executable.workingDir.getPath());

  Map<String, String> customEnvironment = new HashMap<>(nativeConfig.getCustomEnvironment());
  for (Map.Entry<String, String> entry : executable.envVars.entrySet()) {
    customEnvironment.put(entry.getKey(), entry.getValue());
  }
  String testFilter = getTestFilter();
  if (testFilter != null) {
    customEnvironment.put("TESTBRIDGE_TEST_ONLY", testFilter);
  }
  nativeConfig.setCustomEnvironment(customEnvironment);

  Module module =
      ModuleManager.getInstance(project)
          .findModuleByName(BlazeDataStorage.WORKSPACE_MODULE_NAME);
  if (module == null) {
    throw new ExecutionException("Workspace module not found");
  }
  GoApplicationRunningState nativeState =
      new GoApplicationRunningState(env, module, nativeConfig) {
        @Override
        public boolean isDebug() {
          return true;
        }

        @Nullable
        @Override
        public List<String> getBuildingTarget() {
          return null;
        }

        @Nullable
        @Override
        public GoExecutor createBuildExecutor() {
          return null;
        }
      };
  nativeState.setOutputFilePath(executable.binary.getPath());
  return nativeState;
}