Exemplo n.º 1
0
  private void callAntTargetVisitor(
      Element targetNode, Element outTargetNode, Element outProjectNode) {
    // Add antcall/runtarget dependencies
    ArrayList antcallTargets = new ArrayList();
    ArrayList<String> logs = new ArrayList<String>();
    ArrayList<String> signals = new ArrayList<String>();
    ArrayList<String> executables = new ArrayList<String>();
    Visitor visitorTarget = new AntTargetVisitor(antcallTargets, logs, signals, executables);
    targetNode.accept(visitorTarget);
    for (Iterator iterator = antcallTargets.iterator(); iterator.hasNext(); ) {
      String antcallTarget = (String) iterator.next();
      Element dependencyElement = addTextElement(outTargetNode, "dependency", antcallTarget);
      dependencyElement.addAttribute("type", "exec");
    }

    for (String log : logs) {
      addTextElement(outTargetNode, "log", log);
    }

    if (globalSignalList.get(targetNode.attributeValue("name")) != null)
      signals.addAll(globalSignalList.get(targetNode.attributeValue("name")));

    for (String signal : signals) {
      addTextElement(outTargetNode, "signal", signal);
    }

    for (String executable : executables) {
      addTextElement(outTargetNode, "executable", executable);
    }
  }
Exemplo n.º 2
0
  public static List<QueryPVisitor> confirmTicket(List<Long> ticketList)
      throws DataException, IOException, DocumentException {
    String msgIdValue = System.currentTimeMillis() + "";
    String reqIdValue = "802";
    StringBuffer sb = new StringBuffer();
    for (Long id : ticketList) {
      sb.append(id + ",");
    }
    sb.delete(sb.length() - 1, sb.length());
    Map<String, String> ParamMap = new LinkedHashMap<String, String>();
    ParamMap.put("ReqId", reqIdValue);
    ParamMap.put("MsgId", msgIdValue);
    ParamMap.put("ReqParam", sb.toString());
    ParamMap.put("ReqKey", MD5.md5(reqIdValue + msgIdValue + sb.toString() + key).toLowerCase());

    String returnString = HttpclientUtil.Utf8HttpClientUtils(reUrl, ParamMap);
    Document doc = DocumentHelper.parseText(returnString);
    Element root = doc.getRootElement();
    Element ticket;
    QueryPVisitor queryPVisitor;
    List<QueryPVisitor> returnTicketList = Lists.newArrayList();
    for (Iterator i = root.elementIterator("Ticket"); i.hasNext(); ) {
      ticket = (Element) i.next();
      queryPVisitor = new QueryPVisitor();
      ticket.accept(queryPVisitor);
      returnTicketList.add(queryPVisitor);
    }
    if (returnTicketList.isEmpty()) {
      Document document = DocumentHelper.parseText(returnString);
      queryPVisitor = new QueryPVisitor();
      document.accept(queryPVisitor);
      returnTicketList.add(queryPVisitor);
    }
    return returnTicketList;
  }
Exemplo n.º 3
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);
    }
  }
Exemplo n.º 4
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);
    }
  }