Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/lang/instrument/BootClassPath/Setup.java
38828 views
/*1* Copyright (c) 2004, 2011, 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 the 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;525354/*55* Create sub-directory56*/57File f = new File(bootDir);58f.mkdir();5960/*61* Create manifest file with Boot-Class-Path encoding the62* sub-directory name.63*/64try (FileOutputStream out = new FileOutputStream(manifestFile)) {65out.write("Manifest-Version: 1.0\n".getBytes("UTF-8"));6667byte[] premainBytes =68("Premain-Class: " + premainClass + "\n").getBytes("UTF-8");69out.write(premainBytes);7071out.write( "Boot-Class-Path: ".getBytes("UTF-8") );7273byte[] value = bootClassPath.getBytes("UTF-8");74for (int i=0; i<value.length; i++) {75int v = (int)value[i];76if (v < 0) v += 256;77byte[] escaped =78("%" + Integer.toHexString(v)).getBytes("UTF-8");79out.write(escaped);80}81out.write( "\n\n".getBytes("UTF-8") );82}8384/*85* Write the name of the boot dir to "boot.dir"86*/87f = new File(workDir + fileSeparator + "boot.dir");88try (FileOutputStream out = new FileOutputStream(f)) {89out.write(bootDir.getBytes(defaultEncoding));90}91}9293/* ported from test/sun/tools/launcher/UnicodeTest.java */9495private static final String fileSeparator = System.getProperty("file.separator");96private static final String osName = System.getProperty("os.name");97private static final String defaultEncoding = Charset.defaultCharset().name();9899// language names taken from java.util.Locale.getDisplayLanguage for the respective language100private static final String arabic = "\u0627\u0644\u0639\u0631\u0628\u064a\u0629";101private static final String s_chinese = "\u4e2d\u6587";102private static final String t_chinese = "\u4e2d\u6587";103private static final String russian = "\u0440\u0443\u0441\u0441\u043A\u0438\u0439";104private static final String hindi = "\u0939\u093f\u0902\u0926\u0940";105private static final String greek = "\u03b5\u03bb\u03bb\u03b7\u03bd\u03b9\u03ba\u03ac";106private static final String hebrew = "\u05e2\u05d1\u05e8\u05d9\u05ea";107private static final String japanese = "\u65e5\u672c\u8a9e";108private static final String korean = "\ud55c\uad6d\uc5b4";109private static final String lithuanian = "Lietuvi\u0173";110private static final String czech = "\u010de\u0161tina";111private static final String turkish = "T\u00fcrk\u00e7e";112private static final String spanish = "espa\u00f1ol";113private static final String thai = "\u0e44\u0e17\u0e22";114private static final String unicode = arabic + s_chinese + t_chinese115+ russian + hindi + greek + hebrew + japanese + korean116+ lithuanian + czech + turkish + spanish + thai;117118private static String suffix() {119120// Mapping from main platform encodings to language names121// for Unix and Windows, respectively. Use empty suffix122// for Windows encodings where OEM encoding differs.123// Use null if encoding isn't used.124String[][] names = {125{ "UTF-8", unicode, "" },126{ "windows-1256", null, "" },127{ "iso-8859-6", arabic, null },128{ "GBK", s_chinese, s_chinese },129{ "GB18030", s_chinese, s_chinese },130{ "GB2312", s_chinese, null },131{ "x-windows-950", null, t_chinese },132{ "x-MS950-HKSCS", null, t_chinese },133{ "x-euc-tw", t_chinese, null },134{ "Big5", t_chinese, null },135{ "Big5-HKSCS", t_chinese, null },136{ "windows-1251", null, "" },137{ "iso-8859-5", russian, null },138{ "koi8-r", russian, null },139{ "windows-1253", null, "" },140{ "iso-8859-7", greek, null },141{ "windows-1255", null, "" },142{ "iso8859-8", hebrew, null },143{ "windows-31j", null, japanese },144{ "x-eucJP-Open", japanese, null },145{ "x-EUC-JP-LINUX", japanese, null },146{ "x-pck", japanese, null },147{ "x-windows-949", null, korean },148{ "euc-kr", korean, null },149{ "windows-1257", null, "" },150{ "iso-8859-13", lithuanian, null },151{ "windows-1250", null, "" },152{ "iso-8859-2", czech, null },153{ "windows-1254", null, "" },154{ "iso-8859-9", turkish, null },155{ "windows-1252", null, "" },156{ "iso-8859-1", spanish, null },157{ "iso-8859-15", spanish, null },158{ "x-windows-874", null, thai },159{ "tis-620", thai, null },160};161162int column;163if (osName.startsWith("Windows")) {164column = 2;165} else {166column = 1;167}168for (int i = 0; i < names.length; i++) {169if (names[i][0].equalsIgnoreCase(defaultEncoding)) {170return names[i][column];171}172}173return "";174}175}176177178