public void writeExternal(final Element element) throws WriteExternalException {
   super.writeExternal(element);
   JavaRunConfigurationExtensionManager.getInstance().writeExternal(this, element);
   writeModule(element);
   DefaultJDOMExternalizer.writeExternal(this, element);
   final Data persistentData = getPersistentData();
   DefaultJDOMExternalizer.writeExternal(persistentData, element);
   EnvironmentVariablesComponent.writeExternal(element, persistentData.getEnvs());
   final String dirName = persistentData.getDirName();
   if (!dirName.isEmpty()) {
     final Element dirNameElement = new Element("dir");
     dirNameElement.setAttribute("value", FileUtil.toSystemIndependentName(dirName));
     element.addContent(dirNameElement);
   }
   final Element patternsElement = new Element(PATTERNS_EL_NAME);
   for (String o : persistentData.getPatterns()) {
     final Element patternElement = new Element(PATTERN_EL_NAME);
     patternElement.setAttribute(TEST_CLASS_ATT_NAME, o);
     patternsElement.addContent(patternElement);
   }
   final String forkMode = getForkMode();
   if (!forkMode.equals("none")) {
     final Element forkModeElement = new Element("fork_mode");
     forkModeElement.setAttribute("value", forkMode);
     element.addContent(forkModeElement);
   }
   element.addContent(patternsElement);
   PathMacroManager.getInstance(getProject()).collapsePathsRecursively(element);
 }
 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();
 }
 public Data clone() {
   try {
     Data data = (Data) super.clone();
     data.TEST_SEARCH_SCOPE = new TestSearchScope.Wrapper();
     data.setScope(getScope());
     data.myEnvs = new LinkedHashMap<String, String>(myEnvs);
     return data;
   } catch (CloneNotSupportedException e) {
     throw new RuntimeException(e);
   }
 }
 public boolean equals(final Object object) {
   if (!(object instanceof Data)) return false;
   final Data second = (Data) object;
   return Comparing.equal(TEST_OBJECT, second.TEST_OBJECT)
       && Comparing.equal(getMainClassName(), second.getMainClassName())
       && Comparing.equal(getPackageName(), second.getPackageName())
       && Comparing.equal(getMethodName(), second.getMethodName())
       && Comparing.equal(getWorkingDirectory(), second.getWorkingDirectory())
       && Comparing.equal(VM_PARAMETERS, second.VM_PARAMETERS)
       && Comparing.equal(PARAMETERS, second.PARAMETERS)
       && Comparing.equal(myPattern, second.myPattern)
       && Comparing.equal(FORK_MODE, second.FORK_MODE)
       && Comparing.equal(DIR_NAME, second.DIR_NAME);
 }
  public Collection<Module> getValidModules() {
    if (TEST_PACKAGE.equals(myData.TEST_OBJECT) || TEST_PATTERN.equals(myData.TEST_OBJECT)) {
      return Arrays.asList(ModuleManager.getInstance(getProject()).getModules());
    }
    try {
      myData.getTestObject(getProject(), this).checkConfiguration();
    } catch (RuntimeConfigurationError e) {
      return Arrays.asList(ModuleManager.getInstance(getProject()).getModules());
    } catch (RuntimeConfigurationException e) {
      // ignore
    }

    return JavaRunConfigurationModule.getModulesForClass(getProject(), myData.getMainClassName());
  }
 public void readExternal(final Element element) throws InvalidDataException {
   PathMacroManager.getInstance(getProject()).expandPaths(element);
   super.readExternal(element);
   JavaRunConfigurationExtensionManager.getInstance().readExternal(this, element);
   readModule(element);
   DefaultJDOMExternalizer.readExternal(this, element);
   DefaultJDOMExternalizer.readExternal(getPersistentData(), element);
   EnvironmentVariablesComponent.readExternal(element, getPersistentData().getEnvs());
   final Element patternsElement = element.getChild(PATTERNS_EL_NAME);
   if (patternsElement != null) {
     final Set<String> tests = new LinkedHashSet<String>();
     for (Object o : patternsElement.getChildren(PATTERN_EL_NAME)) {
       Element patternElement = (Element) o;
       tests.add(patternElement.getAttributeValue(TEST_CLASS_ATT_NAME));
     }
     myData.setPatterns(tests);
   }
   final Element forkModeElement = element.getChild("fork_mode");
   if (forkModeElement != null) {
     final String mode = forkModeElement.getAttributeValue("value");
     if (mode != null) {
       setForkMode(mode);
     }
   }
   final Element dirNameElement = element.getChild("dir");
   if (dirNameElement != null) {
     final String dirName = dirNameElement.getAttributeValue("value");
     getPersistentData().setDirName(FileUtil.toSystemDependentName(dirName));
   }
 }
 protected ModuleBasedConfiguration createInstance() {
   return new JUnitConfiguration(
       getName(),
       getProject(),
       myData.clone(),
       JUnitConfigurationType.getInstance()
           .getConfigurationFactories()[0]); // throw new RuntimeException("Should not call");
 }
 public void configureClasspath(final JavaParameters javaParameters) throws CantRunException {
   RunConfigurationModule module = getConfigurationModule();
   final String jreHome = isAlternativeJrePathEnabled() ? getAlternativeJrePath() : null;
   final int pathType = JavaParameters.JDK_AND_CLASSES_AND_TESTS;
   if (myData.getScope() == TestSearchScope.WHOLE_PROJECT) {
     JavaParametersUtil.configureProject(module.getProject(), javaParameters, pathType, jreHome);
   } else {
     JavaParametersUtil.configureModule(module, javaParameters, pathType, jreHome);
   }
 }
 public void setName(@NotNull final String qualifiedName) {
   final boolean generatedName = isGeneratedName();
   myData.MAIN_CLASS_NAME = qualifiedName;
   if (generatedName) setGeneratedName();
 }
 public PsiPackage getPsiElement() {
   final String qualifiedName = myData.getPackageName();
   return qualifiedName != null
       ? JavaPsiFacade.getInstance(getProject()).findPackage(qualifiedName)
       : null;
 }
 public void setName(final String qualifiedName) {
   final boolean generatedName = isGeneratedName();
   myData.PACKAGE_NAME = qualifiedName;
   if (generatedName) setGeneratedName();
 }
 public void beMethodConfiguration(final Location<PsiMethod> methodLocation) {
   setModule(myData.setTestMethod(methodLocation));
   setGeneratedName();
 }
 public void setMainClass(final PsiClass testClass) {
   final boolean shouldUpdateName = isGeneratedName();
   setModule(myData.setMainClass(testClass));
   if (shouldUpdateName) setGeneratedName();
 }
 public String getProgramParameters() {
   return myData.getProgramParameters();
 }
 public void setVMParameters(String value) {
   myData.setVMParameters(value);
 }
 @NotNull
 public Map<String, String> getEnvs() {
   return myData.getEnvs();
 }
 public void setPassParentEnvs(boolean passParentEnvs) {
   myData.PASS_PARENT_ENVS = passParentEnvs;
 }
 public void setEnvs(@NotNull Map<String, String> envs) {
   myData.setEnvs(envs);
 }
 public String getWorkingDirectory() {
   return myData.getWorkingDirectory();
 }
 public void setWorkingDirectory(String value) {
   myData.setWorkingDirectory(value);
 }
 public PsiClass getPsiElement() {
   return getConfigurationModule().findClass(myData.getMainClassName());
 }
 public String getVMParameters() {
   return myData.getVMParameters();
 }
 public TestObject getTestObject() {
   return myData.getTestObject(getProject(), this);
 }
 public boolean isGeneratedName() {
   final String name = getName();
   return myData.isGeneratedName(name, getConfigurationModule());
 }
 public String getRunClass() {
   final Data data = getPersistentData();
   return data.TEST_OBJECT != TEST_CLASS && data.TEST_OBJECT != TEST_METHOD
       ? null
       : data.getMainClassName();
 }
 public void setProgramParameters(String value) {
   myData.setProgramParameters(value);
 }
 public void setForkMode(@NotNull String forkMode) {
   myData.FORK_MODE = forkMode;
 }
 public void checkConfiguration() throws RuntimeConfigurationException {
   myData.getTestObject(getProject(), this).checkConfiguration();
   JavaRunConfigurationExtensionManager.checkConfigurationIsValid(this);
 }
 public String getPackage() {
   final Data data = getPersistentData();
   return !Comparing.strEqual(data.TEST_OBJECT, TEST_PACKAGE) ? null : data.getPackageName();
 }
 public void beClassConfiguration(final PsiClass testClass) {
   setMainClass(testClass);
   myData.TEST_OBJECT = TEST_CLASS;
   setGeneratedName();
 }