List of usage examples for org.apache.commons.lang SystemUtils IS_OS_UNIX
boolean IS_OS_UNIX
To view the source code for org.apache.commons.lang SystemUtils IS_OS_UNIX.
Click Source Link
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
.
From source file:org.objectstyle.woproject.maven2.wobootstrap.AbstractBootstrapMojo.java
void initializeLocator() throws MojoExecutionException { if (locator != null) { return;/*from w ww . j a va 2 s. c om*/ } if (webObjectsLibFolder != null && webObjectsVersion != null) { locator = new CustomWebObjectsLocator(webObjectsLibFolder); } else if (illegalSetOfParameters()) { throw new MojoExecutionException( "You must provide both webObjectsLibFolder and webObjectsVersion to use a custom locator for WebObjects libraries"); } else if (SystemUtils.IS_OS_MAC_OSX) { locator = new MacOsWebObjectsLocator(); } else if (SystemUtils.IS_OS_WINDOWS) { locator = new WindowsWebObjectsLocator(); } else if (SystemUtils.IS_OS_UNIX) { locator = new UnixWebObjectsLocator(); } else { throw new MojoExecutionException("Unsupported OS platform."); } }
From source file:org.openhab.binding.network.internal.utils.NetworkUtils.java
/** * Return the working method for the native system ping. If no native ping * works JavaPing is returned./*from w ww . j av a 2 s . c o m*/ */ public IpPingMethodEnum determinePingMethod() { IpPingMethodEnum method; if (SystemUtils.IS_OS_WINDOWS) { method = IpPingMethodEnum.WINDOWS_PING; } else if (SystemUtils.IS_OS_MAC) { method = IpPingMethodEnum.MAC_OS_PING; } else if (SystemUtils.IS_OS_UNIX) { method = IpPingMethodEnum.IPUTILS_LINUX_PING; } else { // We cannot estimate the command line for any other operating system and just return false return IpPingMethodEnum.JAVA_PING; } try { if (nativePing(method, "127.0.0.1", 1000)) { return method; } } catch (IOException ignored) { } catch (InterruptedException e) { Thread.currentThread().interrupt(); // Reset interrupt flag } return IpPingMethodEnum.JAVA_PING; }
From source file:org.openhab.binding.network.service.NetworkService.java
/** * Try's to reach the Device by Ping/*ww w .j a va 2s . c o m*/ */ private static double updateDeviceState(String hostname, int port, int timeout, boolean useSystemPing) throws InvalidConfigurationException { boolean success = false; double pingTime = -1; try { if (!useSystemPing) { pingTime = System.nanoTime(); success = Ping.checkVitality(hostname, port, timeout); pingTime = System.nanoTime() - pingTime; } else { Process proc; if (SystemUtils.IS_OS_UNIX) { pingTime = System.nanoTime(); proc = new ProcessBuilder("ping", "-t", String.valueOf(timeout / 1000), "-c", "1", hostname) .start(); } else if (SystemUtils.IS_OS_WINDOWS) { pingTime = System.nanoTime(); 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(); pingTime = System.nanoTime() - pingTime; success = exitValue == 0; if (!success) { logger.debug("Ping stopped with Error Number: " + exitValue + " on Command :" + "ping" + (SystemUtils.IS_OS_UNIX ? " -t " : " -w ") + (SystemUtils.IS_OS_UNIX ? String.valueOf(timeout / 1000) : String.valueOf(timeout)) + (SystemUtils.IS_OS_UNIX ? " -c" : " -n") + " 1 " + hostname); } } 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 ? pingTime / 1000000.0f : -1; }
From source file:org.openhab.binding.network.service.NetworkUtils.java
public static boolean nativePing(String hostname, int port, int timeout) throws InvalidConfigurationException, IOException, InterruptedException { Process proc;//from www. j av a 2s . co m if (SystemUtils.IS_OS_UNIX) { proc = new ProcessBuilder("ping", "-w", String.valueOf(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 { throw new InvalidConfigurationException("System Ping not supported"); } int exitValue = proc.waitFor(); if (exitValue != 0) { throw new IOException("Ping stopped with Error Number: " + exitValue + " on Command :" + "ping" + (SystemUtils.IS_OS_UNIX ? " -t " : " -w ") + (SystemUtils.IS_OS_UNIX ? String.valueOf(timeout / 1000) : String.valueOf(timeout)) + (SystemUtils.IS_OS_UNIX ? " -c" : " -n") + " 1 " + hostname); } return exitValue == 0; }
From source file:org.sonar.core.util.FileUtilsTest.java
@Test public void cleanDirectory_follows_symlink_to_target_directory() throws IOException { assumeTrue(SystemUtils.IS_OS_UNIX); Path target = temporaryFolder.newFolder().toPath(); Path symToDir = Files.createSymbolicLink(temporaryFolder.newFolder().toPath().resolve("sym_to_dir"), target);// ww w .j a v a 2 s . com Path childFile1 = Files.createFile(target.resolve("file1.txt")); Path childDir1 = Files.createDirectory(target.resolve("subDir1")); Path childFile2 = Files.createFile(childDir1.resolve("file2.txt")); Path childDir2 = Files.createDirectory(childDir1.resolve("subDir2")); assertThat(target).isDirectory(); assertThat(symToDir).isSymbolicLink(); assertThat(childFile1).isRegularFile(); assertThat(childDir1).isDirectory(); assertThat(childFile2).isRegularFile(); assertThat(childDir2).isDirectory(); // on supporting FileSystem, target will change if directory is recreated Object targetKey = getFileKey(target); Object symLinkKey = getFileKey(symToDir); FileUtils.cleanDirectory(symToDir.toFile()); assertThat(target).isDirectory(); assertThat(symToDir).isSymbolicLink(); assertThat(childFile1).doesNotExist(); assertThat(childDir1).doesNotExist(); assertThat(childFile2).doesNotExist(); assertThat(childDir2).doesNotExist(); assertThat(getFileKey(target)).isEqualTo(targetKey); assertThat(getFileKey(symToDir)).isEqualTo(symLinkKey); }
From source file:org.sonar.core.util.FileUtilsTest.java
@Test public void deleteQuietly_deletes_symbolicLink() throws IOException { assumeTrue(SystemUtils.IS_OS_UNIX); Path folder = temporaryFolder.newFolder().toPath(); Path file1 = Files.createFile(folder.resolve("file1.txt")); Path symLink = Files.createSymbolicLink(folder.resolve("link1"), file1); assertThat(file1).isRegularFile();/*from w ww. j a v a2 s .c o m*/ assertThat(symLink).isSymbolicLink(); FileUtils.deleteQuietly(symLink.toFile()); assertThat(symLink).doesNotExist(); assertThat(file1).isRegularFile(); }
From source file:org.sonar.core.util.FileUtilsTest.java
@Test public void deleteDirectory_throws_IOE_if_file_is_symbolicLink() throws IOException { assumeTrue(SystemUtils.IS_OS_UNIX); Path folder = temporaryFolder.newFolder().toPath(); Path file1 = Files.createFile(folder.resolve("file1.txt")); Path symLink = Files.createSymbolicLink(folder.resolve("link1"), file1); assertThat(file1).isRegularFile();//from w w w . j a va 2 s . c o m assertThat(symLink).isSymbolicLink(); expectedException.expect(IOException.class); expectedException .expectMessage("Directory '" + symLink.toFile().getAbsolutePath() + "' is a symbolic link"); FileUtils.deleteDirectory(symLink.toFile()); }
From source file:org.sonar.process.FileUtils2Test.java
@Test public void cleanDirectory_follows_symlink_to_target_directory() throws IOException { assumeTrue(SystemUtils.IS_OS_UNIX); Path target = temporaryFolder.newFolder().toPath(); Path symToDir = Files.createSymbolicLink(temporaryFolder.newFolder().toPath().resolve("sym_to_dir"), target);/*from w ww.j a va 2 s . c o m*/ Path childFile1 = Files.createFile(target.resolve("file1.txt")); Path childDir1 = Files.createDirectory(target.resolve("subDir1")); Path childFile2 = Files.createFile(childDir1.resolve("file2.txt")); Path childDir2 = Files.createDirectory(childDir1.resolve("subDir2")); assertThat(target).isDirectory(); assertThat(symToDir).isSymbolicLink(); assertThat(childFile1).isRegularFile(); assertThat(childDir1).isDirectory(); assertThat(childFile2).isRegularFile(); assertThat(childDir2).isDirectory(); // on supporting FileSystem, target will change if directory is recreated Object targetKey = getFileKey(target); Object symLinkKey = getFileKey(symToDir); FileUtils2.cleanDirectory(symToDir.toFile()); assertThat(target).isDirectory(); assertThat(symToDir).isSymbolicLink(); assertThat(childFile1).doesNotExist(); assertThat(childDir1).doesNotExist(); assertThat(childFile2).doesNotExist(); assertThat(childDir2).doesNotExist(); assertThat(getFileKey(target)).isEqualTo(targetKey); assertThat(getFileKey(symToDir)).isEqualTo(symLinkKey); }
From source file:org.sonar.process.FileUtils2Test.java
@Test public void deleteQuietly_deletes_symbolicLink() throws IOException { assumeTrue(SystemUtils.IS_OS_UNIX); Path folder = temporaryFolder.newFolder().toPath(); Path file1 = Files.createFile(folder.resolve("file1.txt")); Path symLink = Files.createSymbolicLink(folder.resolve("link1"), file1); assertThat(file1).isRegularFile();//from w ww.j ava 2s. com assertThat(symLink).isSymbolicLink(); FileUtils2.deleteQuietly(symLink.toFile()); assertThat(symLink).doesNotExist(); assertThat(file1).isRegularFile(); }
From source file:org.sonar.process.FileUtils2Test.java
@Test public void deleteDirectory_throws_IOE_if_file_is_symbolicLink() throws IOException { assumeTrue(SystemUtils.IS_OS_UNIX); Path folder = temporaryFolder.newFolder().toPath(); Path file1 = Files.createFile(folder.resolve("file1.txt")); Path symLink = Files.createSymbolicLink(folder.resolve("link1"), file1); assertThat(file1).isRegularFile();//from www . ja va2s.co m assertThat(symLink).isSymbolicLink(); expectedException.expect(IOException.class); expectedException .expectMessage("Directory '" + symLink.toFile().getAbsolutePath() + "' is a symbolic link"); FileUtils2.deleteDirectory(symLink.toFile()); }