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:com.alibaba.antx.util.CharsetUtil.java

public static String detectedSystemCharset() {
    String charset = Charset.defaultCharset().name();

    // unix?LANGcharset
    if (SystemUtils.IS_OS_UNIX) {
        String lang = System.getenv("LANG");
        int index = -1;

        if (!StringUtil.isBlank(lang) && (index = lang.indexOf(".")) >= 0) {
            String langCharset = lang.substring(index + 1);

            if (Charset.isSupported(langCharset)) {
                charset = langCharset;/*from  w w w  .j a v  a2s. com*/
            }
        }
    }

    return charset;
}

From source file:configuration.ProgramsFilter.java

public boolean accept(File f) {

    Config config = new Config();
    String filename = f.getName();
    if (f.isDirectory())
        return true;
    if (config.getBoolean("Linux") || SystemUtils.IS_OS_LINUX || SystemUtils.IS_OS_UNIX) {
        return true;
    }// w w w  .j  ava  2s  .  c o m
    if (filename.endsWith(".exe") || filename.endsWith(".com") || filename.endsWith(".jar")) {
        return true;
    } else {
        return false;
    }
}

From source file:net.praqma.clearcase.test.unit.LoadRules2Test.java

@Test
public void testLoadRules2() throws Exception {

    String windows = " -add_loadrules " + "2Cool\\Model " + "2Cool\\Trace " + "2Cool\\Gui "
            + "2Cool\\ServerTest";
    String unix = " -add_loadrules " + "vobs/2Cool/ServerTest " + "vobs/2Cool/Gui " + "vobs/2Cool/Model "
            + "vobs/2Cool/Trace";

    String loadModWindows = " -add_loadrules " + "2Cool\\Gui";
    String loadModUnix = " -add_loadrules " + "/vobs/2Cool/Gui";

    String linuxWindowsSwitch = SystemUtils.IS_OS_UNIX ? "catcs_unix.txt" : "catcs.txt";

    String expectedLoadRuleMod = SystemUtils.IS_OS_UNIX ? loadModUnix : loadModWindows;
    String expectedLoadRuleString = SystemUtils.IS_OS_UNIX ? unix : windows;
    //TODO: Implement a test
    SnapshotView.LoadRules2 lr = new SnapshotView.LoadRules2();
    SnapshotView.LoadRules2 spy = Mockito.spy(lr);
    Mockito.doReturn(mockConsoleOut(linuxWindowsSwitch)).when(spy)
            .getConsoleOutput(Mockito.any(SnapshotView.class));
    String sequence = spy.loadRuleSequence(new SnapshotView());
    if (!SystemUtils.IS_OS_UNIX) {
        spy.apply(new SnapshotView());
        assertEquals(expectedLoadRuleString, spy.getLoadRules());

        SnapshotView.LoadRules2 lr2 = new SnapshotView.LoadRules2(SnapshotView.Components.MODIFIABLE);
        SnapshotView.LoadRules2 spy2 = Mockito.spy(lr2);

        Mockito.doReturn(mockConsoleOut(linuxWindowsSwitch)).when(spy2)
                .getConsoleOutput(Mockito.any(SnapshotView.class));

        spy2.apply(new SnapshotView());
        assertEquals(expectedLoadRuleMod, spy2.getLoadRules());
    } else {/*from w  w w  .  j  a v  a2 s .co  m*/
        //TODO FIX Unit tests for unix, the ordering is different on unix
        assertTrue(true);
    }
}

From source file:com.buaa.cfs.io.nativeio.SharedFileDescriptorFactory.java

public static String getLoadingFailureReason() {
    if (!NativeIO.isAvailable()) {
        return "NativeIO is not available.";
    }//from w  w w  .jav a 2  s. c o m
    if (!SystemUtils.IS_OS_UNIX) {
        return "The OS is not UNIX.";
    }
    return null;
}

From source file:com.consol.citrus.admin.service.executor.AbstractExecuteCommand.java

public ProcessBuilder getProcessBuilder() {
    validateWorkingDirectory(workingDirectory);

    List<String> commands = new ArrayList<String>();
    if (SystemUtils.IS_OS_UNIX) {
        commands.add(BASH);/*  www .  j  av a  2  s .  c o  m*/
        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;
}

From source file:kr.co.bitnine.octopus.util.StringUtils.java

/**
 * Print a log message for starting up and shutting down
 *
 * @param clazz the class of the server/* ww w .j a  v a2  s.  co m*/
 * @param args  arguments
 * @param log   the target log object
 */
public static void startupShutdownMessage(Class<?> clazz, String[] args, final Log log) {
    final String classname = clazz.getSimpleName();
    final String hostname = NetUtils.getHostname();

    final String build = VersionInfo.getUrl() + ", rev. " + VersionInfo.getRevision() + "; compiled by '"
            + VersionInfo.getUser() + "' on " + VersionInfo.getDate();
    String[] msg = new String[] { "Starting " + classname, "  host = " + hostname,
            "  args = " + Arrays.asList(args), "  version = " + VersionInfo.getVersion(),
            "  classpath = " + System.getProperty("java.class.path"), "  build = " + build,
            "  java = " + System.getProperty("java.version") };
    log.info(toStartupShutdownString("STARTUP_MSG: ", msg));

    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);
}

From source file:com.consol.citrus.admin.launcher.process.ExecuteCommand.java

public ProcessBuilder getProcessBuilder() {
    validateWorkingDirectory(workingDirectory);

    List<String> commands = new ArrayList<String>();
    if (SystemUtils.IS_OS_UNIX) {
        commands.add(BASH);//w  ww.jav  a 2s .c  o m
        commands.add(BASH_OPTION_C);
    } else {
        commands.add(CMD);
        commands.add(CMD_OPTION_C);
    }

    commands.add(buildCommand(command));

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

    LOG.trace("Returning ProcessBuilder for command:" + commands);
    return pb;
}

From source file:gmgen.util.MiscUtilities.java

/**
 *  Returns if the specified path name is an absolute path or URL.
 *
 *@param  path  a path// ww w . j  av  a  2  s  .  co  m
 *@return       The absolute path
 *@since        GMGen 3.3
 */
public static boolean isAbsolutePath(String path) {
    if (isURL(path)) {
        return true;
    } else if (path.startsWith("~/") || path.startsWith("~" + File.separator) || path.equals("~")) {
        return true;
    } else if (SystemUtils.IS_OS_WINDOWS) {
        if ((path.length() == 2) && (path.charAt(1) == ':')) {
            return true;
        }

        if ((path.length() > 2) && (path.charAt(1) == ':') && (path.charAt(2) == '\\')) {
            return true;
        }

        if (path.startsWith("\\\\")) {
            return true;
        }
    } else if (SystemUtils.IS_OS_UNIX) {
        // nice and simple
        if ((path.length() > 0) && (path.charAt(0) == '/')) {
            return true;
        }
    }

    return false;
}

From source file:eu.qualimaster.adaptation.platform.ToolBase.java

/**
 * Configures logging from a given file.
 * //from w  w w  .ja v  a  2s  .  c  o  m
 * @param file the file to be used for logging
 * @param reset whether the logging context shall be reset (may be relevant for single-step configurations)
 */
public static void configureLogging(File file, boolean reset) {
    File logDir = new File(System.getProperty("java.io.tmpdir"));
    if (SystemUtils.IS_OS_UNIX) {
        File tmp = new File("/var/log");
        if (isAccessibleDir(tmp)) {
            logDir = tmp;
        }
    }
    System.setProperty("qm.log.dir", logDir.getAbsolutePath());

    if (file.exists() && file.canRead()) {
        LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
        try {
            JoranConfigurator configurator = new JoranConfigurator();
            configurator.setContext(context);
            // Call context.reset() to clear any previous configuration, e.g. default 
            // configuration. For multi-step configuration, omit calling context.reset().
            if (reset) {
                context.reset();
            }
            context.reset();
            configurator.doConfigure(file);
        } catch (JoranException je) {
            // StatusPrinter will handle this
        }
        StatusPrinter.printInCaseOfErrorsOrWarnings(context);
    } // ignore and use default configuration
}

From source file:net.praqma.clearcase.test.unit.LoadRules2Test.java

@Test
public void FB11710() throws Exception {

    String expectedAll = StringUtils.join(new String[] { " -add_loadrules",
            "appTemplate_RelDocs\\appTemplate_RelDocs", "bbRTE_RelDocs\\RTE_RelDocs",
            "bbRTE_Source\\RTE_Source", "appTemplate_Tools\\appTemplate_Tools",
            "appTemplate_Dev\\appTemplate_Dev", "appTemplate_Release\\appTemplate_Release",
            "rwScript_Tools\\Script_Release", "bbRTE_Release\\RTE_Release", "rwScript_Tools\\Script_RelDocs",
            "appTemplate_Source\\appTemplate_Source" }, " ");

    String modifiableLoadLines = StringUtils.join(
            new String[] { " -add_loadrules", "appTemplate_RelDocs\\appTemplate_RelDocs",
                    "appTemplate_Tools\\appTemplate_Tools", "appTemplate_Dev\\appTemplate_Dev",
                    "appTemplate_Release\\appTemplate_Release", "appTemplate_Source\\appTemplate_Source", },
            " ");

    SnapshotView.LoadRules2 lr = new SnapshotView.LoadRules2();
    SnapshotView.LoadRules2 lr2 = new SnapshotView.LoadRules2(SnapshotView.Components.MODIFIABLE);
    SnapshotView.LoadRules2 spy = Mockito.spy(lr);
    SnapshotView.LoadRules2 spy2 = Mockito.spy(lr2);
    Mockito.doReturn(mockConsoleOut("ucm-config-spec-with-readonly.txt")).when(spy)
            .getConsoleOutput(Mockito.any(SnapshotView.class));
    Mockito.doReturn(mockConsoleOut("ucm-config-spec-with-readonly.txt")).when(spy2)
            .getConsoleOutput(Mockito.any(SnapshotView.class));

    if (SystemUtils.IS_OS_UNIX) {
        //TODO: Implement me when possible
        assertTrue(true);//ww  w.j a  va 2s  . c o m
    } else {
        SnapshotView view = new SnapshotView();
        spy.apply(view);
        assertEquals(expectedAll, spy.apply(view).getLoadRules());

        spy2.apply(view);
        assertEquals(modifiableLoadLines, spy2.getLoadRules());
    }
}