1 /*
   2  * Copyright (c) 2018, 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.
   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 package jnlp.converter;
  25 
  26 import java.util.regex.Pattern;
  27 
  28 public enum Platform {
  29     UNKNOWN, WINDOWS, LINUX, MAC;
  30     private static final Platform platform;
  31     private static final int majorVersion;
  32     private static final int minorVersion;
  33 
  34     static {
  35         String os = System.getProperty("os.name").toLowerCase();
  36 
  37         if (os.contains("win")) {
  38             platform = Platform.WINDOWS;
  39         } else if (os.contains("nix") || os.contains("nux")) {
  40             platform = Platform.LINUX;
  41         } else if (os.contains("mac")) {
  42             platform = Platform.MAC;
  43         } else {
  44             platform = Platform.UNKNOWN;
  45         }
  46 
  47         String version = System.getProperty("os.version");
  48         String[] parts = version.split(Pattern.quote("."));
  49 
  50         if (parts.length > 0) {
  51             majorVersion = Integer.parseInt(parts[0]);
  52 
  53             if (parts.length > 1) {
  54                 minorVersion = Integer.parseInt(parts[0]);
  55             } else {
  56                 minorVersion = -1;
  57             }
  58         } else {
  59             majorVersion = -1;
  60             minorVersion = -1;
  61         }
  62     }
  63 
  64     private Platform() {
  65     }
  66 
  67     public static Platform getPlatform() {
  68         return platform;
  69     }
  70 
  71     public static boolean isWindows() {
  72         return (platform == Platform.WINDOWS);
  73     }
  74 
  75     public static int getMajorVersion() {
  76         return majorVersion;
  77     }
  78 
  79     public static int getMinorVersion() {
  80         return minorVersion;
  81     }
  82 }