From adf994a3fd5db791a049a26896c7aae62b559df2 Mon Sep 17 00:00:00 2001 From: "Steven R. Loomis" Date: Tue, 2 Nov 2010 21:44:10 +0000 Subject: [PATCH] ICU-8114 checkin NAFD improvements X-SVN-Rev: 28990 --- .../dev/tools/misc/NonAsciiFileDetector.java | 108 ++++++++++++++---- 1 file changed, 84 insertions(+), 24 deletions(-) diff --git a/tools/release/java/src/com/ibm/icu/dev/tools/misc/NonAsciiFileDetector.java b/tools/release/java/src/com/ibm/icu/dev/tools/misc/NonAsciiFileDetector.java index 2ade6518e9..a2497798ac 100644 --- a/tools/release/java/src/com/ibm/icu/dev/tools/misc/NonAsciiFileDetector.java +++ b/tools/release/java/src/com/ibm/icu/dev/tools/misc/NonAsciiFileDetector.java @@ -7,19 +7,37 @@ package com.ibm.icu.dev.tools.misc; import java.io.BufferedReader; +import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.File; import java.io.FilenameFilter; +import java.util.Map; +import java.util.Map.Entry; +import java.util.TreeMap; import java.util.Vector; public class NonAsciiFileDetector { + + private static boolean VERBOSE = false; + public static class ICUSourceFileFilter implements FilenameFilter { + int matched = 0; + int skipped = 0; public boolean accept(File dir, String name) { - return name.endsWith(".cpp") || name.endsWith(".c") || name.endsWith(".h") || name.endsWith(".java"); + boolean doAccept = name.endsWith(".cpp") || name.endsWith(".c") || name.endsWith(".h") || name.endsWith(".java"); + if(doAccept) { + matched++; + } else { + skipped++; + } + return doAccept; + } + public String stats() { + return "Checked " + matched + " files and skipped " + skipped + " files"; } } @@ -49,13 +67,22 @@ public class NonAsciiFileDetector public static void listFiles(File file, FilenameFilter filter, - Vector list) throws IOException + Vector list) throws IOException { + if(VERBOSE) System.err.println(" .. checking " + file.getPath() ); File files[] = file.listFiles(); if (files != null && files.length > 0) { for (int i = 0; i < files.length; i ++) { if (files[i].isDirectory()) { - listFiles(files[i], filter, list); + if(files[i].getAbsolutePath().equals(files[i].getCanonicalPath())) { + if(!files[i].getName().equals(".svn")) { // skip .svn dirs + listFiles(files[i], filter, list); + } + } else { + if(VERBOSE) { + System.err.println(".. skipping symlink " + files[i].getPath()); + } + } } else { if (filter.accept(file, files[i].getName())) { @@ -66,22 +93,21 @@ public class NonAsciiFileDetector } } - public static Vector getNonAsciiFiles(String directory, + public static Map getNonAsciiFiles(File directory, FilenameFilter filter) throws IOException { - Vector files = new Vector(); - Vector result = new Vector(); - listFiles(new File(directory), filter, files); + Vector files = new Vector(); + Map result = new TreeMap(); + listFiles(directory, filter, files); int filecount = files.size(); if (filecount == 0) { return null; } for (int i = 0; i < filecount; i ++) { - int isnonascii = isNonAscii((File)files.elementAt(i)); + int isnonascii = isNonAscii(files.elementAt(i)); if (isnonascii != -1) { - result.add(((File)files.elementAt(i)).getAbsolutePath()); - result.add(new Integer(isnonascii)); + result.put(files.elementAt(i).getAbsolutePath(),new Integer(isnonascii)); } } return result; @@ -89,20 +115,54 @@ public class NonAsciiFileDetector public static void main(String arg[]) { - try { - Vector nonascii = getNonAsciiFiles(arg[0], new ICUSourceFileFilter()); - System.out.println(); - if (nonascii != null && nonascii.size() > 0) { - for (int i = 0; i < nonascii.size(); i += 2) { - System.out.println("Non ascii files " - + (String)nonascii.elementAt(i) + " " - + ((Integer)nonascii.elementAt(i + 1)).intValue()); - } - System.exit(1); - } - } catch (IOException e) { - e.printStackTrace(); - } + int nextArg = 0; + for(nextArg = 0;nextArg nonascii = getNonAsciiFiles(dir, isff); + boolean noised = false; + System.out.println(); + if (nonascii != null && nonascii.size() > 0) { + for (Entry e : nonascii.entrySet()) { + if(!noised) { + System.out.println("Non ascii files in " + arg[nextArg] + ": "); + noised = true; + } + System.out.println("" + +e.getKey() + ":" + +e.getValue()); + bad++; + } + } else { +// if (VERBOSE==true) { + System.out.println("No non ascii files in " + arg[nextArg]); +// } + } +// if(VERBOSE==true) { + System.out.println( isff.stats()); +// } + } catch (IOException e) { + System.err.println("Error processing " + arg[nextArg]); + e.printStackTrace(); + } + } + if(bad>0) { + System.err.println(bad+" non-ascii files found in total."); + } } }