Ejemplo n.º 1
0
  public void testKotlinJavaScriptProjectWithDirectoryAsStdlib() {
    initProject();
    File jslibJar = PathUtil.getKotlinPathsForDistDirectory().getJsStdLibJarPath();
    File jslibDir = new File(workDir, "KotlinJavaScript");
    try {
      ZipUtil.extract(jslibJar, jslibDir, null);
    } catch (IOException ex) {
      throw new IllegalStateException(ex.getMessage());
    }
    addKotlinJavaScriptDependency("KotlinJavaScript", jslibDir);
    makeAll().assertSuccessful();

    assertEquals(EXPECTED_JS_FILES_IN_OUTPUT_FOR_STDLIB_ONLY, contentOfOutputDir(PROJECT_NAME));
    checkWhen(touch("src/test1.kt"), null, k2jsOutput(PROJECT_NAME));
  }
  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);
  }