Example #1
0
  private byte[] tryTransform(
      byte[] buffer,
      String name,
      ClassLoader loader,
      String key,
      boolean isInterface,
      boolean isOverride) {
    List<RuleScript> ruleScripts;

    if (isInterface) {
      ruleScripts = scriptRepository.scriptsForInterfaceName(key);
    } else {
      ruleScripts = scriptRepository.scriptsForClassName(key);
    }
    byte[] newBuffer = buffer;

    if (ruleScripts != null) {
      //            if (isVerbose()) {
      //                System.out.println("tryTransform : " + name + " for " + key);
      //            }
      int counter = 0;

      for (RuleScript ruleScript : ruleScripts) {
        try {
          // we only transform via isOverride rules if isOverride is true
          // we tarsnform via any matchign rules if isOverride is false
          if (!isOverride || ruleScript.isOverride()) {
            // only do the transform if the script has not been deleted
            synchronized (ruleScript) {
              if (!ruleScript.isDeleted()) {
                maybeDumpClassIntermediate(name, newBuffer);
                newBuffer = transform(ruleScript, loader, name, newBuffer);
              }
            }
          }
        } catch (Throwable th) {
          // yeeeurgh I know this looks ugly with no rethrow but it is appropriate
          // we do not want to pass on any errors or runtime exceptions
          // if a transform fails then we should still allow the load to continue
          // with whatever other transforms succeed. we tarce the throwable to
          // System.err just to ensure it can be seen.

          System.err.println("Transformer.transform : caught throwable " + th);
          th.printStackTrace(System.err);
        }
      }
    }
    return newBuffer;
  }