Java Code Examples for com.intellij.openapi.util.SystemInfo#isLinux()

The following examples show how to use com.intellij.openapi.util.SystemInfo#isLinux() . 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: ExternalStorage.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private static String getOsPrefix() {
  if (SystemInfo.isWindows) {
    return "win";
  }
  else if (SystemInfo.isMac) {
    return "mac";
  }
  else if (SystemInfo.isLinux) {
    return "linux";
  }
  else if (SystemInfo.isFreeBSD) {
    return "bsd";
  }
  else if (SystemInfo.isUnix) {
    return "unix";
  }
  return "other";
}
 
Example 2
Source File: AttachOSHandler.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private static OSType localComputeOsType() {
  if (SystemInfo.isLinux) {
    return OSType.LINUX;
  }

  if (SystemInfo.isMac) {
    return OSType.MACOSX;
  }

  if (SystemInfo.isWindows) {
    return OSType.WINDOWS;
  }

  return OSType.UNKNOWN;
}
 
Example 3
Source File: Platform.java    From reasonml-idea-plugin with MIT License 6 votes vote down vote up
@NotNull
public static String getOsPrefix() {
    if (SystemInfo.isWindows) {
        return "w";
    }

    if (SystemInfo.isLinux) {
        return "l";
    }

    if (SystemInfo.isMac) {
        return "o";
    }

    return "";
}
 
Example 4
Source File: FileSystemMediatorOverride.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
private static FileSystemUtil.Mediator getMediator() {
  if (!Boolean.getBoolean(FORCE_USE_NIO2_KEY)) {
    try {
      if (SystemInfo.isWindows && IdeaWin32.isAvailable()) {
        return check(new IdeaWin32MediatorImpl());
      }
      else if ((SystemInfo.isLinux || SystemInfo.isMac || SystemInfo.isSolaris || SystemInfo.isFreeBSD) && JnaLoader.isLoaded()) {
        return check(new JnaUnixMediatorImpl());
      }
    }
    catch (Throwable t) {
      LOG.warn("Failed to load filesystem access layer: " + SystemInfo.OS_NAME + ", " + SystemInfo.JAVA_VERSION, t);
    }
  }

  return null;
}
 
Example 5
Source File: Analytics.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Nullable
private static String createUserAgent() {
  final String locale = Locale.getDefault().toString();

  if (SystemInfo.isWindows) {
    return "Mozilla/5.0 (Windows; Windows; Windows; " + locale + ")";
  }
  else if (SystemInfo.isMac) {
    return "Mozilla/5.0 (Macintosh; Intel Mac OS X; Macintosh; " + locale + ")";
  }
  else if (SystemInfo.isLinux) {
    return "Mozilla/5.0 (Linux; Linux; Linux; " + locale + ")";
  }

  return null;
}
 
Example 6
Source File: NativeFileWatcherImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * Subclasses should override this method to provide a custom binary to run.
 */
@Nullable
public static File getExecutable() {
  String execPath = System.getProperty(PROPERTY_WATCHER_EXECUTABLE_PATH);
  if (execPath != null) return new File(execPath);

  String[] names = null;
  if (SystemInfo.isWindows) {
    if ("win32-x86".equals(Platform.RESOURCE_PREFIX)) names = new String[]{"fsnotifier.exe"};
    else if ("win32-x86-64".equals(Platform.RESOURCE_PREFIX)) names = new String[]{"fsnotifier64.exe", "fsnotifier.exe"};
  }
  else if (SystemInfo.isMac) {
    names = new String[]{"fsnotifier"};
  }
  else if (SystemInfo.isLinux) {
    if ("linux-x86".equals(Platform.RESOURCE_PREFIX)) names = new String[]{"fsnotifier"};
    else if ("linux-x86-64".equals(Platform.RESOURCE_PREFIX)) names = new String[]{"fsnotifier64"};
    else if ("linux-arm".equals(Platform.RESOURCE_PREFIX)) names = new String[]{"fsnotifier-arm"};
  }
  if (names == null) return PLATFORM_NOT_SUPPORTED;

  return Arrays.stream(names).map(ContainerPathManager.get()::findBinFile).filter(Objects::nonNull).findFirst().orElse(null);
}
 
Example 7
Source File: UnixProcessManager.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static String[] getPSCmd(boolean commandLineOnly, boolean isShortenCommand) {
  String psCommand = "/bin/ps";
  if (!new File(psCommand).isFile()) {
    psCommand = "ps";
  }
  if (SystemInfo.isLinux) {
    return new String[]{psCommand, "-e", "--format", commandLineOnly ? "%a" : "%P%p%a"};
  }
  else if (SystemInfo.isMac || SystemInfo.isFreeBSD) {
    final String command = isShortenCommand ? "comm" : "command";
    return new String[]{psCommand, "-ax", "-o", commandLineOnly ? command : "ppid,pid," + command};
  }
  else {
    throw new IllegalStateException(System.getProperty("os.name") + " is not supported.");
  }
}
 
Example 8
Source File: JnaUnixMediatorImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public FileAttributes getAttributes(@Nonnull String path) {
  Memory buffer = new Memory(256);
  int res = SystemInfo.isLinux ? myLibC.__lxstat64(STAT_VER, path, buffer) : myLibC.lstat(path, buffer);
  if (res != 0) return null;

  int mode = getModeFlags(buffer) & LibC.S_MASK;
  boolean isSymlink = (mode & LibC.S_IFMT) == LibC.S_IFLNK;
  if (isSymlink) {
    if (!loadFileStatus(path, buffer)) {
      return FileAttributes.BROKEN_SYMLINK;
    }
    mode = getModeFlags(buffer) & LibC.S_MASK;
  }

  boolean isDirectory = (mode & LibC.S_IFMT) == LibC.S_IFDIR;
  boolean isSpecial = !isDirectory && (mode & LibC.S_IFMT) != LibC.S_IFREG;
  long size = buffer.getLong(myOffsets[OFF_SIZE]);
  long mTime1 = SystemInfo.is32Bit ? buffer.getInt(myOffsets[OFF_TIME]) : buffer.getLong(myOffsets[OFF_TIME]);
  long mTime2 = myCoarseTs ? 0 : SystemInfo.is32Bit ? buffer.getInt(myOffsets[OFF_TIME] + 4) : buffer.getLong(myOffsets[OFF_TIME] + 8);
  long mTime = mTime1 * 1000 + mTime2 / 1000000;

  boolean writable = ownFile(buffer) ? (mode & LibC.WRITE_MASK) != 0 : myLibC.access(path, LibC.W_OK) == 0;

  return new FileAttributes(isDirectory, isSpecial, isSymlink, false, size, mTime, writable);
}
 
Example 9
Source File: BlazeGDBServerProvider.java    From intellij with Apache License 2.0 5 votes vote down vote up
static boolean shouldUseGdbserver() {
  // Only provide support for Linux for now:
  // - Mac does not have gdbserver, so use the old gdb method for debugging
  // - Windows does not support the gdbwrapper script
  if (!SystemInfo.isLinux) {
    return false;
  }
  return useRemoteDebugging.getValue();
}
 
Example 10
Source File: DesktopStartUIUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void blockATKWrapper() {
  /*
   * The method should be called before java.awt.Toolkit.initAssistiveTechnologies()
   * which is called from Toolkit.getDefaultToolkit().
   */
  if (!SystemInfo.isLinux || !SystemProperties.getBooleanProperty("linux.jdk.accessibility.atkwrapper.block", true)) return;

  if (ScreenReader.isEnabled(ScreenReader.ATK_WRAPPER)) {
    // Replace AtkWrapper with a dummy Object. It'll be instantiated & GC'ed right away, a NOP.
    System.setProperty("javax.accessibility.assistive_technologies", "java.lang.Object");
    getLogger().info(ScreenReader.ATK_WRAPPER + " is blocked, see IDEA-149219");
  }
}
 
Example 11
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 12
Source File: Unity3dPackageWatcher.java    From consulo-unity3d with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static List<String> getUnityUserPaths()
{
	List<String> paths = new SmartList<>();
	if(SystemInfo.isWinVistaOrNewer)
	{
		paths.add(Shell32Util.getFolderPath(ShlObj.CSIDL_LOCAL_APPDATA) + "\\Unity");

		PointerByReference pointerByReference = new PointerByReference();
		// LocalLow
		WinNT.HRESULT hresult = Shell32.INSTANCE.SHGetKnownFolderPath(Guid.GUID.fromString("{A520A1A4-1780-4FF6-BD18-167343C5AF16}"), 0, null, pointerByReference);

		if(hresult.longValue() == 0)
		{
			paths.add(pointerByReference.getValue().getWideString(0) + "\\Unity");
		}
	}
	else if(SystemInfo.isMac)
	{
		paths.add(SystemProperties.getUserHome() + "/Library/Unity");
	}
	else if(SystemInfo.isLinux)
	{
		paths.add(SystemProperties.getUserHome() + "/.config/unity3d");
	}

	return paths;
}
 
Example 13
Source File: DesktopWindowManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static boolean shouldConvert() {
  if (SystemInfo.isLinux || // JRE-managed HiDPI mode is not yet implemented (pending)
      SystemInfo.isMac)     // JRE-managed HiDPI mode is permanent
  {
    return false;
  }
  if (!UIUtil.isJreHiDPIEnabled()) return false; // device space equals user space
  return true;
}
 
Example 14
Source File: LafManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Inject
LafManagerImpl() {
  myLocalizeManager = LocalizeManager.getInstance();

  List<UIManager.LookAndFeelInfo> lafList = ContainerUtil.newArrayList();

  lafList.add(new IntelliJLookAndFeelInfo());

  if (!SystemInfo.isMac) {
    if (SystemInfo.isWin8OrNewer) {
      lafList.add(new NativeModernWhiteLookAndFeelInfo());
    }
    lafList.add(new ModernWhiteLookAndFeelInfo());
    lafList.add(new ModernDarkLookAndFeelInfo());
  }
  lafList.add(new DarculaLookAndFeelInfo());

  if (SystemInfo.isLinux && EarlyAccessProgramManager.is(GTKPlusEAPDescriptor.class)) {
    lafList.add(new UIManager.LookAndFeelInfo("GTK+", "com.sun.java.swing.plaf.gtk.GTKLookAndFeel"));
  }

  for (LookAndFeelProvider provider : LookAndFeelProvider.EP_NAME.getExtensionList()) {
    provider.register(lafList::add);
  }

  myLaFs = lafList.toArray(new UIManager.LookAndFeelInfo[lafList.size()]);

  myCurrentLaf = getDefaultLaf();
}
 
Example 15
Source File: JBUIScale.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
private static Pair<String, Integer> calcSystemFontData() {
  // with JB Linux JDK the label font comes properly scaled based on Xft.dpi settings.
  Font font = UIManager.getFont("Label.font");
  if (SystemInfo.isMacOSElCapitan) {
    // text family should be used for relatively small sizes (<20pt), don't change to Display
    // see more about SF https://medium.com/@mach/the-secret-of-san-francisco-fonts-4b5295d9a745#.2ndr50z2v
    font = new Font(".SF NS Text", font.getStyle(), font.getSize());
  }

  Logger log = getLogger();
  boolean isScaleVerbose = Boolean.getBoolean("ide.ui.scale.verbose");
  if (isScaleVerbose) {
    log.info(String.format("Label font: %s, %d", font.getFontName(), font.getSize()));
  }

  if (SystemInfo.isLinux) {
    Object value = Toolkit.getDefaultToolkit().getDesktopProperty("gnome.Xft/DPI");
    if (isScaleVerbose) {
      log.info(String.format("gnome.Xft/DPI: %s", value));
    }
    if (value instanceof Integer) { // defined by JB JDK when the resource is available in the system
      // If the property is defined, then:
      // 1) it provides correct system scale
      // 2) the label font size is scaled
      int dpi = ((Integer)value).intValue() / 1024;
      if (dpi < 50) dpi = 50;
      float scale = JreHiDpiUtil.isJreHiDPIEnabled() ? 1f : discreteScale(dpi / 96f); // no scaling in JRE-HiDPI mode
      UIUtil.DEF_SYSTEM_FONT_SIZE = font.getSize() / scale; // derive actual system base font size
      if (isScaleVerbose) {
        log.info(String.format("DEF_SYSTEM_FONT_SIZE: %.2f", UIUtil.DEF_SYSTEM_FONT_SIZE));
      }
    }
    else if (!SystemInfo.isJetBrainsJvm) {
      // With Oracle JDK: derive scale from X server DPI, do not change DEF_SYSTEM_FONT_SIZE
      float size = UIUtil.DEF_SYSTEM_FONT_SIZE * getScreenScale();
      font = font.deriveFont(size);
      if (isScaleVerbose) {
        log.info(String.format("(Not-JB JRE) reset font size: %.2f", size));
      }
    }
  }
  else if (SystemInfo.isWindows) {
    //noinspection HardCodedStringLiteral
    @SuppressWarnings("SpellCheckingInspection") Font winFont = (Font)Toolkit.getDefaultToolkit().getDesktopProperty("win.messagebox.font");
    if (winFont != null) {
      font = winFont; // comes scaled
      if (isScaleVerbose) {
        log.info(String.format("Windows sys font: %s, %d", winFont.getFontName(), winFont.getSize()));
      }
    }
  }
  Pair<String, Integer> result = Pair.create(font.getName(), font.getSize());
  if (isScaleVerbose) {
    log.info(String.format("ourSystemFontData: %s, %d", result.first, result.second));
  }
  return result;
}
 
Example 16
Source File: Unity3dBundleType.java    From consulo-unity3d with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public Collection<String> suggestHomePaths()
{
	List<String> paths = new SmartList<>();
	if(SystemInfo.isMac)
	{
		paths.add("/Applications/Unity/Unity.app");
		File hubPath = new File("/Applications/Unity/Hub/Editor");
		if(hubPath.exists())
		{
			for(File versionPath : hubPath.listFiles())
			{
				File unityApp = new File(versionPath, "Unity.app");
				if(unityApp.exists())
				{
					paths.add(unityApp.getPath());
				}
			}
		}
	}
	else if(SystemInfo.isWindows)
	{
		// x64 windows
		paths.add("C:/Program Files (x86)/Unity");
		// x32 windows
		paths.add("C:/Program Files/Unity");
	}
	else if(SystemInfo.isLinux)
	{
		paths.add("/opt/Unity");

		File unityHub = new File(SystemProperties.getUserHome(), "Unity/Hub/Editor/");
		if(unityHub.exists())
		{
			for (File file : unityHub.listFiles())
			{
				if(file.isDirectory())
				{
					paths.add(file.getAbsolutePath());
				}
			}
		}
	}
	return paths;
}
 
Example 17
Source File: AnsibleRunServiceFactory.java    From tc-ansible-runner with MIT License 4 votes vote down vote up
@Override
public boolean canRun(BuildAgentConfiguration agentConfiguration) {
    return SystemInfo.isLinux;
}
 
Example 18
Source File: ProcessGroupUtil.java    From intellij with Apache License 2.0 4 votes vote down vote up
private static boolean useProcessGroup() {
  return SystemInfo.isLinux
      && newProcessGroupForBlazeCommands.getValue()
      && FileUtil.exists(SETSID_PATH);
}
 
Example 19
Source File: DirectoryAccessChecker.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static DirectoryFilter getChain() {
  return SystemInfo.isLinux ? LinuxDirectoryFilter.create() : DirectoryFilter.ACCEPTING_FILTER;
}
 
Example 20
Source File: ExternalSystemTestCase.java    From intellij-quarkus with Eclipse Public License 2.0 4 votes vote down vote up
protected static String getEnvVar() {
  if (SystemInfo.isWindows) return "TEMP";
  else if (SystemInfo.isLinux) return "HOME";
  return "TMPDIR";
}