com.intellij.openapi.util.SystemInfo Java Examples
The following examples show how to use
com.intellij.openapi.util.SystemInfo.
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: SystemHealthMonitor.java From consulo with Apache License 2.0 | 7 votes |
private void checkSignalBlocking() { if (SystemInfo.isUnix && JnaLoader.isLoaded()) { try { LibC lib = Native.loadLibrary("c", LibC.class); Memory buf = new Memory(1024); if (lib.sigaction(LibC.SIGINT, null, buf) == 0) { long handler = Native.POINTER_SIZE == 8 ? buf.getLong(0) : buf.getInt(0); if (handler == LibC.SIG_IGN) { showNotification(new KeyHyperlinkAdapter("ide.sigint.ignored.message")); } } } catch (Throwable t) { LOG.warn(t); } } }
Example #2
Source File: Analytics.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
@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 #3
Source File: JBUIScale.java From consulo with Apache License 2.0 | 6 votes |
private static float computeUserScaleFactor(float scale) { if (!SystemProperties.getBooleanProperty("hidpi", true)) { return 1f; } scale = discreteScale(scale); // Downgrading user scale below 1.0 may be uncomfortable (tiny icons), // whereas some users prefer font size slightly below normal which is ok. if (scale < 1 && sysScale() >= 1) { scale = 1; } // Ignore the correction when UIUtil.DEF_SYSTEM_FONT_SIZE is overridden, see UIUtil.initSystemFontData. if (SystemInfo.isLinux && scale == 1.25f && UIUtil.DEF_SYSTEM_FONT_SIZE == 12) { // Default UI font size for Unity and Gnome is 15. Scaling factor 1.25f works badly on Linux scale = 1f; } return scale; }
Example #4
Source File: VersionControlPathTests.java From azure-devops-intellij with MIT License | 6 votes |
@Test public void localPathFromTfsRepresentationShouldConvertPathCase() throws IOException { File tempDirectory = FileUtil.createTempDirectory("azure-devops", ".tmp"); try { File tempFile = tempDirectory.toPath().resolve("CASE_SENSITIVE.tmp").toFile(); Assert.assertTrue(tempFile.createNewFile()); String tfsRepresentation = tempFile.getAbsolutePath(); // On non-Windows systems, TFS uses a "fake drive" prefix: if (!SystemInfo.isWindows) tfsRepresentation = "U:" + tfsRepresentation; String localPath = VersionControlPath.localPathFromTfsRepresentation(tfsRepresentation); Assert.assertEquals(tempFile.getAbsolutePath(), localPath); if (!SystemInfo.isFileSystemCaseSensitive) { tfsRepresentation = tfsRepresentation.toLowerCase(); localPath = VersionControlPath.localPathFromTfsRepresentation(tfsRepresentation); Assert.assertEquals(tempFile.getAbsolutePath(), localPath); } } finally { FileUtil.delete(tempDirectory); } }
Example #5
Source File: ToggleWindowedModeAction.java From consulo with Apache License 2.0 | 6 votes |
@Override public void update(AnActionEvent event) { super.update(event); Presentation presentation = event.getPresentation(); if (SystemInfo.isMac) { presentation.setEnabledAndVisible(false); return; } Project project = event.getData(CommonDataKeys.PROJECT); if (project == null) { presentation.setEnabled(false); return; } ToolWindowManager mgr = ToolWindowManager.getInstance(project); String id = mgr.getActiveToolWindowId(); presentation.setEnabled(id != null && mgr.getToolWindow(id).isAvailable()); }
Example #6
Source File: NativeFileWatcherImpl.java From consulo with Apache License 2.0 | 6 votes |
/** * 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: ComponentWithBrowseButton.java From consulo with Apache License 2.0 | 6 votes |
public ComponentWithBrowseButton(Comp component, @Nullable ActionListener browseActionListener) { super(new BorderLayout(SystemInfo.isMac ? 0 : 2, 0)); myComponent = component; // required! otherwise JPanel will occasionally gain focus instead of the component setFocusable(false); add(myComponent, BorderLayout.CENTER); myBrowseButton = new FixedSizeButton(myComponent); if (browseActionListener != null) { myBrowseButton.addActionListener(browseActionListener); } add(centerComponentVertically(myBrowseButton), BorderLayout.EAST); myBrowseButton.setToolTipText(UIBundle.message("component.with.browse.button.browse.button.tooltip.text")); // FixedSizeButton isn't focusable but it should be selectable via keyboard. if (ApplicationManager.getApplication() != null) { // avoid crash at design time new MyDoClickAction(myBrowseButton).registerShortcut(myComponent); } if (ScreenReader.isActive()) { myBrowseButton.setFocusable(true); myBrowseButton.getAccessibleContext().setAccessibleName("Browse"); } }
Example #8
Source File: MinimizeCurrentWindowAction.java From consulo with Apache License 2.0 | 6 votes |
@Override public void update(final AnActionEvent e) { final Presentation p = e.getPresentation(); p.setVisible(SystemInfo.isMac); if (SystemInfo.isMac) { Project project = e.getData(CommonDataKeys.PROJECT); if (project != null) { JFrame frame = (JFrame)TargetAWT.to(WindowManager.getInstance().getWindow(project)); if (frame != null) { JRootPane pane = frame.getRootPane(); p.setEnabled(pane != null && pane.getClientProperty(MacMainFrameDecorator.FULL_SCREEN) == null); } } } else { p.setEnabled(false); } }
Example #9
Source File: NewProjectAction.java From consulo with Apache License 2.0 | 6 votes |
@RequiredUIAccess @Nonnull @Override protected JPanel createSouthPanel() { JPanel buttonsPanel = new JPanel(new GridLayout(1, 2, SystemInfo.isMacOSLeopard ? 0 : 5, 0)); myCancelButton = new JButton(CommonBundle.getCancelButtonText()); myCancelButton.addActionListener(e -> doCancelAction()); buttonsPanel.add(myCancelButton); myOkButton = new JButton(CommonBundle.getOkButtonText()) { @Override public boolean isDefaultButton() { return true; } }; myOkButton.setEnabled(false); myOkButton.addActionListener(e -> doOkAction()); buttonsPanel.add(myOkButton); return JBUI.Panels.simplePanel().addToRight(buttonsPanel); }
Example #10
Source File: MouseGestureManager.java From consulo with Apache License 2.0 | 6 votes |
public void add(final IdeFrame frame) { if (!Registry.is("actionSystem.mouseGesturesEnabled")) return; if (SystemInfo.isMacOSSnowLeopard) { try { if (myListeners.containsKey(frame)) { remove(frame); } Object listener = new MacGestureAdapter(this, frame); myListeners.put(frame, listener); } catch (Throwable e) { LOG.debug(e); } } }
Example #11
Source File: FileAttributesReadingTest.java From consulo with Apache License 2.0 | 6 votes |
@Test public void extraLongName() throws Exception { final String prefix = StringUtil.repeatSymbol('a', 128) + "."; final File dir = FileUtil.createTempDirectory( FileUtil.createTempDirectory( FileUtil.createTempDirectory( FileUtil.createTempDirectory( myTempDirectory, prefix, ".dir"), prefix, ".dir"), prefix, ".dir"), prefix, ".dir"); final File file = FileUtil.createTempFile(dir, prefix, ".txt"); assertTrue(file.exists()); FileUtil.writeToFile(file, myTestData); assertFileAttributes(file); if (SystemInfo.isWindows) { assertDirectoriesEqual(dir); } final String target = FileSystemUtil.resolveSymLink(file); assertEquals(file.getPath(), target); }
Example #12
Source File: LockSupportTest.java From consulo with Apache License 2.0 | 6 votes |
@Test(timeout = 30000) public void testUseCanonicalPathLock() throws Exception { Assume.assumeThat(SystemInfo.isFileSystemCaseSensitive, CoreMatchers.is(false)); String path1 = myTempDir.getPath(); String path2 = path1.toUpperCase(Locale.ENGLISH); DesktopImportantFolderLocker lock1 = new DesktopImportantFolderLocker(path1 + "/c", path1 + "/s"); DesktopImportantFolderLocker lock2 = new DesktopImportantFolderLocker(path2 + "/c", path2 + "/s"); try { lock1.lock(); assertThat(lock2.lock(), CoreMatchers.equalTo(DesktopImportantFolderLocker.ActivateStatus.ACTIVATED)); } finally { lock1.dispose(); lock2.dispose(); } }
Example #13
Source File: WinProcessManager.java From consulo with Apache License 2.0 | 6 votes |
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 #14
Source File: RollbarErrorReportSubmitter.java From bamboo-soy with Apache License 2.0 | 6 votes |
private void log(@NotNull IdeaLoggingEvent[] events, @Nullable String additionalInfo) { IdeaLoggingEvent ideaEvent = events[0]; if (ideaEvent.getThrowable() == null) { return; } LinkedHashMap<String, Object> customData = new LinkedHashMap<>(); customData.put(TAG_PLATFORM_VERSION, ApplicationInfo.getInstance().getBuild().asString()); customData.put(TAG_OS, SystemInfo.OS_NAME); customData.put(TAG_OS_VERSION, SystemInfo.OS_VERSION); customData.put(TAG_OS_ARCH, SystemInfo.OS_ARCH); customData.put(TAG_JAVA_VERSION, SystemInfo.JAVA_VERSION); customData.put(TAG_JAVA_RUNTIME_VERSION, SystemInfo.JAVA_RUNTIME_VERSION); if (additionalInfo != null) { customData.put(EXTRA_ADDITIONAL_INFO, additionalInfo); } if (events.length > 1) { customData.put(EXTRA_MORE_EVENTS, Stream.of(events).map(Object::toString).collect(Collectors.joining("\n"))); } rollbar.codeVersion(getPluginVersion()).log(ideaEvent.getThrowable(), customData); }
Example #15
Source File: FileAttributesReadingTest.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull private static FileAttributes getAttributes(@Nonnull final File file, final boolean checkList) { final FileAttributes attributes = FileSystemUtil.getAttributes(file); assertNotNull(attributes); System.out.println(attributes + ": " + file); if (SystemInfo.isWindows && checkList) { final String parent = file.getParent(); if (parent != null) { final FileInfo[] infos = IdeaWin32.getInstance().listChildren(parent); assertNotNull(infos); for (FileInfo info : infos) { if (file.getName().equals(info.getName())) { assertEquals(attributes, info.toFileAttributes()); return attributes; } } fail(file + " not listed"); } } return attributes; }
Example #16
Source File: FileUtil.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull private static String normalizeTail(int prefixEnd, @Nonnull String path, boolean separator) { final StringBuilder result = new StringBuilder(path.length()); result.append(path, 0, prefixEnd); int start = prefixEnd; if (start == 0 && SystemInfo.isWindows && (path.startsWith("//") || path.startsWith("\\\\"))) { start = 2; result.append("//"); separator = true; } for (int i = start; i < path.length(); ++i) { final char c = path.charAt(i); if (c == '/' || c == '\\') { if (!separator) result.append('/'); separator = true; } else { result.append(c); separator = false; } } return result.toString(); }
Example #17
Source File: VMOptions.java From consulo with Apache License 2.0 | 6 votes |
@Nullable public static File getWriteFile() { String vmOptionsFile = System.getProperty("jb.vmOptionsFile"); if (vmOptionsFile == null) { // launchers should specify a path to an options file used to configure a JVM return null; } vmOptionsFile = new File(vmOptionsFile).getAbsolutePath(); if (!FileUtil.isAncestor(ContainerPathManager.get().getHomePath(), vmOptionsFile, true)) { // a file is located outside the IDE installation - meaning it is safe to overwrite return new File(vmOptionsFile); } File appHomeDirectory = ContainerPathManager.get().getAppHomeDirectory(); String fileName = ApplicationNamesInfo.getInstance().getProductName().toLowerCase(Locale.US); if (SystemInfo.is64Bit && !SystemInfo.isMac) fileName += "64"; if (SystemInfo.isWindows) fileName += ".exe"; fileName += ".vmoptions"; return new File(appHomeDirectory, fileName); }
Example #18
Source File: Restarter.java From consulo with Apache License 2.0 | 6 votes |
public static int scheduleRestart(@Nonnull String... beforeRestart) throws IOException { try { int restartCode = getRestartCode(); if (restartCode != 0) { runCommand(beforeRestart); return restartCode; } else if (SystemInfo.isWindows) { restartOnWindows(beforeRestart); return 0; } else if (SystemInfo.isMac) { restartOnMac(beforeRestart); return 0; } } catch (Throwable t) { throw new IOException("Cannot restart application: " + t.getMessage(), t); } runCommand(beforeRestart); throw new IOException("Cannot restart application: not supported."); }
Example #19
Source File: DarculaTextAreaUI.java From consulo with Apache License 2.0 | 5 votes |
@Override protected void installKeyboardActions() { super.installKeyboardActions(); if (SystemInfo.isMac) { InputMap inputMap = getComponent().getInputMap(); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), DefaultEditorKit.upAction); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), DefaultEditorKit.downAction); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, 0), DefaultEditorKit.pageUpAction); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0), DefaultEditorKit.pageDownAction); } }
Example #20
Source File: RootFileElement.java From consulo with Apache License 2.0 | 5 votes |
private static List<VirtualFile> getFileSystemRoots() { LocalFileSystem localFileSystem = LocalFileSystem.getInstance(); final List<VirtualFile> result = new ArrayList<>(StreamSupport.stream(FileSystems.getDefault().getRootDirectories().spliterator(), false). map(root -> localFileSystem.findFileByPath(FileUtil.toSystemIndependentName(root.toString()))). collect(Collectors.toList())); if (SystemInfo.isWin10OrNewer && Boolean.getBoolean("wsl.p9.show.roots.in.file.chooser")) { final List<VirtualFile> wslRoots = ContainerUtil.mapNotNull(WSLUtil.getExistingUNCRoots(), root -> localFileSystem.findFileByPath(FileUtil.toSystemIndependentName(root.getAbsolutePath()))); result.addAll(wslRoots); } return result; }
Example #21
Source File: PathManager.java From dynkt with GNU Affero General Public License v3.0 | 5 votes |
private static String getOSSpecificBinSubdir() { if (SystemInfo.isWindows) { return "win"; } if (SystemInfo.isMac) { return "mac"; } return "linux"; }
Example #22
Source File: DarculaLaf.java From consulo with Apache License 2.0 | 5 votes |
public DarculaLaf() { try { if (SystemInfo.isWindows || SystemInfo.isLinux) { base = new IntelliJMetalLookAndFeel(); } else { final String name = UIManager.getSystemLookAndFeelClassName(); base = (BasicLookAndFeel)Class.forName(name).newInstance(); } } catch (Exception e) { log(e); } }
Example #23
Source File: BlazeGDBServerProvider.java From intellij with Apache License 2.0 | 5 votes |
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 #24
Source File: RunnerWinProcess.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull public static RunnerWinProcess create(@Nonnull GeneralCommandLine commandLine) throws ExecutionException { if (!SystemInfo.isWindows) { throw new RuntimeException(RunnerWinProcess.class.getSimpleName() + " works on Windows only!"); } RunnerMediator.injectRunnerCommand(commandLine); Process process = commandLine.createProcess(); return new RunnerWinProcess(process); }
Example #25
Source File: DesktopInternalDecorator.java From consulo with Apache License 2.0 | 5 votes |
private void init(boolean dumbAware) { enableEvents(AWTEvent.COMPONENT_EVENT_MASK); final JPanel contentPane = new JPanel(new BorderLayout()); installFocusTraversalPolicy(contentPane, new LayoutFocusTraversalPolicy()); contentPane.add(myHeader, BorderLayout.NORTH); JPanel innerPanel = new JPanel(new BorderLayout()); JComponent toolWindowComponent = myToolWindow.getComponent(); if (!dumbAware) { toolWindowComponent = DumbService.getInstance(myProject).wrapGently(toolWindowComponent, myProject); } innerPanel.add(toolWindowComponent, BorderLayout.CENTER); final NonOpaquePanel inner = new NonOpaquePanel(innerPanel); contentPane.add(inner, BorderLayout.CENTER); add(contentPane, BorderLayout.CENTER); if (SystemInfo.isMac) { setBackground(new JBColor(Gray._200, Gray._90)); } // Add listeners registerKeyboardAction(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { ToolWindowManager.getInstance(myProject).activateEditorComponent(); } }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); }
Example #26
Source File: LightBashCodeInsightFixtureTestCase.java From BashSupport with Apache License 2.0 | 5 votes |
/** * Return absolute path to the test data. Not intended to be overridden. * * @return absolute path to the test data. */ @NonNls public final String getTestDataPath() { String basePath = getBasePath(); if (SystemInfo.isWindows) { basePath = StringUtils.replace(basePath, "/", File.separator); } return BashTestUtils.getBasePath() + (basePath.startsWith(File.separator) ? "" : File.separator) + basePath; }
Example #27
Source File: ActionMenu.java From consulo with Apache License 2.0 | 5 votes |
private boolean isTopMenuBarAfterOpenJDKMemLeakFix() { if (isTopMenuBar()) { // looks like openjdk backport fix from jdk 10 // 181 - when bug from jdk 10 reported. maybe build lower if (SystemInfo.isJavaVersionAtLeast(8, 0, 181)) { return true; } // jdk 10 have initial change in screen menu if (SystemInfo.isJavaVersionAtLeast(10, 0, 0)) { return true; } } return false; }
Example #28
Source File: DirectoryChooser.java From consulo with Apache License 2.0 | 5 votes |
@Nullable private String getCommonFragment(int count) { String commonFragment = null; for (String[] path : myPaths) { int index = getFragmentIndex(path, count); if (index == -1) return null; if (commonFragment == null) { commonFragment = path[index]; continue; } if (!Comparing.strEqual(commonFragment, path[index], SystemInfo.isFileSystemCaseSensitive)) return null; } return commonFragment; }
Example #29
Source File: HaxeSdkUtilBase.java From intellij-haxe with Apache License 2.0 | 5 votes |
/** * Patch the PATH environment variable to include the Haxe SDK. The original environment * is modified in place. * * @param env list of environment variables. * @param haxeSdkData SDK for which the environment is being modified. * @return the environment that was passed in. It is modified in place. */ @NotNull public static Map<String,String> patchEnvironment(@NotNull Map<String,String> env, @Nullable HaxeSdkAdditionalDataBase haxeSdkData) { String pathvar = SystemInfo.isWindows ? "Path" : "PATH"; if (haxeSdkData != null) { final String path = getEnvironmentPathPatch(haxeSdkData) + env.get(pathvar); env.put(pathvar, path); } return env; }
Example #30
Source File: LocalFileSystemBase.java From consulo with Apache License 2.0 | 5 votes |
private static boolean isAbsoluteFileOrDriveLetter(@Nonnull File file) { String path = file.getPath(); if (SystemInfo.isWindows && path.length() == 2 && path.charAt(1) == ':') { // just drive letter. // return true, despite the fact that technically it's not an absolute path return true; } return file.isAbsolute(); }