Ejemplo n.º 1
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);
 }
Ejemplo n.º 2
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);
            }
          });
    }
  }