diff --git a/.scalafmt.conf b/.scalafmt.conf index 9437871..5e7d9a0 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -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 @@ -17,6 +18,6 @@ align.openParenCallSite = false align.openParenDefnSite = false # For better code clarity -danglingParentheses = true +danglingParentheses.preset = true trailingCommas = preserve diff --git a/launcher-implementation/src/main/scala/xsbt/boot/Boot.scala b/launcher-implementation/src/main/scala/xsbt/boot/Boot.scala index c1c587b..8d9a93c 100644 --- a/launcher-implementation/src/main/scala/xsbt/boot/Boot.scala +++ b/launcher-implementation/src/main/scala/xsbt/boot/Boot.scala @@ -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)) } diff --git a/launcher-implementation/src/main/scala/xsbt/boot/BootConfiguration.scala b/launcher-implementation/src/main/scala/xsbt/boot/BootConfiguration.scala index e47c3df..168e4ac 100644 --- a/launcher-implementation/src/main/scala/xsbt/boot/BootConfiguration.scala +++ b/launcher-implementation/src/main/scala/xsbt/boot/BootConfiguration.scala @@ -25,19 +25,19 @@ 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." @@ -45,7 +45,7 @@ private[boot] object BootConfiguration { /** 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." /** @@ -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 diff --git a/launcher-implementation/src/main/scala/xsbt/boot/Configuration.scala b/launcher-implementation/src/main/scala/xsbt/boot/Configuration.scala index 4ae2f2f..a22f9a2 100644 --- a/launcher-implementation/src/main/scala/xsbt/boot/Configuration.scala +++ b/launcher-implementation/src/main/scala/xsbt/boot/Configuration.scala @@ -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 _ => () } @@ -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) @@ -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 diff --git a/launcher-implementation/src/main/scala/xsbt/boot/ConfigurationParser.scala b/launcher-implementation/src/main/scala/xsbt/boot/ConfigurationParser.scala index 950d75e..986a7ea 100644 --- a/launcher-implementation/src/main/scala/xsbt/boot/ConfigurationParser.scala +++ b/launcher-implementation/src/main/scala/xsbt/boot/ConfigurationParser.scala @@ -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) = @@ -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), @@ -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 @@ -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 = { diff --git a/launcher-implementation/src/main/scala/xsbt/boot/CoursierUpdate.scala b/launcher-implementation/src/main/scala/xsbt/boot/CoursierUpdate.scala index 73b410e..1f46c1a 100644 --- a/launcher-implementation/src/main/scala/xsbt/boot/CoursierUpdate.scala +++ b/launcher-implementation/src/main/scala/xsbt/boot/CoursierUpdate.scala @@ -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 } @@ -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 @@ -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] = { @@ -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, diff --git a/launcher-implementation/src/main/scala/xsbt/boot/Create.scala b/launcher-implementation/src/main/scala/xsbt/boot/Create.scala index 75bdd84..e859565 100644 --- a/launcher-implementation/src/main/scala/xsbt/boot/Create.scala +++ b/launcher-implementation/src/main/scala/xsbt/boot/Create.scala @@ -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) } @@ -43,8 +43,10 @@ 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, "") } @@ -52,11 +54,11 @@ object Initialize { @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) diff --git a/launcher-implementation/src/main/scala/xsbt/boot/Enumeration.scala b/launcher-implementation/src/main/scala/xsbt/boot/Enumeration.scala index 108313f..45c8fa8 100644 --- a/launcher-implementation/src/main/scala/xsbt/boot/Enumeration.scala +++ b/launcher-implementation/src/main/scala/xsbt/boot/Enumeration.scala @@ -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 } diff --git a/launcher-implementation/src/main/scala/xsbt/boot/FilteredLoader.scala b/launcher-implementation/src/main/scala/xsbt/boot/FilteredLoader.scala index 586d2d4..c6aa4c8 100644 --- a/launcher-implementation/src/main/scala/xsbt/boot/FilteredLoader.scala +++ b/launcher-implementation/src/main/scala/xsbt/boot/FilteredLoader.scala @@ -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) diff --git a/launcher-implementation/src/main/scala/xsbt/boot/Find.scala b/launcher-implementation/src/main/scala/xsbt/boot/Find.scala index 21a5718..1236456 100644 --- a/launcher-implementation/src/main/scala/xsbt/boot/Find.scala +++ b/launcher-implementation/src/main/scala/xsbt/boot/Find.scala @@ -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") @@ -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)) } diff --git a/launcher-implementation/src/main/scala/xsbt/boot/JAnsi.scala b/launcher-implementation/src/main/scala/xsbt/boot/JAnsi.scala index a485b21..39af472 100644 --- a/launcher-implementation/src/main/scala/xsbt/boot/JAnsi.scala +++ b/launcher-implementation/src/main/scala/xsbt/boot/JAnsi.scala @@ -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 diff --git a/launcher-implementation/src/main/scala/xsbt/boot/Launch.scala b/launcher-implementation/src/main/scala/xsbt/boot/Launch.scala index 018513a..8928273 100644 --- a/launcher-implementation/src/main/scala/xsbt/boot/Launch.scala +++ b/launcher-implementation/src/main/scala/xsbt/boot/Launch.scala @@ -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) @@ -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) ) @@ -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 @@ -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") diff --git a/launcher-implementation/src/main/scala/xsbt/boot/LaunchConfiguration.scala b/launcher-implementation/src/main/scala/xsbt/boot/LaunchConfiguration.scala index 4474aa1..80e825c 100644 --- a/launcher-implementation/src/main/scala/xsbt/boot/LaunchConfiguration.scala +++ b/launcher-implementation/src/main/scala/xsbt/boot/LaunchConfiguration.scala @@ -127,8 +127,8 @@ object Value { def get[T](v: Value[T]): T = v match { case e: Explicit[T] => e.value; case _ => throw new BootException("unresolved version: " + v) } - def readImplied[T](s: String, name: String, default: Option[String])( - implicit read: String => T + def readImplied[T](s: String, name: String, default: Option[String])(implicit + read: String => T ): Value[T] = if (s == "read") new Implicit(name, default map read) else Pre.error("expected 'read', got '" + s + "'") @@ -146,7 +146,7 @@ object LaunchCrossVersion { case x if CrossVersionUtil.isFull(s) => xsbti.CrossValue.Full case x if CrossVersionUtil.isBinary(s) => xsbti.CrossValue.Binary case x if CrossVersionUtil.isDisabled(s) => xsbti.CrossValue.Disabled - case x => Pre.error("unknown value '" + x + "' for property 'cross-versioned'") + case x => Pre.error("unknown value '" + x + "' for property 'cross-versioned'") } } @@ -202,7 +202,7 @@ object Application { catch { case _: AbstractMethodError => // Before 0.13 this method did not exist on application, so we need to provide a default value - //in the event we're dealing with an older Application. + // in the event we're dealing with an older Application. if (id.crossVersioned) xsbti.CrossValue.Binary else xsbti.CrossValue.Disabled } diff --git a/launcher-implementation/src/main/scala/xsbt/boot/Locks.scala b/launcher-implementation/src/main/scala/xsbt/boot/Locks.scala index acf1cf0..1052a51 100644 --- a/launcher-implementation/src/main/scala/xsbt/boot/Locks.scala +++ b/launcher-implementation/src/main/scala/xsbt/boot/Locks.scala @@ -95,14 +95,16 @@ object Locks extends xsbti.GlobalLock { } def withChannel(channel: FileChannel) = { - val freeLock = try { - channel.tryLock - } catch { case e: NullPointerException => throw new InternalLockNPE(e) } + val freeLock = + try { + channel.tryLock + } catch { case e: NullPointerException => throw new InternalLockNPE(e) } if (freeLock eq null) { Console.err.println("[info] waiting for lock on " + file + " to be available..."); - val lock = try { - channel.lock - } catch { case e: NullPointerException => throw new InternalLockNPE(e) } + val lock = + try { + channel.lock + } catch { case e: NullPointerException => throw new InternalLockNPE(e) } try { run.call } finally { diff --git a/launcher-implementation/src/main/scala/xsbt/boot/ParallelResolveEngine.scala b/launcher-implementation/src/main/scala/xsbt/boot/ParallelResolveEngine.scala index 1a3893d..7de1165 100644 --- a/launcher-implementation/src/main/scala/xsbt/boot/ParallelResolveEngine.scala +++ b/launcher-implementation/src/main/scala/xsbt/boot/ParallelResolveEngine.scala @@ -42,17 +42,18 @@ private[xsbt] class ParallelResolveEngine( } // Farm out the dependencies for parallel download implicit val ec = ParallelResolveEngine.resolveExecutionContext - val allDownloadsFuture = Future.traverse(report.getDependencies.asScala) { - case dep: IvyNode => - Future { - if (!(dep.isCompletelyEvicted || dep.hasProblem) && - dep.getModuleRevision != null) { - Some(downloadNodeArtifacts(dep, artifactFilter, options)) - } else None - } + val allDownloadsFuture = Future.traverse(report.getDependencies.asScala) { case dep: IvyNode => + Future { + if ( + !(dep.isCompletelyEvicted || dep.hasProblem) && + dep.getModuleRevision != null + ) { + Some(downloadNodeArtifacts(dep, artifactFilter, options)) + } else None + } } val allDownloads = Await.result(allDownloadsFuture, Duration.Inf) - //compute total downloaded size + // compute total downloaded size val totalSize = allDownloads.foldLeft(0L) { case (size, Some(download)) => val dependency = download.dep @@ -61,8 +62,10 @@ private[xsbt] class ParallelResolveEngine( val configurationReport = report.getConfigurationReport(configuration) // Take into account artifacts required by the given configuration - if (dependency.isEvicted(configuration) || - dependency.isBlacklisted(configuration)) { + if ( + dependency.isEvicted(configuration) || + dependency.isBlacklisted(configuration) + ) { configurationReport.addDependency(dependency) } else configurationReport.addDependency(dependency, download.report) } diff --git a/launcher-implementation/src/main/scala/xsbt/boot/ParallelRetrieveEngine.scala b/launcher-implementation/src/main/scala/xsbt/boot/ParallelRetrieveEngine.scala index 59f8abe..5f60772 100644 --- a/launcher-implementation/src/main/scala/xsbt/boot/ParallelRetrieveEngine.scala +++ b/launcher-implementation/src/main/scala/xsbt/boot/ParallelRetrieveEngine.scala @@ -93,20 +93,19 @@ private[xsbt] class ParallelRetrieveEngine( } else { Message.verbose("\tretrieving " + archive) - Future.traverse(artifactAndPaths.getValue().asScala) { - case path: String => - Future { - IvyContext.getContext().checkInterrupted() - val _ = settings.resolveFile(path) - retrieveFile( - settings, - eventManager, - artifact, - archive, - path, - options - ) - } + Future.traverse(artifactAndPaths.getValue().asScala) { case path: String => + Future { + IvyContext.getContext().checkInterrupted() + val _ = settings.resolveFile(path) + retrieveFile( + settings, + eventManager, + artifact, + archive, + path, + options + ) + } } } } @@ -114,14 +113,13 @@ private[xsbt] class ParallelRetrieveEngine( val allRetrived: mSet[RetResult] = Await.result(Future.reduceLeft(allRetrivedFuture.toList)(_ ++ _), Duration.Inf) - val totalCopiedSize = allRetrived.foldLeft(0L) { - case (sum, ret) => - if (ret.copied) - report.addCopiedFile(ret.destFile, ret.artifact) - else - report.addUpToDateFile(ret.destFile, ret.artifact) + val totalCopiedSize = allRetrived.foldLeft(0L) { case (sum, ret) => + if (ret.copied) + report.addCopiedFile(ret.destFile, ret.artifact) + else + report.addUpToDateFile(ret.destFile, ret.artifact) - sum + ret.totalSizeDownloaded + sum + ret.totalSizeDownloaded } val elapsedTime = System.currentTimeMillis() - start diff --git a/launcher-implementation/src/main/scala/xsbt/boot/PlainApplication.scala b/launcher-implementation/src/main/scala/xsbt/boot/PlainApplication.scala index 45615c8..8d4d1da 100644 --- a/launcher-implementation/src/main/scala/xsbt/boot/PlainApplication.scala +++ b/launcher-implementation/src/main/scala/xsbt/boot/PlainApplication.scala @@ -8,16 +8,18 @@ class PlainApplication private (mainMethod: java.lang.reflect.Method) extends xs val IntClass = classOf[Int] val ExitClass = classOf[xsbti.Exit] // It seems we may need to wrap exceptions here... - try mainMethod.getReturnType match { - case ExitClass => - mainMethod.invoke(null, configuration.arguments).asInstanceOf[xsbti.Exit] - case IntClass => - PlainApplication.Exit(mainMethod.invoke(null, configuration.arguments).asInstanceOf[Int]) - case _ => - // Here we still invoke, but return 0 if sucessful (no exceptions). - mainMethod.invoke(null, configuration.arguments) - PlainApplication.Exit(0) - } catch { + try + mainMethod.getReturnType match { + case ExitClass => + mainMethod.invoke(null, configuration.arguments).asInstanceOf[xsbti.Exit] + case IntClass => + PlainApplication.Exit(mainMethod.invoke(null, configuration.arguments).asInstanceOf[Int]) + case _ => + // Here we still invoke, but return 0 if sucessful (no exceptions). + mainMethod.invoke(null, configuration.arguments) + PlainApplication.Exit(0) + } + catch { // This is only thrown if the underlying reflective call throws. // Let's expose the underlying error. case e: java.lang.reflect.InvocationTargetException if e.getCause != null => diff --git a/launcher-implementation/src/main/scala/xsbt/boot/ServerApplication.scala b/launcher-implementation/src/main/scala/xsbt/boot/ServerApplication.scala index a1a71d3..83d72c6 100644 --- a/launcher-implementation/src/main/scala/xsbt/boot/ServerApplication.scala +++ b/launcher-implementation/src/main/scala/xsbt/boot/ServerApplication.scala @@ -35,9 +35,12 @@ object ServerApplication { object ServerLocator { // TODO - Probably want to drop this to reduce classfile size private def locked[U](file: File)(f: => U): U = { - Locks(file, new java.util.concurrent.Callable[U] { - def call(): U = f - }) + Locks( + file, + new java.util.concurrent.Callable[U] { + def call(): U = f + } + ) } // We use the lock file they give us to write the server info. However, // it seems we cannot both use the server info file for locking *and* @@ -48,12 +51,12 @@ object ServerLocator { // Launch the process and read the port... def locate(currentDirectory: File, config: LaunchConfiguration): URI = config.serverConfig match { - case None => sys.error("no server lock file configured. cannot locate server.") + case None => sys.error("no server lock file configured. cannot locate server.") case Some(sc) => locked(makeLockFile(sc.lockFile)) { readProperties(sc.lockFile) match { case Some(uri) if isReachable(uri) => uri - case _ => + case _ => val uri = ServerLauncher.startServer(currentDirectory, config) writeProperties(sc.lockFile, uri) uri @@ -131,7 +134,7 @@ object ServerLauncher { def startServer(currentDirectory: File, config: LaunchConfiguration): URI = { val serverConfig = config.serverConfig match { case Some(c) => c - case None => + case None => throw new RuntimeException( "logic failure: attempting to start a server that isn't configured to be a server. please report a bug." ) @@ -168,17 +171,19 @@ object ServerLauncher { ) errorDumper.start() // Now we look for the URI synch value, and then make sure we close the output files. - try readUntilSynch(new java.io.BufferedReader(new java.io.InputStreamReader(stdout))) match { - case Some(uri) => uri - case _ => - // attempt to get rid of the server (helps prevent hanging / stuck locks, - // though this is not reliable) - try process.destroy() - catch { case e: Exception => } - // block a second to try to get stuff from stderr - errorDumper.close(waitForErrors = true) - sys.error(s"failed to start server process in ${pb.directory} command line ${pb.command}") - } finally { + try + readUntilSynch(new java.io.BufferedReader(new java.io.InputStreamReader(stdout))) match { + case Some(uri) => uri + case _ => + // attempt to get rid of the server (helps prevent hanging / stuck locks, + // though this is not reliable) + try process.destroy() + catch { case e: Exception => } + // block a second to try to get stuff from stderr + errorDumper.close(waitForErrors = true) + sys.error(s"failed to start server process in ${pb.directory} command line ${pb.command}") + } + finally { errorDumper.close(waitForErrors = false) stdout.close() // Do not close stderr here because on Windows that will block, diff --git a/launcher-implementation/src/main/scala/xsbt/boot/Update.scala b/launcher-implementation/src/main/scala/xsbt/boot/Update.scala index 3f9ebbb..37a5731 100644 --- a/launcher-implementation/src/main/scala/xsbt/boot/Update.scala +++ b/launcher-implementation/src/main/scala/xsbt/boot/Update.scala @@ -77,7 +77,7 @@ final class UpdateResult( def this(success: Boolean, scalaVersion: Option[String]) = this(success, scalaVersion, None) } -/** Ensures that the Scala and application jars exist for the given versions or else downloads them.*/ +/** Ensures that the Scala and application jars exist for the given versions or else downloads them. */ final class Update(config: UpdateConfiguration) { import config.{ bootDirectory, @@ -97,9 +97,9 @@ final class Update(config: UpdateConfiguration) { private def addCredentials(): Unit = { 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))) + ) optionProps match { case Some(props) => extractCredentials(("realm", "host", "user", "password"))(props) case None => () @@ -148,7 +148,7 @@ final class Update(config: UpdateConfiguration) { val useCousier = x match { case Some("true") | Some("1") => true case Some(_) => false - case None => + case None => target match { // https://github.com/sbt/sbt/issues/6447 case u: UpdateApp @@ -248,7 +248,7 @@ final class Update(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 @@ -537,7 +537,7 @@ final class Update(config: UpdateConfiguration) { } } - /** 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 urlResolver( id: String, base: String, @@ -575,7 +575,7 @@ final class Update(config: UpdateConfiguration) { false ) - /** Creates a maven-style resolver.*/ + /** Creates a maven-style resolver. */ private def mavenResolver(name: String, root: String, allowInsecureProtocol: Boolean) = { val resolver = new IBiblioResolver resolver.setName(name) @@ -601,10 +601,10 @@ final class Update(config: UpdateConfiguration) { } private def centralRepositoryRoot: String = "https://repo1.maven.org/maven2/" - /** Creates a resolver for Maven Central.*/ + /** Creates a resolver for Maven Central. */ private def mavenMainResolver = defaultMavenResolver("Maven Central") - /** Creates a maven-style resolver with the default root.*/ + /** Creates a maven-style resolver with the default root. */ private def defaultMavenResolver(name: String) = mavenResolver(name, centralRepositoryRoot, false) private def localResolver(ivyUserDirectory: String) = { @@ -620,7 +620,8 @@ final class Update(config: UpdateConfiguration) { val m = SnapshotPattern.matcher(scalaVersion) if (m.matches) { val base = List(1, 2, 3).map(m.group).mkString(".") - val pattern = "https://oss.sonatype.org/content/repositories/snapshots/[organization]/[module]/" + base + "-SNAPSHOT/[artifact]-[revision](-[classifier]).[ext]" + val pattern = + "https://oss.sonatype.org/content/repositories/snapshots/[organization]/[module]/" + base + "-SNAPSHOT/[artifact]-[revision](-[classifier]).[ext]" val resolver = new URLResolver resolver.setName("Sonatype OSS Snapshots") diff --git a/launcher-implementation/src/test/scala/EnumerationTest.scala b/launcher-implementation/src/test/scala/EnumerationTest.scala index f87fd6f..677fa30 100644 --- a/launcher-implementation/src/test/scala/EnumerationTest.scala +++ b/launcher-implementation/src/test/scala/EnumerationTest.scala @@ -31,12 +31,11 @@ object EnumerationTest extends Properties("Enumeration") { ("Expected " + expected) |: (enum.toValue(s) == expected) val map = Map(mapped: _*) - Prop.forAll( - (s: String) => - map.get(s) match { - case Some(v) => valid(s, v) - case None => invalid(s) - } + Prop.forAll((s: String) => + map.get(s) match { + case Some(v) => valid(s, v) + case None => invalid(s) + } ) } object MultiEnum extends Enumeration { diff --git a/launcher-implementation/src/test/scala/ScalaProviderTest.scala b/launcher-implementation/src/test/scala/ScalaProviderTest.scala index 1633bcb..cc4acc0 100644 --- a/launcher-implementation/src/test/scala/ScalaProviderTest.scala +++ b/launcher-implementation/src/test/scala/ScalaProviderTest.scala @@ -92,8 +92,8 @@ object ScalaProviderTest extends verify.BasicTestSuite { private def createExtra(currentDirectory: File) = { val resourceDirectory = new File(currentDirectory, "resources") createDirectory(resourceDirectory) - testResources.foreach( - resource => touch(new File(resourceDirectory, resource.replace('/', File.separatorChar))) + testResources.foreach(resource => + touch(new File(resourceDirectory, resource.replace('/', File.separatorChar))) ) Array(resourceDirectory) } diff --git a/launcher-implementation/src/test/scala/ServerLocatorTest.scala b/launcher-implementation/src/test/scala/ServerLocatorTest.scala index e97bada..fb43114 100644 --- a/launcher-implementation/src/test/scala/ServerLocatorTest.scala +++ b/launcher-implementation/src/test/scala/ServerLocatorTest.scala @@ -39,8 +39,9 @@ object ServerLocatorTest extends verify.BasicTestSuite { |${ServerApplication.SERVER_SYNCH_TEXT}${expected.toASCIIString} |Some more output.""".stripMargin val inputStream = new java.io.BufferedReader(new java.io.StringReader(input)) - val result = try ServerLauncher.readUntilSynch(inputStream) - finally inputStream.close() + val result = + try ServerLauncher.readUntilSynch(inputStream) + finally inputStream.close() assert(result == Some(expected)) } } diff --git a/launcher-implementation/src/test/scala/URITests.scala b/launcher-implementation/src/test/scala/URITests.scala index 9b371ce..401e19f 100644 --- a/launcher-implementation/src/test/scala/URITests.scala +++ b/launcher-implementation/src/test/scala/URITests.scala @@ -37,7 +37,7 @@ object URITests extends Properties("URI Tests") { s"getRawPath: ${fpURI.getRawPath}" |: (fpURI == directURI) && (fpURI.getPath == decoded) && - (fpURI.getRawPath == encoded) + (fpURI.getRawPath == encoded) } property("filePathURI and File.toURI agree for absolute file") = secure { @@ -61,7 +61,7 @@ object URITests extends Properties("URI Tests") { s"getRawPath: ${fpURI.getRawPath}" |: (fpURI == directURI) && (fpURI.getPath == decoded) && - (fpURI.getRawPath == encoded) + (fpURI.getRawPath == encoded) } } diff --git a/project/Transform.scala b/project/Transform.scala index 590b1a9..0eb857f 100644 --- a/project/Transform.scala +++ b/project/Transform.scala @@ -56,8 +56,8 @@ object Transform { inputSources := (inputSourceDirectories.value ** (-DirectoryFilter)).get, transformSources / fileMappings := transformSourceMappings.value, transformSources := { - (transformSources / fileMappings).value.map { - case (in, out) => transform(in, out, sourceProperties.value) + (transformSources / fileMappings).value.map { case (in, out) => + transform(in, out, sourceProperties.value) } }, sourceGenerators += transformSources.taskValue @@ -85,8 +85,8 @@ object Transform { inputResources := (inputResourceDirectories.value ** (-DirectoryFilter)).get, transformResources / fileMappings := transformResourceMappings.value, transformResources := { - (transformResources / fileMappings).value.map { - case (in, out) => transform(in, out, resourceProperties.value) + (transformResources / fileMappings).value.map { case (in, out) => + transform(in, out, resourceProperties.value) } }, resourceGenerators += transformResources.taskValue diff --git a/project/Util.scala b/project/Util.scala index 89a59ff..99a94a2 100644 --- a/project/Util.scala +++ b/project/Util.scala @@ -30,7 +30,7 @@ object Util { scalacOptions ++= { CrossVersion.partialVersion(scalaVersion.value) match { case Some((2, 9)) => Nil // support 2.9 for some subprojects for the Scala Eclipse IDE - case _ => + case _ => Seq( "-feature", "-language:implicitConversions", @@ -66,7 +66,9 @@ object Util { val timestamp = formatter.format(new Date) val content = versionLine(version) + "\ntimestamp=" + timestamp val f = dir / fileName - if (!f.exists || f.lastModified < lastCompilationTime(analysis) || !containsVersion(f, version)) { + if ( + !f.exists || f.lastModified < lastCompilationTime(analysis) || !containsVersion(f, version) + ) { s.log.info("Writing version information to " + f + " :\n" + content) IO.write(f, content) }