-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use coursier to fetch versions (#305)
- Loading branch information
Showing
65 changed files
with
496 additions
and
1,133 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/scala/ru/d10xa/jadd/coursier_/CoursierVersions.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package ru.d10xa.jadd.coursier_ | ||
|
||
import cats.Parallel | ||
import cats.effect.ContextShift | ||
import cats.effect.Sync | ||
import coursier.Repository | ||
import coursier.Versions | ||
import coursier.cache.CachePolicy | ||
import coursier.cache.FileCache | ||
import coursier.core | ||
import coursier.core.Module | ||
|
||
trait CoursierVersions[F[_]] { | ||
def versions(repositories: Seq[Repository], module: Module): F[core.Versions] | ||
} | ||
|
||
object CoursierVersions { | ||
def make[F[_]: Sync: Parallel: ContextShift]: F[CoursierVersions[F]] = | ||
Sync[F].delay(new CoursierVersions[F] { | ||
|
||
implicit val S: coursier.util.Sync[F] = coursier.interop.cats | ||
.coursierSyncFromCats(Sync[F], Parallel[F], ContextShift[F]) | ||
|
||
lazy val cache: FileCache[F] = FileCache[F]()(S).noCredentials | ||
.withCachePolicies(Seq(CachePolicy.ForceDownload)) | ||
|
||
override def versions( | ||
repositories: Seq[Repository], | ||
module: Module): F[core.Versions] = { | ||
Versions(cache) | ||
.withRepositories(repositories) | ||
.withModule(module) | ||
.versions() | ||
} | ||
|
||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package ru.d10xa.jadd | ||
|
||
import cats.data.NonEmptyList | ||
import cats.data.Validated | ||
import cats.data.Validated.Invalid | ||
import cats.data.Validated.Valid | ||
import coursier.util.ValidationNel | ||
|
||
object extensions { | ||
|
||
implicit class CoursierValidationNelExtension[L, R]( | ||
vnel: ValidationNel[L, R]) { | ||
def toCatsValidatedNel: Validated[NonEmptyList[L], R] = vnel.either match { | ||
case Left(h :: t) => Invalid(NonEmptyList(h, t)) | ||
case Right(value) => Valid(value) | ||
} | ||
} | ||
|
||
implicit class ValidatedNelStringOps[A]( | ||
vnel: Validated[NonEmptyList[String], A]) { | ||
import cats.syntax.foldable._ | ||
def joinNel: Validated[String, A] = | ||
vnel.leftMap { | ||
case NonEmptyList(head, Nil) => head | ||
case nel => nel.mkString_("(", ", ", ")") | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +0,0 @@ | ||
package ru.d10xa.jadd.repository | ||
|
||
import java.time.LocalDateTime | ||
import java.time.format.DateTimeFormatter | ||
|
||
import ru.d10xa.jadd.core.types.ScalaVersion | ||
import ru.d10xa.jadd.xml.MavenMetadataVersionsRawReader | ||
|
||
import scala.util.Try | ||
import scala.xml.Elem | ||
|
||
final case class MavenMetadata( | ||
url: Option[String] = None, | ||
repository: Option[String] = None, | ||
versions: Seq[String] = Seq.empty, | ||
lastUpdated: Option[String] = None, | ||
maybeScalaVersion: Option[ScalaVersion] = | ||
None // Metadata from newer to older (scala 2.12, 2.11..) | ||
) { | ||
lazy val lastUpdatedPretty: Option[String] = | ||
lastUpdated.map(MavenMetadata.lastUpdatedPretty) | ||
} | ||
|
||
object MavenMetadata { | ||
def readFromXml(from: MavenMetadata, root: Elem): MavenMetadata = from.copy( | ||
versions = MavenMetadataVersionsRawReader.versions(root), | ||
lastUpdated = MavenMetadataVersionsRawReader.lastUpdated(root) | ||
) | ||
def lastUpdatedPretty(lastUpdated: String): String = { | ||
val formatIn = DateTimeFormatter.ofPattern("yyyyMMddHHmmss") | ||
val formatOut = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss") | ||
def prettyPrintDateFormat(dateStr: String): String = | ||
Try(LocalDateTime.parse(dateStr, formatIn).format(formatOut)) | ||
.getOrElse(dateStr) | ||
prettyPrintDateFormat(lastUpdated) | ||
} | ||
} | ||
Oops, something went wrong.