Remove all warnings from completeProj

This commit is contained in:
Dale Wijnand 2017-12-04 16:18:08 +00:00
parent 34136fb70b
commit 4a5ff4fc0d
No known key found for this signature in database
GPG Key ID: 4F256E3D151DF5EF
7 changed files with 56 additions and 60 deletions

View File

@ -174,6 +174,11 @@ val completeProj = (project in file("internal") / "util-complete")
name := "Completion",
libraryDependencies += jline,
mimaSettings,
mimaBinaryIssueFilters ++= Seq(
// Changed signature or removed something in the internal pacakge
exclude[DirectMissingMethodProblem]("sbt.internal.*"),
exclude[IncompatibleResultTypeProblem]("sbt.internal.*"),
),
)
.configure(addSbtIO, addSbtUtilControl)

View File

@ -10,7 +10,7 @@ package complete
import java.lang.Character.{ toLowerCase => lower }
/** @author Paul Phillips*/
/** @author Paul Phillips */
object EditDistance {
/**
@ -24,7 +24,6 @@ object EditDistance {
insertCost: Int = 1,
deleteCost: Int = 1,
subCost: Int = 1,
transposeCost: Int = 1,
matchCost: Int = 0,
caseCost: Int = 1,
transpositions: Boolean = false

View File

@ -11,11 +11,7 @@ package complete
import History.number
import java.io.File
final class History private (
val lines: IndexedSeq[String],
val path: Option[File],
error: String => Unit
) {
final class History private (val lines: IndexedSeq[String], val path: Option[File]) {
private def reversed = lines.reverse
def all: Seq[String] = lines
@ -52,8 +48,8 @@ final class History private (
}
object History {
def apply(lines: Seq[String], path: Option[File], error: String => Unit): History =
new History(lines.toIndexedSeq, path, sys.error)
def apply(lines: Seq[String], path: Option[File]): History =
new History(lines.toIndexedSeq, path)
def number(s: String): Option[Int] =
try { Some(s.toInt) } catch { case _: NumberFormatException => None }

View File

@ -11,7 +11,7 @@ package complete
import jline.console.ConsoleReader
import jline.console.completer.{ Completer, CompletionHandler }
import scala.annotation.tailrec
import scala.collection.JavaConverters
import scala.collection.JavaConverters._
object JLineCompletion {
def installCustomCompletor(reader: ConsoleReader, parser: Parser[_]): Unit =
@ -154,7 +154,7 @@ object JLineCompletion {
if (line.charAt(line.length - 1) != '\n')
reader.println()
}
reader.printColumns(JavaConverters.seqAsJavaList(columns.map(_.trim)))
reader.printColumns(columns.map(_.trim).asJava)
}
def hasNewline(s: String): Boolean = s.indexOf('\n') >= 0

View File

@ -9,60 +9,64 @@ package sbt.internal.util
package complete
import java.io.File
import sbt.io.IO._
import sbt.io.IO
class FileExamplesTest extends UnitSpec {
"listing all files in an absolute base directory" should
"produce the entire base directory's contents" in {
val _ = new DirectoryStructure {
fileExamples().toList should contain theSameElementsAs (allRelativizedPaths)
withDirectoryStructure() { ds =>
ds.fileExamples().toList should contain theSameElementsAs (ds.allRelativizedPaths)
}
}
"listing files with a prefix that matches none" should
"produce an empty list" in {
val _ = new DirectoryStructure(withCompletionPrefix = "z") {
fileExamples().toList shouldBe empty
"listing files with a prefix that matches none" should "produce an empty list" in {
withDirectoryStructure(withCompletionPrefix = "z") { ds =>
ds.fileExamples().toList shouldBe empty
}
}
"listing single-character prefixed files" should
"produce matching paths only" in {
val _ = new DirectoryStructure(withCompletionPrefix = "f") {
fileExamples().toList should contain theSameElementsAs (prefixedPathsOnly)
"listing single-character prefixed files" should "produce matching paths only" in {
withDirectoryStructure(withCompletionPrefix = "f") { ds =>
ds.fileExamples().toList should contain theSameElementsAs (ds.prefixedPathsOnly)
}
}
"listing directory-prefixed files" should
"produce matching paths only" in {
val _ = new DirectoryStructure(withCompletionPrefix = "far") {
fileExamples().toList should contain theSameElementsAs (prefixedPathsOnly)
"listing directory-prefixed files" should "produce matching paths only" in {
withDirectoryStructure(withCompletionPrefix = "far") { ds =>
ds.fileExamples().toList should contain theSameElementsAs (ds.prefixedPathsOnly)
}
}
it should "produce sub-dir contents only when appending a file separator to the directory" in {
val _ = new DirectoryStructure(withCompletionPrefix = "far" + File.separator) {
fileExamples().toList should contain theSameElementsAs (prefixedPathsOnly)
withDirectoryStructure(withCompletionPrefix = "far" + File.separator) { ds =>
ds.fileExamples().toList should contain theSameElementsAs (ds.prefixedPathsOnly)
}
}
"listing files with a sub-path prefix" should
"produce matching paths only" in {
val _ = new DirectoryStructure(withCompletionPrefix = "far" + File.separator + "ba") {
fileExamples().toList should contain theSameElementsAs (prefixedPathsOnly)
"listing files with a sub-path prefix" should "produce matching paths only" in {
withDirectoryStructure(withCompletionPrefix = "far" + File.separator + "ba") { ds =>
ds.fileExamples().toList should contain theSameElementsAs (ds.prefixedPathsOnly)
}
}
"completing a full path" should
"produce a list with an empty string" in {
val _ = new DirectoryStructure(withCompletionPrefix = "bazaar") {
fileExamples().toList shouldEqual List("")
"completing a full path" should "produce a list with an empty string" in {
withDirectoryStructure(withCompletionPrefix = "bazaar") { ds =>
ds.fileExamples().toList shouldEqual List("")
}
}
// TODO: Remove DelayedInit - https://github.com/scala/scala/releases/tag/v2.11.0-RC1
class DirectoryStructure(withCompletionPrefix: String = "") extends DelayedInit {
def withDirectoryStructure[A](withCompletionPrefix: String = "")(
thunk: DirectoryStructure => A): Unit = {
IO.withTemporaryDirectory { tempDir =>
val ds = new DirectoryStructure(withCompletionPrefix)
ds.createSampleDirStructure(tempDir)
ds.fileExamples = new FileExamples(ds.baseDir, withCompletionPrefix)
thunk(ds)
}
}
final class DirectoryStructure(withCompletionPrefix: String) {
var fileExamples: FileExamples = _
var baseDir: File = _
var childFiles: List[File] = _
@ -72,22 +76,14 @@ class FileExamplesTest extends UnitSpec {
def allRelativizedPaths: List[String] =
(childFiles ++ childDirectories ++ nestedFiles ++ nestedDirectories)
.map(relativize(baseDir, _).get)
.map(IO.relativize(baseDir, _).get)
def prefixedPathsOnly: List[String] =
allRelativizedPaths
.filter(_ startsWith withCompletionPrefix)
.map(_ substring withCompletionPrefix.length)
override def delayedInit(testBody: => Unit): Unit = {
withTemporaryDirectory { tempDir =>
createSampleDirStructure(tempDir)
fileExamples = new FileExamples(baseDir, withCompletionPrefix)
testBody
}
}
private def createSampleDirStructure(tempDir: File): Unit = {
def createSampleDirStructure(tempDir: File): Unit = {
childFiles = toChildFiles(tempDir, List("foo", "bar", "bazaar"))
childDirectories = toChildFiles(tempDir, List("moo", "far"))
nestedFiles = toChildFiles(childDirectories(1), List("farfile1", "barfile2"))

View File

@ -236,10 +236,9 @@ object BasicCommands {
def historyParser(s: State): Parser[() => State] =
Command.applyEffect(HistoryCommands.actionParser) { histFun =>
val logError = (msg: String) => s.log.error(msg)
val hp = s get historyPath getOrElse None
val hp = (s get historyPath).flatten
val lines = hp.toList.flatMap(p => IO.readLines(p)).toIndexedSeq
histFun(CHistory(lines, hp, logError)) match {
histFun(CHistory(lines, hp)) match {
case Some(commands) =>
commands foreach println //printing is more appropriate than logging
(commands ::: s).continue

View File

@ -178,15 +178,16 @@ object Command {
bs map (b => (b, distance(a, b))) filter (_._2 <= maxDistance) sortBy (_._2) take (maxSuggestions) map (_._1)
def distance(a: String, b: String): Int =
EditDistance.levenshtein(a,
b,
insertCost = 1,
deleteCost = 1,
subCost = 2,
transposeCost = 1,
matchCost = -1,
caseCost = 1,
transpositions = true)
EditDistance.levenshtein(
a,
b,
insertCost = 1,
deleteCost = 1,
subCost = 2,
matchCost = -1,
caseCost = 1,
transpositions = true
)
def spacedAny(name: String): Parser[String] = spacedC(name, any)