From 36a16673c06e48c5b9ea64a9422d3731e7cabe8b Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Wed, 8 Jan 2020 09:41:29 -0500 Subject: [PATCH] reduce compiler warnings --- build.sbt | 11 ++++++++--- main-command/src/main/scala/sbt/BasicKeys.scala | 3 ++- main/src/main/scala/sbt/Defaults.scala | 4 +++- main/src/main/scala/sbt/EvaluateTask.scala | 1 + main/src/main/scala/sbt/Main.scala | 1 + main/src/main/scala/sbt/Plugins.scala | 10 +++++----- main/src/main/scala/sbt/internal/BuildStructure.scala | 4 ++-- .../scala/sbt/internal/DeprecatedContinuous.scala | 4 ++++ .../main/scala/sbt/internal/LibraryManagement.scala | 3 ++- .../sbt/internal/server/LanguageServerReporter.scala | 2 +- project/PublishBinPlugin.scala | 2 +- util-tracking/src/main/scala/sbt/util/Tracked.scala | 8 ++++---- 12 files changed, 34 insertions(+), 19 deletions(-) diff --git a/build.sbt b/build.sbt index af48ed518..1d236719c 100644 --- a/build.sbt +++ b/build.sbt @@ -686,9 +686,11 @@ lazy val commandProj = (project in file("main-command")) testedBaseSettings, name := "Command", libraryDependencies ++= Seq(launcherInterface, sjsonNewScalaJson.value, templateResolverApi), + libraryDependencies ++= (scalaVersion.value match { + case v if v.startsWith("2.12.") => List(compilerPlugin(silencerPlugin)) + case _ => List() + }), Compile / scalacOptions += "-Ywarn-unused:-locals,-explicits,-privates", - // Removing -Xfatal-warnings is necessary because BasicKeys contains a Key for a deprecated class. - Compile / scalacOptions -= "-Xfatal-warnings", managedSourceDirectories in Compile += baseDirectory.value / "src" / "main" / "contraband-scala", sourceManaged in (Compile, generateContrabands) := baseDirectory.value / "src" / "main" / "contraband-scala", @@ -863,7 +865,10 @@ lazy val mainProj = (project in file("main")) log4jDependencies ++ Seq(scalaCacheCaffeine, lmCoursierShaded) }, - Compile / scalacOptions -= "-Xfatal-warnings", + libraryDependencies ++= (scalaVersion.value match { + case v if v.startsWith("2.12.") => List(compilerPlugin(silencerPlugin)) + case _ => List() + }), managedSourceDirectories in Compile += baseDirectory.value / "src" / "main" / "contraband-scala", sourceManaged in (Compile, generateContrabands) := baseDirectory.value / "src" / "main" / "contraband-scala", diff --git a/main-command/src/main/scala/sbt/BasicKeys.scala b/main-command/src/main/scala/sbt/BasicKeys.scala index 6b7b85e0c..107b2df88 100644 --- a/main-command/src/main/scala/sbt/BasicKeys.scala +++ b/main-command/src/main/scala/sbt/BasicKeys.scala @@ -9,6 +9,7 @@ package sbt import java.io.File +import com.github.ghik.silencer.silent import sbt.internal.inc.classpath.{ ClassLoaderCache => IncClassLoaderCache } import sbt.internal.classpath.ClassLoaderCache import sbt.internal.server.ServerHandler @@ -34,7 +35,7 @@ object BasicKeys { "The function that constructs the command prompt from the current build state.", 10000 ) - val watch = + @silent val watch = AttributeKey[Watched]("watched", "Continuous execution configuration.", 1000) val serverPort = AttributeKey[Int]("server-port", "The port number used by server command.", 10000) diff --git a/main/src/main/scala/sbt/Defaults.scala b/main/src/main/scala/sbt/Defaults.scala index e1fae5cd1..a3b6cadf5 100755 --- a/main/src/main/scala/sbt/Defaults.scala +++ b/main/src/main/scala/sbt/Defaults.scala @@ -3641,6 +3641,7 @@ object Classpaths { ivyRepo.descriptorOptional } catch { case _: NoSuchMethodError => false } + @com.github.ghik.silencer.silent private[this] def bootRepository(repo: xsbti.Repository): Resolver = { import xsbti.Predefined repo match { @@ -3878,6 +3879,7 @@ trait BuildExtra extends BuildCommon with DefExtra { // I tried "Def.spaceDelimited().parsed" (after importing Def.parserToInput) // but it broke actions/run-task // Maybe it needs to be defined inside a Def.inputTask? + @com.github.ghik.silencer.silent def inputTask[T](f: TaskKey[Seq[String]] => Initialize[Task[T]]): Initialize[InputTask[T]] = InputTask.apply(Def.value((s: State) => Def.spaceDelimited()))(f) @@ -3947,7 +3949,7 @@ trait BuildCommon { /** * Allows a String to be used where a `NameFilter` is expected. * Asterisks (`*`) in the string are interpreted as wildcards. - * All other characters must match exactly. See [[sbt.io.GlobFilter]]. + * All other characters must match exactly. See GlobFilter. */ implicit def globFilter(expression: String): NameFilter = GlobFilter(expression) diff --git a/main/src/main/scala/sbt/EvaluateTask.scala b/main/src/main/scala/sbt/EvaluateTask.scala index 166851cc6..005b2776a 100644 --- a/main/src/main/scala/sbt/EvaluateTask.scala +++ b/main/src/main/scala/sbt/EvaluateTask.scala @@ -154,6 +154,7 @@ object EvaluateTask { import Keys.state import std.Transform + @com.github.ghik.silencer.silent lazy private val sharedProgress = new TaskTimings(reportOnShutdown = true) def taskTimingProgress: Option[ExecuteProgress[Task]] = if (SysProp.taskTimingsOnShutdown) Some(sharedProgress) diff --git a/main/src/main/scala/sbt/Main.scala b/main/src/main/scala/sbt/Main.scala index 5169366cc..639a89427 100644 --- a/main/src/main/scala/sbt/Main.scala +++ b/main/src/main/scala/sbt/Main.scala @@ -200,6 +200,7 @@ object BuiltinCommands { def ScriptCommands: Seq[Command] = Seq(ignore, exit, Script.command, setLogLevel, early, act, nop) + @com.github.ghik.silencer.silent def DefaultCommands: Seq[Command] = Seq( multi, diff --git a/main/src/main/scala/sbt/Plugins.scala b/main/src/main/scala/sbt/Plugins.scala index 4679d511e..191af110e 100644 --- a/main/src/main/scala/sbt/Plugins.scala +++ b/main/src/main/scala/sbt/Plugins.scala @@ -81,7 +81,7 @@ abstract class AutoPlugin extends Plugins.Basic with PluginsFunctions { def trigger: PluginTrigger = noTrigger /** - * This AutoPlugin requires the plugins the [[Plugins]] matcher returned by this method. See [[trigger]]. + * This AutoPlugin requires the plugins the Plugins matcher returned by this method. See [[trigger]]. */ def requires: Plugins = plugins.JvmPlugin @@ -89,20 +89,20 @@ abstract class AutoPlugin extends Plugins.Basic with PluginsFunctions { override def toString: String = label - /** The [[Configuration]]s to add to each project that activates this AutoPlugin.*/ + /** The `Configuration`s to add to each project that activates this AutoPlugin.*/ def projectConfigurations: Seq[Configuration] = Nil - /** The [[Setting]]s to add in the scope of each project that activates this AutoPlugin. */ + /** The `Setting`s to add in the scope of each project that activates this AutoPlugin. */ def projectSettings: Seq[Setting[_]] = Nil /** - * The [[Setting]]s to add to the build scope for each project that activates this AutoPlugin. + * The `Setting` to add to the build scope for each project that activates this AutoPlugin. * The settings returned here are guaranteed to be added to a given build scope only once * regardless of how many projects for that build activate this AutoPlugin. */ def buildSettings: Seq[Setting[_]] = Nil - /** The [[Setting]]s to add to the global scope exactly once if any project activates this AutoPlugin. */ + /** The `Setting`s to add to the global scope exactly once if any project activates this AutoPlugin. */ def globalSettings: Seq[Setting[_]] = Nil // TODO?: def commands: Seq[Command] diff --git a/main/src/main/scala/sbt/internal/BuildStructure.scala b/main/src/main/scala/sbt/internal/BuildStructure.scala index 6d3ee2a9b..157428801 100644 --- a/main/src/main/scala/sbt/internal/BuildStructure.scala +++ b/main/src/main/scala/sbt/internal/BuildStructure.scala @@ -78,7 +78,7 @@ final class StructureIndex( * A resolved build unit. (`ResolvedBuildUnit` would be a better name to distinguish it from the loaded, but unresolved `BuildUnit`.) * @param unit The loaded, but unresolved [[BuildUnit]] this was resolved from. * @param defined The definitive map from project IDs to resolved projects. - * These projects have had [[Reference]]s resolved and [[AutoPlugin]]s evaluated. + * These projects have had `Reference`s resolved and [[AutoPlugin]]s evaluated. * @param rootProjects The list of project IDs for the projects considered roots of this build. * The first root project is used as the default in several situations where a project is not otherwise selected. */ @@ -91,7 +91,7 @@ final class LoadedBuildUnit( /** * The project to use as the default when one is not otherwise selected. - * [[LocalRootProject]] resolves to this from within the same build. + * `LocalRootProject` resolves to this from within the same build. */ val root = rootProjects.headOption.getOrElse( throw new java.lang.AssertionError( diff --git a/main/src/main/scala/sbt/internal/DeprecatedContinuous.scala b/main/src/main/scala/sbt/internal/DeprecatedContinuous.scala index 2bffd0801..c2d654d2f 100644 --- a/main/src/main/scala/sbt/internal/DeprecatedContinuous.scala +++ b/main/src/main/scala/sbt/internal/DeprecatedContinuous.scala @@ -10,11 +10,13 @@ package sbt.internal import java.nio.file.Path import java.util.concurrent.atomic.AtomicReference +import com.github.ghik.silencer.silent import sbt.{ ProjectRef, State, Watched } import sbt.internal.io.{ EventMonitor, Source, WatchState => WS } import sbt.internal.util.AttributeKey import sbt.nio.file.Glob +@silent private[internal] trait DeprecatedContinuous { protected type StartMessage = Option[Either[WS => String, (Int, ProjectRef, Seq[String]) => Option[String]]] @@ -55,6 +57,8 @@ private[internal] trait DeprecatedContinuous { } } } + +@silent private[sbt] object DeprecatedContinuous { private[sbt] val taskDefinitions = Seq( sbt.Keys.watchTransitiveSources := sbt.Defaults.watchTransitiveSourcesTask.value, diff --git a/main/src/main/scala/sbt/internal/LibraryManagement.scala b/main/src/main/scala/sbt/internal/LibraryManagement.scala index b0aa9a521..30144626c 100644 --- a/main/src/main/scala/sbt/internal/LibraryManagement.scala +++ b/main/src/main/scala/sbt/internal/LibraryManagement.scala @@ -17,8 +17,9 @@ import sbt.util.{ CacheStore, CacheStoreFactory, Logger, Tracked, Level } import sbt.io.IO import sbt.io.syntax._ import sbt.Project.richInitializeTask -import sbt.dsl.LinterLevel.Ignore import sjsonnew.JsonFormat +// This is to turn off "`state` is inside the if expression of a regular task." etc +import sbt.dsl.LinterLevel.Ignore private[sbt] object LibraryManagement { diff --git a/main/src/main/scala/sbt/internal/server/LanguageServerReporter.scala b/main/src/main/scala/sbt/internal/server/LanguageServerReporter.scala index d68e12e96..2b01ad059 100644 --- a/main/src/main/scala/sbt/internal/server/LanguageServerReporter.scala +++ b/main/src/main/scala/sbt/internal/server/LanguageServerReporter.scala @@ -27,7 +27,7 @@ import scala.collection.JavaConverters._ import sbt.io.IO /** - * Defines a compiler reporter that uses event logging provided by a [[ManagedLogger]]. + * Defines a compiler reporter that uses event logging provided by a `ManagedLogger`. * * @param maximumErrors The maximum errors. * @param logger The event managed logger. diff --git a/project/PublishBinPlugin.scala b/project/PublishBinPlugin.scala index c013e78d6..a3a890819 100644 --- a/project/PublishBinPlugin.scala +++ b/project/PublishBinPlugin.scala @@ -16,7 +16,7 @@ object PublishBinPlugin extends AutoPlugin { override def globalSettings = Seq(publishLocalBin := (())) override def projectSettings = Def settings ( - publishLocalBin := Classpaths.publishTask(publishLocalBinConfig, deliverLocal).value, + publishLocalBin := Classpaths.publishTask(publishLocalBinConfig).value, publishLocalBinConfig := { Classpaths.publishConfig( false, // publishMavenStyle.value, diff --git a/util-tracking/src/main/scala/sbt/util/Tracked.scala b/util-tracking/src/main/scala/sbt/util/Tracked.scala index 0018fcd23..1e6cd607e 100644 --- a/util-tracking/src/main/scala/sbt/util/Tracked.scala +++ b/util-tracking/src/main/scala/sbt/util/Tracked.scala @@ -7,7 +7,7 @@ package sbt.util -import scala.util.{ Failure, Try, Success } +import scala.util.{ Failure, Try, Success => USuccess } import java.io.File import sbt.io.IO @@ -182,7 +182,7 @@ object Tracked { import CacheImplicits.LongJsonFormat def save(store: CacheStore, value: I): Unit = { Hasher.hash(value) match { - case Success(keyHash) => store.write[Long](keyHash.toLong) + case USuccess(keyHash) => store.write[Long](keyHash.toLong) case Failure(e) => if (isStrictMode) throw e else () @@ -191,9 +191,9 @@ object Tracked { def changed(store: CacheStore, value: I): Boolean = Try { store.read[Long] } match { - case Success(prev: Long) => + case USuccess(prev: Long) => Hasher.hash(value) match { - case Success(keyHash: Int) => keyHash.toLong != prev + case USuccess(keyHash: Int) => keyHash.toLong != prev case Failure(e) => if (isStrictMode) throw e else true