Ejemplo n.º 1
0
  private void processTarget(Element targetNode, Element outProjectNode)
      throws IOException, DocumentException {
    String targetName = targetNode.attributeValue("name");
    log("Processing target: " + targetName, Project.MSG_DEBUG);

    // Add documentation
    // Get comment element before the target element to extract target doc
    String commentText = "";
    List children = targetNode.selectNodes("preceding-sibling::node()");
    if (children.size() > 0) {
      // Scan past the text nodes, which are most likely whitespace
      int index = children.size() - 1;
      Node child = (Node) children.get(index);
      while (index > 0 && child.getNodeType() == Node.TEXT_NODE) {
        index--;
        child = (Node) children.get(index);
      }

      // Check if there is a comment node
      if (child.getNodeType() == Node.COMMENT_NODE) {
        Comment targetComment = (Comment) child;
        commentText = targetComment.getStringValue().trim();

        log(targetName + " comment: " + commentText, Project.MSG_DEBUG);
      } else {
        log("Target has no comment: " + targetName, Project.MSG_WARN);
      }

      Node previousNode = (Node) children.get(children.size() - 1);
    }

    if (!commentText.contains("Private:")) {
      Element outTargetNode = outProjectNode.addElement("target");

      addTextElement(outTargetNode, "name", targetNode.attributeValue("name"));
      addTextElement(outTargetNode, "ifDependency", targetNode.attributeValue("if"));
      addTextElement(outTargetNode, "unlessDependency", targetNode.attributeValue("unless"));
      addTextElement(outTargetNode, "description", targetNode.attributeValue("description"));
      addTextElement(outTargetNode, "tasks", String.valueOf(targetNode.elements().size()));

      // Add location
      Project project = getProject();
      Target antTarget = (Target) project.getTargets().get(targetName);

      if (antTarget == null) return;

      addTextElement(outTargetNode, "location", antTarget.getLocation().toString());

      // Add dependencies
      Enumeration dependencies = antTarget.getDependencies();
      while (dependencies.hasMoreElements()) {
        String dependency = (String) dependencies.nextElement();
        Element dependencyElement = addTextElement(outTargetNode, "dependency", dependency);
        dependencyElement.addAttribute("type", "direct");
      }

      callAntTargetVisitor(targetNode, outTargetNode, outProjectNode);

      // Process the comment text as MediaWiki syntax and convert to HTML
      insertDocumentation(outTargetNode, commentText);

      // Get names of all properties used in this target
      ArrayList properties = new ArrayList();
      Visitor visitor = new AntPropertyVisitor(properties);
      targetNode.accept(visitor);
      for (Iterator iterator = properties.iterator(); iterator.hasNext(); ) {
        String property = (String) iterator.next();
        addTextElement(outTargetNode, "propertyDependency", property);
      }

      // Add the raw XML content of the element
      String targetXml = targetNode.asXML();
      // Replace the CDATA end notation to avoid nested CDATA sections
      targetXml = targetXml.replace("]]>", "] ]>");

      addTextElement(outTargetNode, "source", targetXml, true);
    }
  }
Ejemplo n.º 2
0
  private void processMacro(Element macroNode, Element outProjectNode, String antFile)
      throws IOException, DocumentException {
    String macroName = macroNode.attributeValue("name");
    log("Processing macro: " + macroName, Project.MSG_DEBUG);

    Element outmacroNode = outProjectNode.addElement("macro");
    addTextElement(outmacroNode, "name", macroNode.attributeValue("name"));
    addTextElement(outmacroNode, "description", macroNode.attributeValue("description"));

    // Add location
    // Project project = getProject();
    // Macro antmacro = (Macro) project.getTargets().get(macroName);
    // System.out.println(project.getMacroDefinitions());
    // System.out.println(macroName);
    // MacroInstance antmacro = (MacroInstance)
    // project.getMacroDefinitions().get("http://www.nokia.com/helium:" +
    // macroName);

    // Add the location with just the file path for now and a dummy line
    // number.
    // TODO - Later we should find the line number from the XML input.
    addTextElement(outmacroNode, "location", antFile + ":1:");

    List<Node> statements =
        macroNode.selectNodes(
            "//scriptdef[@name='"
                + macroName
                + "']/attribute | //macrodef[@name='"
                + macroName
                + "']/attribute");
    String usage = "";
    for (Node statement : statements) {
      String defaultval = statement.valueOf("@default");
      if (defaultval.equals("")) defaultval = "value";
      else defaultval = "<i>" + defaultval + "</i>";
      usage = usage + " " + statement.valueOf("@name") + "=\"" + defaultval + "\"";
    }

    String macroElements = "";
    statements =
        macroNode.selectNodes(
            "//scriptdef[@name='"
                + macroName
                + "']/element | //macrodef[@name='"
                + macroName
                + "']/element");
    for (Node statement : statements) {
      macroElements = "&lt;" + statement.valueOf("@name") + "/&gt;\n" + macroElements;
    }
    if (macroElements.equals(""))
      addTextElement(outmacroNode, "usage", "&lt;hlm:" + macroName + " " + usage + "/&gt;");
    else
      addTextElement(
          outmacroNode,
          "usage",
          "&lt;hlm:"
              + macroName
              + " "
              + usage
              + "&gt;\n"
              + macroElements
              + "&lt;/hlm:"
              + macroName
              + "&gt;");

    // Add dependencies
    // Enumeration dependencies = antmacro.getDependencies();
    // while (dependencies.hasMoreElements())
    // {
    // String dependency = (String) dependencies.nextElement();
    // Element dependencyElement = addTextElement(outmacroNode,
    // "dependency", dependency);
    // dependencyElement.addAttribute("type","direct");
    // }

    callAntTargetVisitor(macroNode, outmacroNode, outProjectNode);

    // Add documentation
    // Get comment element before the macro element to extract macro doc
    List children = macroNode.selectNodes("preceding-sibling::node()");
    if (children.size() > 0) {
      // Scan past the text nodes, which are most likely whitespace
      int index = children.size() - 1;
      Node child = (Node) children.get(index);
      while (index > 0 && child.getNodeType() == Node.TEXT_NODE) {
        index--;
        child = (Node) children.get(index);
      }

      // Check if there is a comment node
      String commentText = null;
      if (child.getNodeType() == Node.COMMENT_NODE) {
        Comment macroComment = (Comment) child;
        commentText = macroComment.getStringValue().trim();
        log(macroName + " comment: " + commentText, Project.MSG_DEBUG);
      } else {
        log("Macro has no comment: " + macroName, Project.MSG_WARN);
      }

      insertDocumentation(outmacroNode, commentText);

      Node previousNode = (Node) children.get(children.size() - 1);
    }

    // Get names of all properties used in this macro
    ArrayList properties = new ArrayList();
    Visitor visitor = new AntPropertyVisitor(properties);
    macroNode.accept(visitor);
    for (Iterator iterator = properties.iterator(); iterator.hasNext(); ) {
      String property = (String) iterator.next();
      addTextElement(outmacroNode, "propertyDependency", property);
    }
  }