Example #1
0
  public static void assertEqualsToFile(
      @NotNull File expectedFile,
      @NotNull String actual,
      @NotNull Function1<String, String> sanitizer) {
    try {
      String actualText =
          JetTestUtilsKt.trimTrailingWhitespacesAndAddNewlineAtEOF(
              StringUtil.convertLineSeparators(actual.trim()));

      if (!expectedFile.exists()) {
        FileUtil.writeToFile(expectedFile, actualText);
        Assert.fail("Expected data file did not exist. Generating: " + expectedFile);
      }
      String expected = FileUtil.loadFile(expectedFile, CharsetToolkit.UTF8, true);

      String expectedText =
          JetTestUtilsKt.trimTrailingWhitespacesAndAddNewlineAtEOF(
              StringUtil.convertLineSeparators(expected.trim()));

      if (!Comparing.equal(sanitizer.invoke(expectedText), sanitizer.invoke(actualText))) {
        throw new FileComparisonFailure(
            "Actual data differs from file content: " + expectedFile.getName(),
            expected,
            actual,
            expectedFile.getAbsolutePath());
      }
    } catch (IOException e) {
      throw ExceptionUtilsKt.rethrow(e);
    }
  }
  @NotNull
  private static File copyJarFileWithoutEntry(
      @NotNull File jarPath, @NotNull String... entriesToDelete) {
    try {
      File outputFile =
          new File(
              jarPath.getParentFile(), FileUtil.getNameWithoutExtension(jarPath) + "-after.jar");
      Set<String> toDelete = SetsKt.setOf(entriesToDelete);

      @SuppressWarnings("IOResourceOpenedButNotSafelyClosed")
      JarFile jar = new JarFile(jarPath);
      ZipOutputStream output =
          new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(outputFile)));
      try {
        for (Enumeration<JarEntry> enumeration = jar.entries(); enumeration.hasMoreElements(); ) {
          JarEntry jarEntry = enumeration.nextElement();
          if (toDelete.contains(jarEntry.getName())) {
            continue;
          }
          output.putNextEntry(jarEntry);
          output.write(FileUtil.loadBytes(jar.getInputStream(jarEntry)));
          output.closeEntry();
        }
      } finally {
        output.close();
        jar.close();
      }

      return outputFile;
    } catch (IOException e) {
      throw ExceptionUtilsKt.rethrow(e);
    }
  }
Example #3
0
 @NotNull
 public Class<? extends Annotation> loadAnnotationClassQuietly(@NotNull String fqName) {
   try {
     //noinspection unchecked
     return (Class<? extends Annotation>) initializedClassLoader.loadClass(fqName);
   } catch (ClassNotFoundException e) {
     throw ExceptionUtilsKt.rethrow(e);
   }
 }
Example #4
0
 @NotNull
 public static NameResolverImpl read(@NotNull InputStream in) {
   try {
     ProtoBuf.StringTable simpleNames = ProtoBuf.StringTable.parseDelimitedFrom(in);
     ProtoBuf.QualifiedNameTable qualifiedNames =
         ProtoBuf.QualifiedNameTable.parseDelimitedFrom(in);
     return new NameResolverImpl(simpleNames, qualifiedNames);
   } catch (IOException e) {
     throw ExceptionUtilsKt.rethrow(e);
   }
 }
Example #5
0
 @NotNull
 private static ScriptableObject initScope(
     @NotNull EcmaVersion version, @NotNull Context context, @NotNull List<String> jsLibraries) {
   ScriptableObject scope = context.initStandardObjects();
   try {
     runFileWithRhino(DIST_DIR_JS_PATH + "kotlin.js", context, scope);
     // runFileWithRhino(pathToTestFilesRoot() + "jshint.js", context, scope);
     for (String jsLibrary : jsLibraries) {
       runFileWithRhino(jsLibrary, context, scope);
     }
   } catch (Exception e) {
     throw ExceptionUtilsKt.rethrow(e);
   }
   // scope.sealObject();
   return scope;
 }