FileDocCategorySizeDatePackage
CollectTestCases.javaAPI DocphoneME MR2 API (J2ME)7445Wed May 02 17:59:48 BST 2007tests

CollectTestCases

public class CollectTestCases extends Object
Find the .java and .jasm source files for the unix tests.

Fields Summary
static File
workspacedir
static File
outputdir
static Vector
sourcefiles
static PrintWriter
pw
static Hashtable
env
Constructors Summary
Methods Summary
static booleancheckSkip(java.lang.String s)

        String value = (String)env.get("ENABLE_ISOLATES");
	if (value == null || !value.equals("true")) {
	    if (s.indexOf("isolate") != -1) {
		return true;
	    }
	    if (s.indexOf("dynamic_natives") != -1) {
		return true;
	    }
	    if (s.indexOf("Isolate") != -1) {
		return true;
	    }
	    if (s.indexOf("MShLib") != -1) {
		return true;
	    }
	} else {
            if (s.indexOf("SShLib") != -1) {
		return true;
	    }
        }

        value = (String)env.get("ENABLE_LIB_IMAGES");
	if (value == null || !value.equals("true")) {
	    if (s.indexOf("ShLib") != -1) {
		return true;
	    }
	}

        value = (String)env.get("ENABLE_MULTIPLE_PROFILES_SUPPORT");
	if (value == null || !value.equals("true")) {
	    if (s.indexOf("MVMProfileTest") != -1) {
                return true;
	    }
	    if (s.indexOf("MVMRestrictedTest") != -1) {
                return true;
	    }
        }
	return false;
    
static java.util.VectorlistSourceFiles(java.io.File dir)

        Vector v = new Vector();
        listSourceFiles(v, new File(dir, "src/tests"));
        return v;
    
static voidlistSourceFiles(java.util.Vector list, java.io.File dir)

        String children[] = dir.list();
        if (children == null) {
            return;
        }
        for (int i=0; i<children.length; i++) {
            String child = children[i];
            if (child.equals("SCCS")) {
                continue;
            }
            if (child.equals("CVS")) {
                continue;
            }
            if (child.equals(".")) {
                continue;
            }
            if (child.equals("..")) {
                continue;
            }
	    if (checkSkip(child)) {
		continue;
	    }
            File c = new File(dir, child);
            if (c.isDirectory()) {
                listSourceFiles(list, c);
            } else {
                list.addElement(c.getAbsolutePath());
            }
        }
    
public static voidmain(java.lang.String[] args)

        if (args.length != 2) {
            usage();
            System.exit(1);
        }
        workspacedir = new File(args[0]);
        outputdir = new File(args[1]);

	env = Util.getenv();

        if (!workspacedir.isDirectory()) {
            usage();
            System.exit(1);
        }

        sourcefiles = listSourceFiles(workspacedir);
        FileOutputStream out = 
            new FileOutputStream(new File(outputdir, "testcases.make"));
        pw = new PrintWriter(new OutputStreamWriter(out));

        writeHeader();
        writeList("TEST_JAVA_SRCS",    null,  null, ".java");
        writeList("TEST_JASM_SRCS",    null,  null, ".jasm");

        pw.close();
    
static voidusage()

        System.out.println("Usage: java -jar buildtool.jar " +
                           "testcases <workspacedir> <outputdir>");
    
static voidwriteHeader()

        pw.println("# This file is auto-generated by ");
        pw.println("# $(JVMWorkSpace)/src/tools/buildtool/tests/" +
                      "CollectTestCases.java.");
        pw.println("# Do not edit!");
        pw.println();
        pw.println();
        pw.println();
    
static voidwriteList(java.lang.String varName, java.lang.String includePattern, java.lang.String excludePattern, java.lang.String suffix)
Write a list of files in Makefile format. An example output is
TESTS_JAVA_SRCS = \
e:/cldcvm/src/tests/Sanity.java \
e:/cldcvm/src/tests/Foo.java

param
includePattern if non-null, a file in the list won't be printed if the file's pathname does not contain includePattern as a substring.
param
excludePattern if non-null, a file in the list won't be printed if the file's pathname contains excludePattern as a substring.
param
suffix if non-null, a file in the list won't be printed if the suffix of the file is not suffix.

        /*
         * Note: the list of source files are written into two places:
         *
         * [1] in testcases.make, as a Makefile variable
         * [2] in the file <varName>.lst, such that the list of source files
         *     may be passed to javac as @<varName>.lst.
         *
         * The main reason for having <varName>.lst is Windows may not
         * be able to handle too many source files if we list all of them
         * separately in the command-line.
         */
        FileOutputStream out = 
            new FileOutputStream(new File(outputdir, varName + ".lst"));
        PrintWriter pw2 = new PrintWriter(new OutputStreamWriter(out));

        pw.print(varName + " =");
        for (int i=0; i<sourcefiles.size(); i++) {
            String path = (String)sourcefiles.elementAt(i);

            if (includePattern != null) {
                if (path.indexOf(includePattern) == -1) {
                    continue;
                }
            }
            if (excludePattern != null) {
                if (path.indexOf(excludePattern) != -1) {
                    continue;
                }
            }
            if (suffix != null) {
                if (!path.endsWith(suffix)) {
                    continue;
                }
            }
            pw.print(" \\");
            pw.println();
            pw.print(" ");
            for (int j=0; j<path.length(); j++) { 
                char c = path.charAt(j);
                if (c == '\\") {
                    pw.print("/");
                    pw2.print("/");
                } else {
                    pw.print(c);
                    pw2.print(c);
                }
            }
            pw2.println();
        }
        pw.println();
        pw.println();
        pw2.close();