From: Yoshito Umaoka Date: Fri, 13 Sep 2013 08:14:50 +0000 (+0000) Subject: ICU-10393 Added a new feature to CollectAPI to write out API list in TSV format. X-Git-Tag: milestone-59-0-1~2544 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=02d6148322c82991dd26c7cc2c2ab9967d659e75;p=icu ICU-10393 Added a new feature to CollectAPI to write out API list in TSV format. X-SVN-Rev: 34302 --- diff --git a/icu4j/tools/build/src/com/ibm/icu/dev/tool/docs/APIInfo.java b/icu4j/tools/build/src/com/ibm/icu/dev/tool/docs/APIInfo.java index 6d9487e4769..75083c15133 100644 --- a/icu4j/tools/build/src/com/ibm/icu/dev/tool/docs/APIInfo.java +++ b/icu4j/tools/build/src/com/ibm/icu/dev/tool/docs/APIInfo.java @@ -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) { diff --git a/icu4j/tools/build/src/com/ibm/icu/dev/tool/docs/CollectAPI.java b/icu4j/tools/build/src/com/ibm/icu/dev/tool/docs/CollectAPI.java index 5aac62b2a21..5e46d69a003 100644 --- a/icu4j/tools/build/src/com/ibm/icu/dev/tool/docs/CollectAPI.java +++ b/icu4j/tools/build/src/com/ibm/icu/dev/tool/docs/CollectAPI.java @@ -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(); }