<commit_before>package org.jetbrains.plugins.scala
package project
package template

import com.intellij.openapi.progress.ProcessCanceledException
import com.intellij.openapi.ui.Messages
import org.apache.ivy.util.MessageLogger
import org.jetbrains.plugins.scala.components.libextensions.ProgressIndicatorLogger
import org.jetbrains.plugins.scala.extensions.{IterableOnceExt, withProgressSynchronouslyTry}
import org.jetbrains.plugins.scala.project.template.ScalaVersionDownloadingDialog.{ScalaVersionResolveResult, preselectLatestScala2Version}
import org.jetbrains.sbt.project.template.SComboBox

import java.awt.Point
import java.io.File
import javax.swing.{JComponent, JPopupMenu, JScrollPane}
import scala.util.Try

final class ScalaVersionDownloadingDialog(parent: JComponent) extends VersionDialogBase(parent) {

  {
    init()

    setTitle(ScalaBundle.message("title.download"))
    myVersion.setTextRenderer(Version.abbreviate)

    val versions = Versions.Scala.loadVersionsWithProgress().versions
    if (versions.nonEmpty) {
      myVersion.setItems(versions.toArray)
      preselectLatestScala2Version(myVersion, versions)
    }
    else
      Messages.showErrorDialog(
        createCenterPanel(),
        ScalaBundle.message("no.versions.available.for.download"),
        ScalaBundle.message("title.error.downloading.scala.libraries")
      )
  }

  def showAndGetSelected(): Option[ScalaVersionResolveResult] =
    if (showAndGet()) {
      val scalaVersionStr = myVersion.getSelectedItem.asInstanceOf[String]
      val scalaVersion = ScalaVersion.fromString(scalaVersionStr).getOrElse {
        Messages.showErrorDialog(
          parent,
          ScalaBundle.message("invalid.scala.version.format", scalaVersionStr),
          ScalaBundle.message("error.downloading.scala.version", scalaVersionStr)
        )
        return None
      }

      val tri: Try[ScalaVersionResolveResult] = withProgressSynchronouslyTry(ScalaBundle.message("downloading.scala.version", scalaVersion), canBeCanceled = true) { manager =>
        import DependencyManagerBase._
        val dependencyManager = new DependencyManagerBase {
          override def createLogger: MessageLogger = new ProgressIndicatorLogger(manager.getProgressIndicator)
          override val artifactBlackList: Set[String] = Set.empty
        }

        val (compiler, librarySources) = (
          DependencyDescription.scalaArtifact("compiler", scalaVersion).transitive(),
          // scala3-library has also dependency on scala-library, so set transitive
          DependencyDescription.scalaArtifact("library", scalaVersion).transitive().sources(),
        )
        val compilerClasspathResolveResult = dependencyManager.resolve(compiler)
        // ATTENTION:
        // Sources jars should be resolved in a separate request to dependency manager
        // Otherwise resolved jars will contain only "sources" jar, without "classes"
        val librarySourcesResolveResult = dependencyManager.resolve(librarySources)

        ScalaVersionResolveResult(
          scalaVersion.minor,
          compilerClasspathResolveResult.map(_.file),
          librarySourcesResolveResult.map(_.file)
        )<commit_msg>ScalaVersionDownloadingDialog: use scala version string instead of case class<commit_after>package org.jetbrains.plugins.scala
package project
package template

import com.intellij.openapi.progress.ProcessCanceledException
import com.intellij.openapi.ui.Messages
import org.apache.ivy.util.MessageLogger
import org.jetbrains.plugins.scala.components.libextensions.ProgressIndicatorLogger
import org.jetbrains.plugins.scala.extensions.{IterableOnceExt, withProgressSynchronouslyTry}
import org.jetbrains.plugins.scala.project.template.ScalaVersionDownloadingDialog.{ScalaVersionResolveResult, preselectLatestScala2Version}
import org.jetbrains.sbt.project.template.SComboBox

import java.awt.Point
import java.io.File
import javax.swing.{JComponent, JPopupMenu, JScrollPane}
import scala.util.Try

final class ScalaVersionDownloadingDialog(parent: JComponent) extends VersionDialogBase(parent) {

  {
    init()

    setTitle(ScalaBundle.message("title.download"))
    myVersion.setTextRenderer(Version.abbreviate)

    val versions = Versions.Scala.loadVersionsWithProgress().versions
    if (versions.nonEmpty) {
      myVersion.setItems(versions.toArray)
      preselectLatestScala2Version(myVersion, versions)
    }
    else
      Messages.showErrorDialog(
        createCenterPanel(),
        ScalaBundle.message("no.versions.available.for.download"),
        ScalaBundle.message("title.error.downloading.scala.libraries")
      )
  }

  def showAndGetSelected(): Option[ScalaVersionResolveResult] =
    if (showAndGet()) {
      val scalaVersionStr = myVersion.getSelectedItem.asInstanceOf[String]
      val scalaVersion = ScalaVersion.fromString(scalaVersionStr).getOrElse {
        Messages.showErrorDialog(
          parent,
          ScalaBundle.message("invalid.scala.version.format", scalaVersionStr),
          ScalaBundle.message("error.downloading.scala.version", scalaVersionStr)
        )
        return None
      }

      val tri: Try[ScalaVersionResolveResult] = withProgressSynchronouslyTry(ScalaBundle.message("downloading.scala.version", scalaVersionStr), canBeCanceled = true) { manager =>
        import DependencyManagerBase._
        val dependencyManager = new DependencyManagerBase {
          override def createLogger: MessageLogger = new ProgressIndicatorLogger(manager.getProgressIndicator)
          override val artifactBlackList: Set[String] = Set.empty
        }

        val (compiler, librarySources) = (
          DependencyDescription.scalaArtifact("compiler", scalaVersion).transitive(),
          // scala3-library has also dependency on scala-library, so set transitive
          DependencyDescription.scalaArtifact("library", scalaVersion).transitive().sources(),
        )
        val compilerClasspathResolveResult = dependencyManager.resolve(compiler)
        // ATTENTION:
        // Sources jars should be resolved in a separate request to dependency manager
        // Otherwise resolved jars will contain only "sources" jar, without "classes"
        val librarySourcesResolveResult = dependencyManager.resolve(librarySources)

        ScalaVersionResolveResult(
          scalaVersion.minor,
          compilerClasspathResolveResult.map(_.file),
          librarySourcesResolveResult.map(_.file)
        )
{'fraction_non_alphanumeric': 0.08391499922444548, 'fraction_numerical': 0.0009306654257794323, 'mean_word_length': 4.025720966484801, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 15, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7065011', 'n_tokens_mistral': 1737, 'n_tokens_neox': 1683, 'n_words': 302}