private def detectOldSdksAndBuildWarningMessage()

in ideaSupport/src/main/scala/org/jetbrains/sbtidea/download/cachesCleanup/OldSdkCleanup.scala [58:88]


  private def detectOldSdksAndBuildWarningMessage(
    cachedSdksReport: CachedSdksReport,
  ): Option[OldSdksWithWarningMessage] = {
    val sdks = cachedSdksReport.sdkInfos

    val oldSdks = OldSdkDetector.detectOldSdks(sdks)
    if (oldSdks.isEmpty) {
      logger.debug("No old cached IntelliJ SDK directories found for cleanup")
      return None
    }

    val totalSizeBytes: Long = oldSdks.map(sdk => FileUtils.getDirectorySize(sdk.directory)).sum
    val totalSizeFormatted = CleanupUtils.formatSize(totalSizeBytes)

    val otherSdks = sdks.filterNot(oldSdks.contains)

    //first display newer then older
    val oldSdksPresentableList = CleanupUtils.buildPresentableList(oldSdks.sortBy(_.dirInfo.creationDate).reverse, presentSdkVersionWithCreationDateHint)
    val otherSdksPresentableList = CleanupUtils.buildPresentableList(otherSdks.sortBy(_.dirInfo.creationDate).reverse, presentSdkVersionWithCreationDateHint)

    val warningMessage =
      s"""Detected ${oldSdks.size} old IntelliJ SDK directories in ${cachedSdksReport.baseDirectory.toAbsolutePath}
         |Total size: $totalSizeFormatted
         |Old SDKs:
         |$oldSdksPresentableList
         |Remaining SDKs:
         |$otherSdksPresentableList
         |""".stripMargin.trim

    Some(OldSdksWithWarningMessage(oldSdks, warningMessage))
  }