Skip to content

Commit

Permalink
fix default artifact
Browse files Browse the repository at this point in the history
  • Loading branch information
adpi2 committed May 30, 2024
1 parent a69467e commit 529bf28
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package scaladex.core.model

import java.time.Instant

object ProjectHeader {
def apply(
ref: Project.Reference,
Expand Down Expand Up @@ -52,18 +54,18 @@ final case class ProjectHeader(
def byName(artifacts: Seq[Artifact]): Option[Artifact] =
defaultArtifactName.toSeq
.flatMap(defaultName => artifacts.filter(a => defaultName == a.artifactName))
.maxByOption(_.binaryVersion)
.maxByOption(a => (a.binaryVersion, a.releaseDate))

def ofVersion(version: SemanticVersion): Artifact =
filteredArtifacts
.filter(_.version == version)
.maxBy(a => (a.binaryVersion, a.artifactName))(
Ordering.Tuple2(Ordering[BinaryVersion], Ordering[Artifact.Name].reverse)
.maxBy(a => (a.binaryVersion, a.artifactName, a.releaseDate))(
Ordering.Tuple3(Ordering[BinaryVersion], Ordering[Artifact.Name].reverse, Ordering[Instant])
)

// find version of latest stable artifact then default artifact of that version
def byLatestVersion(artifacts: Seq[Artifact]): Option[Artifact] =
artifacts.sortBy(_.releaseDate).lastOption.map(a => ofVersion(a.version))
artifacts.maxByOption(_.releaseDate).map(a => ofVersion(a.version))

if (preferStableVersion) {
byName(stableArtifacts)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,11 @@ object ArtifactTable {
.map(bv => s"(platform='${bv.platform.label}' AND language_version='${bv.language.label}')")
.mkString("(", " OR ", ")")
val preReleaseFilter = if (preReleases) s"true" else "is_prerelease=false"
val releases =
s"""|SELECT organization, repository, artifact_name, version
Query[(Project.Reference, Artifact.Name), Artifact](
s"""|SELECT ${fields.mkString(", ")}
|FROM $table WHERE
|organization=? AND repository=? AND artifact_name=? AND $binaryVersionFilter AND $preReleaseFilter
|""".stripMargin
val artifactFields = fields.map(f => s"a.$f").mkString(", ")
Query[(Project.Reference, Artifact.Name), Artifact](
s"""|SELECT $artifactFields FROM ($releases) r INNER JOIN $table a ON
| r.version = a.version AND r.organization = a.organization AND
| r.repository = a.repository AND r.artifact_name = a.artifact_name""".stripMargin
)
}

Expand Down

0 comments on commit 529bf28

Please sign in to comment.