Пример #1
0
  public static boolean testRefactoringTestEnvironment(File projectDirectory) {
    IdeMain.setTestMode(TestMode.CORE_TEST);
    TestMain.configureMPS();
    final Project project = loadProject(new File(projectDirectory, REFACTORING_PROJECT));

    final boolean[] b = new boolean[] {true};
    ModelAccess.instance()
        .runReadAction(
            new Runnable() {
              public void run() {
                b[0] =
                    getModel(project, REFACTORING_SANDBOX[0]) != null
                        && getModel(project, REFACTORING_SANDBOX[1]) != null
                        && getLanguage(project, REFACTORING_LANGUAGE[0]) != null
                        && getLanguage(project, REFACTORING_LANGUAGE[1]) != null;
              }
            });

    ThreadUtils.runInUIThreadNoWait(
        new Runnable() {
          public void run() {
            project.dispose();
          }
        });
    return b[0];
  }
Пример #2
0
 public static void testProject(File projectFile, ProjectRunnable pr) {
   IdeMain.setTestMode(TestMode.CORE_TEST);
   Logger.setThreshold("INFO");
   org.apache.log4j.BasicConfigurator.configure();
   TestMain.configureMPS();
   final Project project = loadProject(projectFile);
   pr.execute(project);
 }
Пример #3
0
  public static boolean testProjectReloadForLeaks(final File projectFile, int leakThreshold) {
    TestMain.configureMPS();

    return testActionForLeaks(
        new Runnable() {
          public void run() {
            Project project = loadProject(projectFile);
            ClassLoaderManager.getInstance().reloadAll(new EmptyProgressMonitor());
            project.dispose();
          }
        },
        leakThreshold);
  }
Пример #4
0
  public static boolean testProjectGenerationForLeaks(File projectFile, int leakThreshold) {
    IdeMain.setTestMode(TestMode.CORE_TEST);

    TestMain.configureMPS();

    final Project project = loadProject(projectFile);
    return testActionForLeaks(
        new Runnable() {
          public void run() {
            new ProjectTester(project).testProject();
          }
        },
        leakThreshold);
  }
Пример #5
0
 public Project getProject(String name) {
   if ((name != null ? name.equals(this.projectName) : name == this.projectName)) {
     return this.lastProject;
   } else {
     Project p = TestMain.loadProject(new File(name));
     if (this.lastProject != null) {
       try {
         SwingUtilities.invokeAndWait(
             new Runnable() {
               public void run() {
                 ProjectContainer.this.lastProject.dispose();
               }
             });
       } catch (Exception e) {
         e.printStackTrace();
       }
     }
     this.lastProject = p;
     this.projectName = name;
     return p;
   }
 }
Пример #6
0
  public static boolean testOnProjectCopy(
      final File source,
      final File destinationDir,
      final String projectName,
      ProjectRunnable pr,
      final String... plugins) {
    IdeMain.setTestMode(TestMode.CORE_TEST);
    Logger.setThreshold("WARN");
    org.apache.log4j.BasicConfigurator.configure();
    TestMain.configureMPS(plugins);

    if (destinationDir.exists()) {
      FileUtil.delete(destinationDir);
    }
    if (source.isDirectory()) {
      FileUtil.copyDir(source, destinationDir);
    } else { // it is allowed to have zipped directory here
      try {
        destinationDir.mkdir();
        UnzipUtil.unzip(source, destinationDir);
      } catch (IOException e) {
        e.printStackTrace();
        return false;
      }
    }

    final Project[] project = new MPSProject[] {null};
    try {
      // load a project
      ThreadUtils.runInUIThreadAndWait(
          new Runnable() {
            public void run() {
              try {
                project[0] = loadProject(new File(destinationDir, projectName));
                VirtualFile projectVirtualDir =
                    LocalFileSystem.getInstance().refreshAndFindFileByIoFile(destinationDir);
                assert projectVirtualDir != null;
                projectVirtualDir.refresh(false, true);
              } catch (Throwable t) {
                t.printStackTrace();
              }
            }
          });

      waitUntilAllEventsFlushed();

      // execute test
      return pr.execute(project[0]);
    } catch (Throwable t) {
      t.printStackTrace();
      return false;
    } finally {
      waitUntilAllEventsFlushed();

      // clean up
      ThreadUtils.runInUIThreadAndWait(
          new Runnable() {
            public void run() {
              if (project[0] != null) {
                project[0].dispose();
              }
              FileUtil.delete(destinationDir);
            }
          });
    }
  }