All Downloads are FREE. Search and download functionalities are using the official Maven repository.

mdoc.internal.markdown.Instrumented.scala Maven / Gradle / Ivy

There is a newer version: 2.6.1
Show newest version
package mdoc.internal.markdown

import coursierapi.Dependency
import mdoc.internal.BuildInfo
import scala.util.matching.Regex
import scala.meta.Name
import scala.collection.mutable
import coursierapi.IvyRepository
import coursierapi.Repository
import coursierapi.MavenRepository
import mdoc.Reporter
import scala.util.Failure
import scala.util.Success
import coursierapi.error.CoursierError

case class Instrumented(
    source: String,
    scalacOptionImports: List[Name.Indeterminate],
    dependencyImports: List[Name.Indeterminate],
    repositoryImports: List[Name.Indeterminate],
    fileImports: List[FileImport],
    positionedDependencies: List[PositionedDependency],
    dependencies: Set[Dependency],
    repositories: List[Repository]
)

object Instrumented {
  def fromSource(
      source: String,
      scalacOptionImports: List[Name.Indeterminate],
      dependencyImports: List[Name.Indeterminate],
      repositoryImports: List[Name.Indeterminate],
      fileImports: List[FileImport],
      reporter: Reporter
  ): Instrumented = {
    val positioned = dependencyImports.flatMap(i => PositionedDependency.fromName(i, reporter))
    val dependencies = positioned.map(_.dep).toSet
    val repositories =
      for {
        name <- repositoryImports
        repo <- SharedRepositoryParser.repository(name.value) match {
          case Failure(exception) =>
            exception match {
              case _: CoursierError =>
                reporter.error(name.pos, exception.getMessage())
              case _ =>
                reporter.error(name.pos, exception)
            }
            Nil
          case Success(value) =>
            List(value)
        }
      } yield repo
    Instrumented(
      source,
      scalacOptionImports,
      dependencyImports,
      repositoryImports,
      fileImports,
      positioned,
      dependencies,
      repositories
    )
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy