0N/A/*
3909N/A * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A *
0N/A *
0N/A * Used by BootClassPath.sh.
0N/A *
0N/A * Given a "work directory" this class creates a sub-directory with a
0N/A * name that uses locale specific characters. It the creates a jar
0N/A * manifest file in the work directory with a Boot-Class-Path that
0N/A * encodes the created sub-directory. Finally it creates a file
0N/A * "boot.dir" in the work directory with the name of the sub-directory.
0N/A */
0N/Aimport java.io.File;
0N/Aimport java.io.FileOutputStream;
0N/Aimport java.nio.charset.Charset;
0N/A
0N/Apublic class Setup {
0N/A
0N/A public static void main(String[] args) throws Exception {
0N/A if (args.length < 2) {
0N/A System.err.println("Usage: java Setup <work-dir> <premain-class>");
0N/A return;
0N/A }
0N/A String workDir = args[0];
0N/A String premainClass = args[1];
0N/A
0N/A String manifestFile = workDir + fileSeparator + "MANIFEST.MF";
0N/A String bootClassPath = "boot" + suffix();
0N/A
0N/A String bootDir = workDir + fileSeparator + bootClassPath;
0N/A
0N/A
0N/A /*
0N/A * Create sub-directory
0N/A */
0N/A File f = new File(bootDir);
0N/A f.mkdir();
0N/A
0N/A /*
0N/A * Create manifest file with Boot-Class-Path encoding the
0N/A * sub-directory name.
0N/A */
3646N/A try (FileOutputStream out = new FileOutputStream(manifestFile)) {
3646N/A out.write("Manifest-Version: 1.0\n".getBytes("UTF-8"));
0N/A
3646N/A byte[] premainBytes =
3646N/A ("Premain-Class: " + premainClass + "\n").getBytes("UTF-8");
3646N/A out.write(premainBytes);
0N/A
3646N/A out.write( "Boot-Class-Path: ".getBytes("UTF-8") );
0N/A
3646N/A byte[] value = bootClassPath.getBytes("UTF-8");
3646N/A for (int i=0; i<value.length; i++) {
3646N/A int v = (int)value[i];
3646N/A if (v < 0) v += 256;
3646N/A byte[] escaped =
3646N/A ("%" + Integer.toHexString(v)).getBytes("UTF-8");
3646N/A out.write(escaped);
3646N/A }
3646N/A out.write( "\n\n".getBytes("UTF-8") );
0N/A }
0N/A
0N/A /*
0N/A * Write the name of the boot dir to "boot.dir"
0N/A */
0N/A f = new File(workDir + fileSeparator + "boot.dir");
3646N/A try (FileOutputStream out = new FileOutputStream(f)) {
3646N/A out.write(bootDir.getBytes(defaultEncoding));
3646N/A }
0N/A }
0N/A
0N/A /* ported from test/sun/tools/launcher/UnicodeTest.java */
0N/A
0N/A private static final String fileSeparator = System.getProperty("file.separator");
0N/A private static final String osName = System.getProperty("os.name");
0N/A private static final String defaultEncoding = Charset.defaultCharset().name();
0N/A
0N/A // language names taken from java.util.Locale.getDisplayLanguage for the respective language
0N/A private static final String arabic = "\u0627\u0644\u0639\u0631\u0628\u064a\u0629";
0N/A private static final String s_chinese = "\u4e2d\u6587";
0N/A private static final String t_chinese = "\u4e2d\u6587";
0N/A private static final String russian = "\u0440\u0443\u0441\u0441\u043A\u0438\u0439";
0N/A private static final String hindi = "\u0939\u093f\u0902\u0926\u0940";
0N/A private static final String greek = "\u03b5\u03bb\u03bb\u03b7\u03bd\u03b9\u03ba\u03ac";
0N/A private static final String hebrew = "\u05e2\u05d1\u05e8\u05d9\u05ea";
0N/A private static final String japanese = "\u65e5\u672c\u8a9e";
0N/A private static final String korean = "\ud55c\uad6d\uc5b4";
0N/A private static final String lithuanian = "Lietuvi\u0173";
0N/A private static final String czech = "\u010de\u0161tina";
0N/A private static final String turkish = "T\u00fcrk\u00e7e";
0N/A private static final String spanish = "espa\u00f1ol";
0N/A private static final String thai = "\u0e44\u0e17\u0e22";
0N/A private static final String unicode = arabic + s_chinese + t_chinese
0N/A + russian + hindi + greek + hebrew + japanese + korean
0N/A + lithuanian + czech + turkish + spanish + thai;
0N/A
0N/A private static String suffix() {
0N/A
0N/A // Mapping from main platform encodings to language names
0N/A // for Unix and Windows, respectively. Use empty suffix
0N/A // for Windows encodings where OEM encoding differs.
0N/A // Use null if encoding isn't used.
0N/A String[][] names = {
0N/A { "UTF-8", unicode, "" },
0N/A { "windows-1256", null, "" },
0N/A { "iso-8859-6", arabic, null },
0N/A { "GBK", s_chinese, s_chinese },
0N/A { "GB18030", s_chinese, s_chinese },
0N/A { "GB2312", s_chinese, null },
0N/A { "x-windows-950", null, t_chinese },
0N/A { "x-MS950-HKSCS", null, t_chinese },
0N/A { "x-euc-tw", t_chinese, null },
0N/A { "Big5", t_chinese, null },
0N/A { "Big5-HKSCS", t_chinese, null },
0N/A { "windows-1251", null, "" },
0N/A { "iso-8859-5", russian, null },
0N/A { "koi8-r", russian, null },
0N/A { "windows-1253", null, "" },
0N/A { "iso-8859-7", greek, null },
0N/A { "windows-1255", null, "" },
0N/A { "iso8859-8", hebrew, null },
0N/A { "windows-31j", null, japanese },
0N/A { "x-eucJP-Open", japanese, null },
0N/A { "x-EUC-JP-LINUX", japanese, null },
0N/A { "x-pck", japanese, null },
0N/A { "x-windows-949", null, korean },
0N/A { "euc-kr", korean, null },
0N/A { "windows-1257", null, "" },
0N/A { "iso-8859-13", lithuanian, null },
0N/A { "windows-1250", null, "" },
0N/A { "iso-8859-2", czech, null },
0N/A { "windows-1254", null, "" },
0N/A { "iso-8859-9", turkish, null },
0N/A { "windows-1252", null, "" },
0N/A { "iso-8859-1", spanish, null },
0N/A { "iso-8859-15", spanish, null },
0N/A { "x-windows-874", null, thai },
0N/A { "tis-620", thai, null },
0N/A };
0N/A
0N/A int column;
0N/A if (osName.startsWith("Windows")) {
0N/A column = 2;
0N/A } else {
0N/A column = 1;
0N/A }
0N/A for (int i = 0; i < names.length; i++) {
0N/A if (names[i][0].equalsIgnoreCase(defaultEncoding)) {
0N/A return names[i][column];
0N/A }
0N/A }
0N/A return "";
0N/A }
0N/A}