Example usage for org.apache.commons.lang SystemUtils IS_OS_UNIX

List of usage examples for org.apache.commons.lang SystemUtils IS_OS_UNIX

Introduction

In this page you can find the example usage for org.apache.commons.lang SystemUtils IS_OS_UNIX.

Prototype

boolean IS_OS_UNIX

To view the source code for org.apache.commons.lang SystemUtils IS_OS_UNIX.

Click Source Link

Document

Is true if this is a POSIX compilant system, as in any of AIX, HP-UX, Irix, Linux, MacOSX, Solaris or SUN OS.

The field will return false if OS_NAME is null.

Usage

From source file:net.ssehub.easy.instantiation.core.model.buildlangModel.BuildlangExecution.java

/**
 * Processes the {@link LoadProperties}.
 * //w  w w .  j a  va 2 s .  co  m
 * @param script the script to process the properties for
 * @param base the base path to make relative paths absolute
 * @throws VilException in case that something goes wrong
 */
protected void processProperties(Script script, File base) throws VilException {
    Properties loaded = new Properties();
    for (int p = 0; p < script.getPropertiesCount(); p++) {
        LoadProperties prop = script.getProperties(p);
        String path = prop.getPath();
        path = StringReplacer.substitute(path, new Resolver(environment), getExpressionParser(), this, null);
        File file = absolute(path, base);
        loadProperties(file, loaded, null);
        if (SystemUtils.IS_OS_MAC) {
            loadProperties(file, loaded, "macos");
        } else if (SystemUtils.IS_OS_UNIX) {
            loadProperties(file, loaded, "unix");
        } else if (SystemUtils.IS_OS_WINDOWS) {
            loadProperties(file, loaded, "win");
        }
    }
    for (int v = 0; v < script.getVariableDeclarationCount(); v++) {
        VariableDeclaration var = script.getVariableDeclaration(v);
        String value = loaded.getProperty(var.getName(), null);
        if (null != value) {
            if (var.isConstant() && null != var.getExpression()) {
                throw new VilException("constant '" + var.getName() + "' is already assigned a value",
                        VilException.ID_IS_CONSTANT);
            }
            Object actValue = evaluateExternalValue(var, value);
            environment.setValue(var, actValue);
            tracer.valueDefined(var, null, actValue);
        }
    }
}

From source file:net.ymate.platform.commons.util.RuntimeUtils.java

/**
 * ???Unix
 * 
 * @return
 */
public static boolean isUnixOrLinux() {
    return SystemUtils.IS_OS_UNIX;
}

From source file:net.ymate.platform.commons.util.SystemEnvUtils.java

/**
 * ?????/* www . ja  va 2s  .co m*/
 */
public static void initSystemEnvs() {
    Process p = null;
    try {
        if (SystemUtils.IS_OS_WINDOWS) {
            p = Runtime.getRuntime().exec("cmd /c set");
        } else if (SystemUtils.IS_OS_UNIX) {
            p = Runtime.getRuntime().exec("/bin/sh -c set");
        } else {
            _LOG.warn("Unknown os.name=" + SystemUtils.OS_NAME);
            SYSTEM_ENV_MAP.clear();
        }
        if (p != null) {
            BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
            String line;
            while ((line = br.readLine()) != null) {
                int i = line.indexOf("=");
                if (i > -1) {
                    String key = line.substring(0, i);
                    String value = line.substring(i + 1);
                    SYSTEM_ENV_MAP.put(key, value);
                }
            }
        }
    } catch (IOException e) {
        _LOG.warn(RuntimeUtils.unwrapThrow(e));
    }
}

From source file:net.ymate.platform.core.util.RuntimeUtils.java

/**
 * ?????/*  w ww  .  j  a  v  a2 s.  com*/
 */
public static void initSystemEnvs() {
    Process p = null;
    BufferedReader br = null;
    try {
        if (SystemUtils.IS_OS_WINDOWS) {
            p = Runtime.getRuntime().exec("cmd /c set");
        } else if (SystemUtils.IS_OS_UNIX) {
            p = Runtime.getRuntime().exec("/bin/sh -c set");
        } else {
            _LOG.warn("Unknown os.name=" + SystemUtils.OS_NAME);
            SYSTEM_ENV_MAP.clear();
        }
        if (p != null) {
            br = new BufferedReader(new InputStreamReader(p.getInputStream()));
            String line;
            while ((line = br.readLine()) != null) {
                int i = line.indexOf('=');
                if (i > -1) {
                    String key = line.substring(0, i);
                    String value = line.substring(i + 1);
                    SYSTEM_ENV_MAP.put(key, value);
                }
            }
        }
    } catch (IOException e) {
        _LOG.warn(RuntimeUtils.unwrapThrow(e));
    } finally {
        if (br != null) {
            try {
                br.close();
            } catch (IOException e) {
                _LOG.warn("", e);
            }
        }
        if (p != null) {
            p.destroy();
        }
    }
}

From source file:org.apache.hadoop.fs.TestEnhancedByteBufferAccess.java

public static HdfsConfiguration initZeroCopyTest() {
    Assume.assumeTrue(NativeIO.isAvailable());
    Assume.assumeTrue(SystemUtils.IS_OS_UNIX);
    HdfsConfiguration conf = new HdfsConfiguration();
    conf.setBoolean(DFSConfigKeys.DFS_CLIENT_READ_SHORTCIRCUIT_KEY, true);
    conf.setLong(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, BLOCK_SIZE);
    conf.setInt(DFSConfigKeys.DFS_CLIENT_MMAP_CACHE_SIZE, 3);
    conf.setLong(DFSConfigKeys.DFS_CLIENT_MMAP_CACHE_TIMEOUT_MS, 100);
    conf.set(DFSConfigKeys.DFS_DOMAIN_SOCKET_PATH_KEY,
            new File(sockDir.getDir(), "TestRequestMmapAccess._PORT.sock").getAbsolutePath());
    conf.setBoolean(DFSConfigKeys.DFS_CLIENT_READ_SHORTCIRCUIT_SKIP_CHECKSUM_KEY, true);
    conf.setLong(DFS_HEARTBEAT_INTERVAL_KEY, 1);
    conf.setLong(DFS_CACHEREPORT_INTERVAL_MSEC_KEY, 1000);
    conf.setLong(DFS_NAMENODE_PATH_BASED_CACHE_REFRESH_INTERVAL_MS, 1000);
    return conf;//  w ww.j a va 2  s  .c  o m
}

From source file:org.apache.hadoop.io.nativeio.TestSharedFileDescriptorFactory.java

@Test(timeout = 10000)
public void testCleanupRemainders() throws Exception {
    Assume.assumeTrue(NativeIO.isAvailable());
    Assume.assumeTrue(SystemUtils.IS_OS_UNIX);
    File path = new File(TEST_BASE, "testCleanupRemainders");
    path.mkdirs();/*  w ww .ja  v  a 2s  .com*/
    String remainder1 = path.getAbsolutePath() + Path.SEPARATOR + "woot2_remainder1";
    String remainder2 = path.getAbsolutePath() + Path.SEPARATOR + "woot2_remainder2";
    createTempFile(remainder1);
    createTempFile(remainder2);
    SharedFileDescriptorFactory.create("woot2_", new String[] { path.getAbsolutePath() });
    // creating the SharedFileDescriptorFactory should have removed 
    // the remainders
    Assert.assertFalse(new File(remainder1).exists());
    Assert.assertFalse(new File(remainder2).exists());
    FileUtil.fullyDelete(path);
}

From source file:org.apache.hadoop.util.TestSignalLogger.java

@Test(timeout = 60000)
public void testInstall() throws Exception {
    Assume.assumeTrue(SystemUtils.IS_OS_UNIX);
    SignalLogger.INSTANCE.register(LOG);
    try {//from w ww.j av  a  2  s . c o  m
        SignalLogger.INSTANCE.register(LOG);
        Assert.fail("expected IllegalStateException from double registration");
    } catch (IllegalStateException e) {
        // fall through
    }
}

From source file:org.apache.oodt.commons.exec.TestEnvUtilities.java

/**
 * Tests two environment variables that should exist in any build 
 * environment. USER, HOME/*from  w ww  .ja v  a 2  s.  c  om*/
 * By calling (EnvUtilities.getEnv(String))
 */
public void testSetEnvironmentVar() {
    //Test if an only if HOME and USER is defined (Assumed to be true on unix)
    if (SystemUtils.IS_OS_UNIX) {
        //Makes the assumption that System.properties() is correct.
        String userHomeTruth = System.getProperty("user.home");
        String userNameTruth = System.getProperty("user.name");
        //Test values
        String userHomeTest = EnvUtilities.getEnv("HOME");
        String userNameTest = EnvUtilities.getEnv("USER");
        //Check all three tests
        assertEquals(userHomeTruth, userHomeTest);
        assertEquals(userNameTruth, userNameTest);
    }
}

From source file:org.apache.oodt.commons.exec.TestEnvUtilities.java

/**
 * Tests two environment variables that should exist in any build 
 * environment. USER, HOME/*from  w  w  w.  j av  a2 s. c  o  m*/
 * By getting the environment (EnvUtilities.getEnv()) and reading from this.
 */
public void testGetEnvironment() {
    //Test if an only if HOME and USER is defined (Assumed to be true on unix)
    if (SystemUtils.IS_OS_UNIX) {
        //Makes the assumption that System.properties() is correct.
        String userHomeTruth = System.getProperty("user.home");
        String userNameTruth = System.getProperty("user.name");
        Properties env = EnvUtilities.getEnv();
        //Test values
        String userHomeTest = env.getProperty("HOME");
        String userNameTest = env.getProperty("USER");
        //Check all three tests
        assertEquals(userHomeTruth, userHomeTest);
        assertEquals(userNameTruth, userNameTest);
    }
}

From source file:org.apache.oodt.commons.exec.TestEnvUtilities.java

/**
 * Tests for consistency between the two methods for getting environment variables
 * in EnvUtilities calling getEnv(String) and calling getEnv().getProperty(String).
 *//*from w  ww. j  av  a2s . c  om*/
public void testGetEnvironmentConsistency() {
    //Test if an only if HOME and USER is defined (Assumed to be true on unix)
    if (SystemUtils.IS_OS_UNIX) {
        Properties env = EnvUtilities.getEnv();
        //Test values
        String userHomeTest1 = env.getProperty("HOME");
        String userNameTest1 = env.getProperty("USER");
        String userHomeTest2 = EnvUtilities.getEnv("HOME");
        String userNameTest2 = EnvUtilities.getEnv("USER");
        //Check all three tests
        assertEquals(userHomeTest1, userHomeTest2);
        assertEquals(userNameTest1, userNameTest2);
    }
}