Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scaladex: 1024- Add a fullScalaVersion field in Artifact (#1) #1406

Merged
merged 3 commits into from
May 27, 2024
Merged
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 @@ -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,17 @@ 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 fullScalaVersion = scalaDependencies.sortBy(_.artifactId).lastOption.map(_.version)

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 +121,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("Full Scala Version") { @version.toString }}
</div>
@installBox(InstallTab.allOf(artifact, project.settings.cliArtifacts))
</div>
Expand Down