001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package tests;
028:
029: import java.io.*;
030: import java.util.*;
031: import util.*;
032:
033: /**
034: * Find the .java and .jasm source files for the unix tests.
035: */
036: public class CollectTestCases {
037: static void usage() {
038: System.out.println("Usage: java -jar buildtool.jar "
039: + "testcases <workspacedir> <outputdir>");
040: }
041:
042: static File workspacedir;
043: static File outputdir;
044: static Vector sourcefiles;
045: static PrintWriter pw;
046: static Hashtable env;
047:
048: public static void main(String args[]) throws Throwable {
049: if (args.length != 2) {
050: usage();
051: System.exit(1);
052: }
053: workspacedir = new File(args[0]);
054: outputdir = new File(args[1]);
055:
056: env = Util.getenv();
057:
058: if (!workspacedir.isDirectory()) {
059: usage();
060: System.exit(1);
061: }
062:
063: sourcefiles = listSourceFiles(workspacedir);
064: FileOutputStream out = new FileOutputStream(new File(outputdir,
065: "testcases.make"));
066: pw = new PrintWriter(new OutputStreamWriter(out));
067:
068: writeHeader();
069: writeList("TEST_JAVA_SRCS", null, null, ".java");
070: writeList("TEST_JASM_SRCS", null, null, ".jasm");
071:
072: pw.close();
073: }
074:
075: static Vector listSourceFiles(File dir) {
076: Vector v = new Vector();
077: listSourceFiles(v, new File(dir, "src/tests"));
078: return v;
079: }
080:
081: static void listSourceFiles(Vector list, File dir) {
082: String children[] = dir.list();
083: if (children == null) {
084: return;
085: }
086: for (int i = 0; i < children.length; i++) {
087: String child = children[i];
088: if (child.equals("SCCS")) {
089: continue;
090: }
091: if (child.equals("CVS")) {
092: continue;
093: }
094: if (child.equals(".")) {
095: continue;
096: }
097: if (child.equals("..")) {
098: continue;
099: }
100: if (checkSkip(child)) {
101: continue;
102: }
103: File c = new File(dir, child);
104: if (c.isDirectory()) {
105: listSourceFiles(list, c);
106: } else {
107: list.addElement(c.getAbsolutePath());
108: }
109: }
110: }
111:
112: static boolean checkSkip(String s) {
113: String value = (String) env.get("ENABLE_ISOLATES");
114: if (value == null || !value.equals("true")) {
115: if (s.indexOf("isolate") != -1) {
116: return true;
117: }
118: if (s.indexOf("dynamic_natives") != -1) {
119: return true;
120: }
121: if (s.indexOf("Isolate") != -1) {
122: return true;
123: }
124: if (s.indexOf("MShLib") != -1) {
125: return true;
126: }
127: } else {
128: if (s.indexOf("SShLib") != -1) {
129: return true;
130: }
131: }
132:
133: value = (String) env.get("ENABLE_LIB_IMAGES");
134: if (value == null || !value.equals("true")) {
135: if (s.indexOf("ShLib") != -1) {
136: return true;
137: }
138: }
139:
140: value = (String) env.get("ENABLE_MULTIPLE_PROFILES_SUPPORT");
141: if (value == null || !value.equals("true")) {
142: if (s.indexOf("MVMProfileTest") != -1) {
143: return true;
144: }
145: if (s.indexOf("MVMRestrictedTest") != -1) {
146: return true;
147: }
148: }
149: return false;
150: }
151:
152: static void writeHeader() {
153: pw.println("# This file is auto-generated by ");
154: pw.println("# $(JVMWorkSpace)/src/tools/buildtool/tests/"
155: + "CollectTestCases.java.");
156: pw.println("# Do not edit!");
157: pw.println();
158: pw.println();
159: pw.println();
160: }
161:
162: /**
163: * Write a list of files in Makefile format. An example output is
164: * <pre>
165: * TESTS_JAVA_SRCS = \
166: * e:/cldcvm/src/tests/Sanity.java \
167: * e:/cldcvm/src/tests/Foo.java
168: * </pre>
169: *
170: * @param includePattern if non-null, a file in the <i>list</i>
171: * won't be printed if the file's pathname
172: * does not contain <i>includePattern</i> as
173: * a substring.
174: * @param excludePattern if non-null, a file in the <i>list</i>
175: * won't be printed if the file's pathname
176: * contains <i>excludePattern</i> as
177: * a substring.
178: * @param suffix if non-null, a file in the <i>list</i>
179: * won't be printed if the suffix of the file
180: * is not <i>suffix</i>.
181: */
182: static void writeList(String varName, String includePattern,
183: String excludePattern, String suffix) throws Throwable {
184: /*
185: * Note: the list of source files are written into two places:
186: *
187: * [1] in testcases.make, as a Makefile variable
188: * [2] in the file <varName>.lst, such that the list of source files
189: * may be passed to javac as @<varName>.lst.
190: *
191: * The main reason for having <varName>.lst is Windows may not
192: * be able to handle too many source files if we list all of them
193: * separately in the command-line.
194: */
195: FileOutputStream out = new FileOutputStream(new File(outputdir,
196: varName + ".lst"));
197: PrintWriter pw2 = new PrintWriter(new OutputStreamWriter(out));
198:
199: pw.print(varName + " =");
200: for (int i = 0; i < sourcefiles.size(); i++) {
201: String path = (String) sourcefiles.elementAt(i);
202:
203: if (includePattern != null) {
204: if (path.indexOf(includePattern) == -1) {
205: continue;
206: }
207: }
208: if (excludePattern != null) {
209: if (path.indexOf(excludePattern) != -1) {
210: continue;
211: }
212: }
213: if (suffix != null) {
214: if (!path.endsWith(suffix)) {
215: continue;
216: }
217: }
218: pw.print(" \\");
219: pw.println();
220: pw.print(" ");
221: for (int j = 0; j < path.length(); j++) {
222: char c = path.charAt(j);
223: if (c == '\\') {
224: pw.print("/");
225: pw2.print("/");
226: } else {
227: pw.print(c);
228: pw2.print(c);
229: }
230: }
231: pw2.println();
232: }
233: pw.println();
234: pw.println();
235: pw2.close();
236: }
237: }
|