Skip to content

Commit 3e1651d

Browse files
committed
Drop Scala 2 for the config and specification-level modules
1 parent bfc19a4 commit 3e1651d

File tree

12 files changed

+46
-91
lines changed

12 files changed

+46
-91
lines changed

build.mill.scala

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ object cliBootstrapped extends ScalaCliPublishModule {
9494
}
9595
}
9696

97-
object `specification-level` extends Cross[SpecificationLevel](Scala.all)
97+
object `specification-level` extends Cross[SpecificationLevel](Scala.scala3MainVersions)
9898
with CrossScalaDefaultToInternal
9999
object `build-macros` extends Cross[BuildMacros](Scala.scala3MainVersions)
100100
with CrossScalaDefaultToInternal
101-
object config extends Cross[Config](Scala.all) with CrossScalaDefaultToInternal
101+
object config extends Cross[Config](Scala.scala3MainVersions) with CrossScalaDefaultToInternal
102102
object options extends Cross[Options](Scala.scala3MainVersions) with CrossScalaDefaultToInternal
103103
object directives extends Cross[Directives](Scala.scala3MainVersions)
104104
with CrossScalaDefaultToInternal
@@ -648,27 +648,9 @@ trait Config extends ScalaCliCrossSbtModule
648648
override def crossScalaVersion: String = crossValue
649649
override def moduleDeps: Seq[SonatypeCentralPublishModule] =
650650
Seq(`specification-level`(crossScalaVersion))
651-
override def ivyDeps: T[Agg[Dep]] = {
652-
val maybeCollectionCompat =
653-
if (crossScalaVersion.startsWith("2.12.")) Seq(Deps.collectionCompat)
654-
else Nil
655-
super.ivyDeps() ++ maybeCollectionCompat ++ Agg(
656-
Deps.jsoniterCoreJava8
657-
)
658-
}
659-
override def compileIvyDeps: T[Agg[Dep]] = super.compileIvyDeps() ++ Agg(
660-
Deps.jsoniterMacrosJava8
661-
)
662-
override def scalacOptions: T[Seq[String]] = Task {
663-
super.scalacOptions() ++ Seq("-release", "8")
664-
}
665-
666-
// Disabling Scalafix in 2.13 and 3, so that it doesn't remove
667-
// some compatibility-related imports, that are actually only used
668-
// in Scala 2.12.
669-
override def fix(args: String*): Command[Unit] =
670-
if (crossScalaVersion.startsWith("2.12.")) super.fix(args: _*)
671-
else Task.Command(())
651+
override def ivyDeps: T[Agg[Dep]] = super.ivyDeps() ++ Agg(Deps.jsoniterCore)
652+
override def compileIvyDeps: T[Agg[Dep]] = super.compileIvyDeps() ++ Agg(Deps.jsoniterMacros)
653+
override def scalacOptions: T[Seq[String]] = super.scalacOptions() ++ Seq("-deprecation")
672654
}
673655

674656
trait Options extends ScalaCliCrossSbtModule with ScalaCliPublishModule with HasTests

modules/config/src/main/scala-2.12/scala/cli/config/Util.scala

Lines changed: 0 additions & 14 deletions
This file was deleted.

modules/config/src/main/scala-2.13/scala/cli/config/Util.scala

Lines changed: 0 additions & 3 deletions
This file was deleted.

modules/config/src/main/scala-3/scala/cli/config/Util.scala

Lines changed: 0 additions & 3 deletions
This file was deleted.

modules/config/src/main/scala/scala/cli/config/ConfigDb.scala

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package scala.cli.config
22

3-
import com.github.plokhotnyuk.jsoniter_scala.core.{Key => _, _}
4-
import com.github.plokhotnyuk.jsoniter_scala.macros._
3+
import com.github.plokhotnyuk.jsoniter_scala.core.{Key as _, *}
4+
import com.github.plokhotnyuk.jsoniter_scala.macros.*
55

66
import java.nio.charset.StandardCharsets
77
import java.nio.file.attribute.{PosixFilePermission, PosixFilePermissions}
88
import java.nio.file.{Files, Path}
99

1010
import scala.collection.immutable.ListMap
11-
import scala.jdk.CollectionConverters._
11+
import scala.jdk.CollectionConverters.*
1212
import scala.util.Properties
1313

1414
/** In-memory representation of a configuration DB content.
@@ -50,7 +50,7 @@ final class ConfigDb private (
5050
}
5151

5252
/** Removes an entry from memory */
53-
def remove(key: Key[_]): this.type = {
53+
def remove(key: Key[?]): this.type = {
5454
rawEntries -= key.fullName
5555
this
5656
}
@@ -90,7 +90,9 @@ final class ConfigDb private (
9090
}
9191
val sortedMap: Map[String, RawJson] = ListMap.empty ++ keyValues
9292
val b =
93-
writeToArray(sortedMap, WriterConfig.withIndentionStep((level + 1) * 2))(ConfigDb.codec)
93+
writeToArray(sortedMap, WriterConfig.withIndentionStep((level + 1) * 2))(using
94+
ConfigDb.codec
95+
)
9496
if (b.nonEmpty && b.last == '}'.toByte)
9597
// FIXME We're copying / moving arrays around quite a bit here
9698
b.init ++ (" " * level).getBytes(StandardCharsets.US_ASCII) ++ Array('}'.toByte)
@@ -114,7 +116,7 @@ final class ConfigDb private (
114116
Array('\n': Byte)
115117
}
116118

117-
def saveUnsafe(path: Path): Either[ConfigDb.ConfigDbPermissionsError, Unit] = {
119+
private def saveUnsafe(path: Path): Either[ConfigDb.ConfigDbPermissionsError, Unit] = {
118120
val dir = path.getParent
119121

120122
if (Properties.isWin) {
@@ -164,7 +166,6 @@ final class ConfigDb private (
164166
}
165167

166168
object ConfigDb {
167-
168169
final class ConfigDbFormatError(
169170
message: String,
170171
causeOpt: Option[Throwable] = None
@@ -183,7 +184,7 @@ object ConfigDb {
183184
res += (if (perms.contains(PosixFilePermission.OTHERS_EXECUTE)) 'x' else '-')
184185
res.result()
185186
}
186-
final class ConfigDbPermissionsError(path: Path, perms: Set[PosixFilePermission])
187+
private final class ConfigDbPermissionsError(path: Path, perms: Set[PosixFilePermission])
187188
extends Exception(
188189
s"$path has wrong permissions ${permsString(perms)} (expected at most rwx------)"
189190
)
@@ -208,7 +209,7 @@ object ConfigDb {
208209
map.flatMap {
209210
case (k, v) =>
210211
try {
211-
val subMap = flatten(readFromArray(v.value)(codec))
212+
val subMap = flatten(readFromArray(v.value)(using codec))
212213
subMap.toSeq.map {
213214
case (k0, v0) =>
214215
(k + "." + k0, v0)
@@ -221,7 +222,7 @@ object ConfigDb {
221222
}
222223

223224
val maybeRawEntries =
224-
try Right(flatten(readFromArray(dbContent)(codec)))
225+
try Right(flatten(readFromArray(dbContent)(using codec)))
225226
catch {
226227
case e: JsonReaderException =>
227228
Left(new ConfigDbFormatError(
@@ -241,11 +242,9 @@ object ConfigDb {
241242
* either an error on failure, or a ConfigDb instance on success
242243
*/
243244
def open(path: Path): Either[Exception, ConfigDb] =
244-
if (Files.exists(path))
245-
apply(Files.readAllBytes(path), Some(path.toString))
246-
else
247-
Right(empty)
245+
if Files.exists(path)
246+
then apply(Files.readAllBytes(path), Some(path.toString))
247+
else Right(empty)
248248

249-
def empty: ConfigDb =
250-
new ConfigDb(Map())
249+
def empty: ConfigDb = new ConfigDb(Map())
251250
}

modules/config/src/main/scala/scala/cli/config/ErrorMessages.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@ package scala.cli.config
33
object ErrorMessages {
44
val inlineCredentialsError =
55
"Inline credentials not accepted, please edit the config file manually."
6-
76
}

modules/config/src/main/scala/scala/cli/config/Key.scala

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
package scala.cli.config
22

3-
import com.github.plokhotnyuk.jsoniter_scala.core._
4-
import com.github.plokhotnyuk.jsoniter_scala.macros._
3+
import com.github.plokhotnyuk.jsoniter_scala.core.*
4+
import com.github.plokhotnyuk.jsoniter_scala.macros.*
55

66
import scala.cli.commands.SpecificationLevel
7-
import scala.cli.config.PublishCredentialsAsJson._
8-
import scala.cli.config.RepositoryCredentialsAsJson._
9-
import scala.cli.config.Util._ // only used in 2.12, unused import in 2.13
7+
import scala.cli.config.PublishCredentialsAsJson.*
8+
import scala.cli.config.RepositoryCredentialsAsJson.*
109

1110
/** A configuration key
1211
*/
@@ -73,7 +72,7 @@ object Key {
7372
extends EntryError("Error parsing config JSON", Some(cause))
7473

7574
final class MalformedValue(
76-
entry: Key[_],
75+
entry: Key[?],
7776
input: Seq[String],
7877
messageOrExpectedShape: Either[String, String],
7978
cause: Option[Throwable] = None
@@ -89,7 +88,7 @@ object Key {
8988
)
9089

9190
private final class MalformedEntry(
92-
entry: Key[_],
91+
entry: Key[?],
9392
messages: ::[String]
9493
) extends EntryError(
9594
s"Malformed entry ${entry.fullName}, " +
@@ -153,7 +152,7 @@ object Key {
153152
) extends Key[PasswordOption] {
154153
def parse(json: Array[Byte]): Either[EntryError, PasswordOption] =
155154
try {
156-
val str = readFromArray(json)(stringJsonCodec)
155+
val str = readFromArray(json)(using stringJsonCodec)
157156
PasswordOption.parse(str).left.map { e =>
158157
new MalformedValue(this, Seq(str), Right(e))
159158
}
@@ -163,7 +162,7 @@ object Key {
163162
Left(new JsonReaderError(e))
164163
}
165164
def write(value: PasswordOption): Array[Byte] =
166-
writeToArray(value.asString.value)(stringJsonCodec)
165+
writeToArray(value.asString.value)(using stringJsonCodec)
167166
def asString(value: PasswordOption): Seq[String] = Seq(value.asString.value)
168167
def fromString(values: Seq[String]): Either[MalformedValue, PasswordOption] =
169168
values match {

modules/config/src/main/scala/scala/cli/config/Keys.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package scala.cli.config
22

3-
import com.github.plokhotnyuk.jsoniter_scala.core.{Key => _}
3+
import com.github.plokhotnyuk.jsoniter_scala.core.Key as _
44

55
import scala.cli.commands.SpecificationLevel
66

@@ -142,7 +142,7 @@ object Keys {
142142
)
143143

144144
// Kept for binary compatibility
145-
val repositoriesMirrors = repositoryMirrors
145+
val repositoriesMirrors: Key.StringListEntry = repositoryMirrors
146146

147147
// setting indicating if the global interactive mode was suggested
148148
val globalInteractiveWasSuggested = new Key.BooleanEntry(
@@ -169,7 +169,7 @@ object Keys {
169169
"Publishing credentials, syntax: repositoryAddress value:user value:password [realm]"
170170
)
171171

172-
def all: Seq[Key[_]] = Seq[Key[_]](
172+
def all: Seq[Key[?]] = Seq[Key[?]](
173173
actions,
174174
defaultRepositories,
175175
ghToken,
@@ -194,5 +194,5 @@ object Keys {
194194
userName,
195195
userUrl
196196
)
197-
lazy val map: Map[String, Key[_]] = all.map(e => e.fullName -> e).toMap
197+
lazy val map: Map[String, Key[?]] = all.map(e => e.fullName -> e).toMap
198198
}

modules/config/src/main/scala/scala/cli/config/PasswordOption.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package scala.cli.config
22

3-
import com.github.plokhotnyuk.jsoniter_scala.core._
4-
import com.github.plokhotnyuk.jsoniter_scala.macros._
3+
import com.github.plokhotnyuk.jsoniter_scala.core.*
4+
import com.github.plokhotnyuk.jsoniter_scala.macros.*
55

66
import java.io.ByteArrayOutputStream
77
import java.nio.charset.StandardCharsets
88
import java.nio.file.{Files, Path, Paths}
99

1010
sealed abstract class PasswordOption extends Product with Serializable {
1111
def get(): Secret[String]
12-
def getBytes(): Secret[Array[Byte]] = get().map(_.getBytes(StandardCharsets.UTF_8))
12+
def getBytes: Secret[Array[Byte]] = get().map(_.getBytes(StandardCharsets.UTF_8))
1313
def asString: Secret[String]
1414
}
1515

@@ -27,7 +27,7 @@ abstract class LowPriorityPasswordOption {
2727
Right(PasswordOption.Env(str.stripPrefix("env:")))
2828
else if (str.startsWith("command:["))
2929
try {
30-
val command = readFromString(str.stripPrefix("command:"))(commandCodec)
30+
val command = readFromString(str.stripPrefix("command:"))(using commandCodec)
3131
Right(PasswordOption.Command(command))
3232
}
3333
catch {
@@ -64,7 +64,7 @@ object PasswordOption extends LowPriorityPasswordOption {
6464
val value = new String(Files.readAllBytes(path), StandardCharsets.UTF_8) // trim that?
6565
Secret(value)
6666
}
67-
override def getBytes(): Secret[Array[Byte]] = {
67+
override def getBytes: Secret[Array[Byte]] = {
6868
val value = Files.readAllBytes(path)
6969
Secret(value)
7070
}
@@ -89,7 +89,7 @@ object PasswordOption extends LowPriorityPasswordOption {
8989

9090
val p = b.start()
9191

92-
val is = p.getInputStream()
92+
val is = p.getInputStream
9393
var read = -1
9494
val buf = Array.ofDim[Byte](2048)
9595
val baos = new ByteArrayOutputStream
@@ -106,11 +106,11 @@ object PasswordOption extends LowPriorityPasswordOption {
106106
s"Error running command ${command.mkString(" ")} (exit code: $exitCode)"
107107
)
108108

109-
val res = new String(baos.toByteArray()) // Using default codec here
109+
val res = new String(baos.toByteArray) // Using default codec here
110110
Secret(res)
111111
}
112112
def asString: Secret[String] = {
113-
val json = writeToString(command.toList)(commandCodec)
113+
val json = writeToString(command.toList)(using commandCodec)
114114
Secret(s"command:$json")
115115
}
116116
}

modules/config/src/main/scala/scala/cli/config/RawJson.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package scala.cli.config
22

3-
import com.github.plokhotnyuk.jsoniter_scala.core._
3+
import com.github.plokhotnyuk.jsoniter_scala.core.*
44

55
import java.nio.charset.StandardCharsets
6-
import java.util.Arrays
6+
import java.util
77

88
import scala.util.Try
99
import scala.util.hashing.MurmurHash3
@@ -12,7 +12,7 @@ import scala.util.hashing.MurmurHash3
1212
private[config] final case class RawJson(value: Array[Byte]) {
1313
override lazy val hashCode: Int = MurmurHash3.arrayHash(value)
1414
override def equals(obj: Any): Boolean = obj match {
15-
case that: RawJson => Arrays.equals(value, that.value)
15+
case that: RawJson => util.Arrays.equals(value, that.value)
1616
case _ => false
1717
}
1818
override def toString: String =

0 commit comments

Comments
 (0)