Java Code Examples for com.intellij.openapi.util.SystemInfoRt#isWindows()
The following examples show how to use
com.intellij.openapi.util.SystemInfoRt#isWindows() .
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: SystemInfopageDocSourceTest.java From BashSupport with Apache License 2.0 | 6 votes |
@Test public void testInfoPageCall() throws IOException { if (!SystemInfoRt.isWindows && !"true".equals(System.getenv("CI"))) { SystemInfopageDocSource source = new SystemInfopageDocSource(); String bashInfoPage = source.loadPlainTextInfoPage("bash"); Assert.assertNotNull(bashInfoPage); Assert.assertTrue(bashInfoPage.length() > 500); String html = source.callTextToHtml("abc"); Assert.assertNotNull(html); Assert.assertTrue(html.contains("abc")); html = source.callTextToHtml(bashInfoPage); Assert.assertNotNull(html); Assert.assertTrue(html.length() > 500); } }
Example 2
Source File: FileUtilRt.java From consulo with Apache License 2.0 | 6 votes |
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (args.length == 2) { final Object second = args[1]; if (second instanceof Throwable) { throw (Throwable)second; } final String methodName = method.getName(); if ("visitFile".equals(methodName) || "postVisitDirectory".equals(methodName)) { performDelete(args[0]); } else if (SystemInfoRt.isWindows && "preVisitDirectory".equals(methodName)) { boolean notDirectory = false; try { notDirectory = Boolean.TRUE.equals(ourAttributesIsOtherMethod.invoke(second)); } catch (Throwable ignored) { } if (notDirectory) { performDelete(args[0]); return Result_Skip; } } } return Result_Continue; }
Example 3
Source File: SystemInfopageDocSourceTest.java From BashSupport with Apache License 2.0 | 5 votes |
@Test public void testInfoFileExists() throws IOException { if (!SystemInfoRt.isWindows && !"true".equals(System.getenv("CI"))) { SystemInfopageDocSource source = new SystemInfopageDocSource(); Assert.assertTrue(source.infoFileExists("info")); Assert.assertFalse(source.infoFileExists("thisCommandDoesNotExist")); } }
Example 4
Source File: OSUtilTest.java From BashSupport with Apache License 2.0 | 5 votes |
@Test public void testFindBestExecutable() throws Exception { if (SystemInfoRt.isWindows) { String path = OSUtil.findBestExecutable("info"); Assert.assertNotNull(path); } }
Example 5
Source File: OSUtilTest.java From BashSupport with Apache License 2.0 | 5 votes |
@Test public void testFindBestExecutablePaths() throws Exception { if (SystemInfoRt.isWindows) { String path = OSUtil.findBestExecutable("info", Collections.singletonList("/usr/bin")); Assert.assertNotNull(path); path = OSUtil.findBestExecutable("info", Collections.singletonList("/path/which/is/not/here")); Assert.assertNull(path); } }
Example 6
Source File: FileUtilRt.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull private static String calcCanonicalTempPath() { final File file = new File(System.getProperty("java.io.tmpdir")); try { final String canonical = file.getCanonicalPath(); if (!SystemInfoRt.isWindows || !canonical.contains(" ")) { return canonical; } } catch (IOException ignore) { } return file.getAbsolutePath(); }
Example 7
Source File: Urls.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull public static URI toUriWithoutParameters(@Nonnull Url url) { try { String externalPath = url.getPath(); boolean inLocalFileSystem = url.isInLocalFileSystem(); if (inLocalFileSystem && SystemInfoRt.isWindows && externalPath.charAt(0) != '/') { externalPath = '/' + externalPath; } return new URI(inLocalFileSystem ? "file" : url.getScheme(), inLocalFileSystem ? "" : url.getAuthority(), externalPath, null, null); } catch (URISyntaxException e) { throw new RuntimeException(e); } }
Example 8
Source File: PathUtilRt.java From consulo with Apache License 2.0 | 5 votes |
private static Charset fsCharset() { if (!SystemInfoRt.isWindows && !SystemInfoRt.isMac) { String property = System.getProperty("sun.jnu.encoding"); if (property != null) { try { return Charset.forName(property); } catch (Exception e) { Logger.getInstance(PathUtilRt.class).warn("unknown JNU charset: " + property, e); } } } return null; }
Example 9
Source File: URLUtil.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull public static String toIdeaUrl(@Nonnull String url, boolean removeLocalhostPrefix) { int index = url.indexOf(":/"); if (index < 0 || (index + 2) >= url.length()) { return url; } if (url.charAt(index + 2) != '/') { String prefix = url.substring(0, index); String suffix = url.substring(index + 2); if (SystemInfoRt.isWindows) { return prefix + URLUtil.SCHEME_SEPARATOR + suffix; } else if (removeLocalhostPrefix && prefix.equals(URLUtil.FILE_PROTOCOL) && suffix.startsWith(LOCALHOST_URI_PATH_PREFIX)) { // sometimes (e.g. in Google Chrome for Mac) local file url is prefixed with 'localhost' so we need to remove it return prefix + ":///" + suffix.substring(LOCALHOST_URI_PATH_PREFIX.length()); } else { return prefix + ":///" + suffix; } } else if (SystemInfoRt.isWindows && (index + 3) < url.length() && url.charAt(index + 3) == '/' && url.regionMatches(0, URLUtil.FILE_PROTOCOL_PREFIX, 0, FILE_PROTOCOL_PREFIX.length())) { // file:///C:/test/file.js -> file://C:/test/file.js for (int i = index + 4; i < url.length(); i++) { char c = url.charAt(i); if (c == '/') { break; } else if (c == ':') { return FILE_PROTOCOL_PREFIX + url.substring(index + 4); } } return url; } return url; }
Example 10
Source File: CompletionUtil.java From BashSupport with Apache License 2.0 | 4 votes |
/** * Provide a list of absolute paths on the current system which match the given prefix. * Prefix is path whose last entry may be a partial match. A match with "/etc/def" matches * all files and directories in /etc which start with "def". * * @param prefix A path which is used to collect matching files. * @param accept * @return A list of full paths which match the prefix. */ @NotNull public static List<String> completeAbsolutePath(@NotNull String prefix, Predicate<File> accept) { String nativePath = prefix.startsWith("/") && SystemInfoRt.isWindows ? OSUtil.bashCompatibleToNative(prefix) : prefix; File base = new File(nativePath); //a dot tricks Java into thinking dir/. is equal to dir and thus exists boolean dotSuffix = prefix.endsWith(".") && !prefix.startsWith("."); if (!base.exists() || dotSuffix) { base = base.getParentFile(); if (base == null || !base.exists()) { return Collections.emptyList(); } } File basePath; String matchPrefix; if (base.isDirectory()) { basePath = base; matchPrefix = ""; } else { basePath = base.getParentFile(); matchPrefix = base.getName(); } List<String> result = Lists.newLinkedList(); for (File fileCandidate : collectFiles(basePath, matchPrefix)) { if (!accept.test(fileCandidate)) { continue; } String resultPath; if (fileCandidate.isDirectory()) { resultPath = fileCandidate.getAbsolutePath() + File.separator; } else { resultPath = fileCandidate.getAbsolutePath(); } result.add(OSUtil.toBashCompatible(resultPath)); } return result; }
Example 11
Source File: FileUtilRt.java From consulo with Apache License 2.0 | 4 votes |
@SuppressWarnings("DuplicatedCode") private static int processRoot(@Nonnull String path, @Nonnull Appendable result) { try { if (SystemInfoRt.isWindows && path.length() > 1 && path.charAt(0) == '/' && path.charAt(1) == '/') { result.append("//"); int hostStart = 2; while (hostStart < path.length() && path.charAt(hostStart) == '/') hostStart++; if (hostStart == path.length()) return hostStart; int hostEnd = path.indexOf('/', hostStart); if (hostEnd < 0) hostEnd = path.length(); result.append(path, hostStart, hostEnd); result.append('/'); int shareStart = hostEnd; while (shareStart < path.length() && path.charAt(shareStart) == '/') shareStart++; if (shareStart == path.length()) return shareStart; int shareEnd = path.indexOf('/', shareStart); if (shareEnd < 0) shareEnd = path.length(); result.append(path, shareStart, shareEnd); result.append('/'); return shareEnd; } if (path.length() > 0 && path.charAt(0) == '/') { result.append('/'); return 1; } if (path.length() > 2 && path.charAt(1) == ':' && path.charAt(2) == '/') { result.append(path, 0, 3); return 3; } return 0; } catch (IOException e) { throw new RuntimeException(e); } }
Example 12
Source File: FileUtilRt.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull private static File normalizeFile(@Nonnull File temp) throws IOException { final File canonical = temp.getCanonicalFile(); return SystemInfoRt.isWindows && canonical.getAbsolutePath().contains(" ") ? temp.getAbsoluteFile() : canonical; }