static Path getOsSpecificManagedSdkHome()

in appengine-plugins-core/src/main/java/com/google/cloud/tools/managedcloudsdk/ManagedCloudSdk.java [234:273]


  static Path getOsSpecificManagedSdkHome(
      OsInfo.Name osName, Properties systemProperties, Map<String, String> environment) {
    Path userHome = Paths.get(systemProperties.getProperty("user.home"));
    Path cloudSdkPartialPath = Paths.get("google-cloud-tools-java", "managed-cloud-sdk");
    Path xdgPath = userHome.resolve(".cache").resolve(cloudSdkPartialPath);

    switch (osName) {
      case WINDOWS:
        // Shorter path to mitigate the length limit issue on Windows
        Path shortCloudSdkPartialPath = Paths.get("google", "ct4j-cloud-sdk");
        Path windowsXdgPath = userHome.resolve(".cache").resolve(shortCloudSdkPartialPath);

        String localAppDataEnv = environment.get("LOCALAPPDATA");
        if (localAppDataEnv == null || localAppDataEnv.trim().isEmpty()) {
          logger.warning("LOCALAPPDATA environment is invalid or missing");
          return windowsXdgPath;
        }
        Path localAppData = Paths.get(localAppDataEnv);
        if (!Files.exists(localAppData)) {
          logger.warning(localAppData.toString() + " does not exist");
          return windowsXdgPath;
        }
        return localAppData.resolve(shortCloudSdkPartialPath);

      case MAC:
        Path applicationSupport = userHome.resolve("Library").resolve("Application Support");
        if (!Files.exists(applicationSupport)) {
          logger.warning(applicationSupport.toString() + " does not exist");
          return xdgPath;
        }
        return applicationSupport.resolve(cloudSdkPartialPath);

      case LINUX:
        return xdgPath;

      default:
        // we can't actually get here unless we modify the enum OsInfo.Name
        throw new RuntimeException("OsName is not valid : " + osName);
    }
  }