content: /*****************************************************************
   *   Licensed to the Apache Software Foundation (ASF) under one
   *  or more contributor license agreements.  See the NOTICE file
   *  distributed with this work for additional information
   *  regarding copyright ownership.  The ASF licenses this file
   *  to you under the Apache License, Version 2.0 (the
   *  "License"); you may not use this file except in compliance
   *  with the License.  You may obtain a copy of the License at
   *
   *    http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing,
   *  software distributed under the License is distributed on an
   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   *  KIND, either express or implied.  See the License for the
   *  specific language governing permissions and limitations
   *  under the License.
   ****************************************************************/
  
  package org.apache.cayenne.modeler.osx;
  
  /**
   * @since 4.2
   */
  public class OSXVersion {
  
      public static final OSXVersion UNKNOWN = new OSXVersion(-1, -1);
      public static final OSXVersion CATALINA = new OSXVersion(10, 15);
      public static final OSXVersion BIG_SUR = new OSXVersion(10, 16);
  
      private final int major;
      private final int minor;
  
      public static OSXVersion fromSystemProperties() {
          // sanity check in case this code executed not on macOS
          String osName = System.getProperty("os.name").toLowerCase();
          if(!osName.contains("mac")) {
              return UNKNOWN;
          }
  
          String osVersion = System.getProperty("os.version");
          String[] osVersionComponents = osVersion.split("\\.");
          if(osVersionComponents.length != 2) {
              return UNKNOWN;
          }
          try {
              int major = Integer.parseInt(osVersionComponents[0]);
              int minor = Integer.parseInt(osVersionComponents[1]);
              return new OSXVersion(major, minor);
          } catch (Exception ex) {
              return UNKNOWN;
          }
      }
  
      public OSXVersion(int major, int minor) {
          this.major = major;
          this.minor = minor;
      }
  
      public boolean gt(OSXVersion version) {
          return getMajor() >= version.getMajor()
                  && getMinor() > version.getMinor();
      }
  
      public boolean eq(OSXVersion version) {
          return getMajor() == version.getMajor()
                  && getMinor() == version.getMinor();
      }
  
      public int getMajor() {
          return major;
      }
  
      public int getMinor() {
          return minor;
      }
  }
  