Path: blob/master/test/jdk/java/lang/instrument/BootClassPath/Setup.java
41153 views
/*1* Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24*25*26* Used by BootClassPath.sh.27*28* Given a "work directory" this class creates a sub-directory with a29* name that uses locale specific characters. It then creates a jar30* manifest file in the work directory with a Boot-Class-Path that31* encodes the created sub-directory. Finally it creates a file32* "boot.dir" in the work directory with the name of the sub-directory.33*/34import java.io.File;35import java.io.FileOutputStream;36import java.nio.charset.Charset;3738public class Setup {3940public static void main(String[] args) throws Exception {41if (args.length < 2) {42System.err.println("Usage: java Setup <work-dir> <premain-class>");43return;44}45String workDir = args[0];46String premainClass = args[1];4748String manifestFile = workDir + fileSeparator + "MANIFEST.MF";49String bootClassPath = "boot" + suffix();5051String bootDir = workDir + fileSeparator + bootClassPath;5253/*54* Environment variable settings ("null" if unset)55*/56System.out.println("Env vars:");57System.out.println(" LANG=" + System.getenv("LANG"));58System.out.println(" LC_ALL=" + System.getenv("LC_ALL"));59System.out.println(" LC_CTYPE=" + System.getenv("LC_CTYPE"));6061/*62* Create sub-directory63*/64File f = new File(bootDir);65f.mkdir();6667/*68* Create manifest file with Boot-Class-Path encoding the69* sub-directory name.70*/71try (FileOutputStream out = new FileOutputStream(manifestFile)) {72out.write("Manifest-Version: 1.0\n".getBytes("UTF-8"));7374byte[] premainBytes =75("Premain-Class: " + premainClass + "\n").getBytes("UTF-8");76out.write(premainBytes);7778out.write( "Boot-Class-Path: ".getBytes("UTF-8") );7980byte[] value = bootClassPath.getBytes("UTF-8");81for (int i=0; i<value.length; i++) {82int v = (int)value[i];83if (v < 0) v += 256;84byte[] escaped =85("%" + Integer.toHexString(v)).getBytes("UTF-8");86out.write(escaped);87}88out.write( "\n\n".getBytes("UTF-8") );89}9091/*92* Write the name of the boot dir to "boot.dir"93*/94f = new File(workDir + fileSeparator + "boot.dir");95try (FileOutputStream out = new FileOutputStream(f)) {96out.write(bootDir.getBytes(defaultEncoding));97}98}99100/* ported from test/sun/tools/launcher/UnicodeTest.java */101102private static final String fileSeparator = System.getProperty("file.separator");103private static final String osName = System.getProperty("os.name");104private static final String defaultEncoding = Charset.defaultCharset().name();105106// language names taken from java.util.Locale.getDisplayLanguage for the respective language107private static final String arabic = "\u0627\u0644\u0639\u0631\u0628\u064a\u0629";108private static final String s_chinese = "\u4e2d\u6587";109private static final String t_chinese = "\u4e2d\u6587";110private static final String russian = "\u0440\u0443\u0441\u0441\u043A\u0438\u0439";111private static final String hindi = "\u0939\u093f\u0902\u0926\u0940";112private static final String greek = "\u03b5\u03bb\u03bb\u03b7\u03bd\u03b9\u03ba\u03ac";113private static final String hebrew = "\u05e2\u05d1\u05e8\u05d9\u05ea";114private static final String japanese = "\u65e5\u672c\u8a9e";115private static final String korean = "\ud55c\uad6d\uc5b4";116private static final String lithuanian = "Lietuvi\u0173";117private static final String czech = "\u010de\u0161tina";118private static final String turkish = "T\u00fcrk\u00e7e";119private static final String spanish = "espa\u00f1ol";120private static final String thai = "\u0e44\u0e17\u0e22";121private static final String unicode = arabic + s_chinese + t_chinese122+ russian + hindi + greek + hebrew + japanese + korean123+ lithuanian + czech + turkish + spanish + thai;124125private static String suffix() {126127// Mapping from main platform encodings to language names128// for Unix and Windows, respectively. Use empty suffix129// for Windows encodings where OEM encoding differs.130// Use null if encoding isn't used.131String[][] names = {132{ "UTF-8", unicode, "" },133{ "windows-1256", null, "" },134{ "iso-8859-6", arabic, null },135{ "GBK", s_chinese, s_chinese },136{ "GB18030", s_chinese, s_chinese },137{ "GB2312", s_chinese, null },138{ "x-windows-950", null, t_chinese },139{ "x-MS950-HKSCS", null, t_chinese },140{ "x-euc-tw", t_chinese, null },141{ "Big5", t_chinese, null },142{ "Big5-HKSCS", t_chinese, null },143{ "windows-1251", null, "" },144{ "iso-8859-5", russian, null },145{ "koi8-r", russian, null },146{ "windows-1253", null, "" },147{ "iso-8859-7", greek, null },148{ "windows-1255", null, "" },149{ "iso8859-8", hebrew, null },150{ "windows-31j", null, japanese },151{ "x-eucJP-Open", japanese, null },152{ "x-EUC-JP-LINUX", japanese, null },153{ "x-pck", japanese, null },154{ "x-windows-949", null, korean },155{ "euc-kr", korean, null },156{ "windows-1257", null, "" },157{ "iso-8859-13", lithuanian, null },158{ "windows-1250", null, "" },159{ "iso-8859-2", czech, null },160{ "windows-1254", null, "" },161{ "iso-8859-9", turkish, null },162{ "windows-1252", null, "" },163{ "iso-8859-1", spanish, null },164{ "iso-8859-15", spanish, null },165{ "x-windows-874", null, thai },166{ "tis-620", thai, null },167};168169int column;170if (osName.startsWith("Windows")) {171column = 2;172} else {173column = 1;174}175for (int i = 0; i < names.length; i++) {176if (names[i][0].equalsIgnoreCase(defaultEncoding)) {177return names[i][column];178}179}180return "";181}182}183184185