ICU-6289 Fix build script problems and added NonAsciiFileDetector.

X-SVN-Rev: 24093
This commit is contained in:
Yoshito Umaoka 2008-06-02 17:10:50 +00:00
parent 5aaacb9233
commit c55369fc82
2 changed files with 126 additions and 11 deletions

View file

@ -1,42 +1,50 @@
<!--
/*
*******************************************************************************
* Copyright (C) 2006, International Business Machines Corporation and *
* Copyright (C) 2006-2008, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
* This is the ant build file for ICU tools.
*/
-->
<project name="API-Tools" default="main" basedir=".">
<project name="release-tools" default="tools" basedir=".">
<target name="init">
<tstamp/>
<property name="src.dir" value="src"/>
<property name="build.dir" value="classes"/>
<property name="jar.file" value="cldr.jar"/>
<property name="jarSrc.file" value="cldrsrc.jar"/>
<property file="api-report.properties" />
<mkdir dir="${build.dir}"/>
<echo message="java home: ${java.home}"/>
<echo message="java version: ${java.version}"/>
<echo message="java vendor: ${java.vm.vendor}"/>
<echo message="ant java version: ${ant.java.version}"/>
<echo message="${ant.version}"/>
<echo message="${basedir}"/>
<echo message="${basedir}"/>
<condition property="is.sun.jdk14">
<and>
<equals arg1="${ant.java.version}" arg2="1.4"/>
<contains string="${java.vm.vendor}" substring="Sun Microsystems Inc"/>
</and>
</condition>
<fail unless="is.sun.jdk14" message="Sun JDK1.4 is required."/>
</target>
<target name="doctools" depends="init" description="build StableAPI classes">
<javac includes="com/ibm/icu/dev/tools/docs/*.java"
excludes="**/CVS/**/*"
<target name="tools" depends="init" description="compile release tools">
<javac includes="**/*.java"
srcdir="${src.dir}"
destdir="${build.dir}"
source="1.4"
debug="on" deprecation="off"
encoding="ascii"/>
</target>
<target name="clean" depends="init" description="remove all build targets">
<delete dir="${build.dir}"/>
</target>
<target name="apireport" depends="doctools">
<target name="apireport" depends="tools">
<java classname="com.ibm.icu.dev.tools.docs.StableAPI" fork="yes" failonerror="true">
<arg value = "--oldver"/>
@ -62,7 +70,7 @@
<arg value = "--resultfile"/>
<arg value = "${basedir}/APIChangeReport.html"/>
<classpath>
<pathelement location="${build.dir}"/>
<pathelement path="${java.class.path}/"/>

View file

@ -0,0 +1,107 @@
/*
**********************************************************************
* Copyright (c) 2008, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
*/
package com.ibm.icu.dev.tools.misc;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.File;
import java.io.FilenameFilter;
import java.util.Vector;
public class NonAsciiFileDetector
{
public static class ICUSourceFileFilter implements FilenameFilter
{
public boolean accept(File dir, String name)
{
return name.endsWith(".cpp") || name.endsWith(".c") || name.endsWith(".h") || name.endsWith(".java");
}
}
public static int isNonAscii(File file) throws IOException
{
BufferedReader in = new BufferedReader(new FileReader(file));
int line = 0;
while (true) {
String str = in.readLine();
if (str == null) {
in.close();
return -1;
}
for (int i = 0; i < str.length(); i ++) {
if (str.charAt(i) > 0x7f) {
System.out.println("Ascii test failed in "
+ file.getAbsolutePath() + " line "
+ line + " string\n" + str);
// non-latin1
in.close();
return line;
}
}
line ++;
}
}
public static void listFiles(File file,
FilenameFilter filter,
Vector list) throws IOException
{
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);
}
else {
if (filter.accept(file, files[i].getName())) {
list.add(files[i]);
}
}
}
}
}
public static Vector getNonAsciiFiles(String directory,
FilenameFilter filter)
throws IOException
{
Vector files = new Vector();
Vector result = new Vector();
listFiles(new File(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));
if (isnonascii != -1) {
result.add(((File)files.elementAt(i)).getAbsolutePath());
result.add(new Integer(isnonascii));
}
}
return result;
}
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());
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}