2 *******************************************************************************
\r
3 * Copyright (C) 2005-2010, International Business Machines Corporation and *
\r
4 * others. All Rights Reserved. *
\r
5 *******************************************************************************
\r
8 package com.ibm.icu.dev.tool.docs;
\r
10 import java.io.BufferedReader;
\r
11 import java.io.File;
\r
12 import java.io.FileInputStream;
\r
13 import java.io.FilenameFilter;
\r
14 import java.io.InputStreamReader;
\r
15 import java.io.PrintWriter;
\r
16 import java.util.regex.Matcher;
\r
17 import java.util.regex.Pattern;
\r
19 public final class Deprecator {
\r
20 private boolean undep;
\r
23 Deprecator(boolean undep, int log) {
\r
28 public static void main(String[] args) {
\r
29 String srcPath = null;
\r
30 String dstPath = null;
\r
31 boolean undep = false;
\r
34 boolean help = false;
\r
35 StringBuffer err = new StringBuffer();
\r
37 for (int i = 0; i < args.length; ++i) {
\r
38 String arg = args[i];
\r
39 if (arg.equals("-src")) {
\r
40 srcPath = args[++i];
\r
41 } else if (arg.equals("-dst")) {
\r
42 dstPath = args[++i];
\r
43 } else if (arg.equals("-undep")) {
\r
45 } else if (arg.equals("-help")) {
\r
47 } else if (arg.equals("-silent")) {
\r
49 } else if (arg.equals("-log")) {
\r
51 } else if (arg.equals("-logfiles")) {
\r
53 } else if (arg.equals("-verbose")) {
\r
56 err.append("\nunrecognized argument: " + arg);
\r
63 if (srcPath == null) {
\r
64 err.append("\nsrc must be defined");
\r
66 srcDir = new File(srcPath);
\r
67 if (!(srcDir.exists() && srcDir.isDirectory())) {
\r
68 err.append("\nsrc must be an existing directory: '" + srcPath + "'");
\r
71 if (dstPath == null) {
\r
72 err.append("\ndst must be defined");
\r
74 dstDir = new File(dstPath);
\r
75 if (!dstDir.exists()) {
\r
76 if (!dstDir.mkdirs()) {
\r
77 err.append("\nunable to create dst: '" + dstPath + "'");
\r
79 } else if (!dstDir.isDirectory()) {
\r
80 err.append("\ndst exists but is not directory: '" + dstPath + "'");
\r
84 if (help || err.length() > 0) {
\r
86 System.err.println("Error: " + err.toString());
\r
94 System.out.println("src: " + srcDir.getCanonicalPath());
\r
95 System.out.println("dst: " + dstDir.getCanonicalPath());
\r
96 System.out.println("undep: " + undep);
\r
100 new Deprecator(undep, log).process(srcDir, dstDir);
\r
103 System.out.println("done");
\r
104 System.out.flush();
\r
107 catch(Exception e) {
\r
108 System.err.println("Unexpected error: " + e);
\r
112 static void usage() {
\r
113 PrintWriter pw = new PrintWriter(System.out);
\r
114 pw.println("Usage: Deprecator -src path -dst path [-help]");
\r
115 pw.println(" -src path : the root of the tree of files to work on");
\r
116 pw.println(" -dst path : the root of the tree to put the resulting files");
\r
117 pw.println(" -help : print this usage message and exit, doing nothing");
\r
118 pw.println(" -undep : remove deprecation tags if present (default false)");
\r
120 pw.println(" Add or remove warning deprecations for ICU @draft and @internal APIs");
\r
124 static final String stoplist = "!CVS";
\r
125 static final FilenameFilter ff = new FilenameFilter() {
\r
126 public boolean accept(File dir, String name) {
\r
127 if (name.endsWith(".java")) return true;
\r
128 if (new File(dir, name).isDirectory()) {
\r
129 if (stoplist.indexOf("!"+name) == -1) {
\r
137 void process(File srcDir, File dstDir) {
\r
138 File[] files = srcDir.listFiles(ff);
\r
139 for (int i = 0; i < files.length; ++i) {
\r
141 File d = new File(dstDir, f.getName());
\r
142 if (f.isDirectory()) {
\r
145 System.err.println("cannot create directory: " + d.getPath());
\r
148 } else if (!d.isDirectory()) {
\r
149 System.err.println("file already exists but is not directory: " + d.getPath());
\r
153 System.out.println("process dir: " + f.getPath());
\r
165 ** ** ** @deprecated
\r
167 static final Pattern pat = Pattern.compile("^[\\s*]*@\\s*deprecated.*");
\r
169 void processFile(File srcFile, File dstFile) {
\r
171 System.out.println("process '" + srcFile.getPath() + "'");
\r
175 BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(srcFile)));
\r
177 String line = null;
\r
178 while (null != (line = r.readLine())) {
\r
180 Matcher m = pat.matcher(line);
\r
183 System.out.println(String.valueOf(n) + ": " + line);
\r
189 catch (Exception e) {
\r
190 System.out.flush();
\r
191 System.err.println("caught exception: " + e);
\r