Skip to content

Commit

Permalink
scaladex: 1024- Add a fullScalaVersion field in Artifact (#1)
Browse files Browse the repository at this point in the history
* feat: added fullScalaVersion in Artifact class

* feat: added languageToScalaVersion method

* feat: added 2 fields in ArtifactTable

* feat: added data migration file

* feat: WIP new field added in artifor fullScalaVersion

* fix: deleted POM files used for testing

* fix: [error] (server / scalafixAll) scalafix.sbt.ScalafixFailed: TestError

* fix: fixed " org.flywaydb.core.api.FlywayException: Found more than one migration with version 19"

* fix: scalafmt formatting issues
  • Loading branch information
kannupriyakalra authored May 26, 2024
1 parent a440c15 commit 4fc67e0
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ case class Artifact(
licenses: Set[License],
isNonStandardLib: Boolean,
platform: Platform,
language: Language
language: Language,
fullScalaVersion: Option[SemanticVersion]
) {
val binaryVersion: BinaryVersion = BinaryVersion(platform, language)

Expand Down Expand Up @@ -268,7 +269,7 @@ object Artifact {
def mavenUrl: String = value.replace('.', '/')
}
case class ArtifactId(name: Name, binaryVersion: BinaryVersion) {
def value: String = s"${name}${binaryVersion.encode}"
def value: String = s"$name${binaryVersion.encode}"
def isScala: Boolean = binaryVersion.language.isScala
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class ArtifactSelectionTests extends AsyncFunSpec with Matchers {
Set.empty,
isNonStandardLib = false,
artifactId.binaryVersion.platform,
artifactId.binaryVersion.language
artifactId.binaryVersion.language,
None
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ class ArtifactTests extends AnyFunSpec with Matchers {
releaseDate = Instant.now(),
resolver = resolver,
licenses = Set(),
isNonStandardLib = false
isNonStandardLib = false,
fullScalaVersion = None
)
}
}
28 changes: 22 additions & 6 deletions modules/core/shared/src/test/scala/scaladex/core/test/Values.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ object Values {
releaseDate = creationDate,
resolver = None,
licenses = Set(),
isNonStandardLib = false
isNonStandardLib = false,
fullScalaVersion = None
)
val githubInfo: GithubInfo =
GithubInfo.empty
Expand Down Expand Up @@ -107,7 +108,8 @@ object Values {
releaseDate = creationDate,
resolver = None,
licenses = Set(),
isNonStandardLib = false
isNonStandardLib = false,
fullScalaVersion = None
)
val dependency: ArtifactDependency =
ArtifactDependency(
Expand Down Expand Up @@ -149,7 +151,8 @@ object Values {
name: String,
binaryVersion: BinaryVersion,
version: SemanticVersion,
description: Option[String] = None
description: Option[String] = None,
fullScalaVersion: Option[SemanticVersion] = None
): Artifact = {
val artifactId = ArtifactId(Name(name), binaryVersion)
Artifact(
Expand All @@ -164,14 +167,27 @@ object Values {
releaseDate = Instant.ofEpochMilli(1620911032000L),
resolver = None,
licenses = Set(license),
isNonStandardLib = false
isNonStandardLib = false,
fullScalaVersion = fullScalaVersion
)
}

val `core_3:2.6.1`: Artifact = getArtifact("cats-core", `_3`, `2.6.1`, description = Some("Cats core"))
val `core_3:2.6.1`: Artifact = getArtifact(
"cats-core",
`_3`,
`2.6.1`,
description = Some("Cats core"),
fullScalaVersion = SemanticVersion.parse("3.0.0")
)
val `core_2.13:2.6.1`: Artifact = getArtifact("cats-core", `_2.13`, `2.6.1`, description = Some("Cats core"))
val `core_3:4`: Artifact = getArtifact("cats-core", `_3`, `4`, description = Some("Cats core"))
val `core_3:2.7.0`: Artifact = getArtifact("cats-core", `_3`, `2.7.0`, description = Some("Cats core"))
val `core_3:2.7.0`: Artifact = getArtifact(
"cats-core",
`_3`,
`2.7.0`,
description = Some("Cats core"),
fullScalaVersion = SemanticVersion.parse("3.0.2")
)

val `core_sjs1_3:2.6.1`: Artifact = getArtifact("cats-core", `_sjs1_3`, `2.6.1`, description = Some("Cats core"))
val `core_sjs06_2.13:2.6.1`: Artifact =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE artifacts
ADD COLUMN full_scala_version VARCHAR;
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ object ArtifactTable {
"licenses",
"is_non_standard_Lib",
"platform",
"language_version"
"language_version",
"full_scala_version"
)
// these field are usually excluded when we read artifacts from the artifacts table.
val versionFields: Seq[String] = Seq("is_semantic", "is_prerelease")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,11 @@ package scaladex.server.service
import java.time.Instant

import com.typesafe.scalalogging.LazyLogging
import scaladex.core.model.Artifact
import scaladex.core.model.ArtifactDependency
import scaladex.core.model.ArtifactDependency.Scope
import scaladex.core.model.BinaryVersion
import scaladex.core.model.Java
import scaladex.core.model.Jvm
import scaladex.core.model.License
import scaladex.core.model.Project
import scaladex.core.model.SbtPlugin
import scaladex.core.model.Scala
import scaladex.core.model.SemanticVersion
import scaladex.core.model._
import scaladex.data.cleanup._
import scaladex.data.maven.ArtifactModel
import scaladex.data.maven.Dependency
import scaladex.data.maven.SbtPluginTarget
import scaladex.infra.DataPaths

Expand Down Expand Up @@ -51,7 +43,8 @@ class ArtifactConverter(paths: DataPaths) extends LazyLogging {
pom.licenses.flatMap(l => License.get(l.name)).toSet,
meta.isNonStandard,
meta.binaryVersion.platform,
meta.binaryVersion.language
meta.binaryVersion.language,
extractScalaVersion(pom)
)
val dependencies = pom.dependencies.map { dep =>
ArtifactDependency(
Expand All @@ -63,6 +56,22 @@ class ArtifactConverter(paths: DataPaths) extends LazyLogging {
(artifact, dependencies)
}

private def extractScalaVersion(pom: ArtifactModel): Option[SemanticVersion] = {
val scalaDependencies = pom.dependencies.filter { dep =>
dep.groupId == "org.scala-lang" &&
(dep.artifactId == "scala-library" || dep.artifactId == "scala3-library_3")
}

val sortedScalaDependencies = scalaDependencies.sortBy(_.artifactId)
val fullScalaVersion = scalaDependencies match {
case _ :: _ :: _ => Some(sortedScalaDependencies.last.version)
case head :: Nil => Some(head.version)
case _ => None
}

fullScalaVersion.flatMap(SemanticVersion.parse)
}

/**
* artifactId is often use to express binary compatibility with a scala version (ScalaTarget)
* if the developer follow this convention we extract the relevant parts and we mark
Expand Down Expand Up @@ -117,7 +126,7 @@ class ArtifactConverter(paths: DataPaths) extends LazyLogging {
// For example: io.gatling
case Some(BinaryVersionLookup.FromDependency) =>
for {
dep <- pom.dependencies.find { dep =>
dep: Dependency <- pom.dependencies.find { dep =>
dep.groupId == "org.scala-lang" &&
(dep.artifactId == "scala-library" || dep.artifactId == "scala3-library_3")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ <h3>
@if(artifact.resolver.isEmpty) {
@info("Files") { <a href="@artifact.mavenReference.repoUrl">View all</a> }
}
@artifact.fullScalaVersion.map{ version => @info("Scala version") { @version.toString }}
</div>
@installBox(InstallTab.allOf(artifact, project.settings.cliArtifacts))
</div>
Expand Down

0 comments on commit 4fc67e0

Please sign in to comment.