Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 5 additions & 4 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
version = 2.3.2
edition = 2019-10
version = 3.9.9
runner.dialect = scala213
maxColumn = 100
project.git = true
lineEndings = preserve

# https://docs.scala-lang.org/style/scaladoc.html recommends the JavaDoc style.
# scala/scala is written that way too https://github.com/scala/scala/blob/v2.12.2/src/library/scala/Predef.scala
docstrings = JavaDoc
docstrings.style = Asterisk
docstrings.wrap = false

# This also seems more idiomatic to include whitespace in import x.{ yyy }
spaces.inImportCurlyBraces = true
Expand All @@ -17,6 +18,6 @@ align.openParenCallSite = false
align.openParenDefnSite = false

# For better code clarity
danglingParentheses = true
danglingParentheses.preset = true

trailingCommas = preserve
4 changes: 2 additions & 2 deletions launcher-implementation/src/main/scala/xsbt/boot/Boot.scala
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ object Boot {
catch {
case b: BootException => errorAndExit(b.toString)
case r: xsbti.RetrieveException => errorAndExit(r.getMessage)
case r: xsbti.FullReload => Some(new LauncherArguments(r.arguments.toList, false, false))
case e: Throwable =>
case r: xsbti.FullReload => Some(new LauncherArguments(r.arguments.toList, false, false))
case e: Throwable =>
e.printStackTrace
errorAndExit(Pre.prefixError(e.toString))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,27 @@ private[boot] object BootConfiguration {

val SbtOrg = "org.scala-sbt"

/** The Ivy conflict manager to use for updating.*/
/** The Ivy conflict manager to use for updating. */
val ConflictManagerName = "latest-revision"

/** The name of the local Ivy repository, which is used when compiling sbt from source.*/
/** The name of the local Ivy repository, which is used when compiling sbt from source. */
val LocalIvyName = "local"

/** The pattern used for the local Ivy repository, which is used when compiling sbt from source.*/
/** The pattern used for the local Ivy repository, which is used when compiling sbt from source. */
val LocalPattern = "[organisation]/[module]/[revision]/[type]s/[artifact](-[classifier]).[ext]"

/** The artifact pattern used for the local Ivy repository.*/
/** The artifact pattern used for the local Ivy repository. */
def LocalArtifactPattern = LocalPattern

/** The Ivy pattern used for the local Ivy repository.*/
/** The Ivy pattern used for the local Ivy repository. */
def LocalIvyPattern = LocalPattern

final val FjbgPackage = "ch.epfl.lamp.fjbg."

/** The class name prefix used to hide the Scala classes used by this loader from the application */
final val ScalaPackage = "scala."

/** The class name prefix used to hide the Ivy classes used by this loader from the application*/
/** The class name prefix used to hide the Ivy classes used by this loader from the application */
final val IvyPackage = "org.apache.ivy."

/**
Expand Down Expand Up @@ -92,11 +92,11 @@ private[boot] object BootConfiguration {

val ScalaVersionPrefix = "scala-"

/** The name of the directory to retrieve the application and its dependencies to.*/
/** The name of the directory to retrieve the application and its dependencies to. */
def appDirectoryName(appID: xsbti.ApplicationID, sep: String) =
appID.groupID + sep + appID.name + sep + appID.version

/** The name of the directory in the boot directory to put all jars for the given version of scala in.*/
/** The name of the directory in the boot directory to put all jars for the given version of scala in. */
def baseDirectoryName(scalaOrg: String, scalaVersion: Option[String]) = scalaVersion match {
case None => "other"
case Some(sv) => (if (scalaOrg == ScalaOrg) "" else scalaOrg + ".") + ScalaVersionPrefix + sv
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ object Configuration {
}
def setProperty(head: String): Unit = {
head.split("=", 2) match {
case Array("") => Console.err.println(s"[warn] [launcher] invalid system property '$head'")
case Array(key) => sys.props += key -> ""
case Array("") => Console.err.println(s"[warn] [launcher] invalid system property '$head'")
case Array(key) => sys.props += key -> ""
case Array(key, value) => sys.props += key -> value
case _ => ()
}
Expand All @@ -67,10 +67,12 @@ object Configuration {
def configurationFromFile(path: String, baseDirectory: File): URL = {
val pathURI = filePathURI(path)
def resolve(against: URI): Option[URL] = {
val resolved = against.resolve(pathURI) // variant that accepts String doesn't properly escape (#725)
val exists = try {
(new File(resolved)).exists
} catch { case _: IllegalArgumentException => false }
val resolved =
against.resolve(pathURI) // variant that accepts String doesn't properly escape (#725)
val exists =
try {
(new File(resolved)).exists
} catch { case _: IllegalArgumentException => false }
if (exists) Some(resolved.toURL) else None
}
val against = resolveAgainst(baseDirectory)
Expand Down Expand Up @@ -110,7 +112,8 @@ object Configuration {
if (m.matches())
subPartsIndices flatMap { is =>
fullMatchOnly(is.map(m.group))
} else
}
else
noMatchParts
}
def noMatchParts: List[String] = DefaultVersionPart :: fallbackParts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ class ConfigurationParser {

def toFiles(paths: List[String]): List[File] = paths.map(toFile)
def toFile(path: String): File =
new File(substituteVariables(path).replace('/', File.separatorChar)) // if the path is relative, it will be resolved by Launch later
new File(
substituteVariables(path).replace('/', File.separatorChar)
) // if the path is relative, it will be resolved by Launch later
def file(map: LabelMap, name: String, default: File): (File, LabelMap) =
(orElse(getOrNone(map, name).map(toFile), default), map - name)
def optfile(map: LabelMap, name: String): (Option[File], LabelMap) =
Expand Down Expand Up @@ -213,14 +215,15 @@ class ConfigurationParser {
m.toList.map {
case (key, None) => Predefined(key)
case (key, Some(BootOnly)) => Predefined(key, true)
case (key, Some(value)) =>
case (key, Some(value)) =>
val r = trim(substituteVariables(value).split(",", 8))
val url = try {
new URL(r(0))
} catch {
case e: MalformedURLException =>
Pre.error("invalid URL specified for '" + key + "': " + e.getMessage)
}
val url =
try {
new URL(r(0))
} catch {
case e: MalformedURLException =>
Pre.error("invalid URL specified for '" + key + "': " + e.getMessage)
}
val (optionPart, patterns) = r.tail.partition(OptSet.contains(_))
val options = (
optionPart.contains(BootOnly),
Expand Down Expand Up @@ -270,7 +273,7 @@ class ConfigurationParser {
}
def parsePropertyDefinition(name: String)(value: String) = value.split("=", 2) match {
case Array(mode, value) => (mode, parsePropertyValue(name, value)(defineProperty(name)))
case x => Pre.error("invalid property definition '" + x + "' for property '" + name + "'")
case x => Pre.error("invalid property definition '" + x + "' for property '" + name + "'")
}
def defineProperty(
name: String
Expand All @@ -280,7 +283,8 @@ class ConfigurationParser {
case "set" => new SetProperty(requiredArg)
case _ => Pre.error("unknown action '" + action + "' for property '" + name + "'")
}
private[this] lazy val propertyPattern = Pattern.compile("""(.+)\((.*)\)(?:\[(.*)\])?""") // examples: prompt(Version)[1.0] or set(1.0)
private[this] lazy val propertyPattern =
Pattern.compile("""(.+)\((.*)\)(?:\[(.*)\])?""") // examples: prompt(Version)[1.0] or set(1.0)
def parsePropertyValue[T](name: String, definition: String)(
f: (String, String, Option[String]) => T
): T = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class CousierUpdate(config: UpdateConfiguration) {
.orElse(sys.env.get("COURSIER_CACHE").map(absoluteFile))
.orElse(sys.props.get("coursier.cache").map(absoluteFile)) match {
case Some(dir) => dir
case _ =>
case _ =>
if (isWindows) windowsCacheDirectory
else CacheDefaults.location
}
Expand Down Expand Up @@ -128,7 +128,7 @@ class CousierUpdate(config: UpdateConfiguration) {
case u: UpdateApp =>
val app = u.id
val resolvedName = (app.crossVersioned, scalaVersion) match {
case (xsbti.CrossValue.Full, Some(sv)) => app.getName + "_" + sv
case (xsbti.CrossValue.Full, Some(sv)) => app.getName + "_" + sv
case (xsbti.CrossValue.Binary, Some(sv)) =>
app.getName + "_" + CrossVersionUtil.binaryScalaVersion(sv)
case _ => app.getName
Expand Down Expand Up @@ -273,9 +273,9 @@ class CousierUpdate(config: UpdateConfiguration) {
def bootCredentials = {
val optionProps =
Option(System.getProperty("sbt.boot.credentials")) orElse
Option(System.getenv("SBT_CREDENTIALS")) map (
path => Pre.readProperties(new File(substituteTilde(path)))
)
Option(System.getenv("SBT_CREDENTIALS")) map (path =>
Pre.readProperties(new File(substituteTilde(path)))
)
def extractCredentials(
keys: (String, String, String, String)
)(props: Properties): Option[DirectCredentials] = {
Expand Down Expand Up @@ -348,7 +348,7 @@ class CousierUpdate(config: UpdateConfiguration) {
MavenRepository(root)
}

/** Uses the pattern defined in BuildConfiguration to download sbt from Google code.*/
/** Uses the pattern defined in BuildConfiguration to download sbt from Google code. */
private def ivyRepository(
id: String,
base: String,
Expand Down
14 changes: 8 additions & 6 deletions launcher-implementation/src/main/scala/xsbt/boot/Create.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ object Initialize {
spec: List[AppProperty]
): Unit = {
readLine(promptCreate + " (y/N" + (if (enableQuick) "/s" else "") + ") ") match {
case None => declined("")
case None => declined("")
case Some(line) =>
line.toLowerCase(Locale.ENGLISH) match {
case "y" | "yes" => process(file, spec, selectCreate)
case "s" => process(file, spec, selectQuick)
case "n" | "no" | "" => declined("")
case x =>
case x =>
Console.err.println(" '" + x + "' not understood.")
create(file, promptCreate, enableQuick, spec)
}
Expand All @@ -43,20 +43,22 @@ object Initialize {
): Unit = {
val properties = readProperties(file)
val uninitialized =
for (property <- appProperties; init <- select(property)
if properties.getProperty(property.name) == null)
for (
property <- appProperties; init <- select(property)
if properties.getProperty(property.name) == null
)
yield initialize(properties, property.name, init)
if (!uninitialized.isEmpty) writeProperties(properties, file, "")
}

@nowarn
def initialize(properties: Properties, name: String, init: PropertyInit): Unit = {
init match {
case set: SetProperty => properties.setProperty(name, set.value)
case set: SetProperty => properties.setProperty(name, set.value)
case prompt: PromptProperty =>
def noValue = declined("no value provided for " + prompt.label)
readLine(prompt.label + prompt.default.toList.map(" [" + _ + "]").mkString + ": ") match {
case None => noValue
case None => noValue
case Some(line) =>
val value =
if (isEmpty(line)) orElse(prompt.default, noValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ class Enumeration extends Serializable {
val c = getClass
val correspondingFields = ListMap(c.getDeclaredFields.map(f => (f.getName, f)): _*)
c.getMethods.toList flatMap { method =>
if (method.getParameterTypes.length == 0 && classOf[Value].isAssignableFrom(
method.getReturnType
)) {
for (field <- correspondingFields.get(method.getName)
if field.getType == method.getReturnType) yield method.invoke(this).asInstanceOf[Value]
if (
method.getParameterTypes.length == 0 && classOf[Value].isAssignableFrom(
method.getReturnType
)
) {
for (
field <- correspondingFields.get(method.getName)
if field.getType == method.getReturnType
) yield method.invoke(this).asInstanceOf[Value]
} else
Nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ private[boot] final class BootFilteredLoader(parent: ClassLoader) extends ClassL
@throws(classOf[ClassNotFoundException])
override final def loadClass(className: String, resolve: Boolean): Class[_] = {
// note that we allow xsbti.*
if (className.startsWith(ScalaPackage) || className.startsWith(IvyPackage) || className
.startsWith(SbtBootPackage) || className.startsWith(FjbgPackage))
if (
className.startsWith(ScalaPackage) || className.startsWith(IvyPackage) || className
.startsWith(SbtBootPackage) || className.startsWith(FjbgPackage)
)
throw new ClassNotFoundException(className)
else
super.loadClass(className, resolve)
Expand Down
8 changes: 5 additions & 3 deletions launcher-implementation/src/main/scala/xsbt/boot/Find.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ class Find(config: LaunchConfiguration) {
search.tpe match {
case Search.RootFirst => fromRoot.headOption
case Search.Nearest => fromRoot.lastOption
case Search.Only =>
case Search.Only =>
if (hasProject(current))
Some(current)
else
fromRoot match {
case Nil => Some(current)
case head :: Nil => Some(head)
case xs =>
case xs =>
Console.err.println(
"[error] [launcher] search method is 'only' and multiple ancestor directories match:\n\t" + fromRoot
.mkString("\n\t")
Expand All @@ -55,7 +55,9 @@ object ResolvePaths {
def apply(baseDirectory: File, f: File): File =
if (f.isAbsolute) f
else {
assert(baseDirectory.isDirectory) // if base directory is not a directory, URI.resolve will not work properly
assert(
baseDirectory.isDirectory
) // if base directory is not a directory, URI.resolve will not work properly
val uri = new URI(null, null, f.getPath, null)
new File(baseDirectory.toURI.resolve(uri))
}
Expand Down
8 changes: 4 additions & 4 deletions launcher-implementation/src/main/scala/xsbt/boot/JAnsi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ object JAnsi {
} catch {
case ignore: ClassNotFoundException =>
/* The below code intentionally traps everything. It technically shouldn't trap the
* non-StackOverflowError VirtualMachineErrors and AWTError would be weird, but this is PermGen
* mitigation code that should not render sbt completely unusable if jansi initialization fails.
* [From Mark Harrah, https://github.com/sbt/sbt/pull/633#issuecomment-11957578].
*/
* non-StackOverflowError VirtualMachineErrors and AWTError would be weird, but this is PermGen
* mitigation code that should not render sbt completely unusable if jansi initialization fails.
* [From Mark Harrah, https://github.com/sbt/sbt/pull/633#issuecomment-11957578].
*/
case ex: Throwable =>
Console.err.println(
"[error] [launcher] Jansi found on class path but initialization failed: " + ex
Expand Down
19 changes: 11 additions & 8 deletions launcher-implementation/src/main/scala/xsbt/boot/Launch.scala
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ object Launch {
/** The actual mechanism used to run a launched application. */
def run(launcher: xsbti.Launcher)(config: RunConfiguration): xsbti.MainResult = {
import config._
val appProvider
: xsbti.AppProvider = launcher.app(app, orNull(scalaVersion)) // takes ~40 ms when no update is required
val appProvider: xsbti.AppProvider =
launcher.app(app, orNull(scalaVersion)) // takes ~40 ms when no update is required
val appConfig: xsbti.AppConfiguration =
new AppConfiguration(toArray(arguments), workingDirectory, appProvider)

Expand All @@ -159,7 +159,7 @@ object Launch {
run(config) match {
case e: xsbti.Exit => Some(e.code)
case c: xsbti.Continue => None
case r: xsbti.Reboot =>
case r: xsbti.Reboot =>
launch(run)(
new RunConfiguration(Option(r.scalaVersion), r.app, r.baseDirectory, r.arguments.toList)
)
Expand Down Expand Up @@ -219,14 +219,15 @@ class Launch private[xsbt] (

@nowarn
private[this] val initLoader: ClassLoader = if (isWindows && !isCygwin) {
val version = sys.props.get(Configuration.SbtVersionProperty) orElse Configuration.guessSbtVersion
val version =
sys.props.get(Configuration.SbtVersionProperty) orElse Configuration.guessSbtVersion
if (version.fold(false)(_.startsWith("0."))) jansiLoader(bootLoader) else bootLoader
} else bootLoader

private[this] val scalaProviderClassLoader = new AtomicReference(initLoader)
def topLoader: ClassLoader = scalaProviderClassLoader.get()
private val scalaProviders = new Cache[(String, String), String, xsbti.ScalaProvider](
(x, y) => getScalaProvider(x._1, x._2, y, scalaProviderClassLoader.get)
private val scalaProviders = new Cache[(String, String), String, xsbti.ScalaProvider]((x, y) =>
getScalaProvider(x._1, x._2, y, scalaProviderClassLoader.get)
)

val updateLockFile = if (lockBoot) Some(new File(bootDirectory, "sbt.boot.lock")) else None
Expand Down Expand Up @@ -317,8 +318,10 @@ class Launch private[xsbt] (
// set the Scala version of sbt 1.4.x series to 2.12.12 explicitly
// since util-interface depends on Scala 2.13 by mistake
// https://github.com/sbt/sbt/blob/v1.4.0/project/Dependencies.scala
if (id.groupID() == "org.scala-sbt" &&
id.name() == "sbt" && id.version().startsWith("1.4.")) Some("2.12.12")
if (
id.groupID() == "org.scala-sbt" &&
id.name() == "sbt" && id.version().startsWith("1.4.")
) Some("2.12.12")
else None
}
val app = appModule(id, explicitScalaVersion, true, "app")
Expand Down
Loading