コード例 #1
0
  @Override
  public boolean isConfigurationFromContext(
      JUnitConfiguration unitConfiguration, ConfigurationContext context) {
    if (RunConfigurationProducer.getInstance(PatternConfigurationProducer.class)
        .isMultipleElementsSelected(context)) {
      return false;
    }
    final RunConfiguration predefinedConfiguration =
        context.getOriginalConfiguration(JUnitConfigurationType.getInstance());
    final Location contextLocation = context.getLocation();

    String paramSetName =
        contextLocation instanceof PsiMemberParameterizedLocation
            ? ((PsiMemberParameterizedLocation) contextLocation).getParamSetName()
            : null;
    assert contextLocation != null;
    Location location = JavaExecutionUtil.stepIntoSingleClass(contextLocation);
    if (location == null) {
      return false;
    }
    final PsiElement element = location.getPsiElement();
    final PsiClass testClass = JUnitUtil.getTestClass(element);
    final PsiMethod testMethod = JUnitUtil.getTestMethod(element, false);
    final PsiPackage testPackage;
    if (element instanceof PsiPackage) {
      testPackage = (PsiPackage) element;
    } else if (element instanceof PsiDirectory) {
      testPackage = JavaDirectoryService.getInstance().getPackage(((PsiDirectory) element));
    } else {
      testPackage = null;
    }
    PsiDirectory testDir = element instanceof PsiDirectory ? (PsiDirectory) element : null;
    RunnerAndConfigurationSettings template =
        RunManager.getInstance(location.getProject())
            .getConfigurationTemplate(getConfigurationFactory());
    final Module predefinedModule =
        ((JUnitConfiguration) template.getConfiguration()).getConfigurationModule().getModule();
    final String vmParameters =
        predefinedConfiguration instanceof JUnitConfiguration
            ? ((JUnitConfiguration) predefinedConfiguration).getVMParameters()
            : null;

    if (vmParameters != null
        && !Comparing.strEqual(vmParameters, unitConfiguration.getVMParameters())) return false;
    if (paramSetName != null
        && !Comparing.strEqual(paramSetName, unitConfiguration.getProgramParameters()))
      return false;
    final TestObject testobject = unitConfiguration.getTestObject();
    if (testobject != null) {
      if (testobject.isConfiguredByElement(
          unitConfiguration, testClass, testMethod, testPackage, testDir)) {
        final Module configurationModule = unitConfiguration.getConfigurationModule().getModule();
        if (Comparing.equal(location.getModule(), configurationModule)) return true;
        if (Comparing.equal(predefinedModule, configurationModule)) {
          return true;
        }
      }
    }
    return false;
  }
コード例 #2
0
 public RunProfileState getState(
     @NotNull final Executor executor, @NotNull final ExecutionEnvironment env)
     throws ExecutionException {
   return TestObject.fromString(
       myData.TEST_OBJECT,
       getProject(),
       this,
       env.getRunnerSettings(),
       env.getConfigurationSettings());
 }
コード例 #3
0
 public void checkConfiguration() throws RuntimeConfigurationException {
   super.checkConfiguration();
   final String packageName = myConfiguration.getPersistentData().getPackageName();
   final PsiPackage aPackage =
       JavaPsiFacade.getInstance(myConfiguration.getProject()).findPackage(packageName);
   if (aPackage == null) {
     throw new RuntimeConfigurationWarning(
         ExecutionBundle.message("package.does.not.exist.error.message", packageName));
   }
   if (getSourceScope() == null) {
     myConfiguration.getConfigurationModule().checkForWarning();
   }
 }
コード例 #4
0
 @Override
 protected void notifyByBalloon(
     JUnitRunningModel model, boolean started, final JUnitConsoleProperties consoleProperties) {
   if (myFoundTests) {
     super.notifyByBalloon(model, started, consoleProperties);
   } else {
     final String packageName = myConfiguration.getPackage();
     if (packageName == null) return;
     final Project project = myConfiguration.getProject();
     final PsiPackage aPackage = JavaPsiFacade.getInstance(project).findPackage(packageName);
     if (aPackage == null) return;
     final Module module = myConfiguration.getConfigurationModule().getModule();
     if (module == null) return;
     final Set<Module> modulesWithPackage = new HashSet<Module>();
     final PsiDirectory[] directories = aPackage.getDirectories();
     for (PsiDirectory directory : directories) {
       final Module currentModule =
           ModuleUtil.findModuleForFile(directory.getVirtualFile(), project);
       if (module != currentModule && currentModule != null) {
         modulesWithPackage.add(currentModule);
       }
     }
     if (!modulesWithPackage.isEmpty()) {
       final String testRunDebugId =
           consoleProperties.isDebug() ? ToolWindowId.DEBUG : ToolWindowId.RUN;
       final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
       final Function<Module, String> moduleNameRef =
           new Function<Module, String>() {
             @Override
             public String fun(Module module) {
               final String moduleName = module.getName();
               return "<a href=\"" + moduleName + "\">" + moduleName + "</a>";
             }
           };
       String message = "Tests were not found in module \"" + module.getName() + "\".\n" + "Use ";
       if (modulesWithPackage.size() == 1) {
         message += "module \"" + moduleNameRef.fun(modulesWithPackage.iterator().next()) + "\" ";
       } else {
         message += "one of\n" + StringUtil.join(modulesWithPackage, moduleNameRef, "\n") + "\n";
       }
       message += "instead";
       toolWindowManager.notifyByBalloon(
           testRunDebugId,
           MessageType.WARNING,
           message,
           null,
           new ResetConfigurationModuleAdapter(
               project, consoleProperties, toolWindowManager, testRunDebugId));
     }
   }
 }
コード例 #5
0
  protected void initialize() throws ExecutionException {
    super.initialize();
    final JUnitConfiguration.Data data = myConfiguration.getPersistentData();
    getClassFilter(data); // check if junit found
    configureClasspath();

    try {
      myTempFile = FileUtil.createTempFile("idea_junit", ".tmp");
      myTempFile.deleteOnExit();
      myJavaParameters.getProgramParametersList().add("@" + myTempFile.getAbsolutePath());
    } catch (IOException e) {
      LOG.error(e);
    }

    try {
      myServerSocket = new ServerSocket(0, 0, InetAddress.getByName("127.0.0.1"));
      myJavaParameters.getProgramParametersList().add("-socket" + myServerSocket.getLocalPort());
    } catch (IOException e) {
      LOG.error(e);
    }
  }
コード例 #6
0
 public TestObject getTestObject(final Project project, final JUnitConfiguration configuration) {
   // TODO[dyoma]!
   return TestObject.fromString(TEST_OBJECT, project, configuration, null, null);
 }