protected void loadEventHooks(@SuppressWarnings("hiding") BuildSettings buildSettings) {
    if (buildSettings == null) {
      return;
    }

    loadEventsScript(findEventsScript(new File(buildSettings.getUserHome(), ".grails/scripts")));
    loadEventsScript(findEventsScript(new File(buildSettings.getBaseDir(), "scripts")));

    PluginBuildSettings pluginSettings =
        (PluginBuildSettings) binding.getVariable("pluginSettings");
    for (Resource pluginBase : pluginSettings.getPluginDirectories()) {
      try {
        loadEventsScript(findEventsScript(new File(pluginBase.getFile(), "scripts")));
      } catch (IOException ex) {
        throw new RuntimeException(ex);
      }
    }
  }
 /**
  * This method overrides property retrieval in the scope of the {@code GroovyBeanDefinitionReader}
  * to either:
  *
  * <ul>
  *   <li>Retrieve a variable from the bean builder's binding if it exists
  *   <li>Retrieve a RuntimeBeanReference for a specific bean if it exists
  *   <li>Otherwise just delegate to MetaClass.getProperty which will resolve properties from the
  *       {@code GroovyBeanDefinitionReader} itself
  * </ul>
  */
 public Object getProperty(String name) {
   Binding binding = getBinding();
   if (binding != null && binding.hasVariable(name)) {
     return binding.getVariable(name);
   } else {
     if (this.namespaces.containsKey(name)) {
       return createDynamicElementReader(name);
     }
     if (getRegistry().containsBeanDefinition(name)) {
       GroovyBeanDefinitionWrapper beanDefinition =
           (GroovyBeanDefinitionWrapper)
               getRegistry()
                   .getBeanDefinition(name)
                   .getAttribute(GroovyBeanDefinitionWrapper.class.getName());
       if (beanDefinition != null) {
         return new GroovyRuntimeBeanReference(name, beanDefinition, false);
       } else {
         return new RuntimeBeanReference(name, false);
       }
     }
     // This is to deal with the case where the property setter is the last
     // statement in a closure (hence the return value)
     else if (this.currentBeanDefinition != null) {
       MutablePropertyValues pvs =
           this.currentBeanDefinition.getBeanDefinition().getPropertyValues();
       if (pvs.contains(name)) {
         return pvs.get(name);
       } else {
         DeferredProperty dp =
             this.deferredProperties.get(this.currentBeanDefinition.getBeanName() + name);
         if (dp != null) {
           return dp.value;
         } else {
           return getMetaClass().getProperty(this, name);
         }
       }
     } else {
       return getMetaClass().getProperty(this, name);
     }
   }
 }
  /**
   * Executes the groovy script with the given binding.
   *
   * @param binding Binding
   * @return PicoContainer
   */
  private PicoContainer runGroovyScript(Binding binding) {
    Script script = createGroovyScript(binding);

    Object result = script.run();
    Object picoVariable;
    try {
      picoVariable = binding.getVariable("pico");
    } catch (MissingPropertyException e) {
      picoVariable = result;
    }
    if (picoVariable == null) {
      throw new NullPointerException("Groovy Script Variable: pico");
    }

    if (picoVariable instanceof PicoContainer) {
      return (PicoContainer) picoVariable;
    } else if (picoVariable instanceof NanoContainer) {
      return ((NanoContainer) picoVariable);
    } else {
      throw new NanoContainerMarkupException(
          "Bad type for pico:" + picoVariable.getClass().getName());
    }
  }
  /**
   * execute sql query
   *
   * @throws Exception
   */
  private void executeQuery() {
    Connection con = null;
    try {
      InputStream catExtIs =
          ScriptableMondrianDrillThroughTableModel.class
              .getClassLoader()
              .getResourceAsStream("/" + catalogExtension);
      if (catExtIs != null) {
        Digester catExtDigester = new Digester();
        catExtDigester.setClassLoader(
            ScriptableMondrianDrillThroughTableModel.class.getClassLoader());
        catExtDigester.push(this);
        catExtDigester.addSetProperties("extension");
        catExtDigester.addObjectCreate(
            "extension/script", "com.tonbeller.jpivot.mondrian.script.ScriptColumn");
        catExtDigester.addSetProperties("extension/script");
        catExtDigester.addSetNext("extension/script", "addScript");
        catExtDigester.parse(catExtIs);

        URL scriptsBaseURL =
            Thread.currentThread().getContextClassLoader().getResource(scriptRootUrl);
        scriptEngine = new GroovyScriptEngine(new URL[] {scriptsBaseURL});
      }
      con = getConnection();
      Statement s = con.createStatement();
      s.setMaxRows(maxResults);
      ResultSet rs = s.executeQuery(sql);
      ResultSetMetaData md = rs.getMetaData();
      int numCols = md.getColumnCount();
      List columnTitlesList = new ArrayList();
      // set column headings
      for (int i = 0; i < numCols; i++) {
        //	columns are 1 based
        columnTitlesList.add(i, md.getColumnName(i + 1));
      }
      // loop on script columns
      for (ListIterator sIt = scripts.listIterator(); sIt.hasNext(); ) {
        final ScriptColumn sc = (ScriptColumn) sIt.next();
        columnTitlesList.add(sc.getPosition() - 1, sc.getTitle());
      }
      columnTitles = (String[]) columnTitlesList.toArray(new String[0]);
      // loop through rows
      List tempRows = new ArrayList();
      Map scriptInput = new HashMap();
      Binding binding = new Binding();
      while (rs.next()) {
        List rowList = new ArrayList();
        scriptInput.clear();
        // loop on columns, 1 based
        for (int i = 0; i < numCols; i++) {
          rowList.add(i, rs.getObject(i + 1));
          scriptInput.put(columnTitles[i], rs.getObject(i + 1));
        }
        binding.setVariable("input", scriptInput);
        // loop on script columns
        for (ListIterator sIt = scripts.listIterator(); sIt.hasNext(); ) {
          final ScriptColumn sc = (ScriptColumn) sIt.next();
          scriptEngine.run(sc.getFile(), binding);
          final Object output = binding.getVariable("output");
          if (output instanceof Map) {
            Map outMap = (Map) output;
            rowList.add(
                sc.getPosition() - 1,
                new DefaultCell((String) outMap.get("URL"), (String) outMap.get("Value")));
          } else if (output instanceof String) {
            rowList.add(sc.getPosition() - 1, (String) output);
          } else {
            throw new Exception("Unknown groovy script return type (not a Map nor String).");
          }
        }
        tempRows.add(new DefaultTableRow(rowList.toArray()));
      }
      rs.close();
      rows = (TableRow[]) tempRows.toArray(new TableRow[0]);
    } catch (Exception e) {
      e.printStackTrace();
      logger.error("?", e);
      // problem occured, set table model to zero size
      rows = new TableRow[1];
      columnTitles = new String[1];
      columnTitles[0] = "An error occured";
      Object[] row = new Object[1];
      row[0] = e.toString();
      rows[0] = new DefaultTableRow(row);
      ready = false;
      return;
    } finally {
      try {
        con.close();
      } catch (Exception e1) {
        // ignore
      }
    }
    ready = true;
  }