PageRenderTime 61ms CodeModel.GetById 35ms RepoModel.GetById 0ms app.codeStats 0ms

/test/java/lang/instrument/BootClassPath/Setup.java

https://bitbucket.org/psandoz/lambda-jdk
Java | 176 lines | 109 code | 18 blank | 49 comment | 7 complexity | 4cf5f47b1253be621cb2989c37dde632 MD5 | raw file
Possible License(s): BSD-3-Clause-No-Nuclear-License-2014, LGPL-3.0, GPL-2.0
  1. /*
  2. * Copyright (c) 2004, 2011, 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. * Used by BootClassPath.sh.
  27. *
  28. * Given a "work directory" this class creates a sub-directory with a
  29. * name that uses locale specific characters. It the creates a jar
  30. * manifest file in the work directory with a Boot-Class-Path that
  31. * encodes the created sub-directory. Finally it creates a file
  32. * "boot.dir" in the work directory with the name of the sub-directory.
  33. */
  34. import java.io.File;
  35. import java.io.FileOutputStream;
  36. import java.nio.charset.Charset;
  37. public class Setup {
  38. public static void main(String[] args) throws Exception {
  39. if (args.length < 2) {
  40. System.err.println("Usage: java Setup <work-dir> <premain-class>");
  41. return;
  42. }
  43. String workDir = args[0];
  44. String premainClass = args[1];
  45. String manifestFile = workDir + fileSeparator + "MANIFEST.MF";
  46. String bootClassPath = "boot" + suffix();
  47. String bootDir = workDir + fileSeparator + bootClassPath;
  48. /*
  49. * Create sub-directory
  50. */
  51. File f = new File(bootDir);
  52. f.mkdir();
  53. /*
  54. * Create manifest file with Boot-Class-Path encoding the
  55. * sub-directory name.
  56. */
  57. try (FileOutputStream out = new FileOutputStream(manifestFile)) {
  58. out.write("Manifest-Version: 1.0\n".getBytes("UTF-8"));
  59. byte[] premainBytes =
  60. ("Premain-Class: " + premainClass + "\n").getBytes("UTF-8");
  61. out.write(premainBytes);
  62. out.write( "Boot-Class-Path: ".getBytes("UTF-8") );
  63. byte[] value = bootClassPath.getBytes("UTF-8");
  64. for (int i=0; i<value.length; i++) {
  65. int v = (int)value[i];
  66. if (v < 0) v += 256;
  67. byte[] escaped =
  68. ("%" + Integer.toHexString(v)).getBytes("UTF-8");
  69. out.write(escaped);
  70. }
  71. out.write( "\n\n".getBytes("UTF-8") );
  72. }
  73. /*
  74. * Write the name of the boot dir to "boot.dir"
  75. */
  76. f = new File(workDir + fileSeparator + "boot.dir");
  77. try (FileOutputStream out = new FileOutputStream(f)) {
  78. out.write(bootDir.getBytes(defaultEncoding));
  79. }
  80. }
  81. /* ported from test/sun/tools/launcher/UnicodeTest.java */
  82. private static final String fileSeparator = System.getProperty("file.separator");
  83. private static final String osName = System.getProperty("os.name");
  84. private static final String defaultEncoding = Charset.defaultCharset().name();
  85. // language names taken from java.util.Locale.getDisplayLanguage for the respective language
  86. private static final String arabic = "\u0627\u0644\u0639\u0631\u0628\u064a\u0629";
  87. private static final String s_chinese = "\u4e2d\u6587";
  88. private static final String t_chinese = "\u4e2d\u6587";
  89. private static final String russian = "\u0440\u0443\u0441\u0441\u043A\u0438\u0439";
  90. private static final String hindi = "\u0939\u093f\u0902\u0926\u0940";
  91. private static final String greek = "\u03b5\u03bb\u03bb\u03b7\u03bd\u03b9\u03ba\u03ac";
  92. private static final String hebrew = "\u05e2\u05d1\u05e8\u05d9\u05ea";
  93. private static final String japanese = "\u65e5\u672c\u8a9e";
  94. private static final String korean = "\ud55c\uad6d\uc5b4";
  95. private static final String lithuanian = "Lietuvi\u0173";
  96. private static final String czech = "\u010de\u0161tina";
  97. private static final String turkish = "T\u00fcrk\u00e7e";
  98. private static final String spanish = "espa\u00f1ol";
  99. private static final String thai = "\u0e44\u0e17\u0e22";
  100. private static final String unicode = arabic + s_chinese + t_chinese
  101. + russian + hindi + greek + hebrew + japanese + korean
  102. + lithuanian + czech + turkish + spanish + thai;
  103. private static String suffix() {
  104. // Mapping from main platform encodings to language names
  105. // for Unix and Windows, respectively. Use empty suffix
  106. // for Windows encodings where OEM encoding differs.
  107. // Use null if encoding isn't used.
  108. String[][] names = {
  109. { "UTF-8", unicode, "" },
  110. { "windows-1256", null, "" },
  111. { "iso-8859-6", arabic, null },
  112. { "GBK", s_chinese, s_chinese },
  113. { "GB18030", s_chinese, s_chinese },
  114. { "GB2312", s_chinese, null },
  115. { "x-windows-950", null, t_chinese },
  116. { "x-MS950-HKSCS", null, t_chinese },
  117. { "x-euc-tw", t_chinese, null },
  118. { "Big5", t_chinese, null },
  119. { "Big5-HKSCS", t_chinese, null },
  120. { "windows-1251", null, "" },
  121. { "iso-8859-5", russian, null },
  122. { "koi8-r", russian, null },
  123. { "windows-1253", null, "" },
  124. { "iso-8859-7", greek, null },
  125. { "windows-1255", null, "" },
  126. { "iso8859-8", hebrew, null },
  127. { "windows-31j", null, japanese },
  128. { "x-eucJP-Open", japanese, null },
  129. { "x-EUC-JP-LINUX", japanese, null },
  130. { "x-pck", japanese, null },
  131. { "x-windows-949", null, korean },
  132. { "euc-kr", korean, null },
  133. { "windows-1257", null, "" },
  134. { "iso-8859-13", lithuanian, null },
  135. { "windows-1250", null, "" },
  136. { "iso-8859-2", czech, null },
  137. { "windows-1254", null, "" },
  138. { "iso-8859-9", turkish, null },
  139. { "windows-1252", null, "" },
  140. { "iso-8859-1", spanish, null },
  141. { "iso-8859-15", spanish, null },
  142. { "x-windows-874", null, thai },
  143. { "tis-620", thai, null },
  144. };
  145. int column;
  146. if (osName.startsWith("Windows")) {
  147. column = 2;
  148. } else {
  149. column = 1;
  150. }
  151. for (int i = 0; i < names.length; i++) {
  152. if (names[i][0].equalsIgnoreCase(defaultEncoding)) {
  153. return names[i][column];
  154. }
  155. }
  156. return "";
  157. }
  158. }