Java Code Examples for com.intellij.openapi.util.text.StringUtil#endsWithIgnoreCase()

The following examples show how to use com.intellij.openapi.util.text.StringUtil#endsWithIgnoreCase() . 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: PathManager.java    From dynkt with GNU Affero General Public License v3.0 5 votes vote down vote up
@Nullable
private static String extractRoot(URL resourceURL, String resourcePath) {
	if ((!StringUtil.startsWithChar(resourcePath, '/')) && (!StringUtil.startsWithChar(resourcePath, '\\'))) {
		log("precondition failed: " + resourcePath);
		return null;
	}
	String resultPath = null;
	String protocol = resourceURL.getProtocol();
	if ("file".equals(protocol)) {
		String path = resourceURL.getFile();
		String testPath = path.replace('\\', '/');
		String testResourcePath = resourcePath.replace('\\', '/');
		if (StringUtil.endsWithIgnoreCase(testPath, testResourcePath)) {
			resultPath = path.substring(0, path.length() - resourcePath.length());
		}
	} else if ("jar".equals(protocol)) {
		Pair<String, String> paths = URLUtil.splitJarUrl(resourceURL.getFile());
		if (paths != null) {
			resultPath = paths.first;
		}
	} else if ("bundle".equals(protocol)) {
		resultPath = (new File(
				(PathManager.class.getProtectionDomain().getCodeSource().getLocation() + "").replace("file:/", "")))
						.getAbsolutePath().replace('\\', '/');
	} else {
		throw new UnsupportedOperationException(
				"No '" + protocol + "' known! (" + resourceURL + ", " + resourcePath + ")");
	}
	if (resultPath == null) {
		log("cannot extract: " + resourcePath + " from " + resourceURL);
		return null;
	}
	if ((SystemInfo.isWindows) && (resultPath.startsWith("/"))) {
		resultPath = resultPath.substring(1);
	}
	resultPath = StringUtil.trimEnd(resultPath, File.separator);
	resultPath = URLUtil.unescapePercentSequences(resultPath);

	return resultPath;
}
 
Example 2
Source File: Restarter.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void restartOnMac(@Nonnull final String... beforeRestart) throws IOException {
  File distributionDirectory = ContainerPathManager.get().getAppHomeDirectory();

  File appDirectory = distributionDirectory.getParentFile();
  if (!StringUtil.endsWithIgnoreCase(appDirectory.getName(), ".app")) {
    throw new IOException("Application bundle not found: " + appDirectory.getPath());
  }

  doScheduleRestart(new File(ContainerPathManager.get().getBinPath(), "restarter"), appDirectory, commands -> {
    Collections.addAll(commands, appDirectory.getPath());
    Collections.addAll(commands, beforeRestart);
  });
}
 
Example 3
Source File: PathManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Attempts to extract classpath entry part from passed URL.
 */
@Nullable
@NonNls
private static String extractRoot(URL resourceURL, String resourcePath) {
  if (!(StringUtil.startsWithChar(resourcePath, '/') || StringUtil.startsWithChar(resourcePath, '\\'))) {
    //noinspection HardCodedStringLiteral,UseOfSystemOutOrSystemErr
    System.err.println("precondition failed: " + resourcePath);
    return null;
  }

  String resultPath = null;
  String protocol = resourceURL.getProtocol();
  if (URLUtil.FILE_PROTOCOL.equals(protocol)) {
    String path = resourceURL.getFile();
    String testPath = path.replace('\\', '/');
    String testResourcePath = resourcePath.replace('\\', '/');
    if (StringUtil.endsWithIgnoreCase(testPath, testResourcePath)) {
      resultPath = path.substring(0, path.length() - resourcePath.length());
    }
  }
  else if (URLUtil.JAR_PROTOCOL.equals(protocol)) {
    Pair<String, String> paths = URLUtil.splitJarUrl(resourceURL.getFile());
    if (paths != null) {
      resultPath = paths.first;
    }
  }

  if (resultPath == null) {
    //noinspection HardCodedStringLiteral,UseOfSystemOutOrSystemErr
    System.err.println("cannot extract: " + resourcePath + " from " + resourceURL);
    return null;
  }

  resultPath = StringUtil.trimEnd(resultPath, File.separator);
  resultPath = URLUtil.unescapePercentSequences(resultPath);

  return resultPath;
}
 
Example 4
Source File: AutoMatchStrategy.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected Collection<VirtualFile> filterVariants(final TextFilePatch patch, final Collection<VirtualFile> in) {
  String path = patch.getBeforeName() == null ? patch.getAfterName() : patch.getBeforeName();
  path = path.replace("\\", "/");

  final boolean caseSensitive = SystemInfo.isFileSystemCaseSensitive;
  final Collection<VirtualFile> result = new LinkedList<>();
  for (VirtualFile vf : in) {
    final String vfPath = vf.getPath();
    if ((caseSensitive && vfPath.endsWith(path)) || ((!caseSensitive) && StringUtil.endsWithIgnoreCase(vfPath, path))) {
      result.add(vf);
    }
  }
  return result;
}
 
Example 5
Source File: LafManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void installMacOSXFonts(UIDefaults defaults) {
  final String face = "Helvetica Neue";
  final FontUIResource uiFont = getFont(face, 13, Font.PLAIN);
  initFontDefaults(defaults, uiFont);
  for (Object key : new HashSet<>(defaults.keySet())) {
    if (!(key instanceof String)) continue;
    if (!StringUtil.endsWithIgnoreCase(((String)key), "font")) continue;
    Object value = defaults.get(key);
    if (value instanceof FontUIResource) {
      FontUIResource font = (FontUIResource)value;
      if (font.getFamily().equals("Lucida Grande") || font.getFamily().equals("Serif")) {
        if (!key.toString().contains("Menu")) {
          defaults.put(key, getFont(face, font.getSize(), font.getStyle()));
        }
      }
    }
  }

  FontUIResource uiFont11 = getFont(face, 11, Font.PLAIN);
  defaults.put("TableHeader.font", uiFont11);

  FontUIResource buttonFont = getFont("Helvetica Neue", 13, Font.PLAIN);
  defaults.put("Button.font", buttonFont);
  Font menuFont = getFont("Lucida Grande", 14, Font.PLAIN);
  defaults.put("Menu.font", menuFont);
  defaults.put("MenuItem.font", menuFont);
  defaults.put("MenuItem.acceleratorFont", menuFont);
  defaults.put("PasswordField.font", defaults.getFont("TextField.font"));
}
 
Example 6
Source File: WslDistributionDescriptor.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * @see #getMntRoot()
 */
@Nonnull
private String computeMntRoot() {
  String windowsCurrentDirectory = System.getProperty("user.dir");

  if (StringUtil.isEmpty(windowsCurrentDirectory) || windowsCurrentDirectory.length() < 3) {
    LOG.warn("Could not obtain current directory from user.dir (or path is too short): " + windowsCurrentDirectory);
    return WSLDistribution.DEFAULT_WSL_MNT_ROOT;
  }

  WSLDistribution distribution = WSLUtil.getDistributionById(getId());
  if (distribution == null) {
    return WSLDistribution.DEFAULT_WSL_MNT_ROOT;
  }
  ProcessOutput pwdOutput;
  try {
    pwdOutput = distribution.executeOnWsl(-1, "pwd");
  }
  catch (ExecutionException e) {
    LOG.warn("Error reading pwd output for " + getId(), e);
    return WSLDistribution.DEFAULT_WSL_MNT_ROOT;
  }

  if (pwdOutput.getExitCode() != 0) {
    LOG.info("Non-zero exit code while fetching pwd: " +
             "[id=" + getId() + "; " +
             "[exitCode=" + pwdOutput.getExitCode() + "; " +
             "[stderr=" + pwdOutput.getStderr() + "; " +
             "[stdout=" + pwdOutput.getStdout() + "]");
    return WSLDistribution.DEFAULT_WSL_MNT_ROOT;
  }

  List<String> pwdOutputLines = pwdOutput.getStdoutLines();

  if (pwdOutputLines.size() != 1) {
    LOG.warn("One line response expected from `pwd`: " +
             "[id=" + getId() + "; " +
             "exitCode=" + pwdOutput.getExitCode() + "; " +
             "stderr=" + pwdOutput.getStderr() + "; " +
             "stdout=" + pwdOutput.getStdout() + "]");
    return WSLDistribution.DEFAULT_WSL_MNT_ROOT;
  }

  String wslCurrentDirectory = pwdOutputLines.get(0).trim();

  String currentPathSuffix = WSLDistribution.convertWindowsPath(windowsCurrentDirectory);
  if (StringUtil.endsWithIgnoreCase(wslCurrentDirectory, currentPathSuffix)) {
    return StringUtil.trimEnd(wslCurrentDirectory, currentPathSuffix, true);
  }
  LOG.warn("Wsl current directory does not ends with windows converted suffix: " + "[pwd=" + wslCurrentDirectory + "; " + "suffix=" + currentPathSuffix + "]");
  return WSLDistribution.DEFAULT_WSL_MNT_ROOT;
}
 
Example 7
Source File: SystemHealthMonitor.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void checkEARuntime() {
  if (StringUtil.endsWithIgnoreCase(System.getProperty("java.version", ""), "-ea")) {
    showNotification(new KeyHyperlinkAdapter("unsupported.jvm.ea.message"));
  }
}
 
Example 8
Source File: XmlStringUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static boolean isWrappedInHtml(@Nonnull String tooltip) {
  return StringUtil.startsWithIgnoreCase(tooltip, HTML_START) &&
         StringUtil.endsWithIgnoreCase(tooltip, HTML_END);
}
 
Example 9
Source File: TodoView.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
static String getTabNameForChangeList(@Nonnull String changelistName) {
  changelistName = changelistName.trim();
  String suffix = "Changelist";
  return StringUtil.endsWithIgnoreCase(changelistName, suffix) ? changelistName : changelistName + " " + suffix;
}