diff --git a/modules/core/shared/src/main/scala/scaladex/core/api/Endpoints.scala b/modules/core/shared/src/main/scala/scaladex/core/api/Endpoints.scala index 19537888e..b12745fbb 100644 --- a/modules/core/shared/src/main/scala/scaladex/core/api/Endpoints.scala +++ b/modules/core/shared/src/main/scala/scaladex/core/api/Endpoints.scala @@ -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]] = diff --git a/modules/core/shared/src/main/scala/scaladex/core/model/Artifact.scala b/modules/core/shared/src/main/scala/scaladex/core/model/Artifact.scala index 48bc659a8..059240c8a 100644 --- a/modules/core/shared/src/main/scala/scaladex/core/model/Artifact.scala +++ b/modules/core/shared/src/main/scala/scaladex/core/model/Artifact.scala @@ -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 @@ -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 @@ -115,38 +123,48 @@ case class Artifact( */ def mavenInstall: Option[String] = platform match - case MillPlugin(_) | SbtPlugin(_) | ScalaNative(_) | ScalaJs(_) => None - case Jvm => - Some( - s"""| - | $groupId - | $artifactId - | $version - |""".stripMargin - ) + platform match { + case MillPlugin(_) | SbtPlugin(_) | ScalaNative(_) | ScalaJs(_) => None + case Jvm => + Some( + s"""| + | $groupId + | $artifactId + | $version + |""".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) @@ -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 @@ -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 diff --git a/modules/core/shared/src/main/scala/scaladex/core/model/Platform.scala b/modules/core/shared/src/main/scala/scaladex/core/model/Platform.scala index 67f732ef5..fa73b6f6d 100644 --- a/modules/core/shared/src/main/scala/scaladex/core/model/Platform.scala +++ b/modules/core/shared/src/main/scala/scaladex/core/model/Platform.scala @@ -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] = @@ -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 diff --git a/modules/core/shared/src/main/scala/scaladex/core/model/ProjectHeader.scala b/modules/core/shared/src/main/scala/scaladex/core/model/ProjectHeader.scala index 50753885f..8a71b9544 100644 --- a/modules/core/shared/src/main/scala/scaladex/core/model/ProjectHeader.scala +++ b/modules/core/shared/src/main/scala/scaladex/core/model/ProjectHeader.scala @@ -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 diff --git a/modules/core/shared/src/test/scala/scaladex/core/model/PlatformTests.scala b/modules/core/shared/src/test/scala/scaladex/core/model/PlatformTests.scala index 06de22c4c..a7a2642d5 100644 --- a/modules/core/shared/src/test/scala/scaladex/core/model/PlatformTests.scala +++ b/modules/core/shared/src/test/scala/scaladex/core/model/PlatformTests.scala @@ -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 diff --git a/modules/template/src/main/twirl/scaladex/view/project/headproject.scala.html b/modules/template/src/main/twirl/scaladex/view/project/headproject.scala.html index cc54efcbe..48b48c02c 100644 --- a/modules/template/src/main/twirl/scaladex/view/project/headproject.scala.html +++ b/modules/template/src/main/twirl/scaladex/view/project/headproject.scala.html @@ -96,13 +96,22 @@

} @if(header.latestMillVersions.nonEmpty){ -
{Artifact, BinaryVersion, Project, Version, UserState, Env} +
Mill plugins: @for(platform <- header.latestMillVersions.sorted.reverse) { @platform.version }
} + + @if(header.latestCompilerPluginVersions.nonEmpty){ +
+ Compiler plugins: + @for(platform <- header.latestCompilerPluginVersions.sorted.reverse) { + @platform.toString + } +
+ }
}