use of com.intellij.execution.Location in project intellij-plugins by JetBrains.
the class CucumberJavaRunConfigurationProducer method setupConfigurationFromContext.
@Override
protected boolean setupConfigurationFromContext(CucumberJavaRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
final VirtualFile virtualFile = getFileToRun(context);
if (virtualFile == null) {
return false;
}
final Project project = configuration.getProject();
final PsiElement element = context.getPsiLocation();
if (element == null) {
return false;
}
final Module module = ModuleUtilCore.findModuleForFile(virtualFile, project);
if (module == null)
return false;
String mainClassName = null;
String formatterOptions = null;
final Location location = context.getLocation();
if (location != null) {
if (LocationUtil.isJarAttached(location, PsiDirectory.EMPTY_ARRAY, CUCUMBER_1_0_MAIN_CLASS)) {
mainClassName = CUCUMBER_1_0_MAIN_CLASS;
} else if (LocationUtil.isJarAttached(location, PsiDirectory.EMPTY_ARRAY, CUCUMBER_1_1_MAIN_CLASS)) {
mainClassName = CUCUMBER_1_1_MAIN_CLASS;
}
if (LocationUtil.isJarAttached(location, PsiDirectory.EMPTY_ARRAY, CUCUMBER_1_2_PLUGIN_CLASS)) {
formatterOptions = FORMATTER_OPTIONS_1_2;
} else {
formatterOptions = FORMATTER_OPTIONS;
}
}
if (mainClassName == null) {
return false;
}
final VirtualFile file = getFileToRun(context);
if (file == null) {
return false;
}
if (StringUtil.isEmpty(configuration.getGlue())) {
final NullableComputable<String> glue = getStepsGlue(element);
configuration.setGlue(glue);
}
configuration.setNameFilter(getNameFilter(context));
configuration.setFilePath(file.getPath());
configuration.setProgramParameters(formatterOptions);
if (StringUtil.isEmpty(configuration.MAIN_CLASS_NAME)) {
configuration.MAIN_CLASS_NAME = mainClassName;
}
if (configuration.getNameFilter() != null && configuration.getNameFilter().length() > 0) {
final String newProgramParameters = configuration.getProgramParameters() + " --name \"" + configuration.getNameFilter() + "\"";
configuration.setProgramParameters(newProgramParameters);
}
configuration.myGeneratedName = getConfigurationName(context);
configuration.setGeneratedName();
setupConfigurationModule(context, configuration);
JavaRunConfigurationExtensionManager.getInstance().extendCreatedConfiguration(configuration, location);
return true;
}
use of com.intellij.execution.Location in project intellij-community by JetBrains.
the class TestsUIUtil method getData.
@Nullable
public static Object getData(final AbstractTestProxy testProxy, final String dataId, final TestFrameworkRunningModel model) {
final TestConsoleProperties properties = model.getProperties();
final Project project = properties.getProject();
if (testProxy == null)
return null;
if (AbstractTestProxy.DATA_KEY.is(dataId))
return testProxy;
if (CommonDataKeys.NAVIGATABLE.is(dataId))
return getOpenFileDescriptor(testProxy, model);
if (CommonDataKeys.PSI_ELEMENT.is(dataId)) {
final Location location = testProxy.getLocation(project, properties.getScope());
if (location != null) {
final PsiElement element = location.getPsiElement();
return element.isValid() ? element : null;
} else {
return null;
}
}
if (Location.DATA_KEY.is(dataId))
return testProxy.getLocation(project, properties.getScope());
if (RunConfiguration.DATA_KEY.is(dataId)) {
final RunProfile configuration = properties.getConfiguration();
if (configuration instanceof RunConfiguration) {
return configuration;
}
}
return null;
}
use of com.intellij.execution.Location in project intellij-community by JetBrains.
the class AbstractExcludeFromRunAction method update.
@Override
public void update(AnActionEvent e) {
final Presentation presentation = e.getPresentation();
presentation.setVisible(false);
final DataContext dataContext = e.getDataContext();
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
if (project != null) {
final RunConfiguration configuration = RunConfiguration.DATA_KEY.getData(dataContext);
if (isPatternBasedConfiguration(configuration)) {
final AbstractTestProxy testProxy = AbstractTestProxy.DATA_KEY.getData(dataContext);
if (testProxy != null) {
final Location location = testProxy.getLocation(project, ((T) configuration).getConfigurationModule().getSearchScope());
if (location != null) {
final PsiElement psiElement = location.getPsiElement();
if (psiElement instanceof PsiClass && getPattern((T) configuration).contains(((PsiClass) psiElement).getQualifiedName())) {
presentation.setVisible(true);
}
}
}
}
}
}
use of com.intellij.execution.Location in project intellij-community by JetBrains.
the class TestLocationDataRule method getLocation.
@Nullable
private static Location getLocation(Project project, String fileName, String nameWithoutExtension, PsiClass aClass) {
final PsiAnnotation annotation = AnnotationUtil.findAnnotation(aClass, TestDataPath.class.getName());
if (annotation != null) {
final Location parameterizedLocation = PsiMemberParameterizedLocation.getParameterizedLocation(aClass, "[" + fileName + "]", Parameterized.class.getName());
if (parameterizedLocation != null) {
return parameterizedLocation;
}
if (StringUtil.isJavaIdentifier(nameWithoutExtension)) {
final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(project);
PsiMethod method = aClass.findMethodBySignature(elementFactory.createMethod("test" + nameWithoutExtension, PsiType.VOID), true);
if (method != null) {
return MethodLocation.elementInClass(method, aClass);
}
method = aClass.findMethodBySignature(elementFactory.createMethod("test" + StringUtil.capitalize(nameWithoutExtension), PsiType.VOID), true);
if (method != null) {
return MethodLocation.elementInClass(method, aClass);
}
}
return new PsiLocation<PsiElement>(project, aClass);
}
return null;
}
use of com.intellij.execution.Location in project intellij-community by JetBrains.
the class PatternGradleConfigurationProducer method doSetupConfigurationFromContext.
@Override
protected boolean doSetupConfigurationFromContext(ExternalSystemRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
final Location contextLocation = context.getLocation();
assert contextLocation != null;
final LinkedHashSet<String> tests = new LinkedHashSet<>();
final PsiElement element = myBaseConfigurationProducer.checkPatterns(context, tests);
if (element == null) {
return false;
}
sourceElement.set(element);
String projectPath = null;
Set<String> scriptParameters = ContainerUtil.newLinkedHashSet();
Set<String> tasksToRun = ContainerUtil.newLinkedHashSet();
final Project project = context.getProject();
final List<String> resolvedTests = ContainerUtil.newArrayList();
for (String test : tests) {
final int i = StringUtil.indexOf(test, ",");
String aClass = i < 0 ? test : test.substring(0, i);
final PsiClass psiClass = JavaPsiFacade.getInstance(project).findClass(aClass, GlobalSearchScope.projectScope(project));
if (psiClass == null)
continue;
final PsiFile psiFile = psiClass.getContainingFile();
if (psiFile == null)
continue;
final Module moduleForFile = ProjectFileIndex.SERVICE.getInstance(project).getModuleForFile(psiFile.getVirtualFile());
if (!ExternalSystemApiUtil.isExternalSystemAwareModule(GradleConstants.SYSTEM_ID, moduleForFile))
return false;
projectPath = ExternalSystemApiUtil.getExternalRootProjectPath(moduleForFile);
if (projectPath == null)
return false;
ContainerUtil.addAllNotNull(tasksToRun, getTasksToRun(moduleForFile));
final String method = i != -1 && test.length() > i + 1 ? test.substring(i + 1) : null;
scriptParameters.add(TestMethodGradleConfigurationProducer.createTestFilter(aClass, method));
resolvedTests.add(psiClass.getName() + "," + (method == null ? "" : method));
}
if (tasksToRun.isEmpty() || projectPath == null)
return false;
configuration.getSettings().setExternalProjectPath(projectPath);
configuration.getSettings().setTaskNames(ContainerUtil.newArrayList(tasksToRun));
configuration.getSettings().setScriptParameters(StringUtil.join(scriptParameters, " "));
final String name;
if (resolvedTests.size() > 1) {
name = resolvedTests.get(0) + " and " + (resolvedTests.size() - 1) + " more";
} else {
name = StringUtil.join(tests, "|");
}
configuration.setName(name);
JavaRunConfigurationExtensionManager.getInstance().extendCreatedConfiguration(configuration, contextLocation);
return true;
}
Aggregations