Exemple #1
0
  /**
   * Parse a source xml input.
   *
   * @param project the current project
   * @param source the xml source
   * @exception BuildException if an error occurs
   */
  public void parse(Project project, Object source) throws BuildException {
    getImportStack().addElement(source);
    AntXMLContext context = null;
    context = (AntXMLContext) project.getReference(REFID_CONTEXT);
    if (context == null) {
      context = new AntXMLContext(project);
      project.addReference(REFID_CONTEXT, context);
      project.addReference(REFID_TARGETS, context.getTargets());
    }
    if (getImportStack().size() > 1) {
      // we are in an imported file.
      context.setIgnoreProjectTag(true);
      Target currentTarget = context.getCurrentTarget();
      Target currentImplicit = context.getImplicitTarget();
      Map<String, Target> currentTargets = context.getCurrentTargets();
      try {
        Target newCurrent = new Target();
        newCurrent.setProject(project);
        newCurrent.setName("");
        context.setCurrentTarget(newCurrent);
        context.setCurrentTargets(new HashMap<String, Target>());
        context.setImplicitTarget(newCurrent);
        parse(project, source, new RootHandler(context, mainHandler));
        newCurrent.execute();
      } finally {
        context.setCurrentTarget(currentTarget);
        context.setImplicitTarget(currentImplicit);
        context.setCurrentTargets(currentTargets);
      }
    } else {
      // top level file
      context.setCurrentTargets(new HashMap<String, Target>());
      parse(project, source, new RootHandler(context, mainHandler));
      // Execute the top-level target
      context.getImplicitTarget().execute();

      // resolve extensionOf attributes
      resolveExtensionOfAttributes(project);
    }
  }
  /**
   * Parse a source xml input.
   *
   * @param project the current project
   * @param source the xml source
   * @exception BuildException if an error occurs
   */
  public void parse(Project project, Object source) throws BuildException {
    getImportStack().addElement(source);
    AntXMLContext context = null;
    context = (AntXMLContext) project.getReference(REFID_CONTEXT);
    if (context == null) {
      context = new AntXMLContext(project);
      project.addReference(REFID_CONTEXT, context);
      project.addReference(REFID_TARGETS, context.getTargets());
    }
    if (getImportStack().size() > 1) {
      // we are in an imported file.
      context.setIgnoreProjectTag(true);
      Target currentTarget = context.getCurrentTarget();
      Target currentImplicit = context.getImplicitTarget();
      Map currentTargets = context.getCurrentTargets();
      try {
        Target newCurrent = new Target();
        newCurrent.setProject(project);
        newCurrent.setName("");
        context.setCurrentTarget(newCurrent);
        context.setCurrentTargets(new HashMap());
        context.setImplicitTarget(newCurrent);
        parse(project, source, new RootHandler(context, mainHandler));
        newCurrent.execute();
      } finally {
        context.setCurrentTarget(currentTarget);
        context.setImplicitTarget(currentImplicit);
        context.setCurrentTargets(currentTargets);
      }
    } else {
      // top level file
      context.setCurrentTargets(new HashMap());
      parse(project, source, new RootHandler(context, mainHandler));
      // Execute the top-level target
      context.getImplicitTarget().execute();

      // resolve extensionOf attributes
      for (Iterator i = getExtensionStack().iterator(); i.hasNext(); ) {
        String[] extensionInfo = (String[]) i.next();
        String tgName = extensionInfo[0];
        String name = extensionInfo[1];
        OnMissingExtensionPoint missingBehaviour =
            OnMissingExtensionPoint.valueOf(extensionInfo[2]);
        Hashtable projectTargets = project.getTargets();
        if (!projectTargets.containsKey(tgName)) {
          String message =
              "can't add target "
                  + name
                  + " to extension-point "
                  + tgName
                  + " because the extension-point is unknown.";
          if (missingBehaviour == OnMissingExtensionPoint.FAIL) {
            throw new BuildException(message);
          } else if (missingBehaviour == OnMissingExtensionPoint.WARN) {
            Target target = (Target) projectTargets.get(name);
            context.getProject().log(target, "Warning: " + message, Project.MSG_WARN);
          }
        } else {
          Target t = (Target) projectTargets.get(tgName);
          if (!(t instanceof ExtensionPoint)) {
            throw new BuildException("referenced target " + tgName + " is not an extension-point");
          }
          t.addDependency(name);
        }
      }
    }
  }