Example #1
0
 @Override
 protected RunnerAndConfigurationSettings createConfigurationByElement(
     Location location, ConfigurationContext context) {
   myContext = context;
   if (!((location instanceof MPSLocation))) {
     return null;
   }
   MPSLocation mpsLocation = (MPSLocation) location;
   final MPSPsiElement psiElement = mpsLocation.getPsiElement();
   RunConfiguration config =
       ModelAccess.instance()
           .runReadAction(
               new Computable<RunConfiguration>() {
                 @Override
                 public RunConfiguration compute() {
                   Object mpsItem = psiElement.getMPSItem();
                   if (mpsItem == null) {
                     return null;
                   }
                   if (!(isApplicable(mpsItem))) {
                     return null;
                   }
                   return doCreateConfiguration((T) psiElement.getMPSItem());
                 }
               });
   if (config == null) {
     return null;
   }
   return new RunnerAndConfigurationSettingsImpl(
       RunManagerImpl.getInstanceImpl(location.getProject()), config, false);
 }
  @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;
  }
 @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 void createConfiguration() {
   LOG.assertTrue(myConfiguration == null);
   final Location location = getLocation();
   myConfiguration =
       location != null && !DumbService.isDumb(location.getProject())
           ? PreferredProducerFind.createConfiguration(location, this)
           : null;
   myInitialized = true;
 }
  protected RunnerAndConfigurationSettings createConfigurationByElement(
      final Location location, final ConfigurationContext context) {
    final Module module = context.getModule();
    if (module == null || !ScalaUtils.isSuitableModule(module)) return null;

    final MavenRunnerParameters params = createBuildParameters(location);
    if (params == null) return null;
    return createRunnerAndConfigurationSettings(null, null, params, location.getProject());
  }
  private MavenRunnerParameters createBuildParameters(Location l) {
    final PsiElement element = l.getPsiElement();
    final Project project = l.getProject();

    final Module module = ModuleUtil.findModuleForPsiElement(element);
    if (module == null) return null;

    final MavenProjectsManager mavenProjectsManager = MavenProjectsManager.getInstance(project);
    final MavenProject mavenProject = mavenProjectsManager.findProject(module);

    if (mavenProject == null) return null;

    // todo: check this code
    final List<MavenArtifact> dependencies = mavenProject.getDependencies();
    MavenArtifact artifact = null;
    for (MavenArtifact dependence : dependencies) {
      if (dependence.getArtifactId().equals(GROUP_ID_LIFT)) {
        artifact = dependence;
        break;
      } else if (dependence.getArtifactId().equals(ARTIFACT_ID_LIFT)) {
        artifact = dependence;
        break;
      }
    }
    // final MavenArtifact artifact = mavenProjectModel.findDependency(GROUP_ID_LIFT,
    // ARTIFACT_ID_LIFT);

    if (artifact == null) return null;

    mySourceElement = element;

    MavenExplicitProfiles profiles =
        MavenProjectsManager.getInstance(project).getExplicitProfiles();
    List<String> goals = new ArrayList<String>();

    goals.add(JETTY_RUN);

    final VirtualFile file = module.getModuleFile();
    if (file == null) return null;

    final VirtualFile parent = file.getParent();
    if (parent == null) return null;

    return new MavenRunnerParameters(true, parent.getPath(), goals, profiles);
  }
 public Project getProject() {
   return myLocation.getProject();
 }