Skip to content

Commit

Permalink
Generalize PekkoDependency
Browse files Browse the repository at this point in the history
  • Loading branch information
mdedetrich committed Jan 7, 2024
1 parent 051a798 commit 4f2330c
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,45 @@

package com.github.pjfanning.pekkobuild

object PekkoDependency extends VersionRegex {
override val checkProject: String = "pekko-cluster-sharding-typed"
trait PekkoDependency extends VersionRegex {
lazy val minVersion: String = "1.0.0"
val module: Option[String]
val currentVersion: String

private lazy val moduleName = module match {
case Some(mName) => s"pekko.$mName"
case None => "pekko" // Main pekko module
}

def pekkoDependency(defaultVersion: String): Dependency =
Option(System.getProperty("pekko.sources")) match {
def dependency(defaultVersion: String): Dependency = {
Option(System.getProperty(s"$moduleName.sources")) match {
case Some(pekkoSources) =>
Sources(pekkoSources)
case None =>
Option(System.getProperty("pekko.build.pekko.version")) match {
Option(System.getProperty(s"pekko.build.$moduleName.version")) match {
case Some("main") => snapshotMain
case Some("1.0.x") => snapshot10x
case Some("latest-release") => latestRelease
case Some("default") | None => Artifact(defaultVersion)
case Some(other) => Artifact(other, true)
case Some(other) => Artifact(other, isSnapshot = true)
}
}
}

private val defaultPekkoVersion = System.getProperty("pekko.build.pekko.min.version", "1.0.2")
val minPekkoVersion: String = "1.0.0"
lazy val default: Dependency = pekkoDependency(defaultPekkoVersion)
private lazy val defaultVersion = System.getProperty(s"pekko.build.$moduleName.min.version", currentVersion)
lazy val default: Dependency = dependency(defaultVersion)

lazy val snapshot10x = Artifact(determineLatestSnapshot("1.0"), true)
lazy val snapshotMain = Artifact(determineLatestSnapshot(), true)
lazy val latestRelease = Artifact(determineLatestRelease(), false)
lazy val snapshot10x: Artifact = Artifact(determineLatestSnapshot(minVersion), isSnapshot = true)
lazy val snapshotMain: Artifact = Artifact(determineLatestSnapshot(), isSnapshot = true)
lazy val latestRelease: Artifact = Artifact(determineLatestRelease(), isSnapshot = false)

lazy val pekkoVersion: String = default match {
lazy val version: String = default match {
case Artifact(version, _) => version
case Sources(uri, _) => uri
}

def pekkoVersionDerivedFromDefault(overrideDefaultPekkoVersion: String): String =
pekkoDependency(overrideDefaultPekkoVersion) match {
def versionDerivedFromDefault(overrideDefaultPekkoVersion: String): String =
dependency(overrideDefaultPekkoVersion) match {
case Artifact(version, _) => version
case Sources(uri, _) => uri
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,50 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* license agreements; and to You under the Apache License, version 2.0:
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* This file is part of the Apache Pekko project, which was derived from Akka.
*/

/*
* Copyright (C) 2017-2020 Lightbend Inc. <https://www.lightbend.com>
*/

package com.github.pjfanning.pekkobuild

object PekkoHttpDependency extends VersionRegex {
override val checkProject: String = "pekko-http-testkit"

def pekkoHttpDependency(defaultVersion: String): Dependency =
Option(System.getProperty("pekko.http.sources")) match {
case Some(pekkoSources) =>
Sources(pekkoSources)
case None =>
Option(System.getProperty("pekko.build.pekko.http.version")) match {
case Some("main") => snapshotMain
case Some("1.0.x") => snapshot10x
case Some("latest-release") => latestRelease
case Some("default") | None => Artifact(defaultVersion)
case Some(other) => Artifact(other, true)
}
}

private val defaultPekkoHttpVersion = System.getProperty("pekko.build.pekko.http.min.version", "1.0.0")
lazy val default: Dependency = pekkoHttpDependency(defaultPekkoHttpVersion)

lazy val snapshot10x = Artifact(determineLatestSnapshot("1.0"), true)
lazy val snapshotMain = Artifact(determineLatestSnapshot(), true)
lazy val latestRelease = Artifact(determineLatestRelease(), false)

lazy val pekkoHttpVersion: String = default match {
case Artifact(version, _) => version
case Sources(uri, _) => uri
}

def pekkoHttpVersionDerivedFromDefault(overrideDefaultPekkoHttpVersion: String): String =
pekkoHttpDependency(overrideDefaultPekkoHttpVersion) match {
case Artifact(version, _) => version
case Sources(uri, _) => uri
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ trait VersionRegex {
// `_2.13` is assumed
protected val checkProject: String

protected def determineLatestSnapshot(prefix: String = ""): String = determineLatestVersion(true, prefix)
protected def determineLatestSnapshot(prefix: String = ""): String = determineLatestVersion(useSnapshots = true, prefix)

protected def determineLatestRelease(prefix: String = ""): String = determineLatestVersion(false, prefix)
protected def determineLatestRelease(prefix: String = ""): String = determineLatestVersion(useSnapshots = false, prefix)

protected def determineLatestVersion(useSnapshots: Boolean, prefix: String): String = {
import sbt.librarymanagement.Http.http
Expand Down
3 changes: 1 addition & 2 deletions src/main/scala/com/github/pjfanning/pekkobuild/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ package object pekkobuild {
/** Adds either a source or a binary dependency, depending on whether the above settings are set */
def addPekkoModuleDependency(module: String,
config: String = "",
pekko: Dependency = PekkoDependency.default
): Project =
pekko: Dependency): Project =
pekko match {
case Sources(sources, _) =>
val moduleRef = ProjectRef(uri(sources), module)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* license agreements; and to You under the Apache License, version 2.0:
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* This file is part of the Apache Pekko project, which was derived from Akka.
*/

/*
* Copyright (C) 2017-2020 Lightbend Inc. <https://www.lightbend.com>
*/

package com.github.pjfanning.pekkobuild

object PekkoCoreDependency extends PekkoDependency {
override val checkProject: String = "pekko-cluster-sharding-typed"
override val module: Option[String] = None
override val currentVersion: String = "1.0.2"
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import org.scalatest.wordspec.AnyWordSpec
class PekkoDependencySpec extends AnyWordSpec with Matchers {
"PekkoDependency" should {
"eval pekkoVersionDerivedFromDefault" in {
PekkoDependency.pekkoVersionDerivedFromDefault("1.0.2") shouldEqual "1.0.2"
PekkoCoreDependency.versionDerivedFromDefault("1.0.2") shouldEqual "1.0.2"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* license agreements; and to You under the Apache License, version 2.0:
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* This file is part of the Apache Pekko project, which was derived from Akka.
*/

/*
* Copyright (C) 2017-2020 Lightbend Inc. <https://www.lightbend.com>
*/

package com.github.pjfanning.pekkobuild

object PekkoHttpDependency extends PekkoDependency {
override val checkProject: String = "pekko-http-testkit"
override val module: Option[String] = Some("http")
override val currentVersion: String = "1.0.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import org.scalatest.wordspec.AnyWordSpec
class PekkoHttpDependencySpec extends AnyWordSpec with Matchers {
"PekkoHttpDependency" should {
"eval pekkoHttpVersionDerivedFromDefault" in {
PekkoHttpDependency.pekkoHttpVersionDerivedFromDefault("1.0.0") shouldEqual "1.0.0"
PekkoHttpDependency.versionDerivedFromDefault("1.0.0") shouldEqual "1.0.0"
}
}
}

0 comments on commit 4f2330c

Please sign in to comment.