Ejemplo n.º 1
0
  /**
   * Leave only the value for RCS keywords.
   *
   * <p>For example, <code>$Revision: 1.1 $</code> becomes <code>1.0</code>.
   */
  public String replaceRcsKeywords(String text) {
    if (matcher == null) {
      matcher =
          Pattern.compile(
                  "\\$(Author|Date|Header|Id|Locker|Log|Name|RCSFile|Revision|Source|State): (.+?) \\$")
              .matcher(text);
    } else {
      matcher.reset(text);
    }

    StringBuffer buffer = new StringBuffer();
    while (matcher.find()) {
      String string = matcher.group(2);

      // For the Date: keyword, have a shot at reformatting string
      if ("Date".equals(matcher.group(1))) {
        try {
          DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
          Date date = dateFormat.parse(string);
          string = date.toString();
        } catch (ParseException e) {
        } // if we can't parse, return unchanged
      }

      matcher.appendReplacement(buffer, string);
    }
    matcher.appendTail(buffer);
    return buffer.toString();
  }
Ejemplo n.º 2
0
  public static void main(String[] args) {
    Date start = new Date();
    if (args.length < 3) {
      System.out.println("Wrong number of arguments:\n" + USAGE);
      return;
    }

    // get # threads
    int tc = Integer.parseInt(args[0]);
    String outfile = args[1];

    // make a threadsafe queue of all files to process
    ConcurrentLinkedQueue<String> files = new ConcurrentLinkedQueue<String>();
    for (int i = 2; i < args.length; i++) {
      files.add(args[i]);
    }

    // hastable for results
    Hashtable<String, Integer> results = new Hashtable<String, Integer>(HASH_SIZE, LF);

    // spin up the threads
    Thread[] workers = new Thread[tc];
    for (int i = 0; i < tc; i++) {
      workers[i] = new Worker(files, results);
      workers[i].start();
    }

    // wait for them to finish
    try {
      for (int i = 0; i < tc; i++) {
        workers[i].join();
      }
    } catch (Exception e) {
      System.out.println("Caught Exception: " + e.getMessage());
    }

    // terminal output
    Date end = new Date();
    System.out.println(end.getTime() - start.getTime() + " total milliseconds");
    System.out.println(results.size() + " unique words");

    // sort results for easy comparison/verification
    List<Map.Entry<String, Integer>> sorted_results =
        new ArrayList<Map.Entry<String, Integer>>(results.entrySet());
    Collections.sort(sorted_results, new KeyComp());
    // file output
    try {
      PrintStream out = new PrintStream(outfile);
      for (int i = 0; i < sorted_results.size(); i++) {
        out.println(sorted_results.get(i).getKey() + "\t" + sorted_results.get(i).getValue());
      }
    } catch (Exception e) {
      System.out.println("Caught Exception: " + e.getMessage());
    }
  }
Ejemplo n.º 3
0
  private static boolean compareDateStrings(
      String value1, String value2, String operator, String pattern) {
    if (value1 == null || value2 == null) {
      return false;
    }

    String datePattern = pattern;

    if (pattern == null) {
      datePattern = "yyyy-MM-dd HH:mm:ss.S";
    }
    long time1;
    long time2;

    DateFormat dateFormat = new SimpleDateFormat(datePattern);
    try {
      Date date1 = dateFormat.parse(value1);
      Date date2 = dateFormat.parse(value2);
      time1 = date1.getTime();
      time2 = date2.getTime();
    } catch (ParseException pe) {
      return false;
    }

    if ("=".equals(operator)) {
      return time1 == time2;
    } else if (">".equals(operator)) {
      return time1 > time2;
    } else if ("<".equals(operator)) {
      return time1 < time2;
    } else if (">=".equals(operator)) {
      return time1 >= time2;
    } else if ("<=".equals(operator)) {
      return time1 <= time2;
    }
    return false;
  }
Ejemplo n.º 4
0
  public List getIterationList(String projectId) {
    List<Map> list = new ArrayList<Map>();

    try {

      String apiUrl =
          rallyApiHost
              + "/iteration?"
              + "project="
              + rallyApiHost
              + "/project/"
              + projectId
              + "&fetch=true&order=Name%20desc&start=1&pagesize=100";

      String checkProjectRef = rallyApiHost + "/project/" + projectId;

      log.info("rallyApiUrl:" + apiUrl);
      log.info("checkProjectRef:" + checkProjectRef);

      String responseXML = getRallyXML(apiUrl);

      SimpleDateFormat ISO8601FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
      Date currentDate = new Date();

      org.jdom.input.SAXBuilder bSAX = new org.jdom.input.SAXBuilder();
      org.jdom.Document doc = bSAX.build(new StringReader(responseXML));
      Element root = doc.getRootElement();

      XPath xpath = XPath.newInstance("//Object");
      List xlist = xpath.selectNodes(root);

      Iterator iter = xlist.iterator();
      while (iter.hasNext()) {

        Map map = new HashMap();

        Element item = (Element) iter.next();
        String objId = item.getChildText("ObjectID");
        String name = item.getChildText("Name");
        String state = item.getChildText("State");

        String startDateStr = item.getChildText("StartDate");
        String endDateStr = item.getChildText("EndDate");

        Date startDate = ISO8601FORMAT.parse(startDateStr);
        Date endDate = ISO8601FORMAT.parse(endDateStr);

        boolean isCurrent = false;

        int startCheck = startDate.compareTo(currentDate);
        int endCheck = endDate.compareTo(currentDate);

        if (startCheck < 0 && endCheck > 0) {
          isCurrent = true;
        }

        log.info("name=" + name + " isCurrent=" + isCurrent);

        String releaseRef = item.getAttribute("ref").getValue();

        // In child project, parent object have to be filiered
        Element projectElement = item.getChild("Project");
        String projectRef = projectElement.getAttributeValue("ref");

        if (projectRef.equals(checkProjectRef)) {

          map.put("objId", objId);
          map.put("rallyRef", releaseRef);
          map.put("name", name);
          map.put("state", state);
          map.put("isCurrent", "" + isCurrent);

          list.add(map);
        }
      }

      log.info("-----------");

    } catch (Exception ex) {
      log.error("ERROR: ", ex);
    }

    return list;
  }
Ejemplo n.º 5
0
 protected int putDate(String name, Date d) {
   int start = _buf.position();
   _put(DATE, name);
   _buf.putLong(d.getTime());
   return _buf.position() - start;
 }
Ejemplo n.º 6
0
 protected void putDate(String name, Date d) {
   _put(DATE, name);
   _buf.writeLong(d.getTime());
 }