Java Code Examples for org.apache.commons.lang3.SystemUtils#IS_OS_MAC

The following examples show how to use org.apache.commons.lang3.SystemUtils#IS_OS_MAC . 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: EmbeddedPostgresTest.java    From otj-pg-embedded with Apache License 2.0 6 votes vote down vote up
@Test
public void testValidLocaleSettingsPassthrough() throws IOException {
    try {
        EmbeddedPostgres.Builder builder = null;
        if (SystemUtils.IS_OS_WINDOWS) {
            builder = EmbeddedPostgres.builder()
                    .setLocaleConfig("locale", "en-us")
                    .setLocaleConfig("lc-messages", "en-us");
        } else if (SystemUtils.IS_OS_MAC) {
            builder = EmbeddedPostgres.builder()
                    .setLocaleConfig("locale", "en_US")
                    .setLocaleConfig("lc-messages", "en_US");
        } else if (SystemUtils.IS_OS_LINUX){
            builder = EmbeddedPostgres.builder()
                    .setLocaleConfig("locale", "en_US.utf8")
                    .setLocaleConfig("lc-messages", "en_US.utf8");
        } else {
            fail("System not detected!");
        }
        builder.start();
    } catch (IllegalStateException e){
        e.printStackTrace();
        fail("Failed to set locale settings: " + e.getLocalizedMessage());
    }
}
 
Example 2
Source File: HardwareUtils.java    From JavaSteam with MIT License 6 votes vote down vote up
public static byte[] getMachineID() {
    // the aug 25th 2015 CM update made well-formed machine MessageObjects required for logon
    // this was flipped off shortly after the update rolled out, likely due to linux steamclients running on distros without a way to build a machineid
    // so while a valid MO isn't currently (as of aug 25th) required, they could be in the future and we'll abide by The Valve Law now

    if (SERIAL_NUMBER != null) {
        return SERIAL_NUMBER.getBytes();
    }

    if (SystemUtils.IS_OS_WINDOWS) {
        SERIAL_NUMBER = getSerialNumberWin();
    }
    if (SystemUtils.IS_OS_MAC) {
        SERIAL_NUMBER = getSerialNumberMac();
    }
    if (SystemUtils.IS_OS_LINUX) {
        SERIAL_NUMBER = getSerialNumberUnix();
    }

    return SERIAL_NUMBER == null ? new byte[0] : SERIAL_NUMBER.getBytes();
}
 
Example 3
Source File: CollectEarthUtils.java    From collect-earth with MIT License 5 votes vote down vote up
public static void openFolderInExplorer(String folder) throws IOException {
	if (Desktop.isDesktopSupported()) {
		Desktop.getDesktop().open(new File(folder));
	}else{
		if (SystemUtils.IS_OS_WINDOWS){
			new ProcessBuilder("explorer.exe", "/open," + folder).start(); //$NON-NLS-1$ //$NON-NLS-2$
		}else if (SystemUtils.IS_OS_MAC){
			new ProcessBuilder("usr/bin/open", folder).start(); //$NON-NLS-1$ //$NON-NLS-2$
		}else if ( SystemUtils.IS_OS_UNIX){
			tryUnixFileExplorers(folder);
		}
	}
}
 
Example 4
Source File: DetectInfoUtility.java    From hub-detect with Apache License 2.0 5 votes vote down vote up
public OperatingSystemType findOperatingSystemType() {
    OperatingSystemType operatingSystemType;
    if (SystemUtils.IS_OS_LINUX) {
        return OperatingSystemType.LINUX;
    } else if (SystemUtils.IS_OS_MAC) {
        return OperatingSystemType.MAC;
    } else if (SystemUtils.IS_OS_WINDOWS) {
        return OperatingSystemType.WINDOWS;
    }

    logger.warn("Your operating system is not supported. Linux will be assumed.");
    return OperatingSystemType.LINUX;
}
 
Example 5
Source File: FbxConv.java    From Mundus with Apache License 2.0 5 votes vote down vote up
public FbxConv(String fbxBinary) {
    this.fbxBinary = fbxBinary;
    if (SystemUtils.IS_OS_MAC) {
        os = Os.MAC;
    } else if (SystemUtils.IS_OS_WINDOWS) {
        os = Os.WINDOWS;
    } else if (SystemUtils.IS_OS_LINUX) {
        os = Os.LINUX;
    } else {
        throw new OsNotSupported();
    }

    pb = new ProcessBuilder(fbxBinary);
}
 
Example 6
Source File: SettingsHandler.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static String getFilePaths()
{
	String def_type = "user";
	if (SystemUtils.IS_OS_MAC)
	{
		def_type = "mac_user";
	}
	return FILEPATHS.getProperty("pcgen.filepaths", def_type); //$NON-NLS-1$
}
 
Example 7
Source File: ImageUtilsTest.java    From recheck with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void extract_scale_should_return_value_related_on_os() {
	final int actualScale = ImageUtils.extractScale();
	// Note this is only 2 if on Retina (i.e. not external display).
	final int expectedScale = SystemUtils.IS_OS_MAC ? 2 : 1;
	assertThat( actualScale ).isEqualTo( expectedScale );
}
 
Example 8
Source File: SeleniumHelper.java    From hsac-fitnesse-fixtures with Apache License 2.0 5 votes vote down vote up
/**
 * @return whether current driver connects to browser on a Mac
 */
public boolean connectedToMac() {
    boolean isMac;
    WebDriver driver = driver();
    if (driver instanceof RemoteWebDriver) {
        RemoteWebDriver remoteWebDriver = (RemoteWebDriver) driver;
        Platform platform = remoteWebDriver.getCapabilities().getPlatform();
        isMac = Platform.MAC == platform || Platform.MAC == platform.family();
    } else {
        isMac = SystemUtils.IS_OS_MAC;
    }
    return isMac;
}
 
Example 9
Source File: MeasurementProtocol.java    From thunderstorm with GNU General Public License v3.0 5 votes vote down vote up
private String fixNewLines(String json) {
    String fixed = json.replace("\r\n", "\n").replace("\r", "\n");  // convert Windows and Mac to Unix
    // now convert to the coding dependant on the OS
    if(SystemUtils.IS_OS_WINDOWS) { // Windows
        return fixed.replace("\n", "\r\n");
    } else if(SystemUtils.IS_OS_MAC) {  // Mac OS
        return fixed.replace("\n", "\r");
    } else {    // Unix-based systems
        return fixed;   // "\n"
    }
}
 
Example 10
Source File: InferenceVerticle.java    From konduit-serving with Apache License 2.0 5 votes vote down vote up
public static int getPid() throws UnsatisfiedLinkError {
    if (SystemUtils.IS_OS_WINDOWS) {
        return windows.GetCurrentProcessId();
    } else if (SystemUtils.IS_OS_MAC) {
        return macosx.getpid();
    } else if (SystemUtils.IS_OS_LINUX){
        return linux.getpid();
    } else {
        return -1;
    }
}
 
Example 11
Source File: PlatformUtil.java    From milkman with MIT License 5 votes vote down vote up
private static String getOsSpecificAppDataFolder(String filename) {
	if (SystemUtils.IS_OS_WINDOWS) {
		return Paths.get(System.getenv("LOCALAPPDATA"), "Milkman", filename).toString();
	} else if (SystemUtils.IS_OS_MAC) {
		return Paths.get(System.getProperty("user.home"), "Library", "Application Support", "Milkman", filename).toString();
	} else if (SystemUtils.IS_OS_LINUX) {
		return Paths.get(System.getProperty("user.home"), ".milkman", filename).toString();
	}
	
	return filename;
	
}
 
Example 12
Source File: PlatformUtil.java    From milkman with MIT License 5 votes vote down vote up
public static KeyCombination getControlKeyCombination(KeyCode keyCode){
	KeyCombination.Modifier controlKey = KeyCombination.CONTROL_DOWN;
	if (SystemUtils.IS_OS_MAC){
		controlKey = KeyCombination.META_DOWN;
	}
	return new KeyCodeCombination(keyCode, controlKey);
}
 
Example 13
Source File: DetectInfoUtility.java    From synopsys-detect with Apache License 2.0 5 votes vote down vote up
public OperatingSystemType findOperatingSystemType() {
    if (SystemUtils.IS_OS_LINUX) {
        return OperatingSystemType.LINUX;
    } else if (SystemUtils.IS_OS_MAC) {
        return OperatingSystemType.MAC;
    } else if (SystemUtils.IS_OS_WINDOWS) {
        return OperatingSystemType.WINDOWS;
    }

    logger.warn("Your operating system is not supported. Linux will be assumed.");
    return OperatingSystemType.LINUX;
}
 
Example 14
Source File: FirefoxLocatorFixed.java    From collect-earth with MIT License 5 votes vote down vote up
public static String tryToFindFolder(){
	String path = null;
	if (SystemUtils.IS_OS_WINDOWS){
		return findInUsualWindowsLocations();
	}else if (SystemUtils.IS_OS_MAC){
		return findInUsualMacLocations();
	}

	return path;		  
}
 
Example 15
Source File: VaultDownloader.java    From vertx-config with Apache License 2.0 5 votes vote down vote up
private static URL getURL(String version) {
  StringBuilder url = new StringBuilder();
  url.append("https://releases.hashicorp.com/vault/").append(version).append("/vault_").append(version).append("_");

  if (SystemUtils.IS_OS_MAC) {
    url.append("darwin_");
  } else if (SystemUtils.IS_OS_LINUX) {
    url.append("linux_");
  }  else if (SystemUtils.IS_OS_WINDOWS) {
    url.append("windows_");
  } else {
    throw new IllegalStateException("Unsupported operating system");
  }

  if (ArchUtils.getProcessor().is64Bit()) {
    url.append("amd64.zip");
  } else {
    url.append("386.zip");
  }

  System.out.println("Downloading " + url.toString());
  try {
    return new URL(url.toString());
  } catch (Exception e) {
    throw new RuntimeException(e);
  }

}
 
Example 16
Source File: StaffApplication.java    From RemoteSupportTool with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("Duplicates")
protected synchronized void doHandleKeyRelease(KeyEvent e) {
    if (handler == null) return;
    //LOGGER.debug("key released: " + e.paramString());

    // Get code of the released key.
    // Keypad arrows are translated to regular arrow keys.
    final int keyCode;
    switch (e.getKeyCode()) {
        case KeyEvent.VK_KP_DOWN:
            keyCode = KeyEvent.VK_DOWN;
            break;
        case KeyEvent.VK_KP_LEFT:
            keyCode = KeyEvent.VK_LEFT;
            break;
        case KeyEvent.VK_KP_RIGHT:
            keyCode = KeyEvent.VK_RIGHT;
            break;
        case KeyEvent.VK_KP_UP:
            keyCode = KeyEvent.VK_UP;
            break;
        default:
            keyCode = e.getKeyCode();
            break;
    }

    // Never press undefined key codes.
    if (keyCode == KeyEvent.VK_UNDEFINED) {
        return;
    }

    // Never send caps lock, num lock and scroll lock key.
    if (keyCode == KeyEvent.VK_CAPS_LOCK || keyCode == KeyEvent.VK_NUM_LOCK || keyCode == KeyEvent.VK_SCROLL_LOCK) {
        return;
    }

    // Detect, if a control key was pressed.
    final boolean isControlKey = e.isActionKey() ||
            keyCode == KeyEvent.VK_BACK_SPACE ||
            keyCode == KeyEvent.VK_DELETE ||
            keyCode == KeyEvent.VK_ENTER ||
            keyCode == KeyEvent.VK_SPACE ||
            keyCode == KeyEvent.VK_TAB ||
            keyCode == KeyEvent.VK_ESCAPE ||
            keyCode == KeyEvent.VK_ALT ||
            keyCode == KeyEvent.VK_ALT_GRAPH ||
            keyCode == KeyEvent.VK_CONTROL ||
            keyCode == KeyEvent.VK_SHIFT ||
            keyCode == KeyEvent.VK_META;

    // Release control keys.
    if (isControlKey) {
        //LOGGER.debug("release key \"{}\" ({})", keyCode, KeyEvent.getKeyText(keyCode));
        handler.sendKeyRelease(keyCode);
        e.consume();
    }

    // Release other keys, if they are pressed together with a modifier key.
    else if (e.isControlDown() || e.isMetaDown() || windowsKeyDown || (!SystemUtils.IS_OS_MAC && e.isAltDown()) || pressedKeys.contains(keyCode)) {
        //LOGGER.debug("release key \"{}\" ({})", keyCode, KeyEvent.getKeyText(keyCode));
        handler.sendKeyRelease(keyCode);
        pressedKeys.remove((Integer) keyCode);
        e.consume();
    }

    // Forget, that the Windows key is pressed.
    if (keyCode == KeyEvent.VK_WINDOWS) {
        synchronized (Frame.this) {
            windowsKeyDown = false;
        }
    }
}
 
Example 17
Source File: Utils.java    From JavaSteam with MIT License 4 votes vote down vote up
public static EOSType getOSType() {
    if (SystemUtils.IS_OS_WINDOWS_7) {
        return EOSType.Windows7;
    }
    if (SystemUtils.IS_OS_WINDOWS_8) {
        return EOSType.Windows8;
    }
    if (SystemUtils.IS_OS_WINDOWS_10) {
        return EOSType.Windows10;
    }
    if (SystemUtils.IS_OS_WINDOWS_95) {
        return EOSType.Win95;
    }
    if (SystemUtils.IS_OS_WINDOWS_98) {
        return EOSType.Win98;
    }
    if (SystemUtils.IS_OS_WINDOWS_2000) {
        return EOSType.Win2000;
    }
    if (SystemUtils.IS_OS_WINDOWS_2003) {
        return EOSType.Win2003;
    }
    if (SystemUtils.IS_OS_WINDOWS_2008) {
        return EOSType.Win2008;
    }
    if (SystemUtils.IS_OS_WINDOWS_2012) {
        return EOSType.Win2012;
    }
    if (SystemUtils.IS_OS_WINDOWS_ME) {
        return EOSType.WinME;
    }
    if (SystemUtils.IS_OS_WINDOWS_NT) {
        return EOSType.WinNT;
    }
    if (SystemUtils.IS_OS_WINDOWS_VISTA) {
        return EOSType.WinVista;
    }
    if (SystemUtils.IS_OS_WINDOWS_XP) {
        return EOSType.WinXP;
    }
    if (SystemUtils.IS_OS_WINDOWS) {
        return EOSType.WinUnknown;
    }
    if (SystemUtils.IS_OS_MAC_OSX_TIGER) {
        return EOSType.MacOS104;
    }
    if (SystemUtils.IS_OS_MAC_OSX_LEOPARD) {
        return EOSType.MacOS105;
    }
    if (SystemUtils.IS_OS_MAC_OSX_SNOW_LEOPARD) {
        return EOSType.MacOS106;
    }
    if (SystemUtils.IS_OS_MAC_OSX_LION) {
        return EOSType.MacOS107;
    }
    if (SystemUtils.IS_OS_MAC_OSX_MOUNTAIN_LION) {
        return EOSType.MacOS108;
    }
    if (SystemUtils.IS_OS_MAC_OSX_MAVERICKS) {
        return EOSType.MacOS109;
    }
    if (SystemUtils.IS_OS_MAC_OSX_YOSEMITE) {
        return EOSType.MacOS1010;
    }
    if (SystemUtils.IS_OS_MAC_OSX_EL_CAPITAN) {
        return EOSType.MacOS1011;
    }
    if (checkOS("Mac OS X", "10.12")) {
        return EOSType.MacOS1012;
    }
    if (checkOS("Mac OS X", "10.13")) {
        return EOSType.Macos1013;
    }
    if (checkOS("Mac OS X", "10.14")) {
        return EOSType.Macos1014;
    }
    if (SystemUtils.IS_OS_MAC) {
        return EOSType.MacOSUnknown;
    }
    if (JAVA_RUNTIME != null && JAVA_RUNTIME.startsWith("Android")) {
        return EOSType.AndroidUnknown;
    }
    if (SystemUtils.IS_OS_LINUX) {
        return EOSType.LinuxUnknown;
    }
    return EOSType.Unknown;
}
 
Example 18
Source File: ContentEditor.java    From milkman with MIT License 4 votes vote down vote up
private void setupCodeArea() {
		codeArea = new CodeArea();
//		codeArea.setWrapText(true);
		setupParagraphGraphics();
		EventStream<Object> highLightTrigger = EventStreams.merge(codeArea.multiPlainChanges(),
				EventStreams.changesOf(highlighters.getSelectionModel().selectedItemProperty()),
				EventStreams.eventsOf(format, MouseEvent.MOUSE_CLICKED));


		//behavior of TAB: 2 spaces, allow outdention via SHIFT-TAB, if cursor is at beginning
		Nodes.addInputMap(codeArea, InputMap.consume(
				EventPattern.keyPressed(KeyCode.TAB),
				e -> codeArea.replaceSelection("  ")
		));

		Nodes.addInputMap(codeArea, InputMap.consume(
				EventPattern.keyPressed(KeyCode.TAB, SHIFT_DOWN),
				e -> {
					var paragraph = codeArea.getParagraph(codeArea.getCurrentParagraph());
					var indentation = StringUtils.countStartSpaces(paragraph.getText());

					//is the cursor in the white spaces
					if (codeArea.getCaretColumn() <= indentation){
						var charsToRemove = Math.min(indentation, 2);

						codeArea.replaceText(new IndexRange(codeArea.getAbsolutePosition(codeArea.getCurrentParagraph(), 0),
								codeArea.getAbsolutePosition(codeArea.getCurrentParagraph(), (int) charsToRemove)),
								"");
					}
				}
		));

		// sync highlighting:
//		Subscription cleanupWhenNoLongerNeedIt = highLightTrigger
//				 .successionEnds(Duration.ofMillis(500))
//				 .subscribe(ignore -> {
//					System.out.println("Triggered highlight via end-of-succession");
//					 highlightCode();
//				 });

		// async highlighting:
		Subscription cleanupWhenNoLongerNeedIt = highLightTrigger.successionEnds(Duration.ofMillis(500))
				.supplyTask(this::highlightCodeAsync).awaitLatest(codeArea.multiPlainChanges()).filterMap(t -> {
					if (t.isSuccess()) {
						return Optional.of(t.get());
					} else {
						t.getFailure().printStackTrace();
						return Optional.empty();
					}
				}).subscribe(this::applyHighlighting);

		KeyCombination.Modifier controlKey = KeyCombination.CONTROL_DOWN;
		if (SystemUtils.IS_OS_MAC){
			controlKey = KeyCombination.META_DOWN;
		}
		val keyCombination = PlatformUtil.getControlKeyCombination(KeyCode.F);
		codeArea.setOnKeyPressed(e -> {
			if (keyCombination.match(e)) {
				focusSearch();
			}
		});
	}
 
Example 19
Source File: DockerComposeRuntime.java    From carnotzet with Apache License 2.0 4 votes vote down vote up
public DockerComposeRuntime(Carnotzet carnotzet, String instanceId, CommandRunner commandRunner) {
	// Due to limitations in docker for mac and windows, mapping local ports to container ports is the preferred technique for those users.
	// https://docs.docker.com/docker-for-mac/networking/#i-cannot-ping-my-containers
	this(carnotzet, instanceId, commandRunner, SystemUtils.IS_OS_MAC || SystemUtils.IS_OS_WINDOWS);
}
 
Example 20
Source File: Robot.java    From RemoteSupportTool with Apache License 2.0 4 votes vote down vote up
public synchronized void printText(String text) {
    //LOGGER.debug("printText \"{}\"", text);
    waitForIdle();

    // release keys, that may have been set previously
    //final List<Integer> oldPressedKeys = new ArrayList<>(pressedKeys);
    releasePressedKeys();

    //noinspection EmptyFinallyBlock
    try {
        // Try to print the text through the native API of the operating system.
        boolean textWasSent = false;
        if (SystemUtils.IS_OS_WINDOWS)
            textWasSent = WindowsUtils.sendText(text, this);
        else if (SystemUtils.IS_OS_MAC)
            textWasSent = MacUtils.sendText(text);
        else if (SystemUtils.IS_OS_LINUX)
            textWasSent = LinuxUtils.sendText(text);

        // Otherwise try to print the text through the Robot class.
        if (!textWasSent) {
            for (int i = 0; i < text.length(); i++) {
                final char character = text.charAt(i);
                final int code = KeyEvent.getExtendedKeyCodeForChar(character);

                if (KeyEvent.VK_UNDEFINED != code) {
                    keyPress(code);
                    keyRelease(code);
                } else {
                    LOGGER.warn("Can't detect key code for character \"{}\".", character);
                }
            }
        }

    } finally {
        // reset previously pressed keys
        //releasePressedKeys();
        //for (Integer code : oldPressedKeys) {
        //    keyPress(code);
        //}
    }
}