mirror of https://github.com/sbt/sbt.git
Remove def autoImport: Any from AutoPlugin.
This commit is contained in:
parent
cc80d216ab
commit
ff77d0b0f2
|
|
@ -90,7 +90,7 @@ final class DetectedModules[T](val modules: Seq[(String, T)])
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Auto-detected auto plugin. */
|
/** Auto-detected auto plugin. */
|
||||||
case class DetectedAutoPlugin(val name: String, val value: AutoPlugin, val hasStableAutoImport: Boolean)
|
case class DetectedAutoPlugin(val name: String, val value: AutoPlugin, val hasAutoImport: Boolean)
|
||||||
|
|
||||||
/** Auto-discovered modules for the build definition project. These include modules defined in build definition sources
|
/** Auto-discovered modules for the build definition project. These include modules defined in build definition sources
|
||||||
* as well as modules in binary dependencies.
|
* as well as modules in binary dependencies.
|
||||||
|
|
@ -105,6 +105,7 @@ final class DetectedPlugins(val plugins: DetectedModules[Plugin], val autoPlugin
|
||||||
if (hasAutoImport) Some(name + ".autoImport")
|
if (hasAutoImport) Some(name + ".autoImport")
|
||||||
else None
|
else None
|
||||||
}))
|
}))
|
||||||
|
|
||||||
/** A function to select the right [[AutoPlugin]]s from [[autoPlugins]] for a [[Project]]. */
|
/** A function to select the right [[AutoPlugin]]s from [[autoPlugins]] for a [[Project]]. */
|
||||||
lazy val deducePlugins: (Plugins, Logger) => Seq[AutoPlugin] = Plugins.deducer(autoPlugins.toList map {_.value})
|
lazy val deducePlugins: (Plugins, Logger) => Seq[AutoPlugin] = Plugins.deducer(autoPlugins.toList map {_.value})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ object PluginDiscovery
|
||||||
)
|
)
|
||||||
val detectedAutoPugins = discover[AutoPlugin](AutoPlugins)
|
val detectedAutoPugins = discover[AutoPlugin](AutoPlugins)
|
||||||
val allAutoPlugins = (defaultAutoPlugins ++ detectedAutoPugins.modules) map { case (name, value) =>
|
val allAutoPlugins = (defaultAutoPlugins ++ detectedAutoPugins.modules) map { case (name, value) =>
|
||||||
DetectedAutoPlugin(name, value, sbt.Plugins.hasStableAutoImport(value, loader))
|
DetectedAutoPlugin(name, value, sbt.Plugins.hasAutoImportGetter(value, loader))
|
||||||
}
|
}
|
||||||
new DetectedPlugins(discover[Plugin](Plugins), allAutoPlugins, discover[Build](Builds))
|
new DetectedPlugins(discover[Plugin](Plugins), allAutoPlugins, discover[Build](Builds))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,14 +19,19 @@ Steps for plugin authors:
|
||||||
1. Determine if the AutoPlugin should automatically be activated when all requirements are met, or should be opt-in.
|
1. Determine if the AutoPlugin should automatically be activated when all requirements are met, or should be opt-in.
|
||||||
2. Determine the [[AutoPlugins]]s that, when present (or absent), act as the requirements for the AutoPlugin.
|
2. Determine the [[AutoPlugins]]s that, when present (or absent), act as the requirements for the AutoPlugin.
|
||||||
3. Determine the settings/configurations to that the AutoPlugin injects when activated.
|
3. Determine the settings/configurations to that the AutoPlugin injects when activated.
|
||||||
|
4. Determine the keys and other names to be automatically imported to *.sbt scripts.
|
||||||
|
|
||||||
For example, the following will automatically add the settings in `projectSettings`
|
For example, the following will automatically add the settings in `projectSettings`
|
||||||
to a project that has both the `Web` and `Javascript` plugins enabled.
|
to a project that has both the `Web` and `Javascript` plugins enabled.
|
||||||
|
|
||||||
object MyPlugin extends AutoPlugin {
|
object Plugin extends sbt.AutoPlugin {
|
||||||
def requires = Web && Javascript
|
def requires = Web && Javascript
|
||||||
def trigger = allRequirements
|
def trigger = allRequirements
|
||||||
override def projectSettings = Seq(...)
|
override def projectSettings = Seq(...)
|
||||||
|
|
||||||
|
object autoImport {
|
||||||
|
lazy val obfuscate = taskKey[Seq[File]]("Obfuscates the source.")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Steps for users:
|
Steps for users:
|
||||||
|
|
@ -43,6 +48,7 @@ will activate `MyPlugin` defined above and have its settings automatically added
|
||||||
<Project>.addPlugins( Web && Javascript ).disablePlugins(MyPlugin)
|
<Project>.addPlugins( Web && Javascript ).disablePlugins(MyPlugin)
|
||||||
|
|
||||||
then the `MyPlugin` settings (and anything that activates only when `MyPlugin` is activated) will not be added.
|
then the `MyPlugin` settings (and anything that activates only when `MyPlugin` is activated) will not be added.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
abstract class AutoPlugin extends Plugins.Basic with PluginsFunctions
|
abstract class AutoPlugin extends Plugins.Basic with PluginsFunctions
|
||||||
{
|
{
|
||||||
|
|
@ -63,10 +69,6 @@ abstract class AutoPlugin extends Plugins.Basic with PluginsFunctions
|
||||||
|
|
||||||
override def toString: String = label
|
override def toString: String = label
|
||||||
|
|
||||||
/** When this method is overridden with a val or a lazy val, `autoImport._` is automatically
|
|
||||||
* imported to *.sbt scripts. */
|
|
||||||
def autoImport: Any = ()
|
|
||||||
|
|
||||||
/** 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
|
def projectConfigurations: Seq[Configuration] = Nil
|
||||||
|
|
||||||
|
|
@ -309,15 +311,17 @@ ${listConflicts(conflicting)}""")
|
||||||
case ap: AutoPlugin => model(ap)
|
case ap: AutoPlugin => model(ap)
|
||||||
}
|
}
|
||||||
|
|
||||||
private[sbt] def hasStableAutoImport(ap: AutoPlugin, loader: ClassLoader): Boolean = {
|
private[sbt] def hasAutoImportGetter(ap: AutoPlugin, loader: ClassLoader): Boolean = {
|
||||||
import reflect.runtime.{universe => ru}
|
import reflect.runtime.{universe => ru}
|
||||||
import util.control.Exception.catching
|
import util.control.Exception.catching
|
||||||
val m = ru.runtimeMirror(loader)
|
val m = ru.runtimeMirror(loader)
|
||||||
val im = m.reflect(ap)
|
val im = m.reflect(ap)
|
||||||
val fmOpt = catching(classOf[ScalaReflectionException]) opt {
|
val hasGetterOpt = catching(classOf[ScalaReflectionException]) opt {
|
||||||
val autoImportSym = im.symbol.asType.toType.declaration(ru.newTermName("autoImport")).asTerm
|
im.symbol.asType.toType.declaration(ru.newTermName("autoImport")) match {
|
||||||
im.reflectField(autoImportSym)
|
case ru.NoSymbol => false
|
||||||
|
case sym => sym.asTerm.isGetter
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fmOpt.isDefined
|
hasGetterOpt getOrElse false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ object Imports
|
||||||
}
|
}
|
||||||
|
|
||||||
object X extends AutoPlugin {
|
object X extends AutoPlugin {
|
||||||
override lazy val autoImport = Imports
|
val autoImport = Imports
|
||||||
def requires = Plugins.empty
|
def requires = Plugins.empty
|
||||||
def trigger = noTrigger
|
def trigger = noTrigger
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,21 +3,19 @@ package sbttest // you need package http://stackoverflow.com/questions/9822008/
|
||||||
import sbt._
|
import sbt._
|
||||||
import Keys._
|
import Keys._
|
||||||
|
|
||||||
object Imports {
|
|
||||||
object bN extends AutoPlugin {
|
|
||||||
def requires = empty
|
|
||||||
def trigger = allRequirements
|
|
||||||
}
|
|
||||||
lazy val check = taskKey[Unit]("Checks that the AutoPlugin and Build are automatically added.")
|
|
||||||
}
|
|
||||||
|
|
||||||
object C extends AutoPlugin {
|
object C extends AutoPlugin {
|
||||||
override lazy val autoImport = Imports
|
object autoImport {
|
||||||
|
object bN extends AutoPlugin {
|
||||||
|
def requires = empty
|
||||||
|
def trigger = allRequirements
|
||||||
|
}
|
||||||
|
lazy val check = taskKey[Unit]("Checks that the AutoPlugin and Build are automatically added.")
|
||||||
|
}
|
||||||
def requires = empty
|
def requires = empty
|
||||||
def trigger = noTrigger
|
def trigger = noTrigger
|
||||||
}
|
}
|
||||||
|
|
||||||
import Imports._
|
import C.autoImport._
|
||||||
|
|
||||||
object A extends AutoPlugin {
|
object A extends AutoPlugin {
|
||||||
def requires = bN
|
def requires = bN
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue