Java Code Examples for org.apache.commons.lang.SystemUtils#IS_OS_UNIX

The following examples show how to use org.apache.commons.lang.SystemUtils#IS_OS_UNIX . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractTerminalCommand.java    From citrus-admin with Apache License 2.0 6 votes vote down vote up
@Override
public ProcessBuilder getProcessBuilder() {
    validateWorkingDirectory(workingDirectory);

    List<String> commands = new ArrayList<>();
    if (SystemUtils.IS_OS_UNIX) {
        commands.add(BASH);
        commands.add(BASH_OPTION_C);
    } else {
        commands.add(CMD);
        commands.add(CMD_OPTION_C);
    }

    commands.add(buildCommand());

    ProcessBuilder pb = new ProcessBuilder(commands);
    pb.directory(workingDirectory);

    LOG.debug("Process builder commands: " + commands);
    return pb;
}
 
Example 2
Source File: TestEnvUtilities.java    From oodt with Apache License 2.0 6 votes vote down vote up
/**
 * Tests two environment variables that should exist in any build 
 * environment. USER, HOME
 * 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);
    } 
}
 
Example 3
Source File: StringUtils.java    From hadoop with Apache License 2.0 5 votes vote down vote up
static void startupShutdownMessage(Class<?> clazz, String[] args,
                                   final LogAdapter LOG) { 
  final String hostname = NetUtils.getHostname();
  final String classname = clazz.getSimpleName();
  LOG.info(
      toStartupShutdownString("STARTUP_MSG: ", new String[] {
          "Starting " + classname,
          "  host = " + hostname,
          "  args = " + Arrays.asList(args),
          "  version = " + VersionInfo.getVersion(),
          "  classpath = " + System.getProperty("java.class.path"),
          "  build = " + VersionInfo.getUrl() + " -r "
                       + VersionInfo.getRevision()  
                       + "; compiled by '" + VersionInfo.getUser()
                       + "' on " + VersionInfo.getDate(),
          "  java = " + System.getProperty("java.version") }
      )
    );

  if (SystemUtils.IS_OS_UNIX) {
    try {
      SignalLogger.INSTANCE.register(LOG);
    } catch (Throwable t) {
      LOG.warn("failed to register any UNIX signal loggers: ", t);
    }
  }
  ShutdownHookManager.get().addShutdownHook(
    new Runnable() {
      @Override
      public void run() {
        LOG.info(toStartupShutdownString("SHUTDOWN_MSG: ", new String[]{
          "Shutting down " + classname + " at " + hostname}));
      }
    }, SHUTDOWN_HOOK_PRIORITY);

}
 
Example 4
Source File: SharedFileDescriptorFactory.java    From hadoop with Apache License 2.0 5 votes vote down vote up
public static String getLoadingFailureReason() {
  if (!NativeIO.isAvailable()) {
    return "NativeIO is not available.";
  }
  if (!SystemUtils.IS_OS_UNIX) {
    return "The OS is not UNIX.";
  }
  return null;
}
 
Example 5
Source File: StringUtils.java    From big-c with Apache License 2.0 5 votes vote down vote up
static void startupShutdownMessage(Class<?> clazz, String[] args,
                                   final LogAdapter LOG) { 
  final String hostname = NetUtils.getHostname();
  final String classname = clazz.getSimpleName();
  LOG.info(
      toStartupShutdownString("STARTUP_MSG: ", new String[] {
          "Starting " + classname,
          "  host = " + hostname,
          "  args = " + Arrays.asList(args),
          "  version = " + VersionInfo.getVersion(),
          "  classpath = " + System.getProperty("java.class.path"),
          "  build = " + VersionInfo.getUrl() + " -r "
                       + VersionInfo.getRevision()  
                       + "; compiled by '" + VersionInfo.getUser()
                       + "' on " + VersionInfo.getDate(),
          "  java = " + System.getProperty("java.version") }
      )
    );

  if (SystemUtils.IS_OS_UNIX) {
    try {
      SignalLogger.INSTANCE.register(LOG);
    } catch (Throwable t) {
      LOG.warn("failed to register any UNIX signal loggers: ", t);
    }
  }
  ShutdownHookManager.get().addShutdownHook(
    new Runnable() {
      @Override
      public void run() {
        LOG.info(toStartupShutdownString("SHUTDOWN_MSG: ", new String[]{
          "Shutting down " + classname + " at " + hostname}));
      }
    }, SHUTDOWN_HOOK_PRIORITY);

}
 
Example 6
Source File: SharedFileDescriptorFactory.java    From big-c with Apache License 2.0 5 votes vote down vote up
public static String getLoadingFailureReason() {
  if (!NativeIO.isAvailable()) {
    return "NativeIO is not available.";
  }
  if (!SystemUtils.IS_OS_UNIX) {
    return "The OS is not UNIX.";
  }
  return null;
}
 
Example 7
Source File: AbstractTerminalCommand.java    From citrus-admin with Apache License 2.0 5 votes vote down vote up
@Override
public ProcessBuilder getShell() {
    validateWorkingDirectory(workingDirectory);

    List<String> commands = new ArrayList<>();
    if (SystemUtils.IS_OS_UNIX) {
        commands.add(BASH);
    } else {
        commands.add(CMD);
    }

    ProcessBuilder pb = new ProcessBuilder(commands);
    pb.directory(workingDirectory);
    return pb;
}
 
Example 8
Source File: ProcessLauncherTest.java    From citrus-admin with Apache License 2.0 5 votes vote down vote up
private TerminalCommand getSleepCommand(int sleepInSeconds) throws InterruptedException {
    String command;
    if (SystemUtils.IS_OS_UNIX) {
        command = String.format("ping -c %s 127.0.0.1", sleepInSeconds);
    } else {
        command = String.format("ping -n %s 127.0.0.1", sleepInSeconds);
    }
    return new AbstractTerminalCommand(new File(System.getProperty("user.dir"))) { public String buildCommand() { return command; } };
}
 
Example 9
Source File: StringUtils.java    From tajo with Apache License 2.0 5 votes vote down vote up
/**
 * Print a log message for starting up and shutting down
 * @param clazz the class of the server
 * @param args arguments
 * @param LOG the target log object
 */
public static void startupShutdownMessage(Class<?> clazz, String[] args,
                                          final org.apache.commons.logging.Log LOG) {
  final String hostname = org.apache.hadoop.net.NetUtils.getHostname();
  final String classname = clazz.getSimpleName();
  LOG.info(
      toStartupShutdownString("STARTUP_MSG: ", new String[] {
          "Starting " + classname,
          "  host = " + hostname,
          "  args = " + Arrays.asList(args),
          "  version = " + org.apache.tajo.util.VersionInfo.getVersion(),
          "  classpath = " + System.getProperty("java.class.path"),
          "  build = " + org.apache.tajo.util.VersionInfo.getUrl() + " -r "
              + org.apache.tajo.util.VersionInfo.getRevision()
              + "; compiled by '" + org.apache.tajo.util.VersionInfo.getUser()
              + "' on " + org.apache.tajo.util.VersionInfo.getDate(),
          "  java = " + System.getProperty("java.version") }
      )
  );

  if (SystemUtils.IS_OS_UNIX) {
    try {
      SignalLogger.INSTANCE.register(LOG);
    } catch (Throwable t) {
      LOG.warn("failed to register any UNIX signal loggers: ", t);
    }
  }
  ShutdownHookManager.get().addShutdownHook(
      new Runnable() {
        @Override
        public void run() {
          LOG.info(toStartupShutdownString("SHUTDOWN_MSG: ", new String[]{
              "Shutting down " + classname + " at " + hostname}));
        }
      }, SHUTDOWN_HOOK_PRIORITY);
}
 
Example 10
Source File: TestEnvUtilities.java    From oodt with Apache License 2.0 5 votes vote down vote up
/**
 * Tests two environment variables that should exist in any build 
 * environment. USER, HOME
 * 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);
    } 
}
 
Example 11
Source File: TestEnvUtilities.java    From oodt with Apache License 2.0 5 votes vote down vote up
/**
 * Tests for consistency between the two methods for getting environment variables
 * in EnvUtilities calling getEnv(String) and calling getEnv().getProperty(String).
 */
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);
    }
}
 
Example 12
Source File: TestEnvUtilities.java    From oodt with Apache License 2.0 5 votes vote down vote up
public void testStaticEnvironment(){
  if(SystemUtils.IS_OS_UNIX){
    Properties env = EnvUtilities.getEnv();
    Properties env2 = EnvUtilities.getEnv();
    
    assertEquals(env, env2);
  }
}
 
Example 13
Source File: RuntimeUtils.java    From ymate-platform-v2 with Apache License 2.0 4 votes vote down vote up
/**
 * @return 当前操作系统是否为类Unix系统
 */
public static boolean isUnixOrLinux() {
    return SystemUtils.IS_OS_UNIX;
}