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 @@ -60,6 +60,7 @@ case class Artifact(

def sbtInstall: Option[String] =
val install = platform match
case CompilerPlugin => throw new UnsupportedOperationException("CompilerPlugin sbtInstall not supported yet")
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,6 +97,7 @@ case class Artifact(
|interp.resolvers() = interp.resolvers() :+ res""".stripMargin

val install = platform match
case CompilerPlugin => throw new UnsupportedOperationException("CompilerPlugin ammInstall not supported yet")
case MillPlugin(_) | SbtPlugin(_) | ScalaNative(_) | ScalaJs(_) => None
case Jvm =>
language match
Expand All @@ -115,6 +117,7 @@ case class Artifact(
*/
def mavenInstall: Option[String] =
platform match
case CompilerPlugin => throw new UnsupportedOperationException("CompilerPlugin mavenInstall not supported yet")
case MillPlugin(_) | SbtPlugin(_) | ScalaNative(_) | ScalaJs(_) => None
case Jvm =>
Some(
Expand All @@ -130,6 +133,7 @@ case class Artifact(
*/
def gradleInstall: Option[String] =
platform match
case CompilerPlugin => throw new UnsupportedOperationException("CompilerPlugin gradleInstall not supported yet")
case MillPlugin(_) | SbtPlugin(_) | ScalaNative(_) | ScalaJs(_) => None
case Jvm => Some(s"compile group: '$groupId', name: '$artifactId', version: '$version'")

Expand All @@ -138,6 +142,7 @@ case class Artifact(
*/
def millInstall: Option[String] =
val install = platform match
case CompilerPlugin => throw new UnsupportedOperationException("CompilerPlugin millInstall not supported yet")
case MillPlugin(_) => Some(s"import $$ivy.`$groupId::$name::$version`")
case SbtPlugin(_) => None
case ScalaNative(_) | ScalaJs(_) => Some(s"""ivy"$groupId::$name::$version"""")
Expand All @@ -159,6 +164,7 @@ case class Artifact(

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

def csLaunch: Option[String] =
platform match
case CompilerPlugin => throw new UnsupportedOperationException("CompilerPlugin csLaunch not supported yet")
case MillPlugin(_) | SbtPlugin(_) => None
case ScalaNative(_) | ScalaJs(_) => Some(s"cs launch $groupId::$name::$version")
case Jvm =>
Expand All @@ -190,6 +197,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 @@ -28,6 +28,7 @@ final case class BinaryVersion(platform: Platform, language: Language):
case Jvm => language.toString
case p: SbtPlugin => p.toString
case p: MillPlugin => p.toString
case CompilerPlugin => s"CompilerPlugin ($language)"
case _ => s"$platform ($language)"
end BinaryVersion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ case object Jvm extends Platform:
override def value: String = "jvm"
override def isValid: Boolean = true

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

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 +85,7 @@ object Platform:
case ScalaNative(version) => (3, Some(version))
case SbtPlugin(version) => (2, Some(version))
case MillPlugin(version) => (1, Some(version))
case CompilerPlugin => (0, None)
}

def parse(input: String): Option[Platform] =
Expand All @@ -89,5 +95,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 @@ -196,6 +196,20 @@ class ArtifactTests extends AnyFunSpec with Matchers:
)
)
}

it("should allow creating Artifact with CompilerPlugin platform without exceptions") {
val artifact = createArtifact(
groupId = "org.example",
artifactId = "myplugin_2.13",
version = "1.0.0",
binaryVersion = BinaryVersion(CompilerPlugin, Scala.`2.13`),
artifactName = Some(Name("myplugin"))
)

artifact.platform shouldBe CompilerPlugin
artifact.language shouldBe Scala.`2.13`
artifact.binaryVersion.isValid shouldBe true
}
}

private def createArtifact(
Expand Down
36 changes: 36 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,40 @@ 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 artifact: Artifact = Artifact(
groupId = GroupId("org"),
artifactId = ArtifactId("example-compiler-plugin_2.13"),
version = Version("1.0.0"),
projectRef = reference,
description = Some("Example compiler plugin"),
binaryVersion = BinaryVersion(CompilerPlugin, Scala.`2.13`),
fullScalaVersion = Some(Scala.`2.13`.version),
developers = Seq.empty,
scaladocUrl = None,
versionScheme = None,
creationDate = now.minus(5, ChronoUnit.MINUTES)
)
val creationDate: Instant = now.minus(5, ChronoUnit.MINUTES)
val githubInfo: GithubInfo = GithubInfo(
description = Some("Example compiler plugin for testing"),
homepage = None,
logo = None,
stars = 10,
forks = 2,
watchers = 5,
issues = 0,
language = Some("Scala"),
topics = Seq("compiler-plugin", "scala"),
defaultBranch = "main"
)
val projectDocument: ProjectDocument =
ProjectDocument
.default(reference)
.copy(
languages = Seq(Scala.`2.13`),
platforms = Seq(CompilerPlugin)
)
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 Down Expand Up @@ -66,11 +69,27 @@ 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)
.filter(d => Set(Cats.projectDocument.reference, Scalafix.projectDocument.reference).contains(d.reference))
val createdDocs = byCreated.items
.map(_.document)
.filter(d => Set(Cats.projectDocument.reference, Scalafix.projectDocument.reference).contains(d.reference))
val starsDocs = byStars.items
.map(_.document)
.filter(d => Set(Cats.projectDocument.reference, Scalafix.projectDocument.reference).contains(d.reference))
val commitDocs = byCommitActivity.items
.map(_.document)
.filter(d => Set(Cats.projectDocument.reference, Scalafix.projectDocument.reference).contains(d.reference))
val contribDocs = byContributors.items
.map(_.document)
.filter(d => Set(Cats.projectDocument.reference, Scalafix.projectDocument.reference).contains(d.reference))

(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 +144,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)
}

"remove missing document should not fail" in {
for _ <- searchEngine.delete(Cats.reference)
yield succeed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,21 @@ class FrontPage(env: Env, database: WebDatabase, searchEngine: SearchEngine)(usi
EcosystemVersion(millP.version, count, search = Url(s"search?platform=${millP.value}"))
}
)
val compilerPluginEcosystem = EcosystemHighlight(
"Compiler Plugin",
platforms.collect {
case (CompilerPlugin, count) =>
EcosystemVersion(Version(1), count, search = Url(s"search?platform=${CompilerPlugin.value}"))
}
)

frontpage(
env,
topics,
Seq(scala3Ecosystem, scala2Ecosystem).flatten,
Seq(scalajsEcosystem, scalaNativeEcosystem).flatten,
Seq(sbtPluginEcosystem, millPluginEcosystem).flatten,
Seq(compilerPluginEcosystem).flatten,
latestProjects,
mostDependedUpon,
userInfo,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package scaladex.server.route

import scala.concurrent.Await
import scala.concurrent.Future
import scala.concurrent.duration.Duration

import scaladex.core.model.*
import scaladex.core.test.Values

import org.apache.pekko.http.scaladsl.model.StatusCodes
import org.apache.pekko.http.scaladsl.server.Directives.*
import org.apache.pekko.http.scaladsl.server.Route
import org.scalatest.BeforeAndAfterEach

class FrontPageTests extends ControllerBaseSuite with BeforeAndAfterEach:
import Values.*

override def beforeEach(): Unit =
database.reset()
Await.result(insertCompilerPluginProject(), Duration.Inf)

private def insertCompilerPluginProject(): Future[Unit] =
for
_ <- artifactService.insertArtifact(CompilerPluginProj.artifact, Seq.empty)
_ <- database.updateProjectCreationDate(CompilerPluginProj.reference, CompilerPluginProj.creationDate)
_ <- database.updateGithubInfoAndStatus(CompilerPluginProj.reference, CompilerPluginProj.githubInfo, ok)
yield ()

val frontPage = new FrontPage(config.env, database, searchEngine)
val route: Route = frontPage.route(None)

it("should display CompilerPlugin section on front page") {
Get("/") ~> route ~> check {
status shouldBe StatusCodes.OK
val responseBody = responseAs[String]

// Check that the CompilerPlugin section is present
responseBody should include("Compiler Plugins")
responseBody should include("Compiler Plugin")
responseBody should include("search?platform=compiler-plugin")
}
}

it("should display CompilerPlugin with correct project count") {
Get("/") ~> route ~> check {
status shouldBe StatusCodes.OK
val responseBody = responseAs[String]

// Check that the CompilerPlugin section shows the project count
responseBody should include("projects")
}
}

it("should have CompilerPlugin as a separate section from Build Tool Plugins") {
Get("/") ~> route ~> check {
status shouldBe StatusCodes.OK
val responseBody = responseAs[String]

// Check that both sections exist
responseBody should include("Build Tool Plugins")
responseBody should include("Compiler Plugins")

// Check that CompilerPlugin is not mixed with build tool plugins
val buildToolPluginsIndex = responseBody.indexOf("Build Tool Plugins")
val compilerPluginsIndex = responseBody.indexOf("Compiler Plugins")
compilerPluginsIndex should be > buildToolPluginsIndex
}
}
end FrontPageTests
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
scalaVersions: Seq[EcosystemHighlight],
platforms: Seq[EcosystemHighlight],
buildToolPlugins: Seq[EcosystemHighlight],
compilerPlugins: Seq[EcosystemHighlight],
latestProjects: Seq[ProjectDocument],
mostDependedUpon: Seq[ProjectDocument],
user: Option[UserState],
Expand All @@ -28,6 +29,7 @@ <h1 class="text-center">The Scala Library Index</h1>
@ecosystemHighlights("Scala Versions", scalaVersions)
@ecosystemHighlights("Platforms", platforms)
@ecosystemHighlights("Build Tool Plugins", buildToolPlugins)
@ecosystemHighlights("Compiler Plugins", compilerPlugins)
</div>
</div>
</div>
Expand Down
Loading