util.PosixComplianceUtil.java Source code

Java tutorial

Introduction

Here is the source code for util.PosixComplianceUtil.java

Source

/**
 * This file is a component of jiminix
 *
 * Copyright (c) 2013 Jason Campos <jcampos8782@gmail.com>
 * All Rights Reserved.
 *
 * This software is licensed under The MIT License (MIT)
 * http://opensource.org/licenses/MIT
 */
package util;

import javax.inject.Singleton;

import org.apache.commons.lang.SystemUtils;

/**
 * Tool to determine whether or not the underlying operating system is Posix compliant.
 * This class should be created via an injection framework. There are varying degrees of Posix compliance: 
 * Full, Partial, Non, and Undetermined. 
 * 
 * @author Jason Campos <jcampos8782@gmail.com>
 */
@Singleton
public class PosixComplianceUtil {

    public enum PosixComplianceLevel {
        Full, Partial, Non, Undetermined
    }

    /**
     * Checks whether the user OS is Posix compliant. 
     * @return The compliance level of the underlying OS
     */
    public PosixComplianceLevel checkOsCompatibility() {
        if (isFullyPosixCompliant()) {
            return PosixComplianceLevel.Full;
        }

        if (isWindows()) {
            return PosixComplianceLevel.Non;
        }

        if (isMostlyPosixCompliant()) {
            return PosixComplianceLevel.Partial;
        }

        return PosixComplianceLevel.Undetermined;
    }

    private boolean isFullyPosixCompliant() {
        return SystemUtils.IS_OS_AIX || SystemUtils.IS_OS_HP_UX || SystemUtils.IS_OS_IRIX
                || SystemUtils.IS_OS_MAC_OSX || SystemUtils.IS_OS_SOLARIS;
    }

    private boolean isMostlyPosixCompliant() {
        return SystemUtils.IS_OS_LINUX || SystemUtils.IS_OS_MAC || SystemUtils.IS_OS_UNIX;
    }

    private boolean isWindows() {
        return getOs().toLowerCase().contains("windows");
    }

    private String getOs() {
        return System.getProperty("os.name");
    }
}