use of com.intellij.execution.Location in project intellij-community by JetBrains.
the class GradleRunnerUtil method getData.
public static Object getData(@NotNull Project project, @NonNls String dataId, @NotNull ExecutionInfo executionInfo) {
if (CommonDataKeys.NAVIGATABLE.is(dataId)) {
final Location location = getLocation(project, executionInfo);
final OpenFileDescriptor openFileDescriptor = location == null ? null : location.getOpenFileDescriptor();
if (openFileDescriptor != null && openFileDescriptor.getFile().isValid()) {
return openFileDescriptor;
}
}
if (CommonDataKeys.PSI_ELEMENT.is(dataId)) {
final Location location = getLocation(project, executionInfo);
if (location != null) {
final PsiElement element = location.getPsiElement();
return element.isValid() ? element : null;
} else {
return null;
}
}
if (Location.DATA_KEY.is(dataId))
return getLocation(project, executionInfo);
return null;
}
use of com.intellij.execution.Location in project intellij-community by JetBrains.
the class TestClassGradleConfigurationProducer method doIsConfigurationFromContext.
@Override
protected boolean doIsConfigurationFromContext(ExternalSystemRunConfiguration configuration, ConfigurationContext context) {
final Location contextLocation = context.getLocation();
assert contextLocation != null;
if (RunConfigurationProducer.getInstance(PatternConfigurationProducer.class).isMultipleElementsSelected(context)) {
return false;
}
if (getPsiMethodForLocation(contextLocation) != null)
return false;
PsiClass testClass = getPsiClassForLocation(contextLocation);
if (testClass == null || testClass.getQualifiedName() == null)
return false;
if (context.getModule() == null)
return false;
final String projectPath = resolveProjectPath(context.getModule());
if (projectPath == null)
return false;
if (!StringUtil.equals(projectPath, configuration.getSettings().getExternalProjectPath())) {
return false;
}
if (!configuration.getSettings().getTaskNames().containsAll(getTasksToRun(context.getModule())))
return false;
final String scriptParameters = configuration.getSettings().getScriptParameters() + ' ';
int i = scriptParameters.indexOf("--tests ");
if (i == -1)
return false;
String str = scriptParameters.substring(i + "--tests ".length()).trim() + ' ';
return str.startsWith(testClass.getQualifiedName() + ' ') && !str.contains("--tests");
}
use of com.intellij.execution.Location in project intellij-community by JetBrains.
the class TestClassGradleConfigurationProducer method doSetupConfigurationFromContext.
@Override
protected boolean doSetupConfigurationFromContext(ExternalSystemRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
final Location contextLocation = context.getLocation();
assert contextLocation != null;
if (RunConfigurationProducer.getInstance(PatternConfigurationProducer.class).isMultipleElementsSelected(context)) {
return false;
}
PsiClass testClass = getPsiClassForLocation(contextLocation);
if (testClass == null) {
return false;
}
sourceElement.set(testClass);
final Module module = context.getModule();
if (module == null)
return false;
if (!ExternalSystemApiUtil.isExternalSystemAwareModule(GradleConstants.SYSTEM_ID, module))
return false;
final String projectPath = resolveProjectPath(module);
if (projectPath == null)
return false;
List<String> tasksToRun = getTasksToRun(module);
if (tasksToRun.isEmpty())
return false;
configuration.getSettings().setExternalProjectPath(projectPath);
configuration.getSettings().setTaskNames(tasksToRun);
configuration.getSettings().setScriptParameters(String.format("--tests %s", testClass.getQualifiedName()));
configuration.setName(testClass.getName());
JavaRunConfigurationExtensionManager.getInstance().extendCreatedConfiguration(configuration, contextLocation);
return true;
}
use of com.intellij.execution.Location in project intellij-community by JetBrains.
the class TestMethodGradleConfigurationProducer method doIsConfigurationFromContext.
@Override
protected boolean doIsConfigurationFromContext(ExternalSystemRunConfiguration configuration, ConfigurationContext context) {
if (RunConfigurationProducer.getInstance(PatternConfigurationProducer.class).isMultipleElementsSelected(context)) {
return false;
}
final Location contextLocation = context.getLocation();
assert contextLocation != null;
PsiMethod psiMethod = getPsiMethodForLocation(contextLocation);
if (psiMethod == null)
return false;
final PsiClass containingClass = psiMethod.getContainingClass();
if (containingClass == null)
return false;
final Module module = context.getModule();
if (module == null)
return false;
final String projectPath = resolveProjectPath(module);
if (projectPath == null)
return false;
if (!StringUtil.equals(projectPath, configuration.getSettings().getExternalProjectPath())) {
return false;
}
if (!configuration.getSettings().getTaskNames().containsAll(getTasksToRun(module)))
return false;
final String scriptParameters = configuration.getSettings().getScriptParameters() + ' ';
final String testFilter = createTestFilter(containingClass, psiMethod);
return scriptParameters.contains(testFilter);
}
use of com.intellij.execution.Location in project intellij-community by JetBrains.
the class AbstractTestNGPackageConfigurationProducer method setupConfigurationFromContext.
@Override
protected boolean setupConfigurationFromContext(TestNGConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
final PsiElement element = context.getPsiLocation();
PsiPackage aPackage = JavaRuntimeConfigurationProducerBase.checkPackage(element);
if (aPackage == null) {
return false;
}
final Location location = context.getLocation();
if (location == null) {
return false;
}
if (!LocationUtil.isJarAttached(location, aPackage, TestNGUtil.TEST_ANNOTATION_FQN)) {
return false;
}
final TestData data = configuration.data;
data.PACKAGE_NAME = aPackage.getQualifiedName();
data.TEST_OBJECT = TestType.PACKAGE.getType();
data.setScope(setupPackageConfiguration(context, configuration, data.getScope()));
configuration.setGeneratedName();
sourceElement.set(aPackage);
return true;
}
Aggregations