예제 #1
0
 /**
  * Load an antlib from a URL.
  *
  * @param classLoader the classloader to use.
  * @param url the url to load the definitions from.
  */
 private void loadAntlib(ClassLoader classLoader, URL url) {
   try {
     Antlib antlib = Antlib.createAntlib(getProject(), url, getURI());
     antlib.setClassLoader(classLoader);
     antlib.setURI(getURI());
     antlib.execute();
   } catch (BuildException ex) {
     throw ProjectHelper.addLocationToBuildException(ex, getLocation());
   }
 }
예제 #2
0
  /**
   * Add a definition using the attributes of Definer
   *
   * @param al the ClassLoader to use
   * @param name the name of the definition
   * @param classname the classname of the definition
   * @throws BuildException if an error occurs
   */
  protected void addDefinition(ClassLoader al, String name, String classname)
      throws BuildException {
    Class<?> cl = null;
    try {
      try {
        name = ProjectHelper.genComponentName(getURI(), name);

        if (onError != OnError.IGNORE) {
          cl = Class.forName(classname, true, al);
        }

        if (adapter != null) {
          adapterClass = Class.forName(adapter, true, al);
        }

        if (adaptTo != null) {
          adaptToClass = Class.forName(adaptTo, true, al);
        }

        AntTypeDefinition def = new AntTypeDefinition();
        def.setName(name);
        def.setClassName(classname);
        def.setClass(cl);
        def.setAdapterClass(adapterClass);
        def.setAdaptToClass(adaptToClass);
        def.setRestrict(restrict);
        def.setClassLoader(al);
        if (cl != null) {
          def.checkClass(getProject());
        }
        ComponentHelper.getComponentHelper(getProject()).addDataTypeDefinition(def);
      } catch (ClassNotFoundException cnfe) {
        String msg =
            getTaskName()
                + " class "
                + classname
                + " cannot be found"
                + "\n using the classloader "
                + al;
        throw new BuildException(msg, cnfe, getLocation());
      } catch (NoClassDefFoundError ncdfe) {
        String msg =
            getTaskName()
                + " A class needed by class "
                + classname
                + " cannot be found: "
                + ncdfe.getMessage()
                + "\n using the classloader "
                + al;
        throw new BuildException(msg, ncdfe, getLocation());
      }
    } catch (BuildException ex) {
      switch (onError) {
        case OnError.FAIL_ALL:
        case OnError.FAIL:
          throw ex;
        case OnError.REPORT:
          log(ex.getLocation() + "Warning: " + ex.getMessage(), Project.MSG_WARN);
          break;
        default:
          log(ex.getLocation() + ex.getMessage(), Project.MSG_DEBUG);
      }
    }
  }