Skip to content

Commit

Permalink
Merge pull request #204 from alejandrohdezma/feature/on
Browse files Browse the repository at this point in the history
Add utility extension method to simplify adding settings for specific scala versions
  • Loading branch information
alejandrohdezma authored Jan 29, 2024
2 parents 47952f5 + b6cf144 commit 7379ca0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,35 @@ import scala.reflect.macros._
import sbt.Keys._
import sbt._

@SuppressWarnings(
Array(
"scalafix:Disable.scala.collection.mutable",
"scalafix:DisableSyntax.implicitConversion",
"scalafix:Disable.blocking.io"
)
)
@SuppressWarnings(Array("scalafix:DisableSyntax.implicitConversion"))
object ModulesPlugin extends AutoPlugin {

override def trigger = allRequirements

object autoImport {

implicit class AnyOnOps(version: String) {

/** Transforms the given value into an `Option`.
*
* The result will be `None` if the version string doesn't match the provided major version.
*/
def on[A](major: Int)(a: => A): Option[A] =
CrossVersion
.partialVersion(version)
.collect { case (`major`, _) => a }

/** Transforms the given value into an `Option`.
*
* The result will be `None` if the version string doesn't match the provided major/minor versions.
*/
def on[A](major: Int, minor: Int)(a: => A): Option[A] =
CrossVersion
.partialVersion(version)
.collect { case (`major`, `minor`) => a }

}

implicit class ProjectOpsWithProjectReferenceList(private val project: Project) extends AnyVal {

/** Adds classpath dependencies on internal or external projects. */
Expand Down
7 changes: 2 additions & 5 deletions project/dependencies.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
unmanagedSourceDirectories in Compile +=
baseDirectory
.in(ThisBuild)
.value
.getParentFile / "modules" / "sbt-modules" / "src" / "main" / "scala"
Compile / unmanagedSourceDirectories +=
(ThisBuild / baseDirectory).value.getParentFile / "modules" / "sbt-modules" / "src" / "main" / "scala"

0 comments on commit 7379ca0

Please sign in to comment.