use of com.intellij.execution.actions.ConfigurationContext 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.execution.actions.ConfigurationContext 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);
}
use of com.intellij.execution.actions.ConfigurationContext in project kotlin by JetBrains.
the class KotlinTestNgConfigurationProducer method onFirstRun.
@Override
public void onFirstRun(ConfigurationFromContext configuration, ConfigurationContext context, Runnable startRunnable) {
KtNamedDeclaration declarationToRun = getDeclarationToRun(configuration.getSourceElement());
final PsiNamedElement lightElement = CollectionsKt.firstOrNull(LightClassUtilsKt.toLightElements(declarationToRun));
// Copied from TestNGInClassConfigurationProducer.onFirstRun()
if (lightElement instanceof PsiMethod || lightElement instanceof PsiClass) {
PsiMethod psiMethod;
PsiClass containingClass;
if (lightElement instanceof PsiMethod) {
psiMethod = (PsiMethod) lightElement;
containingClass = psiMethod.getContainingClass();
} else {
psiMethod = null;
containingClass = (PsiClass) lightElement;
}
InheritorChooser inheritorChooser = new InheritorChooser() {
@Override
protected void runForClasses(List<PsiClass> classes, PsiMethod method, ConfigurationContext context, Runnable performRunnable) {
((TestNGConfiguration) context.getConfiguration().getConfiguration()).bePatternConfiguration(classes, method);
super.runForClasses(classes, method, context, performRunnable);
}
@Override
protected void runForClass(PsiClass aClass, PsiMethod psiMethod, ConfigurationContext context, Runnable performRunnable) {
if (lightElement instanceof PsiMethod) {
Project project = psiMethod.getProject();
MethodLocation methodLocation = new MethodLocation(project, psiMethod, PsiLocation.fromPsiElement(aClass));
((TestNGConfiguration) context.getConfiguration().getConfiguration()).setMethodConfiguration(methodLocation);
} else {
((TestNGConfiguration) context.getConfiguration().getConfiguration()).setClassConfiguration(aClass);
}
super.runForClass(aClass, psiMethod, context, performRunnable);
}
};
if (inheritorChooser.runMethodInAbstractClass(context, startRunnable, psiMethod, containingClass, new Condition<PsiClass>() {
@Override
public boolean value(PsiClass aClass) {
return aClass.hasModifierProperty(PsiModifier.ABSTRACT) && TestNGUtil.hasTest(aClass);
}
}))
return;
}
super.onFirstRun(configuration, context, startRunnable);
}
use of com.intellij.execution.actions.ConfigurationContext in project intellij-community by JetBrains.
the class PyStudyRunContextAction method update.
@Override
public void update(AnActionEvent event) {
final ConfigurationContext context = ConfigurationContext.getFromContext(event.getDataContext());
final Location location = context.getLocation();
if (location == null)
return;
super.update(event);
final InputEvent inputEvent = event.getInputEvent();
final Presentation presentation = event.getPresentation();
if (inputEvent == null && !(context.getDataContext().getData(PlatformDataKeys.CONTEXT_COMPONENT) instanceof EditorGutter)) {
presentation.setText("");
}
}
use of com.intellij.execution.actions.ConfigurationContext in project android by JetBrains.
the class TestConfigurationTesting method createConfigurationFromPsiElement.
@Nullable
private static RunConfiguration createConfigurationFromPsiElement(@NotNull Project project, @NotNull PsiElement psiElement) {
ConfigurationContext context = createContext(project, psiElement);
RunnerAndConfigurationSettings settings = context.getConfiguration();
if (settings == null) {
return null;
}
RunConfiguration configuration = settings.getConfiguration();
if (configuration instanceof AndroidTestRunConfiguration || configuration instanceof AndroidJUnitConfiguration) {
return configuration;
}
return null;
}
Aggregations