public Map findShells()

in powershell-agent/src/main/java/jetbrains/buildServer/powershell/agent/detect/cmd/CommandLinePowerShellDetector.java [83:123]


  public Map<String, PowerShellInfo> findShells(Set<String> skipPaths) {
    LOG.info("Detecting PowerShell using CommandLinePowerShellDetector");
    // group by home
    final Map<String, PowerShellInfo> shells = new HashMap<>();
    final List<String> pathsToCheck = myDetectionPaths
      .getPaths()
      .stream()
      .filter(path -> !skipPaths.contains(path))
      .collect(Collectors.toList());
    if (LOG.isDebugEnabled()) {
      LOG.debug("Will be detecting PowerShell in the following locations: [\n" + StringUtil.join(pathsToCheck, "\n") + "\n");
    }

    File script = null;
    try {
      script = prepareDetectionScript();
      if (script != null) {
        final String scriptPath = script.getAbsolutePath();
        if (LOG.isDebugEnabled()) {
          LOG.info("Detection script path is: " + scriptPath);
        }
        // try release versions. powershell has already been renamed to pwsh.
        // pwsh-preview is used for -preview versions of powershell core
        LOG.debug("Detecting PowerShell.Core...");
        doDetectionCycle(shells, pathsToCheck, SystemInfo.isWindows ? EXECUTABLES_WIN : EXECUTABLES_NIX, scriptPath);
        // handle the case when JetRegistry.exe could not be executed. Try to search for desktop edition inside given paths
        if (SystemInfo.isWindows) {
          doDetectionCycle(shells, pathsToCheck, EXECUTABLES_WIN_DESKTOP, scriptPath, WIN_ADDITIONAL_PARAMETERS);
        }
        if (shells.isEmpty() && !SystemInfo.isWindows) {
          LOG.debug("No release versions of PowerShell.Core were detected. Trying to detect legacy and beta versions...");
          doDetectionCycle(shells, pathsToCheck, EXECUTABLES_NIX_LEGACY, scriptPath);
        }
      }
      return shells;
    } finally {
      if (script != null) {
        FileUtil.delete(script);
      }
    }
  }