diff options
author | Seth Tisue <seth@tisue.net> | 2016-10-20 21:08:41 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-20 21:08:41 -0700 |
commit | c7603bb00bccbe9f840c012a3154056717198e5a (patch) | |
tree | d3edd04e46a7e11e6fe45876e64aaef797d4b3be | |
parent | e09aca81bd3b29154fd4402d27fcb260d9765c39 (diff) | |
parent | 0b131f48a0ad2b25275a3050a0c485519633943d (diff) | |
download | scala-c7603bb00bccbe9f840c012a3154056717198e5a.tar.gz scala-c7603bb00bccbe9f840c012a3154056717198e5a.tar.bz2 scala-c7603bb00bccbe9f840c012a3154056717198e5a.zip |
Merge pull request #5463 from adriaanm/merge-2.11-to-2.12
Merge 2.11 to 2.12
-rw-r--r-- | build.sbt | 22 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/settings/MutableSettings.scala | 18 | ||||
-rw-r--r-- | src/library/scala/collection/immutable/StringLike.scala | 1 | ||||
-rw-r--r-- | src/library/scala/sys/process/ProcessBuilder.scala | 8 | ||||
-rw-r--r-- | src/library/scala/sys/process/package.scala | 10 | ||||
-rw-r--r-- | src/repl-jline/scala/tools/nsc/interpreter/jline/JLineReader.scala | 7 | ||||
-rw-r--r-- | test/junit/scala/tools/nsc/settings/SettingsTest.scala | 67 |
7 files changed, 109 insertions, 24 deletions
@@ -195,7 +195,7 @@ lazy val commonSettings = clearSourceAndResourceDirectories ++ publishSettings + // directly to stdout outputStrategy in run := Some(StdoutOutput), Quiet.silenceScalaBinaryVersionWarning -) +) ++ removePomDependencies /** Extra post-processing for the published POM files. These are needed to create POMs that * are equivalent to the ones from the Ant build. In the long term this should be removed and @@ -224,10 +224,16 @@ def fixPom(extra: (String, scala.xml.Node)*): Setting[_] = { ) ++ extra) } } +val pomDependencyExclusions = + settingKey[Seq[(String, String)]]("List of (groupId, artifactId) pairs to exclude from the POM and ivy.xml") + +pomDependencyExclusions in Global := Nil + /** Remove unwanted dependencies from the POM and ivy.xml. */ -def removePomDependencies(deps: (String, String)*): Seq[Setting[_]] = Seq( +lazy val removePomDependencies: Seq[Setting[_]] = Seq( pomPostProcess := { n => val n2 = pomPostProcess.value.apply(n) + val deps = pomDependencyExclusions.value import scala.xml._ import scala.xml.transform._ new RuleTransformer(new RewriteRule { @@ -245,6 +251,7 @@ def removePomDependencies(deps: (String, String)*): Seq[Setting[_]] = Seq( import scala.xml._ import scala.xml.transform._ val f = deliverLocal.value + val deps = pomDependencyExclusions.value val e = new RuleTransformer(new RewriteRule { override def transform(node: Node) = node match { case e: Elem if e.label == "dependency" && { @@ -337,7 +344,9 @@ lazy val library = configureAsSubproject(project) "/project/name" -> <name>Scala Library</name>, "/project/description" -> <description>Standard library for the Scala Programming Language</description>, "/project/packaging" -> <packaging>jar</packaging> - ) + ), + // Remove the dependency on "forkjoin" from the POM because it is included in the JAR: + pomDependencyExclusions += ((organization.value, "forkjoin")) ) .settings(filterDocSources("*.scala" -- (regexFileFilter(".*/runtime/.*\\$\\.scala") || regexFileFilter(".*/runtime/ScalaRunTime\\.scala") || @@ -418,12 +427,9 @@ lazy val compiler = configureAsSubproject(project) "/project/description" -> <description>Compiler for the Scala Programming Language</description>, "/project/packaging" -> <packaging>jar</packaging> ), - apiURL := None + apiURL := None, + pomDependencyExclusions ++= List(("org.apache.ant", "ant"), ("org.scala-lang.modules", "scala-asm")) ) - .settings(removePomDependencies( - ("org.apache.ant", "ant"), - ("org.scala-lang.modules", "scala-asm") - ): _*) .dependsOn(library, reflect) lazy val interactive = configureAsSubproject(project) diff --git a/src/compiler/scala/tools/nsc/settings/MutableSettings.scala b/src/compiler/scala/tools/nsc/settings/MutableSettings.scala index 7b4c55c2af..822e0f16bf 100644 --- a/src/compiler/scala/tools/nsc/settings/MutableSettings.scala +++ b/src/compiler/scala/tools/nsc/settings/MutableSettings.scala @@ -751,11 +751,19 @@ class MutableSettings(val errorFn: String => Unit) override def isHelping: Boolean = sawHelp override def help: String = { - val choiceLength = choices.map(_.length).max + 1 - val formatStr = s" %-${choiceLength}s %s" - choices.zipAll(descriptions, "", "").map { - case (arg, descr) => formatStr.format(arg, descr) - } mkString (f"$descr%n", f"%n", "") + val describe: ((String, String)) => String = { + val choiceWidth = choices.map(_.length).max + 1 + val formatStr = s" %-${choiceWidth}s %s" + locally { + case (choice, description) => formatStr.format(choice, description) + } + } + val verboseDefault = default match { + case Some("_" :: Nil) => Some("All choices are enabled by default." :: Nil) + case _ => default + } + val orelse = verboseDefault.map(_.mkString(f"%nDefault: ", ", ", f"%n")).getOrElse("") + choices.zipAll(descriptions, "", "").map(describe).mkString(f"${descr}%n", f"%n", orelse) } def clear(): Unit = { diff --git a/src/library/scala/collection/immutable/StringLike.scala b/src/library/scala/collection/immutable/StringLike.scala index 155d25d933..af8703293f 100644 --- a/src/library/scala/collection/immutable/StringLike.scala +++ b/src/library/scala/collection/immutable/StringLike.scala @@ -139,6 +139,7 @@ self => /** Returns this string with first character converted to upper case. * If the first character of the string is capitalized, it is returned unchanged. + * This method does not convert characters outside the Basic Multilingual Plane (BMP). */ def capitalize: String = if (toString == null) null diff --git a/src/library/scala/sys/process/ProcessBuilder.scala b/src/library/scala/sys/process/ProcessBuilder.scala index 9713b712fc..fe4c30ee50 100644 --- a/src/library/scala/sys/process/ProcessBuilder.scala +++ b/src/library/scala/sys/process/ProcessBuilder.scala @@ -90,19 +90,19 @@ import ProcessBuilder._ * * If not specified, the input of the external commands executed with `run` or * `!` will not be tied to anything, and the output will be redirected to the - * stdout and stderr of the Scala process. For the methods `!!` and `lines`, no + * stdout and stderr of the Scala process. For the methods `!!` and `lineStream`, no * input will be provided, and the output will be directed according to the * semantics of these methods. * * Some methods will cause stdin to be used as input. Output can be controlled - * with a [[scala.sys.process.ProcessLogger]] -- `!!` and `lines` will only + * with a [[scala.sys.process.ProcessLogger]] -- `!!` and `lineStream` will only * redirect error output when passed a `ProcessLogger`. If one desires full * control over input and output, then a [[scala.sys.process.ProcessIO]] can be * used with `run`. * - * For example, we could silence the error output from `lines_!` like this: + * For example, we could silence the error output from `lineStream_!` like this: * {{{ - * val etcFiles = "find /etc" lines_! ProcessLogger(line => ()) + * val etcFiles = "find /etc" lineStream_! ProcessLogger(line => ()) * }}} * * ==Extended Example== diff --git a/src/library/scala/sys/process/package.scala b/src/library/scala/sys/process/package.scala index ff0fd920c9..bf4287dfc3 100644 --- a/src/library/scala/sys/process/package.scala +++ b/src/library/scala/sys/process/package.scala @@ -25,7 +25,7 @@ package scala.sys { * * {{{ * import scala.sys.process._ - * "ls" #| "grep .scala" #&& Seq("sh", "-c", "scalac *.scala") #|| "echo nothing found" lines + * "ls" #| "grep .scala" #&& Seq("sh", "-c", "scalac *.scala") #|| "echo nothing found" lineStream * }}} * * We describe below the general concepts and architecture of the package, @@ -92,7 +92,7 @@ package scala.sys { * * - Return status of the process (`!` methods) * - Output of the process as a `String` (`!!` methods) - * - Continuous output of the process as a `Stream[String]` (`lines` methods) + * - Continuous output of the process as a `Stream[String]` (`lineStream` methods) * - The `Process` representing it (`run` methods) * * Some simple examples of these methods: @@ -109,7 +109,7 @@ package scala.sys { * // a Stream[String] * def sourceFilesAt(baseDir: String): Stream[String] = { * val cmd = Seq("find", baseDir, "-name", "*.scala", "-type", "f") - * cmd.lines + * cmd.lineStream * } * }}} * @@ -167,8 +167,8 @@ package scala.sys { * def sourceFilesAt(baseDir: String): (Stream[String], StringBuffer) = { * val buffer = new StringBuffer() * val cmd = Seq("find", baseDir, "-name", "*.scala", "-type", "f") - * val lines = cmd lines_! ProcessLogger(buffer append _) - * (lines, buffer) + * val lineStream = cmd lineStream_! ProcessLogger(buffer append _) + * (lineStream, buffer) * } * }}} * diff --git a/src/repl-jline/scala/tools/nsc/interpreter/jline/JLineReader.scala b/src/repl-jline/scala/tools/nsc/interpreter/jline/JLineReader.scala index 95964e18d9..dc04230d0b 100644 --- a/src/repl-jline/scala/tools/nsc/interpreter/jline/JLineReader.scala +++ b/src/repl-jline/scala/tools/nsc/interpreter/jline/JLineReader.scala @@ -32,11 +32,14 @@ class InteractiveReader(completer: () => Completion) extends interpreter.Interac private val consoleReader = { val reader = new JLineConsoleReader() - reader setPaginationEnabled interpreter.`package`.isPaged + reader setPaginationEnabled interpreter.isPaged - // ASAP + // turn off magic ! reader setExpandEvents false + // enable detecting pasted tab char (when next char is immediately available) which is taken raw, not completion + reader setCopyPasteDetection true + reader setHistory history.asInstanceOf[JHistory] reader diff --git a/test/junit/scala/tools/nsc/settings/SettingsTest.scala b/test/junit/scala/tools/nsc/settings/SettingsTest.scala index 0f2d206273..24bfb3dcde 100644 --- a/test/junit/scala/tools/nsc/settings/SettingsTest.scala +++ b/test/junit/scala/tools/nsc/settings/SettingsTest.scala @@ -180,4 +180,71 @@ class SettingsTest { assertThrows[IllegalArgumentException](check(expected = "2.11", "-Xsource", "2.11"), _ == "-Xsource requires an argument, the syntax is -Xsource:<version>") assertThrows[IllegalArgumentException](check(expected = "2.11", "-Xsource:2.invalid"), _ contains "Bad version (2.invalid)") } + + // equal with stripped margins and normalized line endings + private def marginallyEquals(s1: String, s2: String): Boolean = { + def normally(s: String): String = s.stripMargin.lines.mkString("\n") + normally(s1) == normally(s2) + } + + @Test def helpHasDefault(): Unit = { + val s = new MutableSettings(msg => throw new IllegalArgumentException(msg)) + object mChoices extends s.MultiChoiceEnumeration { + val a = Choice("a", "help a") + val b = Choice("b", "help b") + val c = Choice("c", "help c") + } + val m = s.MultiChoiceSetting("-m", "args", "magic sauce", mChoices, Some(List("b"))) + + def check(args: String*)(t: s.MultiChoiceSetting[mChoices.type] => Boolean): Boolean = { + m.clear() + val (ok, rest) = s.processArguments(args.toList, processAll = true) + assert(rest.isEmpty) + t(m) + } + + import mChoices._ + + assertTrue(check("-m")(_.value == Set(b))) + assertTrue(check("-m") { _ => + val expected = + """|magic sauce + | a help a + | b help b + | c help c + |Default: b + |""" + marginallyEquals(expected, m.help) + }) + } + @Test def helpHasDefaultAll(): Unit = { + val s = new MutableSettings(msg => throw new IllegalArgumentException(msg)) + object mChoices extends s.MultiChoiceEnumeration { + val a = Choice("a", "help a") + val b = Choice("b", "help b") + val c = Choice("c", "help c") + } + val m = s.MultiChoiceSetting("-m", "args", "magic sauce", mChoices, Some(List("_"))) + + def check(args: String*)(t: s.MultiChoiceSetting[mChoices.type] => Boolean): Boolean = { + m.clear() + val (ok, rest) = s.processArguments(args.toList, processAll = true) + assert(rest.isEmpty) + t(m) + } + + import mChoices._ + + assertTrue(check("-m")(_.value == Set(a, b, c))) + assertTrue(check("-m") { _ => + val expected = + """|magic sauce + | a help a + | b help b + | c help c + |Default: All choices are enabled by default. + |""" + marginallyEquals(expected, m.help) + }) + } } |