2

すべてのsbtSetting[T]のマップ、またはすべての設定の依存関係と競合するコンテナーにアクセスするにはどうすればよいですか?

それらすべてとそれらの依存関係も印刷したいと思います。出力は次のようになります。

setting(ScopedKey(Scope(Select(ThisBuild),Global,Global,Global),managed-directory))
    ScopedKey(Scope(Select(ThisBuild),Global,Global,Global),base-directory)
        ScopedKey(Scope(Select(ThisBuild),Global,Global,Global),this-project)
...

以下は、これを行うために使用しているSBTビルド定義です。

this-projectキーがすべての設定に含まれているわけではありません。どこに保管されていますか?

import sbt._
import sbt.Logger
import Keys._
import PlayProject._

object TheBuild extends Build {

  lazy val howItWorksProject = Project(
    id = "howItWorks",
    base = file("./modules/howItWorks")
  )

  val projDef: ProjectDefinition[_] = howItWorksProject
  var count  = 0

  def printSettingsDependencies(setting: Setting[_], settings: Seq[Setting[_]], indent: String): Unit = {
    println("debug printSettingsDependencies start" + (count+=1))
    println(setting)
    println("debug setting =" + setting)
    println("debug setting.dependencies = " + setting.dependencies)

    setting.dependencies.foreach {
      n =>
        println("debug it = " + n)
        println("debug finding ...")
        val settingOption = settings.find {
          it =>
            println("\t"+it.key.key.label + "?=" + n.key.label)
            it.key.key.label == n.key.label
        }
        println("debug found = "+settingOption)
        println(indent + settingOption)
        printSettingsDependencies(settingOption.get, settings, indent + indent)
    }
  }
}

inspect this-project出力:

> inspect this-project
[info] Setting: sbt.ResolvedProject = Project(id: howItWorks, base: C:\Users\pawel\workspace\kody\ria-template\modules\howItWorks, aggregate: List(), dependencies: List(), delegates: List(), configurations: List(compile, runtime, test, provided, optional))
[info] Description:
[info]  Provides the current project for the referencing scope.
[info] Provided by:
[info]  {file:/C:/Users/pawel/workspace/kody/ria-template/}howItWorks/*:this-project
[info] Reverse dependencies:
[info]  *:ivy-configurations
[info]  *:base-directory
[info]  *:name
[info] Delegates:
[info]  *:this-project
[info]  {.}/*:this-project
[info]  */*:this-project

inspect base-directory出力:

> inspect base-directory
[info] Setting: java.io.File = C:\Users\pawel\workspace\kody\ria-template\modules\howItWorks
[info] Description:
[info]  The base directory.  Depending on the scope, this is the base directory for the build, project, configuration, or task.
[info] Provided by:
[info]  {file:/C:/Users/pawel/workspace/kody/ria-template/}howItWorks/*:base-directory
[info] Dependencies:
[info]  *:this-project
[info] Reverse dependencies:
[info]  *:ivy-paths
[info]  *:target
[info]  *:unmanaged-base
[info]  *:runner
[info]  *:source-directory
[info] Delegates:
[info]  *:base-directory
[info]  {.}/*:base-directory
[info]  */*:base-directory
[info] Related:
[info]  {.}/*:base-directory

show sbt-version

> show sbt-version
[info] 0.11.3
4

1 に答える 1

2

私はこれがあなたが必要としているものだと思います:

import sbt._
import Keys._

object TheBuild extends Build {

    lazy val allSettings = TaskKey[Seq[sbt.Project.Setting[_]]]("all-settings", "")

    lazy val printIt = TaskKey[Unit]("print-it", "")

    lazy val testSettings = Defaults.defaultSettings ++ Seq(
        allSettings <<= (state) map { s =>
            val extracted = Project.extract(s)
            import extracted._
            structure.settings
        },

        printIt <<= (allSettings) map { all =>
            // there are more than one base-directories with different scopes, not all of them have the dependencies
            val baseDirectories = all.filter(s => s.key.key.label == "base-directory" && !s.dependencies.isEmpty)
            // pick the first one to demonstrate this works
            printSettingsDependencies(baseDirectories(0), all, "\t")
        })

    def printSettingsDependencies(setting: Setting[_], settings: Seq[Setting[_]], indent: String): Unit = {
        println(indent + setting)

        setting.dependencies.foreach { n =>
            val settingOption = settings.find { _.key.key.label == n.key.label }
            if (settingOption.isDefined) {
                printSettingsDependencies(settingOption.get, settings, indent + indent)
            }
        }
    }

    lazy val howItWorksProject: Project = Project("howItWorks", file(".")) settings (testSettings: _*)
}

出力:

> print-it
    setting(ScopedKey(Scope(Select(ProjectRef(file:/Users/balagez/Sites/test/,howItWorks)),Global,Global,Global),base-directory)) at NoPosition
        setting(ScopedKey(Scope(Select(ProjectRef(file:/Users/balagez/Sites/test/,howItWorks)),Global,Global,Global),this-project)) at NoPosition
[success] Total time: 0 s, completed Oct 12, 2012 7:50:29 PM
于 2012-10-12T17:54:46.953 に答える