Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ trait Endpoints extends JsonSchemas with endpoints4s.algebra.Endpoints with endp

private val platformFilters = qs[Seq[Platform]](
"platform",
qsDoc("Filter on platform versions", Seq("jvm", "sjs1", "native0.5", "sbt1", "mill0.11"))
qsDoc("Filter on platform versions", Seq("jvm", "sjs1", "native0.5", "sbt1", "mill0.11", "compiler-plugin"))
)

private val binaryVersionFilters: QueryString[Seq[BinaryVersion]] =
Expand Down
139 changes: 84 additions & 55 deletions modules/core/shared/src/main/scala/scaladex/core/model/Artifact.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,21 @@ case class Artifact(

def sbtInstall: Option[String] =
val install = platform match
case SbtPlugin(_) => Some(s"""addSbtPlugin("$groupId" % "$name" % "$version")""")
case MillPlugin(_) => None
case _ if isNonStandardLib => Some(s"""libraryDependencies += "$groupId" % "$artifactId" % "$version"""")
case ScalaJs(_) | ScalaNative(_) =>
Some(s"""libraryDependencies += "$groupId" %%% "$name" % "$version"""")
case Jvm =>
language match
case Java => Some(s"""libraryDependencies += "$groupId" % "$name" % "$version"""")
case Scala(Version.Patch(_, _, _)) =>
Some(s"""libraryDependencies += "$groupId" % "$name" % "$version" cross CrossVersion.full""")
case _ => Some(s"""libraryDependencies += "$groupId" %% "$name" % "$version"""")
val install = platform match {
case SbtPlugin(_) => Some(s"""addSbtPlugin("$groupId" % "$name" % "$version")""")
case MillPlugin(_) => None
case _ if isNonStandardLib => Some(s"""libraryDependencies += "$groupId" % "$artifactId" % "$version"""")
case ScalaJs(_) | ScalaNative(_) =>
Some(s"""libraryDependencies += "$groupId" %%% "$name" % "$version"""")
case Jvm =>
language match {
case Java => Some(s"""libraryDependencies += "$groupId" % "$name" % "$version"""")
case Scala(Version.Patch(_, _, _)) =>
Some(s"""libraryDependencies += "$groupId" % "$name" % "$version" cross CrossVersion.full""")
case _ => Some(s"""libraryDependencies += "$groupId" %% "$name" % "$version"""")
}
case CompilerPlugin => throw new UnsupportedOperationException("CompilerPlugin not supported in sbtInstall")
}

(install, resolver.flatMap(_.sbt)) match
case (None, _) => None
Expand All @@ -96,13 +100,17 @@ case class Artifact(
|interp.resolvers() = interp.resolvers() :+ res""".stripMargin

val install = platform match
case MillPlugin(_) | SbtPlugin(_) | ScalaNative(_) | ScalaJs(_) => None
case Jvm =>
language match
case _ if isNonStandardLib => Some(s"import $$ivy.`$groupId:$artifactId:$version`")
case Java => Some(s"import $$ivy.`$groupId:$artifactId:$version`")
case Scala(Version.Patch(_, _, _)) => Some(s"import $$ivy.`$groupId:::$name:$version`")
case _ => Some(s"import $$ivy.`$groupId::$name:$version`")
val install = platform match {
case MillPlugin(_) | SbtPlugin(_) | ScalaNative(_) | ScalaJs(_) => None
case Jvm =>
language match {
case _ if isNonStandardLib => Some(s"import $$ivy.`$groupId:$artifactId:$version`")
case Java => Some(s"import $$ivy.`$groupId:$artifactId:$version`")
case Scala(Version.Patch(_, _, _)) => Some(s"import $$ivy.`$groupId:::$name:$version`")
case _ => Some(s"import $$ivy.`$groupId::$name:$version`")
}
case CompilerPlugin => throw new UnsupportedOperationException("CompilerPlugin not supported in ammInstall")
}

(install, resolver.map(addResolver)) match
case (None, _) => None
Expand All @@ -115,38 +123,48 @@ case class Artifact(
*/
def mavenInstall: Option[String] =
platform match
case MillPlugin(_) | SbtPlugin(_) | ScalaNative(_) | ScalaJs(_) => None
case Jvm =>
Some(
s"""|<dependency>
| <groupId>$groupId</groupId>
| <artifactId>$artifactId</artifactId>
| <version>$version</version>
|</dependency>""".stripMargin
)
platform match {
case MillPlugin(_) | SbtPlugin(_) | ScalaNative(_) | ScalaJs(_) => None
case Jvm =>
Some(
s"""|<dependency>
| <groupId>$groupId</groupId>
| <artifactId>$artifactId</artifactId>
| <version>$version</version>
|</dependency>""".stripMargin
)
case CompilerPlugin => throw new UnsupportedOperationException("CompilerPlugin not supported in mavenInstall")
}

/** string representation for gradle dependency
* @return
*/
def gradleInstall: Option[String] =
platform match
case MillPlugin(_) | SbtPlugin(_) | ScalaNative(_) | ScalaJs(_) => None
case Jvm => Some(s"compile group: '$groupId', name: '$artifactId', version: '$version'")
platform match {
case MillPlugin(_) | SbtPlugin(_) | ScalaNative(_) | ScalaJs(_) => None
case Jvm => Some(s"compile group: '$groupId', name: '$artifactId', version: '$version'")
case CompilerPlugin => throw new UnsupportedOperationException("CompilerPlugin not supported in gradleInstall")
}

/** string representation for mill dependency
* @return
*/
def millInstall: Option[String] =
val install = platform match
case MillPlugin(_) => Some(s"import $$ivy.`$groupId::$name::$version`")
case SbtPlugin(_) => None
case ScalaNative(_) | ScalaJs(_) => Some(s"""ivy"$groupId::$name::$version"""")
case Jvm =>
language match
case _ if isNonStandardLib => Some(s"""ivy"$groupId:$artifactId:$version"""")
case Java => Some(s"""ivy"$groupId:$artifactId:$version"""")
case Scala(Version.Patch(_, _, _)) => Some(s"""ivy"$groupId:::$name:$version"""")
case _ => Some(s"""ivy"$groupId::$name:$version"""")
val install = platform match {
case MillPlugin(_) => Some(s"import $$ivy.`$groupId::$name::$version`")
case SbtPlugin(_) => None
case ScalaNative(_) | ScalaJs(_) => Some(s"""ivy"$groupId::$name::$version"""")
case Jvm =>
language match {
case _ if isNonStandardLib => Some(s"""ivy"$groupId:$artifactId:$version"""")
case Java => Some(s"""ivy"$groupId:$artifactId:$version"""")
case Scala(Version.Patch(_, _, _)) => Some(s"""ivy"$groupId:::$name:$version"""")
case _ => Some(s"""ivy"$groupId::$name:$version"""")
}
case CompilerPlugin => throw new UnsupportedOperationException("CompilerPlugin not supported in millInstall")
}
(install, resolver.flatMap(_.url)) match
case (None, _) => None
case (Some(install), None) => Some(install)
Expand All @@ -159,25 +177,33 @@ case class Artifact(

def scalaCliInstall: Option[String] =
binaryVersion.platform match
case MillPlugin(_) | SbtPlugin(_) => None
case ScalaNative(_) | ScalaJs(_) => Some(s"""//> using dep "$groupId::$name::$version"""")
case Jvm =>
language match
case _ if isNonStandardLib => Some(s"""//> using dep "$groupId:$artifactId:$version"""")
case Java => Some(s"""//> using dep "$groupId:$artifactId:$version"""")
case Scala(Version.Patch(_, _, _)) => Some(s"""//> using dep "$groupId:::$name:$version"""")
case _ => Some(s"""//> using dep "$groupId::$name:$version"""")
binaryVersion.platform match {
case MillPlugin(_) | SbtPlugin(_) => None
case ScalaNative(_) | ScalaJs(_) => Some(s"""//> using dep "$groupId::$name::$version"""")
case Jvm =>
language match {
case _ if isNonStandardLib => Some(s"""//> using dep "$groupId:$artifactId:$version"""")
case Java => Some(s"""//> using dep "$groupId:$artifactId:$version"""")
case Scala(Version.Patch(_, _, _)) => Some(s"""//> using dep "$groupId:::$name:$version"""")
case _ => Some(s"""//> using dep "$groupId::$name:$version"""")
}
case CompilerPlugin => throw new UnsupportedOperationException("CompilerPlugin not supported in scalaCliInstall")
}

def csLaunch: Option[String] =
platform match
case MillPlugin(_) | SbtPlugin(_) => None
case ScalaNative(_) | ScalaJs(_) => Some(s"cs launch $groupId::$name::$version")
case Jvm =>
language match
case _ if isNonStandardLib => Some(s"cs launch $groupId:$artifactId:$version")
case Java => Some(s"cs launch $groupId:$artifactId:$version")
case Scala(Version.Patch(_, _, _)) => Some(s"cs launch $groupId:::$name:$version")
case _ => Some(s"cs launch $groupId::$name:$version")
platform match {
case MillPlugin(_) | SbtPlugin(_) => None
case ScalaNative(_) | ScalaJs(_) => Some(s"cs launch $groupId::$name::$version")
case Jvm =>
language match {
case _ if isNonStandardLib => Some(s"cs launch $groupId:$artifactId:$version")
case Java => Some(s"cs launch $groupId:$artifactId:$version")
case Scala(Version.Patch(_, _, _)) => Some(s"cs launch $groupId:::$name:$version")
case _ => Some(s"cs launch $groupId::$name:$version")
}
case CompilerPlugin => throw new UnsupportedOperationException("CompilerPlugin not supported in csLaunch")
}

def defaultScaladoc: Option[String] =
resolver match
Expand Down Expand Up @@ -229,7 +255,10 @@ case class Artifact(
end Artifact

object Artifact:
private val dateFormatter = DateTimeFormatter.ofPattern("MMM d, uuuu").withZone(ZoneOffset.UTC)
val dateFormatter = DateTimeFormatter.ofPattern("MMM d, uuuu").withZone(ZoneOffset.UTC)

type Name = Artifact.Name
type Reference = Artifact.Reference

case class Name(value: String) extends AnyVal:
override def toString: String = value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,20 @@ object MillPlugin:

given ordering: Ordering[MillPlugin] = Ordering.by(p => p.asInstanceOf[Platform])


case object CompilerPlugin extends Platform:
override def toString: String = "Compiler Plugin"
override def value: String = "compiler-plugin"
override def isValid: Boolean = true

object Platform:
given ordering: Ordering[Platform] = Ordering.by {
case Jvm => (5, None)
case ScalaJs(version) => (4, Some(version))
case ScalaNative(version) => (3, Some(version))
case SbtPlugin(version) => (2, Some(version))
case MillPlugin(version) => (1, Some(version))
case Jvm => (6, None)
case ScalaJs(version) => (5, Some(version))
case ScalaNative(version) => (4, Some(version))
case SbtPlugin(version) => (3, Some(version))
case MillPlugin(version) => (2, Some(version))
case CompilerPlugin => (1, None)
}

def parse(input: String): Option[Platform] =
Expand All @@ -89,5 +96,6 @@ object Platform:
case s"native$version" => Version.parseSemantically(version).map(ScalaNative.apply)
case s"sbt$version" => Version.parseSemantically(version).map(SbtPlugin.apply)
case s"mill$version" => Version.parseSemantically(version).map(MillPlugin.apply)
case "compiler-plugin" => Some(CompilerPlugin)
case _ => None
end Platform
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,5 @@ final case class ProjectHeader(
def latestScalaNativeVersions: Seq[ScalaNative] = latestPlatforms.collect { case v: ScalaNative => v }
def latestSbtVersions: Seq[SbtPlugin] = latestPlatforms.collect { case v: SbtPlugin => v }
def latestMillVersions: Seq[MillPlugin] = latestPlatforms.collect { case v: MillPlugin => v }
def latestCompilerPluginVersions: Seq[CompilerPlugin] = latestPlatforms.collect { case v: CompilerPlugin => v }
end ProjectHeader
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ class PlatformTests extends AnyFunSpec with Matchers:
Version.SemanticLike(2, Some(0), Some(0), preRelease = Some(Milestone(2)))
)
Platform.parse("mill0.10").get shouldBe MillPlugin.`0.10`
Platform.parse("compiler-plugin").get shouldBe CompilerPlugin
}
end PlatformTests
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,22 @@ <h1>
}

@if(header.latestMillVersions.nonEmpty){
<div>{Artifact, BinaryVersion, Project, Version, UserState, Env}
<div>
Mill plugins:
@for(platform <- header.latestMillVersions.sorted.reverse) {
<a href="@header.versionsUrl(platform)" class="targets">@platform.version</a>
}
</div>
}

@if(header.latestCompilerPluginVersions.nonEmpty){
<div>
Compiler plugins:
@for(platform <- header.latestCompilerPluginVersions.sorted.reverse) {
<a href="@header.versionsUrl(platform)" class="targets">@platform.toString</a>
}
</div>
}
</div>
}
</div>
Expand Down
Loading