use of com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration in project intellij-community by JetBrains.
the class AssignRunConfigurationShortcutAction method actionPerformed.
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
Project project = getProject(e);
assert project != null;
final List<ExternalSystemNode> selectedNodes = ExternalSystemDataKeys.SELECTED_NODES.getData(e.getDataContext());
if (selectedNodes == null || selectedNodes.size() != 1 || !(selectedNodes.get(0) instanceof RunConfigurationNode))
return;
RunnerAndConfigurationSettings settings = ((RunConfigurationNode) selectedNodes.get(0)).getSettings();
assert settings != null;
ExternalSystemRunConfiguration runConfiguration = (ExternalSystemRunConfiguration) settings.getConfiguration();
String actionIdPrefix = getActionPrefix(project, runConfiguration.getSettings().getExternalProjectPath());
String actionId = actionIdPrefix + settings.getName();
AnAction action = ActionManager.getInstance().getAction(actionId);
if (action == null) {
ExternalSystemKeymapExtension.getOrRegisterAction(project, settings);
}
new EditKeymapsDialog(project, actionId).show();
}
use of com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration in project intellij-community by JetBrains.
the class GradleApplicationEnvironmentProvider method createExecutionEnvironment.
@Nullable
public ExecutionEnvironment createExecutionEnvironment(@NotNull Project project, @NotNull ExecuteRunConfigurationTask executeRunConfigurationTask, @Nullable Executor executor) {
if (!isApplicable(executeRunConfigurationTask))
return null;
ApplicationConfiguration applicationConfiguration = (ApplicationConfiguration) executeRunConfigurationTask.getRunProfile();
PsiClass mainClass = applicationConfiguration.getMainClass();
if (mainClass == null)
return null;
VirtualFile virtualFile = mainClass.getContainingFile().getVirtualFile();
Module module = ProjectFileIndex.SERVICE.getInstance(project).getModuleForFile(virtualFile);
if (module == null)
return null;
final JavaParameters params = new JavaParameters();
JavaParametersUtil.configureConfiguration(params, applicationConfiguration);
params.getVMParametersList().addParametersString(applicationConfiguration.getVMParameters());
String javaExePath = null;
try {
final Sdk jdk = JavaParametersUtil.createProjectJdk(project, applicationConfiguration.getAlternativeJrePath());
if (jdk == null)
throw new RuntimeException(ExecutionBundle.message("run.configuration.error.no.jdk.specified"));
final SdkTypeId type = jdk.getSdkType();
if (!(type instanceof JavaSdkType))
throw new RuntimeException(ExecutionBundle.message("run.configuration.error.no.jdk.specified"));
javaExePath = ((JavaSdkType) type).getVMExecutablePath(jdk);
if (javaExePath == null)
throw new RuntimeException(ExecutionBundle.message("run.configuration.cannot.find.vm.executable"));
javaExePath = FileUtil.toSystemIndependentName(javaExePath);
} catch (CantRunException e) {
ExecutionErrorDialog.show(e, "Cannot use specified JRE", project);
}
StringBuilder parametersString = new StringBuilder();
for (String parameter : params.getProgramParametersList().getParameters()) {
parametersString.append("args '").append(parameter).append("'\n");
}
StringBuilder vmParametersString = new StringBuilder();
for (String parameter : params.getVMParametersList().getParameters()) {
vmParametersString.append("jvmArgs '").append(parameter).append("'\n");
}
ExternalSystemTaskExecutionSettings taskSettings = new ExternalSystemTaskExecutionSettings();
taskSettings.setExternalSystemIdString(GradleConstants.SYSTEM_ID.getId());
taskSettings.setExternalProjectPath(ExternalSystemApiUtil.getExternalProjectPath(module));
final String runAppTaskName = "run " + mainClass.getName();
taskSettings.setTaskNames(Collections.singletonList(runAppTaskName));
String executorId = executor == null ? DefaultRunExecutor.EXECUTOR_ID : executor.getId();
ExecutionEnvironment environment = ExternalSystemUtil.createExecutionEnvironment(project, GradleConstants.SYSTEM_ID, taskSettings, executorId);
if (environment != null) {
RunnerAndConfigurationSettings runnerAndConfigurationSettings = environment.getRunnerAndConfigurationSettings();
assert runnerAndConfigurationSettings != null;
ExternalSystemRunConfiguration runConfiguration = (ExternalSystemRunConfiguration) runnerAndConfigurationSettings.getConfiguration();
final String gradlePath = GradleProjectResolverUtil.getGradlePath(module);
if (gradlePath == null)
return null;
final String sourceSetName;
if (GradleConstants.GRADLE_SOURCE_SET_MODULE_TYPE_KEY.equals(ExternalSystemApiUtil.getExternalModuleType(module))) {
sourceSetName = GradleProjectResolverUtil.getSourceSetName(module);
} else {
sourceSetName = ModuleRootManager.getInstance(module).getFileIndex().isInTestSourceContent(virtualFile) ? "test" : "main";
}
if (sourceSetName == null)
return null;
@Language("Groovy") String initScript = "projectsEvaluated {\n" + " rootProject.allprojects {\n" + " if(project.path == '" + gradlePath + "' && project.sourceSets) {\n" + " project.tasks.create(name: '" + runAppTaskName + "', overwrite: true, type: JavaExec) {\n" + (javaExePath != null ? " executable = '" + javaExePath + "'\n" : "") + " classpath = project.sourceSets.'" + sourceSetName + "'.runtimeClasspath\n" + " main = '" + mainClass.getQualifiedName() + "'\n" + parametersString.toString() + vmParametersString.toString() + " }\n" + " }\n" + " }\n" + "}\n";
runConfiguration.putUserData(GradleTaskManager.INIT_SCRIPT_KEY, initScript);
return environment;
} else {
return null;
}
}
use of com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration in project intellij-community by JetBrains.
the class TestClassGradleConfigurationProducer method onFirstRun.
@Override
public void onFirstRun(final ConfigurationFromContext fromContext, final ConfigurationContext context, @NotNull final Runnable performRunnable) {
final InheritorChooser inheritorChooser = new InheritorChooser() {
@Override
protected void runForClasses(List<PsiClass> classes, PsiMethod method, ConfigurationContext context, Runnable performRunnable) {
if (!StringUtil.equals(context.getModule().getOptionValue(ExternalSystemConstants.EXTERNAL_SYSTEM_ID_KEY), GradleConstants.SYSTEM_ID.toString())) {
return;
}
ExternalSystemRunConfiguration configuration = (ExternalSystemRunConfiguration) fromContext.getConfiguration();
if (!applyTestConfiguration(configuration, context, ArrayUtil.toObjectArray(classes, PsiClass.class)))
return;
super.runForClasses(classes, method, context, performRunnable);
}
@Override
protected void runForClass(PsiClass aClass, PsiMethod psiMethod, ConfigurationContext context, Runnable performRunnable) {
if (!StringUtil.equals(context.getModule().getOptionValue(ExternalSystemConstants.EXTERNAL_SYSTEM_ID_KEY), GradleConstants.SYSTEM_ID.toString())) {
return;
}
ExternalSystemRunConfiguration configuration = (ExternalSystemRunConfiguration) fromContext.getConfiguration();
if (!applyTestConfiguration(configuration, context, aClass))
return;
super.runForClass(aClass, psiMethod, context, performRunnable);
}
};
if (inheritorChooser.runMethodInAbstractClass(context, performRunnable, null, (PsiClass) fromContext.getSourceElement()))
return;
super.onFirstRun(fromContext, context, performRunnable);
}
use of com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration in project intellij-community by JetBrains.
the class TestClassGradleConfigurationProducer method applyTestConfiguration.
private static boolean applyTestConfiguration(@NotNull ExternalSystemRunConfiguration configuration, @NotNull ConfigurationContext context, @NotNull PsiClass... containingClasses) {
final Module module = context.getModule();
if (!ExternalSystemApiUtil.isExternalSystemAwareModule(GradleConstants.SYSTEM_ID, module))
return false;
final String projectPath = ExternalSystemApiUtil.getExternalProjectPath(module);
if (projectPath == null)
return false;
List<String> tasksToRun = getTasksToRun(module);
if (tasksToRun.isEmpty())
return false;
configuration.getSettings().setExternalProjectPath(projectPath);
configuration.getSettings().setTaskNames(tasksToRun);
StringBuilder buf = new StringBuilder();
for (PsiClass aClass : containingClasses) {
buf.append(String.format("--tests %s ", aClass.getQualifiedName()));
}
configuration.getSettings().setScriptParameters(buf.toString());
configuration.setName(StringUtil.join(containingClasses, aClass -> aClass.getName(), "|"));
return true;
}
use of com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration in project intellij-community by JetBrains.
the class TestMethodGradleConfigurationProducer method onFirstRun.
@Override
public void onFirstRun(final ConfigurationFromContext fromContext, final ConfigurationContext context, @NotNull final Runnable performRunnable) {
final PsiMethod psiMethod = (PsiMethod) fromContext.getSourceElement();
final PsiClass containingClass = psiMethod.getContainingClass();
final InheritorChooser inheritorChooser = new InheritorChooser() {
@Override
protected void runForClasses(List<PsiClass> classes, PsiMethod method, ConfigurationContext context, Runnable performRunnable) {
if (!StringUtil.equals(context.getModule().getOptionValue(ExternalSystemConstants.EXTERNAL_SYSTEM_ID_KEY), GradleConstants.SYSTEM_ID.toString())) {
return;
}
ExternalSystemRunConfiguration configuration = (ExternalSystemRunConfiguration) fromContext.getConfiguration();
if (!applyTestMethodConfiguration(configuration, context, psiMethod, ArrayUtil.toObjectArray(classes, PsiClass.class)))
return;
super.runForClasses(classes, method, context, performRunnable);
}
@Override
protected void runForClass(PsiClass aClass, PsiMethod psiMethod, ConfigurationContext context, Runnable performRunnable) {
if (!StringUtil.equals(context.getModule().getOptionValue(ExternalSystemConstants.EXTERNAL_SYSTEM_ID_KEY), GradleConstants.SYSTEM_ID.toString())) {
return;
}
ExternalSystemRunConfiguration configuration = (ExternalSystemRunConfiguration) fromContext.getConfiguration();
if (!applyTestMethodConfiguration(configuration, context, psiMethod, aClass))
return;
super.runForClass(aClass, psiMethod, context, performRunnable);
}
};
if (inheritorChooser.runMethodInAbstractClass(context, performRunnable, psiMethod, containingClass))
return;
super.onFirstRun(fromContext, context, performRunnable);
}
Aggregations