2 *******************************************************************************
\r
3 * Copyright (C) 2005, 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.File;
\r
11 import java.io.FilenameFilter;
\r
12 import java.io.PrintWriter;
\r
13 import java.io.BufferedReader;
\r
14 import java.io.InputStreamReader;
\r
15 import java.io.FileInputStream;
\r
16 import java.util.regex.*;
\r
18 public final class Deprecator {
\r
19 private boolean undep;
\r
22 Deprecator(boolean undep, int log) {
\r
27 public static void main(String[] args) {
\r
28 String srcPath = null;
\r
29 String dstPath = null;
\r
30 boolean undep = false;
\r
33 boolean help = false;
\r
34 StringBuffer err = new StringBuffer();
\r
36 for (int i = 0; i < args.length; ++i) {
\r
37 String arg = args[i];
\r
38 if (arg.equals("-src")) {
\r
39 srcPath = args[++i];
\r
40 } else if (arg.equals("-dst")) {
\r
41 dstPath = args[++i];
\r
42 } else if (arg.equals("-undep")) {
\r
44 } else if (arg.equals("-help")) {
\r
46 } else if (arg.equals("-silent")) {
\r
48 } else if (arg.equals("-log")) {
\r
50 } else if (arg.equals("-logfiles")) {
\r
52 } else if (arg.equals("-verbose")) {
\r
55 err.append("\nunrecognized argument: " + arg);
\r
62 if (srcPath == null) {
\r
63 err.append("\nsrc must be defined");
\r
65 srcDir = new File(srcPath);
\r
66 if (!(srcDir.exists() && srcDir.isDirectory())) {
\r
67 err.append("\nsrc must be an existing directory: '" + srcPath + "'");
\r
70 if (dstPath == null) {
\r
71 err.append("\ndst must be defined");
\r
73 dstDir = new File(dstPath);
\r
74 if (!dstDir.exists()) {
\r
75 if (!dstDir.mkdirs()) {
\r
76 err.append("\nunable to create dst: '" + dstPath + "'");
\r
78 } else if (!dstDir.isDirectory()) {
\r
79 err.append("\ndst exists but is not directory: '" + dstPath + "'");
\r
83 if (help || err.length() > 0) {
\r
85 System.err.println("Error: " + err.toString());
\r
93 System.out.println("src: " + srcDir.getCanonicalPath());
\r
94 System.out.println("dst: " + dstDir.getCanonicalPath());
\r
95 System.out.println("undep: " + undep);
\r
99 new Deprecator(undep, log).process(srcDir, dstDir);
\r
102 System.out.println("done");
\r
103 System.out.flush();
\r
106 catch(Exception e) {
\r
107 System.err.println("Unexpected error: " + e);
\r
111 static void usage() {
\r
112 PrintWriter pw = new PrintWriter(System.out);
\r
113 pw.println("Usage: Deprecator -src path -dst path [-help]");
\r
114 pw.println(" -src path : the root of the tree of files to work on");
\r
115 pw.println(" -dst path : the root of the tree to put the resulting files");
\r
116 pw.println(" -help : print this usage message and exit, doing nothing");
\r
117 pw.println(" -undep : remove deprecation tags if present (default false)");
\r
119 pw.println(" Add or remove warning deprecations for ICU @draft and @internal APIs");
\r
123 static final String stoplist = "!CVS";
\r
124 static final FilenameFilter ff = new FilenameFilter() {
\r
125 public boolean accept(File dir, String name) {
\r
126 if (name.endsWith(".java")) return true;
\r
127 if (new File(dir, name).isDirectory()) {
\r
128 if (stoplist.indexOf("!"+name) == -1) {
\r
136 void process(File srcDir, File dstDir) {
\r
137 File[] files = srcDir.listFiles(ff);
\r
138 for (int i = 0; i < files.length; ++i) {
\r
140 File d = new File(dstDir, f.getName());
\r
141 if (f.isDirectory()) {
\r
144 System.err.println("cannot create directory: " + d.getPath());
\r
147 } else if (!d.isDirectory()) {
\r
148 System.err.println("file already exists but is not directory: " + d.getPath());
\r
152 System.out.println("process dir: " + f.getPath());
\r
164 ** ** ** @deprecated
\r
166 static final Pattern pat = Pattern.compile("^[\\s*]*@\\s*deprecated.*");
\r
168 void processFile(File srcFile, File dstFile) {
\r
170 System.out.println("process '" + srcFile.getPath() + "'");
\r
174 BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(srcFile)));
\r
176 String line = null;
\r
177 while (null != (line = r.readLine())) {
\r
179 Matcher m = pat.matcher(line);
\r
182 System.out.println(String.valueOf(n) + ": " + line);
\r
188 catch (Exception e) {
\r
189 System.out.flush();
\r
190 System.err.println("caught exception: " + e);
\r