public static void assertJarFilesEqual(File file1, File file2) throws IOException {
    final File tempDirectory1;
    final File tempDirectory2;

    final JarFile jarFile1 = new JarFile(file1);
    try {
      final JarFile jarFile2 = new JarFile(file2);
      try {
        tempDirectory1 = PlatformTestCase.createTempDir("tmp1");
        tempDirectory2 = PlatformTestCase.createTempDir("tmp2");
        ZipUtil.extract(jarFile1, tempDirectory1, null);
        ZipUtil.extract(jarFile2, tempDirectory2, null);
      } finally {
        jarFile2.close();
      }
    } finally {
      jarFile1.close();
    }

    final VirtualFile dirAfter =
        LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDirectory1);
    assertNotNull(tempDirectory1.toString(), dirAfter);
    final VirtualFile dirBefore =
        LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDirectory2);
    assertNotNull(tempDirectory2.toString(), dirBefore);
    ApplicationManager.getApplication()
        .runWriteAction(
            new Runnable() {
              @Override
              public void run() {
                dirAfter.refresh(false, true);
                dirBefore.refresh(false, true);
              }
            });
    assertDirectoriesEqual(dirAfter, dirBefore);
  }
예제 #2
0
  public static VirtualFile createTestProjectStructure(
      String tempName,
      Module module,
      String rootPath,
      Collection<File> filesToDelete,
      boolean addProjectRoots)
      throws IOException {
    File dir = FileUtil.createTempDirectory(tempName, null, false);
    filesToDelete.add(dir);

    VirtualFile vDir =
        LocalFileSystem.getInstance()
            .refreshAndFindFileByPath(dir.getCanonicalPath().replace(File.separatorChar, '/'));
    assert vDir != null && vDir.isDirectory() : dir;
    PlatformTestCase.synchronizeTempDirVfs(vDir);

    EdtTestUtil.runInEdtAndWait(
        () -> {
          AccessToken token = WriteAction.start();
          try {
            if (rootPath != null) {
              VirtualFile vDir1 =
                  LocalFileSystem.getInstance()
                      .findFileByPath(rootPath.replace(File.separatorChar, '/'));
              if (vDir1 == null) {
                throw new Exception(rootPath + " not found");
              }
              VfsUtil.copyDirectory(null, vDir1, vDir, null);
            }

            if (addProjectRoots) {
              addSourceContentToRoots(module, vDir);
            }
          } finally {
            token.finish();
          }
        });
    return vDir;
  }