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 @@ -40,6 +40,7 @@ case class Artifact(
val sep = binaryVersion match
case BinaryVersion(Jvm, Java) | BinaryVersion(SbtPlugin(_), _) => ":"
case BinaryVersion(ScalaJs(_) | ScalaNative(_), _) => ":::"
case BinaryVersion(CompilerPlugin(_), _) => "::"
case _ => "::"
s"$groupId$sep$name"

Expand All @@ -60,6 +61,7 @@ case class Artifact(

def sbtInstall: Option[String] =
val install = platform match
case CompilerPlugin(_) => Some(s"""addCompilerPlugin("$groupId" % "$artifactId" % "$version")""")
case SbtPlugin(_) => Some(s"""addSbtPlugin("$groupId" % "$name" % "$version")""")
case MillPlugin(_) => None
case _ if isNonStandardLib => Some(s"""libraryDependencies += "$groupId" % "$artifactId" % "$version"""")
Expand Down Expand Up @@ -96,7 +98,7 @@ case class Artifact(
|interp.resolvers() = interp.resolvers() :+ res""".stripMargin

val install = platform match
case MillPlugin(_) | SbtPlugin(_) | ScalaNative(_) | ScalaJs(_) => None
case CompilerPlugin(_) | MillPlugin(_) | SbtPlugin(_) | ScalaNative(_) | ScalaJs(_) => None
case Jvm =>
language match
case _ if isNonStandardLib => Some(s"import $$ivy.`$groupId:$artifactId:$version`")
Expand All @@ -115,7 +117,7 @@ case class Artifact(
*/
def mavenInstall: Option[String] =
platform match
case MillPlugin(_) | SbtPlugin(_) | ScalaNative(_) | ScalaJs(_) => None
case CompilerPlugin(_) | MillPlugin(_) | SbtPlugin(_) | ScalaNative(_) | ScalaJs(_) => None
case Jvm =>
Some(
s"""|<dependency>
Expand All @@ -130,16 +132,16 @@ case class Artifact(
*/
def gradleInstall: Option[String] =
platform match
case MillPlugin(_) | SbtPlugin(_) | ScalaNative(_) | ScalaJs(_) => None
case CompilerPlugin(_) | MillPlugin(_) | SbtPlugin(_) | ScalaNative(_) | ScalaJs(_) => None
case Jvm => Some(s"compile group: '$groupId', name: '$artifactId', version: '$version'")

/** string representation for mill dependency
* @return
*/
def millInstall: Option[String] =
val install = platform match
case CompilerPlugin(_) | SbtPlugin(_) => None
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
Expand All @@ -159,7 +161,7 @@ case class Artifact(

def scalaCliInstall: Option[String] =
binaryVersion.platform match
case MillPlugin(_) | SbtPlugin(_) => None
case CompilerPlugin(_) | MillPlugin(_) | SbtPlugin(_) => None
case ScalaNative(_) | ScalaJs(_) => Some(s"""//> using dep "$groupId::$name::$version"""")
case Jvm =>
language match
Expand All @@ -170,7 +172,7 @@ case class Artifact(

def csLaunch: Option[String] =
platform match
case MillPlugin(_) | SbtPlugin(_) => None
case CompilerPlugin(_) | MillPlugin(_) | SbtPlugin(_) => None
case ScalaNative(_) | ScalaJs(_) => Some(s"cs launch $groupId::$name::$version")
case Jvm =>
language match
Expand All @@ -190,6 +192,7 @@ case class Artifact(
val targetParam = platform match
case ScalaJs(_) => Some("t" -> "JS")
case Jvm => Some("t" -> "JVM")
case CompilerPlugin(_) => None
case _ => None

val scalaVersionParam = language match
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ final case class BinaryVersion(platform: Platform, language: Language):
case Version.Major(1) => s"_${sv.value}_1.0"
case Version.Minor(0, 13) => s"_${sv.value}_0.13"
case sbtV => s"_sbt${sbtV.value}_${sv.value}"
case (CompilerPlugin(fullScalaVersion), _) => s"_${fullScalaVersion.value}"
case (platform, language) => s"_${platform.value}_${language.value}"

override def toString: String = platform match
case Jvm => language.toString
case p: SbtPlugin => p.toString
case p: MillPlugin => p.toString
case p: CompilerPlugin => s"CompilerPlugin (${p.scalaVersion})"
case _ => s"$platform ($language)"
end BinaryVersion

Expand All @@ -51,6 +53,9 @@ object BinaryVersion:
case ("_mill", Some(millV), Some(scalaV)) => Some(BinaryVersion(MillPlugin(millV), Scala(scalaV)))
case ("_sbt", Some(sbtV), Some(scalaV)) => Some(BinaryVersion(SbtPlugin(sbtV), Scala(scalaV)))
case ("_", Some(scalaV), Some(sbtV)) => Some(BinaryVersion(SbtPlugin(sbtV), Scala(scalaV)))
case ("_", Some(fullScalaV @ Version.SemanticLike(_, Some(_), Some(_), None, _, _)), None) =>
// Full Scala version (major.minor.patch) indicates a compiler plugin
Some(BinaryVersion(CompilerPlugin(fullScalaV), Scala.fromFullVersion(fullScalaV)))
case ("_", Some(scalaV), None) => Some(BinaryVersion(Jvm, Scala(scalaV)))
case ("", None, None) => Some(BinaryVersion(Jvm, Java))
case _ => None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ case object Jvm extends Platform:
override def value: String = "jvm"
override def isValid: Boolean = true

case class CompilerPlugin(scalaVersion: Version) extends Platform:
override def toString: String = s"Compiler Plugin (Scala $scalaVersion)"
override def value: String = s"compiler-plugin_${scalaVersion.value}"
override def isValid: Boolean = scalaVersion match
case Version.SemanticLike(major, Some(minor), Some(patch), None, _, _) if major >= 2 => true
case _ => false

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

case class ScalaJs(version: Version) extends Platform:
override def toString: String = s"Scala.js $version"
override def value: String = s"sjs${version.value}"
Expand Down Expand Up @@ -80,6 +90,7 @@ object Platform:
case ScalaNative(version) => (3, Some(version))
case SbtPlugin(version) => (2, Some(version))
case MillPlugin(version) => (1, Some(version))
case CompilerPlugin(version) => (0, Some(version))
}

def parse(input: String): Option[Platform] =
Expand All @@ -89,5 +100,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 s"compiler-plugin_$version" => Version.parseSemantically(version).map(CompilerPlugin.apply)
case _ => None
end Platform
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,14 @@ class ArtifactIdTests extends AsyncFunSpec with Matchers:
result shouldBe expected
result.value shouldBe artifactId
}

it("parses compiler plugin with full Scala version") {
val artifactId = "kind-projector_2.13.16"
val fullScalaVersion = Version(2, 13, 16)
val expected = ArtifactId(Name("kind-projector"), BinaryVersion(CompilerPlugin(fullScalaVersion), Scala.`2.13`))
val result = ArtifactId(artifactId)
result shouldBe expected
result.value shouldBe artifactId
}
}
end ArtifactIdTests
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,22 @@ class ArtifactTests extends AnyFunSpec with Matchers:
)
)
}

it("should allow creating Artifact with CompilerPlugin platform with full Scala version") {
val fullScalaVersion = Version(2, 13, 16)
val artifact = createArtifact(
groupId = "org.typelevel",
artifactId = "kind-projector_2.13.16",
version = "0.13.2",
binaryVersion = BinaryVersion(CompilerPlugin(fullScalaVersion), Scala.`2.13`),
artifactName = Some(Name("kind-projector"))
)

artifact.platform shouldBe CompilerPlugin(fullScalaVersion)
artifact.language shouldBe Scala.`2.13`
artifact.binaryVersion.isValid shouldBe true
artifact.sbtInstall should contain("""addCompilerPlugin("org.typelevel" % "kind-projector_2.13.16" % "0.13.2")""")
}
}

private def createArtifact(
Expand Down
11 changes: 11 additions & 0 deletions modules/core/shared/src/test/scala/scaladex/core/test/Values.scala
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,15 @@ object Values:
object Scala3:
val organization: Project.Organization = Project.Organization("scala")
val reference: Project.Reference = Project.Reference.unsafe("scala/scala3")

object CompilerPluginProj:
val reference: Project.Reference = Project.Reference.unsafe("org/example-compiler-plugin")
val fullScalaVersion: Version = Version(2, 13, 16)
val projectDocument: ProjectDocument =
ProjectDocument
.default(reference)
.copy(
languages = Seq(Scala.`2.13`),
platforms = Seq(CompilerPlugin(fullScalaVersion))
)
end Values
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import scala.concurrent.Future
import scala.concurrent.duration.Duration

import scaladex.core.model.BinaryVersion
import scaladex.core.model.CompilerPlugin
import scaladex.core.model.Jvm
import scaladex.core.model.Project
import scaladex.core.model.Scala
Expand All @@ -17,6 +18,7 @@ import scaladex.core.model.search.PageParams
import scaladex.core.model.search.ProjectDocument
import scaladex.core.model.search.SearchParams
import scaladex.core.model.search.Sorting
import scaladex.core.test.Values
import scaladex.core.test.Values.*
import scaladex.core.util.ScalaExtensions.*
import scaladex.infra.config.ElasticsearchConfig
Expand All @@ -33,7 +35,8 @@ class ElasticsearchEngineTests extends AsyncFreeSpec with Matchers with BeforeAn
val searchEngine: ElasticsearchEngine = ElasticsearchEngine.open(config)
val pageParams: PageParams = PageParams(1, 20)

val projects: Seq[ProjectDocument] = Seq(Cats.projectDocument, Scalafix.projectDocument)
val projects: Seq[ProjectDocument] =
Seq(Cats.projectDocument, Scalafix.projectDocument, Values.CompilerPluginProj.projectDocument)

private def insertAll(projects: Seq[ProjectDocument]): Future[Unit] =
for
Expand All @@ -56,8 +59,8 @@ class ElasticsearchEngineTests extends AsyncFreeSpec with Matchers with BeforeAn

"sort by dependent, created, stars, forks, and contributors" in {
val params = SearchParams(queryString = "*")
val catsFirst = Seq(Cats.projectDocument, Scalafix.projectDocument)
val scalafixFirst = Seq(Scalafix.projectDocument, Cats.projectDocument)
val catsFirst = Seq(Cats.projectDocument, Scalafix.projectDocument, Values.CompilerPluginProj.projectDocument)
val scalafixFirst = Seq(Scalafix.projectDocument, Cats.projectDocument, Values.CompilerPluginProj.projectDocument)
for
_ <- insertAll(projects)
byDependent <- searchEngine.find(params.copy(sorting = Sorting.Dependent), pageParams)
Expand All @@ -66,11 +69,17 @@ class ElasticsearchEngineTests extends AsyncFreeSpec with Matchers with BeforeAn
byCommitActivity <- searchEngine.find(params.copy(sorting = Sorting.CommitActivity), pageParams)
byContributors <- searchEngine.find(params.copy(sorting = Sorting.Contributors), pageParams)
yield
(byDependent.items.map(_.document) should contain).theSameElementsInOrderAs(catsFirst)
(byCreated.items.map(_.document) should contain).theSameElementsInOrderAs(scalafixFirst) // todo fix
(byStars.items.map(_.document) should contain).theSameElementsInOrderAs(catsFirst)
(byCommitActivity.items.map(_.document) should contain).theSameElementsInOrderAs(catsFirst)
(byContributors.items.map(_.document) should contain).theSameElementsInOrderAs(catsFirst)
val depDocs = byDependent.items.map(_.document)
val createdDocs = byCreated.items.map(_.document)
val starsDocs = byStars.items.map(_.document)
val commitDocs = byCommitActivity.items.map(_.document)
val contribDocs = byContributors.items.map(_.document)

(depDocs should contain).theSameElementsInOrderAs(catsFirst)
(createdDocs should contain).theSameElementsInOrderAs(scalafixFirst) // todo fix
(starsDocs should contain).theSameElementsInOrderAs(catsFirst)
(commitDocs should contain).theSameElementsInOrderAs(catsFirst)
(contribDocs should contain).theSameElementsInOrderAs(catsFirst)
end for
}

Expand Down Expand Up @@ -125,6 +134,14 @@ class ElasticsearchEngineTests extends AsyncFreeSpec with Matchers with BeforeAn
yield (scalaJsVersions should contain).theSameElementsInOrderAs(expected)
}

"count by platforms includes compiler plugin" in {
val params = SearchParams(queryString = "*")
for
_ <- insertAll(projects)
platforms <- searchEngine.countByPlatforms(params)
yield platforms should contain(CompilerPlugin -> 1L)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be CompilerPlugin(Version(2, 13, 16))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

}

"remove missing document should not fail" in {
for _ <- searchEngine.delete(Cats.reference)
yield succeed
Expand Down
Loading