]> granicus.if.org Git - icu/commitdiff
ICU-10393 Added a new feature to CollectAPI to write out API list in TSV format.
authorYoshito Umaoka <y.umaoka@gmail.com>
Fri, 13 Sep 2013 08:14:50 +0000 (08:14 +0000)
committerYoshito Umaoka <y.umaoka@gmail.com>
Fri, 13 Sep 2013 08:14:50 +0000 (08:14 +0000)
X-SVN-Rev: 34302

icu4j/tools/build/src/com/ibm/icu/dev/tool/docs/APIInfo.java
icu4j/tools/build/src/com/ibm/icu/dev/tool/docs/CollectAPI.java

index 6d9487e4769fc56c4713a0a1f14eaeb040f4c4dd..75083c151332bc5b0e13a2f107db23a977ab82d9 100644 (file)
@@ -424,8 +424,12 @@ class APIInfo {
     }
 
     public void print(PrintWriter pw, boolean detail, boolean html, boolean withStatus) {
-        StringBuffer buf = new StringBuffer();
+        StringBuilder buf = new StringBuilder();
+        format(buf, detail, html, withStatus);
+        pw.print(buf.toString());
+    }
 
+    public void format(StringBuilder buf, boolean detail, boolean html, boolean withStatus) {
         // remove all occurrences of icu packages from the param string
         // fortunately, all the packages have 4 chars (lang, math, text, util).
         String xsig = sig;
@@ -519,8 +523,6 @@ class APIInfo {
             buf.append(xsig.substring(n));
             break;
         }
-
-        pw.print(buf.toString());
     }
 
     public void println(PrintWriter pw, boolean detail, boolean html) {
index 5aac62b2a21bcc945e317d2982e96c5d86b84470..5e46d69a003a1cae2a27b6be5f73d4718da652a9 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *******************************************************************************
- * Copyright (C) 2010, International Business Machines Corporation and         *
+ * Copyright (C) 2010-2013, International Business Machines Corporation and    *
  * others. All Rights Reserved.                                                *
  *******************************************************************************
  */
@@ -144,10 +144,53 @@ public class CollectAPI {
         pw.close();
     }
 
+    void writeTSV(String outfile, BitSet filter) throws IOException {
+        FileOutputStream fos = new FileOutputStream(outfile);
+        PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(fos, "UTF-8")));
+
+        for (APIInfo info : _apidata.set) {
+            if (!filter.get(info.getVal(APIInfo.STA))) {
+                continue;
+            }
+            StringBuilder buf = new StringBuilder();
+
+            // package
+            buf.append(info.getPackageName());
+            buf.append("\t");
+
+            // class
+            String className = info.getClassName();
+            if (className.length() == 0) {
+                className = info.getName();
+            }
+            buf.append(className);
+            buf.append("\t");
+
+            // signature, etc
+            info.format(buf, false, false, false);
+            buf.append("\t");
+
+            // status
+            buf.append(APIInfo.getTypeValName(APIInfo.STA, info.getVal(APIInfo.STA)));
+            buf.append("\t");
+
+            // version
+            String statusVer = info.getStatusVersion();
+            if (statusVer.length() == 0) {
+                statusVer = "[N/A]";
+            }
+            buf.append(statusVer);
+
+            pw.println(buf.toString());
+        }
+        pw.close();
+    }
+
     public static void main(String[] args) {
-        String apifile = null;
-        String outfile = "api.html";
+        String apifile = null; 
+        String outfile = null;
         BitSet filter = new BitSet(MAXSTATE + 1);
+        boolean isTSV = false;
 
         // default filter
         filter.set(APIInfo.STA_STABLE);
@@ -186,6 +229,8 @@ public class CollectAPI {
                 }
                 i++;
                 outfile = args[i];
+            } else if (args[i].equals("-t")) {
+                isTSV = true;
             } else {
                 apifile = args[i];
                 if (i + 1 != args.length) {
@@ -203,7 +248,17 @@ public class CollectAPI {
         CollectAPI collection = new CollectAPI(apifile);
 
         try {
-            collection.writeHTML(outfile, filter);
+            if (isTSV) {
+                if (outfile == null) {
+                    outfile = "api.tsv";
+                }
+                collection.writeTSV(outfile, filter);
+            } else {
+                if (outfile == null) {
+                    outfile = "api.html";
+                }
+                collection.writeHTML(outfile, filter);
+            }
         } catch (IOException e) {
             e.printStackTrace();
         }