com.intellij.openapi.util.SystemInfoRt Java Examples

The following examples show how to use com.intellij.openapi.util.SystemInfoRt. 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 vote down vote up
@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 vote down vote up
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: StartupUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void logStartupInfo(final Logger log) {
  LoggerFactory factory = LoggerFactoryInitializer.getFactory();

  Runtime.getRuntime().addShutdownHook(new Thread("Shutdown hook - logging") {
    @Override
    public void run() {
      log.info("------------------------------------------------------ IDE SHUTDOWN ------------------------------------------------------");
      factory.shutdown();
    }
  });
  log.info("------------------------------------------------------ IDE STARTED ------------------------------------------------------");
  log.info("Using logger factory: " + factory.getClass().getSimpleName());

  ApplicationInfo appInfo = ApplicationInfoImpl.getShadowInstance();
  ApplicationNamesInfo namesInfo = ApplicationNamesInfo.getInstance();
  String buildDate = new SimpleDateFormat("dd MMM yyyy HH:ss", Locale.US).format(appInfo.getBuildDate().getTime());
  log.info("IDE: " + namesInfo.getFullProductName() + " (build #" + appInfo.getBuild() + ", " + buildDate + ")");
  log.info("OS: " + SystemInfoRt.OS_NAME + " (" + SystemInfoRt.OS_VERSION + ", " + SystemInfo.OS_ARCH + ")");
  log.info("JRE: " + System.getProperty("java.runtime.version", "-") + " (" + System.getProperty("java.vendor", "-") + ")");
  log.info("JVM: " + System.getProperty("java.vm.version", "-") + " (" + System.getProperty("java.vm.name", "-") + ")");

  List<String> arguments = ManagementFactory.getRuntimeMXBean().getInputArguments();
  if (arguments != null) {
    log.info("JVM Args: " + StringUtil.join(arguments, " "));
  }
}
 
Example #4
Source File: BashInterpreterDetection.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
@Nullable
public String findBestLocation() {
    List<String> locations = SystemInfo.isWindows ? POSSIBLE_EXE_LOCATIONS_WINDOWS : POSSIBLE_EXE_LOCATIONS;

    for (String guessLocation : locations) {
        if (isSuitable(guessLocation)) {
            return guessLocation;
        }
    }

    String pathLocation = OSUtil.findBestExecutable(SystemInfoRt.isWindows ? "bash.exe" : "bash");
    return isSuitable(pathLocation) ? pathLocation : null;
}
 
Example #5
Source File: ChangesBrowserFilePathNode.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static String getRelativePath(@javax.annotation.Nullable FilePath parent, @Nonnull FilePath child) {
  boolean isLocal = !child.isNonLocal();
  boolean caseSensitive = isLocal && SystemInfoRt.isFileSystemCaseSensitive;
  String result = parent != null ? FileUtil.getRelativePath(parent.getPath(), child.getPath(), '/', caseSensitive) : null;

  result = result == null ? child.getPath() : result;

  return isLocal ? FileUtil.toSystemDependentName(result) : result;
}
 
Example #6
Source File: URLUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@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 #7
Source File: PathUtilRt.java    From consulo with Apache License 2.0 5 votes vote down vote up
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 #8
Source File: Urls.java    From consulo with Apache License 2.0 5 votes vote down vote up
@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 #9
Source File: FileUtilRt.java    From consulo with Apache License 2.0 5 votes vote down vote up
@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 #10
Source File: FileUtilRt.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static boolean extensionEquals(@Nonnull String filePath, @Nonnull String extension) {
  int extLen = extension.length();
  if (extLen == 0) {
    int lastSlash = Math.max(filePath.lastIndexOf('/'), filePath.lastIndexOf('\\'));
    return filePath.indexOf('.', lastSlash + 1) == -1;
  }
  int extStart = filePath.length() - extLen;
  return extStart >= 1 && filePath.charAt(extStart - 1) == '.' && filePath.regionMatches(!SystemInfoRt.isFileSystemCaseSensitive, extStart, extension, 0, extLen);
}
 
Example #11
Source File: PathManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static Collection<String> getUtilClassPath() {
  final Class<?>[] classes = {PathManager.class,            // module 'util'
          Nonnull.class,                // module 'annotations'
          SystemInfoRt.class,           // module 'util-rt'
          Document.class,               // jDOM
          THashSet.class,               // trove4j
          TypeMapper.class,             // JNA
          FileUtils.class,              // JNA (jna-platform)
          PatternMatcher.class          // OROMatcher
  };

  final Set<String> classPath = new HashSet<String>();
  for (Class<?> aClass : classes) {
    final String path = getJarPathForClass(aClass);
    if (path != null) {
      classPath.add(path);
    }
  }

  final String resourceRoot = getResourceRoot(PathManager.class, "/messages/CommonBundle.properties");  // platform-resources-en
  if (resourceRoot != null) {
    classPath.add(new File(resourceRoot).getAbsolutePath());
  }

  return Collections.unmodifiableCollection(classPath);
}
 
Example #12
Source File: AttachExternalProjectAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Override
public void update(@Nonnull AnActionEvent e) {
  ProjectSystemId externalSystemId = e.getDataContext().getData(ExternalSystemDataKeys.EXTERNAL_SYSTEM_ID);
  if (externalSystemId != null) {
    String name = externalSystemId.getReadableName();
    e.getPresentation().setText(ExternalSystemBundle.message("action.attach.external.project.text", name));
    e.getPresentation().setDescription(ExternalSystemBundle.message("action.attach.external.project.description", name));
  }

  e.getPresentation().setIcon(SystemInfoRt.isMac ? AllIcons.ToolbarDecorator.Mac.Add : AllIcons.ToolbarDecorator.Add);
}
 
Example #13
Source File: ProjectCoreUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static boolean isProjectOrWorkspaceFile(@Nonnull VirtualFile file, @Nullable FileType fileType) {
  VirtualFile parent = file.isDirectory() ? file : file.getParent();
  while (parent != null) {
    if (Comparing.equal(parent.getNameSequence(), Project.DIRECTORY_STORE_FOLDER, SystemInfoRt.isFileSystemCaseSensitive)) return true;
    parent = parent.getParent();
  }
  return false;
}
 
Example #14
Source File: VfsUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static boolean equalsIgnoreParameters(@Nonnull Url url, @Nonnull VirtualFile file) {
  if (file.isInLocalFileSystem()) {
    return url.isInLocalFileSystem() && (SystemInfoRt.isFileSystemCaseSensitive ? url.getPath().equals(file.getPath()) : url.getPath().equalsIgnoreCase(file.getPath()));
  }
  else if (url.isInLocalFileSystem()) {
    return false;
  }

  Url fileUrl = Urls.parseUrlUnsafe(file.getUrl());
  return fileUrl != null && fileUrl.equalsIgnoreParameters(url);
}
 
Example #15
Source File: OSUtilTest.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
@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 #16
Source File: OSUtilTest.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
@Test
public void testFindBestExecutable() throws Exception {
    if (SystemInfoRt.isWindows) {
        String path = OSUtil.findBestExecutable("info");
        Assert.assertNotNull(path);
    }
}
 
Example #17
Source File: SystemInfopageDocSourceTest.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
@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 #18
Source File: CompletionProviderUtils.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
static Collection<LookupElement> createPathItems(List<String> osPathes) {
    return osPathes.stream()
            .map(path ->
                    //fix the windows file and directory pathes to be cygwin compatible
                    SystemInfoRt.isWindows ? OSUtil.toBashCompatible(path) : path
            )
            .map(path -> {
                int groupId = path.startsWith("/") ? CompletionGrouping.AbsoluteFilePath.ordinal() : CompletionGrouping.RelativeFilePath.ordinal();
                return PrioritizedLookupElement.withGrouping(createPathLookupElement(path, !path.endsWith("/")), groupId);
            }).collect(Collectors.toList());
}
 
Example #19
Source File: BundleBase.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static String replaceMnemonicAmpersand(@Nullable final String value) {
  if (value == null) {
    //noinspection ConstantConditions
    return null;
  }

  if (value.indexOf('&') >= 0) {
    boolean useMacMnemonic = value.contains("&&");
    StringBuilder realValue = new StringBuilder();
    int i = 0;
    while (i < value.length()) {
      char c = value.charAt(i);
      if (c == '\\') {
        if (i < value.length() - 1 && value.charAt(i + 1) == '&') {
          realValue.append('&');
          i++;
        }
        else {
          realValue.append(c);
        }
      }
      else if (c == '&') {
        if (i < value.length() - 1 && value.charAt(i + 1) == '&') {
          if (SystemInfoRt.isMac) {
            realValue.append(MNEMONIC);
          }
          i++;
        }
        else {
          if (!SystemInfoRt.isMac || !useMacMnemonic) {
            realValue.append(MNEMONIC);
          }
        }
      }
      else {
        realValue.append(c);
      }
      i++;
    }

    return realValue.toString();
  }
  return value;
}
 
Example #20
Source File: DetachExternalProjectAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
public DetachExternalProjectAction() {
  getTemplatePresentation().setText(ExternalSystemBundle.message("action.detach.external.project.text", "external"));
  getTemplatePresentation().setDescription(ExternalSystemBundle.message("action.detach.external.project.description"));
  getTemplatePresentation().setIcon(SystemInfoRt.isMac ? AllIcons.ToolbarDecorator.Mac.Remove : AllIcons.ToolbarDecorator.Remove);
}
 
Example #21
Source File: FileUtilRt.java    From consulo with Apache License 2.0 4 votes vote down vote up
@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 #22
Source File: FileUtilRt.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
public static String getRelativePath(@Nonnull String basePath, @Nonnull String filePath, char separator) {
  return getRelativePath(basePath, filePath, separator, SystemInfoRt.isFileSystemCaseSensitive);
}
 
Example #23
Source File: FileUtilRt.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
private static File normalizeFile(@Nonnull File temp) throws IOException {
  final File canonical = temp.getCanonicalFile();
  return SystemInfoRt.isWindows && canonical.getAbsolutePath().contains(" ") ? temp.getAbsoluteFile() : canonical;
}
 
Example #24
Source File: CompletionUtil.java    From BashSupport with Apache License 2.0 4 votes vote down vote up
/**
 * 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;
}