public void testClasspathConfiguration() throws CantRunException {
   JavaParameters parameters = new JavaParameters();
   RunConfigurationModule module = new JavaRunConfigurationModule(myProject, false);
   Module module1 = getModule1();
   Module module2 = getModule2();
   addDependency(module1, module2);
   Module module3 = getModule3();
   addDependency(module2, module3);
   addDependency(module1, module3);
   addOutputs(module1, 1);
   addOutputs(module2, 2);
   addOutputs(module3, 3);
   module.setModule(module1);
   parameters.configureByModule(module.getModule(), JavaParameters.JDK_AND_CLASSES_AND_TESTS);
   ArrayList<String> classPath = new ArrayList<>();
   StringTokenizer tokenizer =
       new StringTokenizer(parameters.getClassPath().getPathsString(), File.pathSeparator);
   while (tokenizer.hasMoreTokens()) {
     String token = tokenizer.nextToken();
     classPath.add(token);
   }
   CHECK.singleOccurence(classPath, getOutput(module1, false));
   CHECK.singleOccurence(classPath, getOutput(module1, false));
   CHECK.singleOccurence(classPath, getOutput(module1, true));
   CHECK.singleOccurence(classPath, getOutput(module2, false));
   CHECK.singleOccurence(classPath, getOutput(module2, true));
   CHECK.singleOccurence(classPath, getOutput(module3, false));
   CHECK.singleOccurence(classPath, getOutput(module3, true));
   CHECK.singleOccurence(classPath, getFSPath(findFile(MOCK_JUNIT)));
 }
 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);
   }
 }
 @Override
 protected boolean isApplicableFor(@NotNull RunConfigurationBase configuration) {
   if (configuration instanceof ModuleBasedConfiguration
       && configuration instanceof CommonProgramRunConfigurationParameters) {
     final RunConfigurationModule runConfigurationModule =
         ((ModuleBasedConfiguration) configuration).getConfigurationModule();
     return ExternalSystemApiUtil.isExternalSystemAwareModule(
         GradleConstants.SYSTEM_ID, runConfigurationModule.getModule());
   }
   return false;
 }
 protected void configureClasspath(final JavaParameters javaParameters) throws CantRunException {
   RunConfigurationModule module = getConfiguration().getConfigurationModule();
   final String jreHome =
       getConfiguration().isAlternativeJrePathEnabled()
           ? getConfiguration().getAlternativeJrePath()
           : null;
   final int pathType = JavaParameters.JDK_AND_CLASSES_AND_TESTS;
   if (configureByModule(module.getModule())) {
     JavaParametersUtil.configureModule(module, javaParameters, pathType, jreHome);
   } else {
     JavaParametersUtil.configureProject(
         getConfiguration().getProject(), javaParameters, pathType, jreHome);
   }
 }
Пример #5
0
 protected void initialize() throws ExecutionException {
   defaultInitialize();
   final JUnitConfiguration.Data data = myConfiguration.getPersistentData();
   RunConfigurationModule module = myConfiguration.getConfigurationModule();
   final Project project = module.getProject();
   addJUnit4Parameter(data, project);
   final ExecutionException[] exception = new ExecutionException[1];
   ApplicationManager.getApplication()
       .runReadAction(
           new Runnable() {
             public void run() {
               try {
                 myConfiguration.configureClasspath(myJavaParameters);
               } catch (CantRunException e) {
                 exception[0] = e;
               }
             }
           });
   if (exception[0] != null) throw exception[0];
   final LinkedHashMap<PsiMethod, TestInfo> methods = new LinkedHashMap<PsiMethod, TestInfo>();
   for (AbstractTestProxy failedTest : myFailedTests) {
     Location location = failedTest.getLocation(project);
     if (!(location instanceof MethodLocation)) continue;
     PsiElement psiElement = location.getPsiElement();
     LOG.assertTrue(psiElement instanceof PsiMethod);
     PsiMethod method = (PsiMethod) psiElement;
     methods.put(method, ((TestProxy) failedTest).getInfo());
   }
   addClassesListToJavaParameters(
       methods.keySet(),
       new Function<PsiElement, String>() {
         public String fun(PsiElement element) {
           if (element instanceof PsiMethod) {
             final PsiMethod method = (PsiMethod) element;
             final TestInfo testInfo = methods.get(method);
             return JavaExecutionUtil.getRuntimeQualifiedName(
                     ((MethodLocation) testInfo.getLocation(project)).getContainingClass())
                 + ","
                 + testInfo.getName();
           }
           return null;
         }
       },
       data.getPackageName(),
       true,
       false);
 }
 private static String getConfigurationName(PsiClass aClass, RunConfigurationModule module) {
   String qualifiedName = aClass.getQualifiedName();
   Project project = module.getProject();
   if (qualifiedName != null) {
     PsiClass psiClass =
         JavaPsiFacade.getInstance(project)
             .findClass(qualifiedName.replace('$', '.'), GlobalSearchScope.projectScope(project));
     if (psiClass != null) {
       return psiClass.getName();
     } else {
       int lastDot = qualifiedName.lastIndexOf('.');
       if (lastDot == -1 || lastDot == qualifiedName.length() - 1) {
         return qualifiedName;
       }
       return qualifiedName.substring(lastDot + 1, qualifiedName.length());
     }
   }
   return module.getModuleName();
 }
 @Override
 protected void validateConfiguration(
     @NotNull RunConfigurationBase configuration, boolean isExecution) throws Exception {
   super.validateConfiguration(configuration, isExecution);
   if (configuration instanceof ModuleBasedConfiguration
       && configuration instanceof CommonProgramRunConfigurationParameters) {
     final String workingDirectory =
         ((CommonProgramRunConfigurationParameters) configuration).getWorkingDirectory();
     if (("$" + PathMacroUtil.MODULE_DIR_MACRO_NAME + "$").equals(workingDirectory)) {
       final RunConfigurationModule runConfigurationModule =
           ((ModuleBasedConfiguration) configuration).getConfigurationModule();
       final String projectPath =
           ExternalSystemApiUtil.getExternalProjectPath(runConfigurationModule.getModule());
       if (StringUtil.isNotEmpty(projectPath)) {
         ((CommonProgramRunConfigurationParameters) configuration)
             .setWorkingDirectory(projectPath);
       }
     }
   }
 }