public boolean isGeneratedName( final String name, final JavaRunConfigurationModule configurationModule) { if (TEST_OBJECT == null) return true; if ((TEST_CLASS.equals(TEST_OBJECT) || TEST_METHOD.equals(TEST_OBJECT)) && getMainClassName().length() == 0) { return JavaExecutionUtil.isNewName(name); } if (TEST_METHOD.equals(TEST_OBJECT) && getMethodName().length() == 0) { return JavaExecutionUtil.isNewName(name); } return Comparing.equal(name, getGeneratedName(configurationModule)); }
public void bePatternConfiguration(List<PsiClass> classes, PsiMethod method) { data.TEST_OBJECT = TestType.PATTERN.getType(); final String suffix; if (method != null) { data.METHOD_NAME = method.getName(); suffix = "," + data.METHOD_NAME; } else { suffix = ""; } LinkedHashSet<String> patterns = new LinkedHashSet<String>(); for (PsiClass pattern : classes) { patterns.add(JavaExecutionUtil.getRuntimeQualifiedName(pattern) + suffix); } data.setPatterns(patterns); final Module module = RunConfigurationProducer.getInstance(TestNGPatternConfigurationProducer.class) .findModule(this, getConfigurationModule().getModule(), patterns); if (module == null) { data.setScope(TestSearchScope.WHOLE_PROJECT); setModule(null); } else { setModule(module); } setGeneratedName(); }
public String getGeneratedName(final JavaRunConfigurationModule configurationModule) { if (TEST_PACKAGE.equals(TEST_OBJECT) || TEST_DIRECTORY.equals(TEST_OBJECT)) { final String moduleName = TEST_SEARCH_SCOPE.getScope() == TestSearchScope.WHOLE_PROJECT ? "" : configurationModule.getModuleName(); final String packageName = getPackageName(); if (packageName.length() == 0) { if (moduleName.length() > 0) { return ExecutionBundle.message("default.junit.config.name.all.in.module", moduleName); } return DEFAULT_PACKAGE_NAME; } if (moduleName.length() > 0) { return ExecutionBundle.message( "default.junit.config.name.all.in.package.in.module", packageName, moduleName); } return packageName; } if (TEST_PATTERN.equals(TEST_OBJECT)) { final int size = myPattern.size(); if (size == 0) return "Temp suite"; return StringUtil.getShortName(myPattern.iterator().next()) + (size > 1 ? " and " + (size - 1) + " more" : ""); } final String className = JavaExecutionUtil.getPresentableClassName(getMainClassName(), configurationModule); if (TEST_METHOD.equals(TEST_OBJECT)) { return className + '.' + getMethodName(); } return className; }
public void bePatternConfiguration(List<PsiClass> classes, PsiMethod method) { myData.TEST_OBJECT = TEST_PATTERN; final Set<String> patterns = new HashSet<String>(); final String methodSufiix; if (method != null) { myData.METHOD_NAME = method.getName(); methodSufiix = "," + myData.METHOD_NAME; } else { methodSufiix = ""; } for (PsiClass pattern : classes) { patterns.add(JavaExecutionUtil.getRuntimeQualifiedName(pattern) + methodSufiix); } myData.setPatterns(patterns); final Module module = PatternConfigurationProducer.findModule( this, getConfigurationModule().getModule(), patterns); if (module == null) { myData.setScope(TestSearchScope.WHOLE_PROJECT); setModule(null); } else { setModule(module); } setGeneratedName(); }
@Override protected RunnerAndConfigurationSettings findExistingByElement( Location location, @NotNull RunnerAndConfigurationSettings[] existingConfigurations, ConfigurationContext context) { final PsiClass aClass = ApplicationConfigurationType.getMainClass(location.getPsiElement()); if (aClass == null) { return null; } final Module predefinedModule = ((ApplicationConfiguration) ((RunManagerImpl) RunManagerEx.getInstanceEx(location.getProject())) .getConfigurationTemplate(getConfigurationFactory()) .getConfiguration()) .getConfigurationModule() .getModule(); for (RunnerAndConfigurationSettings existingConfiguration : existingConfigurations) { final ApplicationConfiguration appConfiguration = (ApplicationConfiguration) existingConfiguration.getConfiguration(); if (Comparing.equal( JavaExecutionUtil.getRuntimeQualifiedName(aClass), appConfiguration.MAIN_CLASS_NAME)) { if (Comparing.equal( location.getModule(), appConfiguration.getConfigurationModule().getModule())) { return existingConfiguration; } final Module configurationModule = appConfiguration.getConfigurationModule().getModule(); if (Comparing.equal(location.getModule(), configurationModule)) return existingConfiguration; if (Comparing.equal(predefinedModule, configurationModule)) { return existingConfiguration; } } } return null; }
private RunnerAndConfigurationSettings createConfiguration( final PsiClass aClass, final ConfigurationContext context, Location location) { final Project project = aClass.getProject(); RunnerAndConfigurationSettings settings = cloneTemplateConfiguration(project, context); final ApplicationConfiguration configuration = (ApplicationConfiguration) settings.getConfiguration(); configuration.MAIN_CLASS_NAME = JavaExecutionUtil.getRuntimeQualifiedName(aClass); configuration.setName(configuration.getGeneratedName()); setupConfigurationModule(context, configuration); JavaRunConfigurationExtensionManager.getInstance() .extendCreatedConfiguration(configuration, location); return settings; }
public RunnerAndConfigurationSettings createConfigurationByElement( Location location, final ConfigurationContext context) { location = JavaExecutionUtil.stepIntoSingleClass(location); if (location == null) return null; final PsiElement element = location.getPsiElement(); if (!element.isPhysical()) return null; PsiElement currentElement = element; PsiMethod method; while ((method = findMain(currentElement)) != null) { final PsiClass aClass = method.getContainingClass(); if (ConfigurationUtil.MAIN_CLASS.value(aClass)) { myPsiElement = method; return createConfiguration(aClass, context, location); } currentElement = method.getParent(); } final PsiClass aClass = ApplicationConfigurationType.getMainClass(element); if (aClass == null) return null; myPsiElement = aClass; return createConfiguration(aClass, context, location); }
public Module setMainClass(final PsiClass testClass) { MAIN_CLASS_NAME = JavaExecutionUtil.getRuntimeQualifiedName(testClass); PsiPackage containingPackage = JUnitUtil.getContainingPackage(testClass); PACKAGE_NAME = containingPackage != null ? containingPackage.getQualifiedName() : ""; return JavaExecutionUtil.findModule(testClass); }