1 /* 2 * Copyright (c) 2004, 2005, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * 26 * 27 * Used by BootClassPath.sh. 28 * 29 * Given a "work directory" this class creates a sub-directory with a 30 * name that uses locale specific characters. It the creates a jar 31 * manifest file in the work directory with a Boot-Class-Path that 32 * encodes the created sub-directory. Finally it creates a file 33 * "boot.dir" in the work directory with the name of the sub-directory. 34 */ 35 import java.io.File; 36 import java.io.FileOutputStream; 37 import java.nio.charset.Charset; 38 39 public class Setup { 40 41 public static void main(String[] args) throws Exception { 42 if (args.length < 2) { 43 System.err.println("Usage: java Setup <work-dir> <premain-class>"); 44 return; 45 } 46 String workDir = args[0]; 47 String premainClass = args[1]; 48 49 String manifestFile = workDir + fileSeparator + "MANIFEST.MF"; 50 String bootClassPath = "boot" + suffix(); 51 52 String bootDir = workDir + fileSeparator + bootClassPath; 53 54 55 /* 56 * Create sub-directory 57 */ 58 File f = new File(bootDir); 59 f.mkdir(); 60 61 /* 62 * Create manifest file with Boot-Class-Path encoding the 63 * sub-directory name. 64 */ 65 FileOutputStream out = new FileOutputStream(manifestFile); 66 out.write("Manifest-Version: 1.0\n".getBytes("UTF-8")); 67 68 byte[] premainBytes = ("Premain-Class: " + premainClass + "\n").getBytes("UTF-8"); 69 out.write(premainBytes); 70 71 out.write( "Boot-Class-Path: ".getBytes("UTF-8") ); 72 73 byte[] value = bootClassPath.getBytes("UTF-8"); 74 for (int i=0; i<value.length; i++) { 75 int v = (int)value[i]; 76 if (v < 0) v += 256; 77 byte[] escaped = ("%" + Integer.toHexString(v)).getBytes("UTF-8"); 78 out.write(escaped); 79 } 80 out.write( "\n\n".getBytes("UTF-8") ); 81 out.close(); 82 83 /* 84 * Write the name of the boot dir to "boot.dir" 85 */ 86 f = new File(workDir + fileSeparator + "boot.dir"); 87 out = new FileOutputStream(f); 88 out.write(bootDir.getBytes(defaultEncoding)); 89 out.close(); 90 } 91 92 /* ported from test/sun/tools/launcher/UnicodeTest.java */ 93 94 private static final String fileSeparator = System.getProperty("file.separator"); 95 private static final String osName = System.getProperty("os.name"); 96 private static final String defaultEncoding = Charset.defaultCharset().name(); 97 98 // language names taken from java.util.Locale.getDisplayLanguage for the respective language 99 private static final String arabic = "\u0627\u0644\u0639\u0631\u0628\u064a\u0629"; 100 private static final String s_chinese = "\u4e2d\u6587"; 101 private static final String t_chinese = "\u4e2d\u6587"; 102 private static final String russian = "\u0440\u0443\u0441\u0441\u043A\u0438\u0439"; 103 private static final String hindi = "\u0939\u093f\u0902\u0926\u0940"; 104 private static final String greek = "\u03b5\u03bb\u03bb\u03b7\u03bd\u03b9\u03ba\u03ac"; 105 private static final String hebrew = "\u05e2\u05d1\u05e8\u05d9\u05ea"; 106 private static final String japanese = "\u65e5\u672c\u8a9e"; 107 private static final String korean = "\ud55c\uad6d\uc5b4"; 108 private static final String lithuanian = "Lietuvi\u0173"; 109 private static final String czech = "\u010de\u0161tina"; 110 private static final String turkish = "T\u00fcrk\u00e7e"; 111 private static final String spanish = "espa\u00f1ol"; 112 private static final String thai = "\u0e44\u0e17\u0e22"; 113 private static final String unicode = arabic + s_chinese + t_chinese 114 + russian + hindi + greek + hebrew + japanese + korean 115 + lithuanian + czech + turkish + spanish + thai; 116 117 private static String suffix() { 118 119 // Mapping from main platform encodings to language names 120 // for Unix and Windows, respectively. Use empty suffix 121 // for Windows encodings where OEM encoding differs. 122 // Use null if encoding isn't used. 123 String[][] names = { 124 { "UTF-8", unicode, "" }, 125 { "windows-1256", null, "" }, 126 { "iso-8859-6", arabic, null }, 127 { "GBK", s_chinese, s_chinese }, 128 { "GB18030", s_chinese, s_chinese }, 129 { "GB2312", s_chinese, null }, 130 { "x-windows-950", null, t_chinese }, 131 { "x-MS950-HKSCS", null, t_chinese }, 132 { "x-euc-tw", t_chinese, null }, 133 { "Big5", t_chinese, null }, 134 { "Big5-HKSCS", t_chinese, null }, 135 { "windows-1251", null, "" }, 136 { "iso-8859-5", russian, null }, 137 { "koi8-r", russian, null }, 138 { "windows-1253", null, "" }, 139 { "iso-8859-7", greek, null }, 140 { "windows-1255", null, "" }, 141 { "iso8859-8", hebrew, null }, 142 { "windows-31j", null, japanese }, 143 { "x-eucJP-Open", japanese, null }, 144 { "x-EUC-JP-LINUX", japanese, null }, 145 { "x-pck", japanese, null }, 146 { "x-windows-949", null, korean }, 147 { "euc-kr", korean, null }, 148 { "windows-1257", null, "" }, 149 { "iso-8859-13", lithuanian, null }, 150 { "windows-1250", null, "" }, 151 { "iso-8859-2", czech, null }, 152 { "windows-1254", null, "" }, 153 { "iso-8859-9", turkish, null }, 154 { "windows-1252", null, "" }, 155 { "iso-8859-1", spanish, null }, 156 { "iso-8859-15", spanish, null }, 157 { "x-windows-874", null, thai }, 158 { "tis-620", thai, null }, 159 }; 160 161 int column; 162 if (osName.startsWith("Windows")) { 163 column = 2; 164 } else { 165 column = 1; 166 } 167 for (int i = 0; i < names.length; i++) { 168 if (names[i][0].equalsIgnoreCase(defaultEncoding)) { 169 return names[i][column]; 170 } 171 } 172 return ""; 173 } 174 }