Exemple #1
0
  public void initialise() throws InitialisationException {
    try {
      GroovyClassLoader loader = new GroovyClassLoader(getClass().getClassLoader());
      // defaults to the logical name of the Transformer can be changed by explicit setting of the
      // scriptName
      if (script == null) {
        script = getName() + ".groovy";
      }
      if (scriptLocation == null) {
        scriptLocation = loader.getResource(script);
      }

      if (scriptLocation == null) {
        File file = new File(script);
        if (file.exists()) {
          scriptLocation = file.toURL();
        } else {
          throw new InitialisationException(
              new Message(Messages.CANT_LOAD_X_FROM_CLASSPATH_FILE, "Groovy Script: " + script),
              this);
        }
      }
      logger.info("Loading Groovy transformer with script " + scriptLocation.toExternalForm());
      Class groovyClass = loader.parseClass(new GroovyCodeSource(scriptLocation));
      transformer = (GroovyObject) groovyClass.newInstance();
    } catch (Exception e) {
      throw new InitialisationException(
          new Message(Messages.FAILED_TO_CREATE_X, "Groovy transformer"), e, this);
    }
  }
 public URL getResource(String name) {
   return delegate.getResource(name);
 }