Java Code Examples for com.sun.jna.Platform#isMac()

The following examples show how to use com.sun.jna.Platform#isMac() . 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: JvmDiscoverer.java    From apm-agent-java with Apache License 2.0 6 votes vote down vote up
public static ForHotSpotVm withDefaultTempDir() {
         String temporaryDirectory;
         if (Platform.isMac()) {
             temporaryDirectory = System.getenv("TMPDIR");
             if (temporaryDirectory == null) {
                 temporaryDirectory = "/tmp";
             }
         } else if (Platform.isWindows()) {
	temporaryDirectory = System.getenv("TEMP");
	if (temporaryDirectory == null) {
                 temporaryDirectory = "c:/Temp";
             }
} else {
             temporaryDirectory = "/tmp";
         }
         return new ForHotSpotVm(temporaryDirectory);
     }
 
Example 2
Source File: LibraryFinder.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
private static String findCoreLibrary() {
    String path="";
    if (Platform.isWindows()) {
    	try {
	    	path = getCPath(true);
	       	path = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, path, "InstallDir");
    	} catch (Exception ignored) {
    		try {
		    	path = getCPath(false);
		       	path = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, path, "InstallDir");
    		} catch (Exception ignored1) {
    			return "";
    		}
    	}
       	path = path + "CoreFoundation.dll";
       	File f = new File(path);
       	if (f.exists())
       		return path;
    } else if (Platform.isMac()) {
         return "/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation";
    }
    return "";
}
 
Example 3
Source File: LibraryFinder.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
private static String findMobileLibrary() {
	if (Platform.isWindows()) {
		String path;
	    try {
	    	path = getMDPath(true);
	    	path = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, path, "iTunesMobileDeviceDLL");
	    } catch (Exception ignored) {
	    	try {
		    	path = getMDPath(false);
		    	path = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, path, "iTunesMobileDeviceDLL");
	    	} catch (Exception ignored1) {
	    		log.info(ignored.getMessage());
	    		return "";
	    	}
		}
    	File f = new File(path);
    	if (f.exists())
    		return path;
	} else {
		if (Platform.isMac()) {
			return "/System/Library/PrivateFrameworks/MobileDevice.framework/MobileDevice";
		}
	}
	return "";
}
 
Example 4
Source File: Processes.java    From Java-Memory-Manipulation with Apache License 2.0 6 votes vote down vote up
public static Process byId(int id) {
	if ((Platform.isMac() || Platform.isLinux()) && !isSudo()) {
		throw new RuntimeException("You need to run as root/sudo for unix/osx based environments.");
	}
	
	if (Platform.isWindows()) {
		return new Win32Process(id, Kernel32.OpenProcess(0x438, true, id));
	} else if (Platform.isLinux()) {
		return new UnixProcess(id);
	} else if (Platform.isMac()) {
		IntByReference out = new IntByReference();
		if (mac.task_for_pid(mac.mach_task_self(), id, out) != 0) {
			throw new IllegalStateException("Failed to find mach task port for process, ensure you are running as sudo.");
		}
		return new MacProcess(id, out.getValue());
	}
	throw new IllegalStateException("Process " + id + " was not found. Are you sure its running?");
}
 
Example 5
Source File: Processes.java    From Java-Memory-Manipulation with Apache License 2.0 6 votes vote down vote up
public static Process byName(String name) {
	if (Platform.isWindows()) {
		Tlhelp32.PROCESSENTRY32.ByReference entry = new Tlhelp32.PROCESSENTRY32.ByReference();
		Pointer snapshot = Kernel32.CreateToolhelp32Snapshot(Tlhelp32.TH32CS_SNAPALL.intValue(), 0);
		try {
			while (Kernel32.Process32NextW(snapshot, entry)) {
				String processName = Native.toString(entry.szExeFile);
				if (name.equals(processName)) {
					return byId(entry.th32ProcessID.intValue());
				}
			}
		} finally {
			Kernel32.CloseHandle(snapshot);
		}
	} else if (Platform.isMac() || Platform.isLinux()) {
		return byId(Utils.exec("bash", "-c", "ps -A | grep -m1 \"" + name + "\" | awk '{print $1}'"));
	} else {
		throw new UnsupportedOperationException("Unknown operating system! (" + System.getProperty("os.name") + ")");
	}
	throw new IllegalStateException("Process '" + name + "' was not found. Are you sure its running?");
}
 
Example 6
Source File: NativeCallsJNAImpl.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
private static final NativeCalls getImplInstance() {
  if (Platform.isLinux()) {
    return new LinuxNativeCalls();
  }
  if (Platform.isWindows()) {
    return new WinNativeCalls();
  }
  if (Platform.isSolaris()) {
    return new SolarisNativeCalls();
  }
  if (Platform.isMac()) {
    return new MacOSXNativeCalls();
  }
  if (Platform.isFreeBSD()) {
    return new FreeBSDNativeCalls();
  }
  return new POSIXNativeCalls();
}
 
Example 7
Source File: Processes.java    From Java-Memory-Manipulation with Apache License 2.0 6 votes vote down vote up
public static Process byId(int id) {
	if ((Platform.isMac() || Platform.isLinux()) && !isSudo()) {
		throw new RuntimeException("You need to run as root/sudo for unix/osx based environments.");
	}
	
	if (Platform.isWindows()) {
		return new Win32Process(id, Kernel32.OpenProcess(0x438, true, id));
	} else if (Platform.isLinux()) {
		return new UnixProcess(id);
	} else if (Platform.isMac()) {
		IntByReference out = new IntByReference();
		if (mac.task_for_pid(mac.mach_task_self(), id, out) != 0) {
			throw new IllegalStateException("Failed to find mach task port for process, ensure you are running as sudo.");
		}
		return new MacProcess(id, out.getValue());
	}
	throw new IllegalStateException("Process " + id + " was not found. Are you sure its running?");
}
 
Example 8
Source File: Processes.java    From Java-Memory-Manipulation with Apache License 2.0 6 votes vote down vote up
public static Process byName(String name) {
	if (Platform.isWindows()) {
		Tlhelp32.PROCESSENTRY32.ByReference entry = new Tlhelp32.PROCESSENTRY32.ByReference();
		Pointer snapshot = Kernel32.CreateToolhelp32Snapshot(Tlhelp32.TH32CS_SNAPALL.intValue(), 0);
		try {
			while (Kernel32.Process32NextW(snapshot, entry)) {
				String processName = Native.toString(entry.szExeFile);
				if (name.equals(processName)) {
					return byId(entry.th32ProcessID.intValue());
				}
			}
		} finally {
			Kernel32.CloseHandle(snapshot);
		}
	} else if (Platform.isMac() || Platform.isLinux()) {
		return byId(Utils.exec("bash", "-c", "ps -A | grep -m1 \"" + name + "\" | awk '{print $1}'"));
	} else {
		throw new UnsupportedOperationException("Unknown operating system! (" + System.getProperty("os.name") + ")");
	}
	throw new IllegalStateException("Process '" + name + "' was not found. Are you sure its running?");
}
 
Example 9
Source File: NativeCallsJNAImpl.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
private static final NativeCalls getImplInstance() {
  if (Platform.isLinux()) {
    return new LinuxNativeCalls();
  }
  if (Platform.isWindows()) {
    return new WinNativeCalls();
  }
  if (Platform.isSolaris()) {
    return new SolarisNativeCalls();
  }
  if (Platform.isMac()) {
    return new MacOSXNativeCalls();
  }
  if (Platform.isFreeBSD()) {
    return new FreeBSDNativeCalls();
  }
  return new POSIXNativeCalls();
}
 
Example 10
Source File: PtyUtil.java    From WebIDE-Backend with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private static String getPlatformFolder() {
    String result;

    if (Platform.isMac()) {
        result = "macosx";
    } else if (Platform.isWindows()) {
        result = "win";
    } else if (Platform.isLinux()) {
        result = "linux";
    } else if (Platform.isFreeBSD()) {
        result = "freebsd";
    } else if (Platform.isOpenBSD()) {
        result = "openbsd";
    } else {
        throw new IllegalStateException("Platform " + Platform.getOSType() + " is not supported");
    }

    return result;
}
 
Example 11
Source File: Provider.java    From SikuliX1 with MIT License 6 votes vote down vote up
/**
 * Get global hotkey provider for current platform
 *
 * @param useSwingEventQueue whether the provider should be using Swing Event queue or a regular thread
 * @return new instance of Provider, or null if platform is not supported
 * @see X11Provider
 * @see WindowsProvider
 * @see CarbonProvider
 */
public static com.tulskiy.keymaster.common.Provider getCurrentProvider(boolean useSwingEventQueue) {
    com.tulskiy.keymaster.common.Provider provider;
    if (Platform.isX11()) {
        provider = new X11Provider();
    } else if (Platform.isWindows()) {
        provider = new WindowsProvider();
    } else if (Platform.isMac()) {
        provider = new CarbonProvider();
    } else {
        //LOGGER.warn("No suitable provider for " + System.getProperty("os.name"));
        return null;
    }
    provider.setUseSwingEventQueue(useSwingEventQueue);
    provider.init();
    return provider;

}
 
Example 12
Source File: ApplicationStartup.java    From azure-devops-intellij with MIT License 5 votes vote down vote up
/**
 * Finds the OS type the plugin is running on and calls the setup for it
 */
protected void doOsSetup(final File vstsDirectory, final String ideLocation) {
    if (Platform.isMac()) {
        logger.debug("Mac operating system detected");
        cacheIdeLocation(vstsDirectory, ideLocation + MAC_EXE_DIR);
    } else {
        logger.debug("Linux operating system detected ");
        cacheIdeLocation(vstsDirectory, ideLocation + LINUX_EXE_DIR);
    }
}
 
Example 13
Source File: PtyUtil.java    From WebIDE-Backend with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static String getNativeLibraryName() {
    String result;

    if (Platform.isMac()) {
        result = "libpty.dylib";
    } else if (Platform.isWindows()) {
        result = "winpty.dll";
    } else if (Platform.isLinux() || Platform.isFreeBSD() || Platform.isOpenBSD()) {
        result = "libpty.so";
    } else {
        throw new IllegalStateException("Platform " + Platform.getOSType() + " is not supported");
    }

    return result;
}
 
Example 14
Source File: WkHtmlToPdfLoader.java    From htmltopdf-java with MIT License 5 votes vote down vote up
private static String getLibraryResource() {
    return "/wkhtmltox/0.12.5/"
            + (Platform.isWindows() ? "" : "lib")
            + "wkhtmltox"
            + (Platform.is64Bit() ? "" : ".32")
            + (Platform.isWindows() ? ".dll"
                : Platform.isMac() ? ".dylib"
                    : ".so");
}
 
Example 15
Source File: ANBImplement.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public void listen() {
	log.info("start listenning...");
	MDLibrary.am_device_notification.ByReference[] cb = new MDLibrary.am_device_notification.ByReference[1];
	mdLib.AMDeviceNotificationSubscribe(this, 0, 0, 0, cb);
	if (Platform.isMac()) {
		cfLib.CFRunLoopRun();
	}
}
 
Example 16
Source File: UnixDomainSocketLibrary.java    From buck with Apache License 2.0 5 votes vote down vote up
private static boolean isBsdish() {
  return Platform.isMac()
      || Platform.isFreeBSD()
      || Platform.isNetBSD()
      || Platform.isOpenBSD()
      || Platform.iskFreeBSD();
}
 
Example 17
Source File: CLibrary.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private static CLibrary init() {
    if (Platform.isMac() || Platform.isOpenBSD()) {
        return (CLibrary) Native.loadLibrary("c", BSDCLibrary.class);
    } else if (Platform.isFreeBSD()) {
        return (CLibrary) Native.loadLibrary("c", FreeBSDCLibrary.class);
    } else if (Platform.isSolaris()) {
        return (CLibrary) Native.loadLibrary("c", SolarisCLibrary.class);
    } else if (Platform.isLinux()) {
        return (CLibrary) Native.loadLibrary("c", LinuxCLibrary.class);
    } else {
        return (CLibrary) Native.loadLibrary("c", CLibrary.class);
    }
}
 
Example 18
Source File: HostnameUtilsMacTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public boolean canRun() {
    return super.canRun() && Platform.isMac();
}
 
Example 19
Source File: PListUtil.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
public static String getPlatform() {
    if (Platform.isMac())
        return "darwin";
    return "windows";
}
 
Example 20
Source File: LibraryFinder.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
private static boolean systemLoad(String path) {
	if (path.isEmpty()) {
		return false;
	}
	File file = new File(path);
    if (!file.exists()) {
      	return false;
    }
   		if (Platform.isWindows()) {
           path = path.replace("\\\\", "\\");
           path = path.replace("\\", "\\\\");
           path = path.replace("/", "\\\\");
   	    } else if (Platform.isMac()){
           path = path.replace("\\\\", "\\");
           path = path.replace("\\", "/");
       	}
    try {
    	System.out.println("+++path+++ "+path);
        System.load(path);
		ANBActivator
		.getDefault()
		.getLog()
		.log(new Status(IStatus.ERROR, ANBActivator.PLUGIN_ID, 0, 
				"System.load() path = "+path, null));
        return true;
    } catch (SecurityException se) {
		ANBActivator
		.getDefault()
		.getLog()
		.log(new Status(IStatus.ERROR, ANBActivator.PLUGIN_ID, 0, 
				"System.load() path = "+path + " failed due to SecurityException", null));
    	
       	return false;
    } catch (UnsatisfiedLinkError le) {
		ANBActivator
		.getDefault()
		.getLog()
		.log(new Status(IStatus.ERROR, ANBActivator.PLUGIN_ID, 0, 
				"System.load() path = "+path + " failed due to UnsatisfiedLinkError", null));
    	
       	return false;
    } catch (NullPointerException ne) {
		ANBActivator
		.getDefault()
		.getLog()
		.log(new Status(IStatus.ERROR, ANBActivator.PLUGIN_ID, 0, 
				"System.load() path = "+path + " failed due to NullPointerException", null));
    	
       	return false;
    } catch (Throwable e) {
		ANBActivator
		.getDefault()
		.getLog()
		.log(new Status(IStatus.ERROR, ANBActivator.PLUGIN_ID, 0, 
				"System.load() path = "+path + " failed", null));
    	
       	return false;
    }
}