Java Code Examples for com.intellij.openapi.util.SystemInfo#OS_NAME

The following examples show how to use com.intellij.openapi.util.SystemInfo#OS_NAME . 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: OSProcessUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static int getProcessID(@Nonnull Process process) {
  if (SystemInfo.isWindows) {
    try {
      if (process instanceof WinPtyProcess) {
        return ((WinPtyProcess)process).getChildProcessId();
      }
      return WinProcessManager.getProcessId(process);
    }
    catch (Throwable e) {
      throw new IllegalStateException("Cannot get PID from instance of " + process.getClass() + ", OS: " + SystemInfo.OS_NAME, e);
    }
  }
  else if (SystemInfo.isUnix) {
    return UnixProcessManager.getProcessId(process);
  }
  throw new IllegalStateException("Unknown OS: " + SystemInfo.OS_NAME);
}
 
Example 2
Source File: WinProcessManager.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static int getProcessId(Process process) {
  String processClassName = process.getClass().getName();
  if (processClassName.equals("java.lang.Win32Process") || processClassName.equals("java.lang.ProcessImpl")) {
    try {
      if (SystemInfo.IS_AT_LEAST_JAVA9) {
        //noinspection JavaReflectionMemberAccess
        return ((Long)Process.class.getMethod("pid").invoke(process)).intValue();
      }

      long handle = assertNotNull(ReflectionUtil.getField(process.getClass(), process, long.class, "handle"));
      return Kernel32.INSTANCE.GetProcessId(new WinNT.HANDLE(Pointer.createConstant(handle)));
    }
    catch (Throwable t) {
      throw new IllegalStateException("Failed to get PID from instance of " + process.getClass() + ", OS: " + SystemInfo.OS_NAME, t);
    }
  }

  throw new IllegalStateException("Unable to get PID from instance of " + process.getClass() + ", OS: " + SystemInfo.OS_NAME);
}
 
Example 3
Source File: UnixProcessManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static int getProcessId(@Nonnull Process process) {
  try {
    if (SystemInfo.IS_AT_LEAST_JAVA9 && "java.lang.ProcessImpl".equals(process.getClass().getName())) {
      //noinspection JavaReflectionMemberAccess
      return ((Long)Process.class.getMethod("pid").invoke(process)).intValue();
    }

    return assertNotNull(ReflectionUtil.getField(process.getClass(), process, int.class, "pid"));
  }
  catch (Throwable t) {
    throw new IllegalStateException("Failed to get PID from instance of " + process.getClass() + ", OS: " + SystemInfo.OS_NAME, t);
  }
}
 
Example 4
Source File: JnaUnixMediatorImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
JnaUnixMediatorImpl() throws Exception {
  if (SystemInfo.isLinux) {
    if ("arm".equals(SystemInfo.OS_ARCH)) {
      if (SystemInfo.is32Bit) {
        myOffsets = LINUX_ARM;
      }
      else {
        throw new IllegalStateException("AArch64 architecture is not supported");
      }
    }
    else if ("ppc".equals(SystemInfo.OS_ARCH)) {
      myOffsets = SystemInfo.is32Bit ? LNX_PPC32 : LNX_PPC64;
    }
    else {
      myOffsets = SystemInfo.is32Bit ? LINUX_32 : LINUX_64;
    }
  }
  else if (SystemInfo.isMac | SystemInfo.isFreeBSD) {
    myOffsets = SystemInfo.is32Bit ? BSD_32 : BSD_64;
  }
  else if (SystemInfo.isSolaris) {
    myOffsets = SystemInfo.is32Bit ? SUN_OS_32 : SUN_OS_64;
  }
  else {
    throw new IllegalStateException("Unsupported OS/arch: " + SystemInfo.OS_NAME + "/" + SystemInfo.OS_ARCH);
  }

  myLibC = (LibC)Native.loadLibrary("c", LibC.class);
  myUid = myLibC.getuid();
  myGid = myLibC.getgid();
}
 
Example 5
Source File: LaFUsagesCollector.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public Set<UsageDescriptor> getUsages(@Nullable Project project) throws CollectUsagesException {
  UIManager.LookAndFeelInfo laf = LafManager.getInstance().getCurrentLookAndFeel();
  String key = SystemInfo.OS_NAME + " - ";
  if (!StringUtil.isEmptyOrSpaces(SystemInfo.SUN_DESKTOP)) {
    key += SystemInfo.SUN_DESKTOP + " - ";
  }
  return laf != null ? Collections.singleton(new UsageDescriptor(key + laf.getName(), 1)) : Collections.<UsageDescriptor>emptySet();
}
 
Example 6
Source File: UnixProcessManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static void checkCLib() {
  if (C_LIB == null) {
    throw new IllegalStateException("Couldn't load c library, OS: " + SystemInfo.OS_NAME + ", isUnix: " + SystemInfo.isUnix);
  }
}
 
Example 7
Source File: ExecUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public UnsupportedSystemException() {
  super("Unsupported OS/desktop: " + SystemInfo.OS_NAME + '/' + SystemInfo.SUN_DESKTOP);
}