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 java.util.zip.*;
032: import util.*;
033:
034: /**
035: * Create the romtestclasses.zip that contains classes that need to be
036: * romized for the romizer unit tests.
037: */
038: public class CreateRomTestClasses {
039: static void usage() {
040: System.out.println("Usage: java -jar buildtool.jar "
041: + "romtestclasses cldc_classes.zip "
042: + "cldcx_classes.zip tests.jar <outputfile>");
043: }
044:
045: static File workspacedir;
046: static File outputdir;
047: static Vector sourcefiles;
048: static PrintWriter pw;
049:
050: public static void main(String args[]) throws Throwable {
051: if (args.length != 4) {
052: usage();
053: System.exit(1);
054: }
055: File cldc_classes_zip = new File(args[0]);
056: File cldcx_classes_zip = new File(args[1]);
057: File tests_jar = new File(args[2]);
058: File output = new File(args[3]);
059:
060: FileOutputStream out = new FileOutputStream(output);
061: ZipOutputStream zout = new ZipOutputStream(out);
062:
063: // Simply copy all entries from cldc_classes_zip and cldcx_classes_zip
064: copyZipEntries(zout, cldc_classes_zip, null);
065: copyZipEntries(zout, cldcx_classes_zip, null);
066:
067: // We need to filter out the entries in tests_jar if:
068: // (1) The test is a negative test case
069: // (2) The test may use a feature that's not supported by the
070: // VM's configuration (e.g., floating point or CLDC 1.1 API)
071: Filter filter = new Filter();
072: copyZipEntries(zout, tests_jar, filter);
073:
074: zout.close();
075: }
076:
077: /**
078: * Copy the content of of the given zip file source
079: * to the ZIP file output stream
080: */
081: static void copyZipEntries(ZipOutputStream zout, File src,
082: Filter filter) throws Throwable {
083: ZipFile zipSrc = null;
084:
085: try {
086: zipSrc = new ZipFile(src);
087: } catch (Throwable t) {
088: System.out.println("Unexpected error:");
089: t.printStackTrace();
090: System.out.println();
091: System.out
092: .println("Your JDK_DIR cannot handle long JAR entries");
093: System.out.println("Please upgrade to JDK 1.4.1 or later.");
094: System.out.println("JDK version '1.4.1' is known to work.");
095: System.exit(-1);
096: }
097: for (Enumeration e = zipSrc.entries(); e.hasMoreElements();) {
098: ZipEntry entry = (ZipEntry) e.nextElement();
099: String name = entry.getName();
100: if (name.startsWith("META-INF")) {
101: continue;
102: }
103: if (filter != null && !filter.includeEntry(entry.getName())) {
104: continue;
105: }
106:
107: int size = (int) entry.getSize();
108: byte data[] = new byte[size];
109: InputStream in = zipSrc.getInputStream(entry);
110: DataInputStream din = new DataInputStream(in);
111: din.readFully(data);
112:
113: zout.putNextEntry(entry);
114: zout.write(data, 0, data.length);
115: zout.closeEntry();
116:
117: din.close();
118: }
119: }
120:
121: static class Filter {
122: static final String include_prefixes[] = { "Sanity",
123: "com/sun/tck/cldc/lib/",
124: "vm/share/rom/ROMOptimizer/functional_test1_b",
125: "vm/share/rom/ROMWriter/generate_java_fieldmap2_rom",
126: "vm/share/rom/ROMWriter/generate_java_fieldmap1_rom",
127: "vm/share/rom/ROMInliner/rom_", "util/",
128: "bench/NativeMethod.class", "rom/",
129: "vm/share/natives/sni", "vm/share/natives/kni",
130: "vm/share/runtime/JVM/JVM_SetHeapLimit1",
131: "vm/cpu/share/InterpreterGenerator/FastMemRoutines",
132: "vm/share/memory/FinalizerWeakRef", "anilib",
133: "isolate/tests/Natives",
134: "vm/cpu/arm/CodeGenerator_arm", "mps/HiddenClass",
135: "mps/hidden",
136: "vm/cpu/share/CodeGenerator/InitStaticArrayTest",
137: "vm/share/compiler/BytecodeCompileClosure/A", };
138: static final String include_infixes[] = { "/SNI_", };
139: static final String include_suffixes[] = { "_rom.class", };
140:
141: static final String exclude_prefixes[] = {
142: "rom/unrestricted/NotRomized.class",
143: "rom/restricted/NotRomized.class",
144: "rom/hidden/NotRomized.class", };
145:
146: /**
147: * @return true iff the given entry should be included in
148: * the output ZIP file
149: */
150: public boolean includeEntry(String name) {
151: if (!name.endsWith(".class")) {
152: return false;
153: }
154:
155: boolean include = false;
156: for (int i = 0; i < include_prefixes.length; i++) {
157: String prefix = include_prefixes[i];
158: if (name.startsWith(prefix)) {
159: include = true;
160: break;
161: }
162: }
163: for (int i = 0; i < include_suffixes.length; i++) {
164: String prefix = include_suffixes[i];
165: if (name.endsWith(prefix)) {
166: include = true;
167: break;
168: }
169: }
170: for (int i = 0; i < include_infixes.length; i++) {
171: String prefix = include_infixes[i];
172: if (name.indexOf(prefix) != -1) {
173: include = true;
174: break;
175: }
176: }
177:
178: if (include) {
179: for (int i = 0; i < exclude_prefixes.length; i++) {
180: String prefix = exclude_prefixes[i];
181: if (name.startsWith(prefix)) {
182: include = false;
183: break;
184: }
185: }
186: }
187:
188: if (include) {
189: System.out.println("Added to ROM: " + name);
190: }
191:
192: return include;
193: }
194: }
195: }
|