本文整理汇总了Java中org.apache.commons.lang.SystemUtils.IS_OS_UNIX属性的典型用法代码示例。如果您正苦于以下问题:Java SystemUtils.IS_OS_UNIX属性的具体用法?Java SystemUtils.IS_OS_UNIX怎么用?Java SystemUtils.IS_OS_UNIX使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.commons.lang.SystemUtils
的用法示例。
在下文中一共展示了SystemUtils.IS_OS_UNIX属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getProcessBuilder
@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;
}
示例2: obtainConfigurationFile
/**
* Returns the configuration file, possibly considering OS-specific default file locations.
*
* @param fileName the file name
* @return the related file object
*/
static File obtainConfigurationFile(String fileName) {
File result = null;
if (SystemUtils.IS_OS_UNIX) {
File tmp = new File("/etc/qualiMaster", fileName);
if (isReadable(tmp)) {
result = tmp;
} else {
tmp = relocate(fileName);
if (isReadable(tmp)) {
result = tmp;
}
}
}
if (null == result) {
// use local directory instead (interactive mode)
result = new File(fileName);
}
return result;
}
示例3: startupShutdownMessage
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,
" user = " + System.getProperty("user.name"),
" 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);
}
示例4: getLoadingFailureReason
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;
}
示例5: create
static BaseConnection create()
{
if (SystemUtils.IS_OS_MAC_OSX)
return new BaseConnectionOsx();
if (SystemUtils.IS_OS_UNIX)
return new BaseConnectionUnix();
if (SystemUtils.IS_OS_WINDOWS)
return new BaseConnectionWindows();
throw new IllegalStateException("This OS is not supported");
}
示例6: startupShutdownMessage
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);
}
示例7: getShell
@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;
}
示例8: getSleepCommand
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; } };
}
示例9: osShellPath
protected String osShellPath()
{
if (SystemUtils.IS_OS_UNIX)
{
return "/bin/sh";
}
throw new IllegalArgumentException("At the moment your system is not supported");
}
开发者ID:fbalicchia,项目名称:graylog-plugin-backup-configuration,代码行数:10,代码来源:AbstractMongoBackupStrategy.java
示例10: getDirInAppData
public static @Nullable String getDirInAppData(String dir) {
if (SystemUtils.IS_OS_WINDOWS) {
return System.getenv("APPDATA") + "/." + dir;
} else if (SystemUtils.IS_OS_MAC) {
return SystemUtils.USER_HOME + "/Library/Application Support/" + dir;
} else if (SystemUtils.IS_OS_UNIX) {
return SystemUtils.USER_HOME + "/." + dir;
}
return null;
}
示例11: startupShutdownMessage
/**
* 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 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);
}
示例12: startupShutdownMessage
/**
* 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 = 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);
}
示例13: configureLogging
/**
* Configures logging from a given file.
*
* @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
}
示例14: isUnixOrLinux
/**
* @return 当前操作系统是否为类Unix系统
*/
public static boolean isUnixOrLinux() {
return SystemUtils.IS_OS_UNIX;
}
示例15: updateDeviceState
/**
* Try's to reach the Device by Ping
*/
private static boolean updateDeviceState(String hostname, int port, int timeout, boolean useSystemPing) throws InvalidConfigurationException {
boolean success = false;
try {
if( !useSystemPing ) {
success = Ping.checkVitality(hostname, port, timeout);
} else {
Process proc;
if( SystemUtils.IS_OS_UNIX ) {
proc = new ProcessBuilder("ping", "-t", String.valueOf((int)(timeout / 1000)), "-c", "1", hostname).start();
} else if( SystemUtils.IS_OS_WINDOWS) {
proc = new ProcessBuilder("ping", "-w", String.valueOf(timeout), "-n", "1", hostname).start();
} else {
logger.error("The System Ping is not supported on this Operating System");
throw new InvalidConfigurationException("System Ping not supported");
}
int exitValue = proc.waitFor();
success = exitValue == 0;
if( exitValue != 2 && exitValue != 0 ) {
logger.debug("Ping stopped with Error Number: " + exitValue +
" on Command :" + "ping" +
(SystemUtils.IS_OS_UNIX ? " -t " : " -w ") +
String.valueOf(timeout) +
(SystemUtils.IS_OS_UNIX ? " -c" : " -n") +
" 1 " + hostname);
return false;
}
}
logger.debug("established connection [host '{}' port '{}' timeout '{}']", new Object[] {hostname, port, timeout});
}
catch (SocketTimeoutException se) {
logger.debug("timed out while connecting to host '{}' port '{}' timeout '{}'", new Object[] {hostname, port, timeout});
}
catch (IOException ioe) {
logger.debug("couldn't establish network connection [host '{}' port '{}' timeout '{}']", new Object[] {hostname, port, timeout});
} catch (InterruptedException e) {
logger.debug("ping program was interrupted");
}
return success ? true : false;
}