< prev index next >

src/java.base/share/classes/java/lang/VersionProps.java.template

Print this page
rev 48062 : 8192833: JEP 322: Time-Based Release Versioning


  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.lang;
  27 
  28 import java.io.PrintStream;
  29 import java.util.Arrays;
  30 import java.util.List;
  31 import java.util.Optional;
  32 
  33 class VersionProps {
  34 
  35 
  36     private static final String launcher_name =
  37         "@@LAUNCHER_NAME@@";
  38 
  39     private static final String java_version =
  40         "@@VERSION_SHORT@@";
  41 



  42     private static final String java_runtime_name =
  43         "@@RUNTIME_NAME@@";
  44 
  45     private static final String java_runtime_version =
  46         "@@VERSION_STRING@@";
  47 
  48     private static final String VERSION_NUMBER =
  49         "@@VERSION_NUMBER@@";
  50 
  51     private static final String VERSION_BUILD =
  52         "@@VERSION_BUILD@@";
  53 
  54     private static final String VERSION_PRE =
  55         "@@VERSION_PRE@@";
  56 
  57     private static final String VERSION_OPT =
  58         "@@VERSION_OPT@@";
  59 










  60     static {
  61         init();
  62     }
  63 
  64     public static void init() {
  65         System.setProperty("java.version", java_version);

  66         System.setProperty("java.runtime.version", java_runtime_version);
  67         System.setProperty("java.runtime.name", java_runtime_name);


  68     }
  69 
  70     private static int parseVersionNumber(String version, int prevIndex, int index) {
  71         if (index - prevIndex > 1 &&
  72             Character.digit(version.charAt(prevIndex), 10) <= 0)
  73             throw new IllegalArgumentException("Leading zeros not supported (" +
  74                     version.substring(prevIndex, index) + ")");
  75         return Integer.parseInt(version, prevIndex, index, 10);
  76     }
  77 
  78     // This method is reflectively used by regression tests.
  79     static List<Integer> parseVersionNumbers(String version) {
  80         // Let's find the size of an array required to hold $VNUM components
  81         int size = 0;
  82         int prevIndex = 0;
  83         do {
  84             prevIndex = version.indexOf('.', prevIndex) + 1;
  85             size++;
  86         } while (prevIndex > 0);
  87         Integer[] verNumbers = new Integer[size];


 145      */
 146     public static void println(boolean err) {
 147         print(err, true);
 148     }
 149 
 150     /**
 151      * Print version info.
 152      */
 153     private static void print(boolean err, boolean newln) {
 154         boolean isHeadless = false;
 155         PrintStream ps = err ? System.err : System.out;
 156 
 157         /* Report that we're running headless if the property is true */
 158         String headless = System.getProperty("java.awt.headless");
 159         if ( (headless != null) && (headless.equalsIgnoreCase("true")) ) {
 160             isHeadless = true;
 161         }
 162 
 163         /* First line: platform version. */
 164         if (err) {
 165             ps.println(launcher_name + " version \"" + java_version + "\"");


 166         } else {
 167             /* Use a format more in line with GNU conventions */
 168             ps.println(launcher_name + " " + java_version);


 169         }
 170 
 171         /* Second line: runtime version (ie, libraries). */
 172         String jdk_debug_level = System.getProperty("jdk.debug", "release");
 173         /* Debug level is not printed for "release" builds */
 174         if ("release".equals(jdk_debug_level)) {

 175             jdk_debug_level = "";
 176         } else {
 177             jdk_debug_level = jdk_debug_level + " ";
 178         }
 179 
 180         ps.print(java_runtime_name + " (" + jdk_debug_level + "build " + java_runtime_version);
 181 
 182         ps.println(')');
 183 
 184         /* Third line: JVM information. */
 185         String java_vm_name    = System.getProperty("java.vm.name");
 186         String java_vm_version = System.getProperty("java.vm.version");
 187         String java_vm_info    = System.getProperty("java.vm.info");
 188         ps.println(java_vm_name + " (" + jdk_debug_level + "build " + java_vm_version + ", " +
 189                    java_vm_info + ")");


 190     }
 191 
 192 }


  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.lang;
  27 
  28 import java.io.PrintStream;
  29 import java.util.Arrays;
  30 import java.util.List;
  31 import java.util.Optional;
  32 
  33 class VersionProps {
  34 

  35     private static final String launcher_name =
  36         "@@LAUNCHER_NAME@@";
  37 
  38     private static final String java_version =
  39         "@@VERSION_SHORT@@";
  40 
  41     private static final String java_version_date =
  42         "@@VERSION_DATE@@";
  43 
  44     private static final String java_runtime_name =
  45         "@@RUNTIME_NAME@@";
  46 
  47     private static final String java_runtime_version =
  48         "@@VERSION_STRING@@";
  49 
  50     private static final String VERSION_NUMBER =
  51         "@@VERSION_NUMBER@@";
  52 
  53     private static final String VERSION_BUILD =
  54         "@@VERSION_BUILD@@";
  55 
  56     private static final String VERSION_PRE =
  57         "@@VERSION_PRE@@";
  58 
  59     private static final String VERSION_OPT =
  60         "@@VERSION_OPT@@";
  61 
  62     private static final boolean isLTS =
  63         "@@VERSION_OPT@@".startsWith("LTS");
  64 
  65     private static final String VENDOR_VERSION_STRING =
  66         "@@VENDOR_VERSION_STRING@@";
  67 
  68     private static final String vendor_version =
  69         (VENDOR_VERSION_STRING.length() > 0
  70          ? " " + VENDOR_VERSION_STRING : "");
  71 
  72     static {
  73         init();
  74     }
  75 
  76     public static void init() {
  77         System.setProperty("java.version", java_version);
  78         System.setProperty("java.version.date", java_version_date);
  79         System.setProperty("java.runtime.version", java_runtime_version);
  80         System.setProperty("java.runtime.name", java_runtime_name);
  81         if (VENDOR_VERSION_STRING.length() > 0)
  82             System.setProperty("java.vendor.version", VENDOR_VERSION_STRING);
  83     }
  84 
  85     private static int parseVersionNumber(String version, int prevIndex, int index) {
  86         if (index - prevIndex > 1 &&
  87             Character.digit(version.charAt(prevIndex), 10) <= 0)
  88             throw new IllegalArgumentException("Leading zeros not supported (" +
  89                     version.substring(prevIndex, index) + ")");
  90         return Integer.parseInt(version, prevIndex, index, 10);
  91     }
  92 
  93     // This method is reflectively used by regression tests.
  94     static List<Integer> parseVersionNumbers(String version) {
  95         // Let's find the size of an array required to hold $VNUM components
  96         int size = 0;
  97         int prevIndex = 0;
  98         do {
  99             prevIndex = version.indexOf('.', prevIndex) + 1;
 100             size++;
 101         } while (prevIndex > 0);
 102         Integer[] verNumbers = new Integer[size];


 160      */
 161     public static void println(boolean err) {
 162         print(err, true);
 163     }
 164 
 165     /**
 166      * Print version info.
 167      */
 168     private static void print(boolean err, boolean newln) {
 169         boolean isHeadless = false;
 170         PrintStream ps = err ? System.err : System.out;
 171 
 172         /* Report that we're running headless if the property is true */
 173         String headless = System.getProperty("java.awt.headless");
 174         if ( (headless != null) && (headless.equalsIgnoreCase("true")) ) {
 175             isHeadless = true;
 176         }
 177 
 178         /* First line: platform version. */
 179         if (err) {
 180             ps.println(launcher_name + " version \"" + java_version + "\""
 181                        + " " + java_version_date
 182                        + (isLTS ? " LTS" : ""));
 183         } else {
 184             /* Use a format more in line with GNU conventions */
 185             ps.println(launcher_name + " " + java_version
 186                        + " " + java_version_date
 187                        + (isLTS ? " LTS" : ""));
 188         }
 189 
 190         /* Second line: runtime version (ie, libraries). */
 191         String jdk_debug_level = System.getProperty("jdk.debug", "release");

 192         if ("release".equals(jdk_debug_level)) {
 193            /* Do not show debug level "release" builds */
 194             jdk_debug_level = "";
 195         } else {
 196             jdk_debug_level = jdk_debug_level + " ";
 197         }
 198 
 199         ps.println(java_runtime_name + vendor_version
 200                    + " (" + jdk_debug_level + "build " + java_runtime_version + ")");

 201 
 202         /* Third line: JVM information. */
 203         String java_vm_name    = System.getProperty("java.vm.name");
 204         String java_vm_version = System.getProperty("java.vm.version");
 205         String java_vm_info    = System.getProperty("java.vm.info");
 206         ps.println(java_vm_name + vendor_version
 207                    + " (" + jdk_debug_level + "build " + java_vm_version + ", "
 208                             + java_vm_info + ")");
 209 
 210     }
 211 
 212 }
< prev index next >