コード例 #1
0
  /**
   * Returns the Shell command path.
   *
   * @return The shell command path.
   */
  public static String getShellPath() {
    try {
      IPath path = ShellExecutable.getPath();
      if (path != null) {
        return path.toOSString();
      }
    } catch (CoreException e) {
      IdeLog.logError(ConfigurationsPlugin.getDefault(), e);
    }

    return null;
  }
コード例 #2
0
ファイル: GitIndex.java プロジェクト: unbug/studio3
 private IStatus doCommit(String commitMessage) {
   if (Platform.OS_WIN32.equals(Platform.getOS())) {
     commitMessage = commitMessage.replace("\"", "\\\""); // $NON-NLS-1$ //$NON-NLS-2$
   }
   return repository.execute(
       GitRepository.ReadWrite.WRITE,
       repository.workingDirectory(),
       ShellExecutable.getEnvironment(repository.workingDirectory()),
       "commit",
       "-m",
       commitMessage); //$NON-NLS-1$ //$NON-NLS-2$
 }
  /**
   * @param executableName name of the binary.
   * @param appendExtension ".exe" is appended for windows when searching the PATH.
   * @param searchLocations Common locations to search.
   * @param filter File filter
   * @param workingDirectory
   * @return
   */
  public static IPath find(
      String executableName,
      boolean appendExtension,
      List<IPath> searchLocations,
      FileFilter filter,
      IPath workingDirectory) {
    if (executableName == null) {
      return null;
    }

    // Grab PATH from shell if possible
    Map<String, String> env = ShellExecutable.getEnvironment(workingDirectory);
    String pathENV;
    if (env != null && env.containsKey(PATH)) {
      pathENV = PathUtil.convertPATH(env.get(PATH));
    } else {
      pathENV = System.getenv(PATH);
    }

    boolean infoLoggingEnabled = IdeLog.isInfoEnabled(CorePlugin.getDefault(), IDebugScopes.SHELL);
    // Grab PATH...
    String[] paths = pathENV.split(File.pathSeparator);
    if (infoLoggingEnabled) {
      IdeLog.logInfo(
          CorePlugin.getDefault(),
          MessageFormat.format(
              "Searching for {0} in PATH locations: {1}",
              executableName, StringUtil.join(", ", paths)),
          IDebugScopes.SHELL); // $NON-NLS-1$ //$NON-NLS-2$
    }
    // Now search the PATH locations
    for (String pathString : paths) {
      IPath path = Path.fromOSString(pathString).append(executableName);
      IPath result = findExecutable(path, appendExtension);
      if (result != null && (filter == null || filter.accept(result.toFile()))) {
        if (infoLoggingEnabled) {
          IdeLog.logInfo(
              CorePlugin.getDefault(),
              MessageFormat.format("Found executable on PATH: {0}", result),
              IDebugScopes.SHELL); // $NON-NLS-1$
        }
        return result;
      }
    }

    // Still no path. Let's try some default locations.
    if (searchLocations != null) {
      for (IPath location : searchLocations) {
        IPath result = findExecutable(location.append(executableName), appendExtension);
        if (result != null && (filter == null || filter.accept(result.toFile()))) {
          if (infoLoggingEnabled) {
            IdeLog.logInfo(
                CorePlugin.getDefault(),
                MessageFormat.format("Found executable at common location: {0}", result),
                IDebugScopes.SHELL); // $NON-NLS-1$
          }
          return result;
        }
      }
    }

    return null;
  }