< prev index next >

src/java.desktop/share/classes/sun/awt/OSInfo.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2012, 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  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 sun.awt;
  27 
  28 import java.security.PrivilegedAction;
  29 import java.util.HashMap;
  30 import java.util.Map;
  31 
  32 import static sun.awt.OSInfo.OSType.*;
  33 
  34 /**
  35  * @author Pavel Porvatov
  36  */
  37 public class OSInfo {
  38     public static enum OSType {
  39         WINDOWS,
  40         LINUX,
  41         SOLARIS,
  42         MACOSX,

  43         UNKNOWN
  44     }
  45 
  46     /*
  47        The map windowsVersionMap must contain all windows version constants except WINDOWS_UNKNOWN,
  48        and so the method getWindowsVersion() will return the constant for known OS.
  49        It allows compare objects by "==" instead of "equals".
  50      */
  51     public static final WindowsVersion WINDOWS_UNKNOWN = new WindowsVersion(-1, -1);
  52     public static final WindowsVersion WINDOWS_95 = new WindowsVersion(4, 0);
  53     public static final WindowsVersion WINDOWS_98 = new WindowsVersion(4, 10);
  54     public static final WindowsVersion WINDOWS_ME = new WindowsVersion(4, 90);
  55     public static final WindowsVersion WINDOWS_2000 = new WindowsVersion(5, 0);
  56     public static final WindowsVersion WINDOWS_XP = new WindowsVersion(5, 1);
  57     public static final WindowsVersion WINDOWS_2003 = new WindowsVersion(5, 2);
  58     public static final WindowsVersion WINDOWS_VISTA = new WindowsVersion(6, 0);
  59     public static final WindowsVersion WINDOWS_7 = new WindowsVersion(6, 1);
  60 
  61     private static final String OS_NAME = "os.name";
  62     private static final String OS_VERSION = "os.version";


  88      * Returns type of operating system.
  89      */
  90     public static OSType getOSType() throws SecurityException {
  91         String osName = System.getProperty(OS_NAME);
  92 
  93         if (osName != null) {
  94             if (osName.contains("Windows")) {
  95                 return WINDOWS;
  96             }
  97 
  98             if (osName.contains("Linux")) {
  99                 return LINUX;
 100             }
 101 
 102             if (osName.contains("Solaris") || osName.contains("SunOS")) {
 103                 return SOLARIS;
 104             }
 105 
 106             if (osName.contains("OS X")) {
 107                 return MACOSX;




 108             }
 109 
 110             // determine another OS here
 111         }
 112 
 113         return UNKNOWN;
 114     }
 115 
 116     public static PrivilegedAction<OSType> getOSTypeAction() {
 117         return osTypeAction;
 118     }
 119 
 120     public static WindowsVersion getWindowsVersion() throws SecurityException {
 121         String osVersion = System.getProperty(OS_VERSION);
 122 
 123         if (osVersion == null) {
 124             return WINDOWS_UNKNOWN;
 125         }
 126 
 127         synchronized (windowsVersionMap) {


   1 /*
   2  * Copyright (c) 1997, 2019, 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  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 sun.awt;
  27 
  28 import java.security.PrivilegedAction;
  29 import java.util.HashMap;
  30 import java.util.Map;
  31 
  32 import static sun.awt.OSInfo.OSType.*;
  33 
  34 /**
  35  * @author Pavel Porvatov
  36  */
  37 public class OSInfo {
  38     public static enum OSType {
  39         WINDOWS,
  40         LINUX,
  41         SOLARIS,
  42         MACOSX,
  43         AIX,
  44         UNKNOWN
  45     }
  46 
  47     /*
  48        The map windowsVersionMap must contain all windows version constants except WINDOWS_UNKNOWN,
  49        and so the method getWindowsVersion() will return the constant for known OS.
  50        It allows compare objects by "==" instead of "equals".
  51      */
  52     public static final WindowsVersion WINDOWS_UNKNOWN = new WindowsVersion(-1, -1);
  53     public static final WindowsVersion WINDOWS_95 = new WindowsVersion(4, 0);
  54     public static final WindowsVersion WINDOWS_98 = new WindowsVersion(4, 10);
  55     public static final WindowsVersion WINDOWS_ME = new WindowsVersion(4, 90);
  56     public static final WindowsVersion WINDOWS_2000 = new WindowsVersion(5, 0);
  57     public static final WindowsVersion WINDOWS_XP = new WindowsVersion(5, 1);
  58     public static final WindowsVersion WINDOWS_2003 = new WindowsVersion(5, 2);
  59     public static final WindowsVersion WINDOWS_VISTA = new WindowsVersion(6, 0);
  60     public static final WindowsVersion WINDOWS_7 = new WindowsVersion(6, 1);
  61 
  62     private static final String OS_NAME = "os.name";
  63     private static final String OS_VERSION = "os.version";


  89      * Returns type of operating system.
  90      */
  91     public static OSType getOSType() throws SecurityException {
  92         String osName = System.getProperty(OS_NAME);
  93 
  94         if (osName != null) {
  95             if (osName.contains("Windows")) {
  96                 return WINDOWS;
  97             }
  98 
  99             if (osName.contains("Linux")) {
 100                 return LINUX;
 101             }
 102 
 103             if (osName.contains("Solaris") || osName.contains("SunOS")) {
 104                 return SOLARIS;
 105             }
 106 
 107             if (osName.contains("OS X")) {
 108                 return MACOSX;
 109             }
 110 
 111             if (osName.contains("AIX")) {
 112                 return AIX;
 113             }
 114 
 115             // determine another OS here
 116         }
 117 
 118         return UNKNOWN;
 119     }
 120 
 121     public static PrivilegedAction<OSType> getOSTypeAction() {
 122         return osTypeAction;
 123     }
 124 
 125     public static WindowsVersion getWindowsVersion() throws SecurityException {
 126         String osVersion = System.getProperty(OS_VERSION);
 127 
 128         if (osVersion == null) {
 129             return WINDOWS_UNKNOWN;
 130         }
 131 
 132         synchronized (windowsVersionMap) {


< prev index next >