Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 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
28 changes: 18 additions & 10 deletions build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import java.io.File
object DepVersions {
def mdoc = "2.3.6"
def scala213 = "2.13.18"
def scala3 = "3.3.7"
def scalaJs = "1.20.2"

def scala = Seq(scala213, "2.12.21")
def scala = Seq(scala213, "2.12.21", scala3)
}

object Deps {
Expand Down Expand Up @@ -105,19 +106,24 @@ trait Versions extends Cross.Module[String] with ScalaModule with VersionsPublis
val scala213Opts =
if (sv.startsWith("2.13.")) Seq("-Ymacro-annotations")
else Nil
super.scalacOptions() ++ scala213Opts ++ Seq(
"-deprecation",
"--release",
"8"
)
val releaseOpts =
if (sv.startsWith("3.")) Seq("-release", "8")
else Seq("--release", "8")
super.scalacOptions() ++ scala213Opts ++ Seq("-deprecation") ++ releaseOpts
}
def sources = Task {
super.sources() ++ Seq(versions.shared.sources())
val sv = scalaVersion()
val versionSpecific =
if (sv.startsWith("3.")) versions.shared.sources3()
else versions.shared.sources2()
super.sources() ++ Seq(versions.shared.sources(), versionSpecific)
}

def compileMvnDeps = Seq(
mvn"io.github.alexarchambault::data-class:0.2.7"
)
def compileMvnDeps = Task {
val sv = scalaVersion()
if (sv.startsWith("3.")) Seq.empty
else Seq(mvn"io.github.alexarchambault::data-class:0.2.7")
}

def mimaBinaryIssueFilters = super.mimaBinaryIssueFilters() ++ Seq(
// Additional abstract method on *sealed* trait
Expand Down Expand Up @@ -157,6 +163,8 @@ trait VersionsJs extends Versions with ScalaJSModule {
object versions extends Module {
object shared extends Module {
def sources = Task.Source("src")
def sources2 = Task.Source("src-2")
def sources3 = Task.Source("src-3")
def testSources = Task.Source("test/src")
}
object jvm extends Cross[VersionsJvm](DepVersions.scala)
Expand Down
64 changes: 64 additions & 0 deletions versions/shared/src-3/coursier/version/ModuleMatcher.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package coursier.version

import java.util.regex.Pattern

import scala.annotation.tailrec
import scala.util.matching.Regex

// Adapted from https://github.com/coursier/coursier/blob/876a6604d0cd0c3783ed729f5399549f52a3a385/modules/coursier/shared/src/main/scala/coursier/util/ModuleMatcher.scala

case class ModuleMatcher(
organizationMatcher: String,
nameMatcher: String,
attributeMatchers: Map[String, String] = Map.empty
) {

import ModuleMatcher.blobToPattern

lazy val orgPattern = blobToPattern(organizationMatcher)
lazy val namePattern = blobToPattern(nameMatcher)
lazy val attributesPattern = attributeMatchers
.iterator
.map {
case (k, v) =>
(k, blobToPattern(v))
}
.toMap

def matches(organization: String, name: String): Boolean =
matches(organization, name, Map.empty)

def matches(organization: String, name: String, attributes: Map[String, String]): Boolean =
orgPattern.pattern.matcher(organization).matches() &&
namePattern.pattern.matcher(name).matches() &&
attributes.keySet == attributesPattern.keySet &&
attributesPattern.forall {
case (k, p) =>
attributes.get(k).exists(p.pattern.matcher(_).matches())
}

}

object ModuleMatcher {

def all: ModuleMatcher =
ModuleMatcher("*", "*")

@tailrec
private def blobToPattern(s: String, b: StringBuilder = new StringBuilder): Regex =
if (s.isEmpty)
b.result().r
else {
val idx = s.indexOf('*')
if (idx < 0) {
b ++= Pattern.quote(s)
b.result().r
} else {
if (idx > 0)
b ++= Pattern.quote(s.substring(0, idx))
b ++= ".*"
blobToPattern(s.substring(idx + 1), b)
}
}

}
36 changes: 36 additions & 0 deletions versions/shared/src-3/coursier/version/ModuleMatchers.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package coursier.version

// Adapted from https://github.com/coursier/coursier/blob/f0b10fb1744e5bdf94bf17857dfb3cb19fda2e5b/modules/coursier/shared/src/main/scala/coursier/util/ModuleMatchers.scala

case class ModuleMatchers(
exclude: Set[ModuleMatcher],
include: Set[ModuleMatcher] = Set(),
includeByDefault: Boolean = true
) {

// If modules are included by default:
// Those matched by anything in exclude are excluded, but for those also matched by something in include.
// If modules are excluded by default:
// Those matched by anything in include are included, but for those also matched by something in exclude.

def matches(organization: String, name: String): Boolean =
matches(organization, name, Map.empty)

def matches(organization: String, name: String, attributes: Map[String, String]): Boolean =
if (includeByDefault)
!exclude.exists(_.matches(organization, name, attributes)) ||
include.exists(_.matches(organization, name, attributes))
else
include.exists(_.matches(organization, name, attributes)) &&
!exclude.exists(_.matches(organization, name, attributes))

}

object ModuleMatchers {
def all: ModuleMatchers =
ModuleMatchers(Set.empty, Set.empty)
def only(organization: String, name: String): ModuleMatchers =
only(organization, name, Map.empty)
def only(organization: String, name: String, attributes: Map[String, String]): ModuleMatchers =
ModuleMatchers(Set.empty, Set(ModuleMatcher(organization, name, attributes)), includeByDefault = false)
}
Loading
Loading