2016-04-08 18 views
1

Ich versuche, eine SBT Aufgabe zu schreiben, die wie folgt verwendet werden:Sequential Eingabeaufgabe in SBT

> deploy key1=value1 key2=value2 ... 

und führe Folgendes aus:

  1. liest eine Standardeigenschaftendatei
  2. fügt Die analysierten Schlüssel und Werte für das Properties-Objekt
  3. schreibt das neue Properties-Objekt in resources/config.properties
  4. Pakete ein fettes .jar mit sbt-assembly
  5. die Standardeigenschaften zu Ressourcen/config.properties

Ich habe versucht, es zu erreichen mit Def.sequential schreibt, aber ich kann nicht einen Weg zu finden, es zu benutzen mit inputKey scheinen. Mein build.sbt sieht wie folgt aus:

val config = inputKey[Unit] (
    "Set configuration options before deployment.") 
val deploy = inputKey[Unit](
    "assemble fat .jar with configuration options") 
val defaultProperties = settingKey[Properties](
    "default application properties.") 
val propertiesPath = settingKey[File]("path to config.properties") 
val writeDefaultProperties = taskKey[Unit]("write default properties file.") 
val parser = (((' ' ~> StringBasic) <~ '=') ~ StringBasic).+ 

lazy val root = (project in file(".")) 
    .settings(
    propertiesPath := { 
     val base = (resourceDirectory in Compile).value 
     base/"config.properties" 
    }, 
    defaultProperties := { 
     val path = propertiesPath.value 
     val defaultConfig = new Properties 
     IO.load(defaultConfig, path) 
     defaultConfig 
    }, 
    config := { 
     val path = propertiesPath.value 
     val defaultConfig = defaultProperties.value 
     val options = parser.parsed 
     val deployConfig = new Properties 
     deployConfig.putAll(defaultConfig) 
     options.foreach(option => 
     deployConfig 
      .setProperty(option._1, option._2)) 
     IO.write(deployConfig, "", path) 
    }, 
    writeDefaultProperties := { 
     val default = defaultProperties.value 
     val path = propertiesPath.value 
     IO.write(default, "", path) 
    }, 
    deploy := Def.sequential(
     config.parsed, // does not compile 
     assembly, 
     writeDefaultProperties), 
    ...) 

Kann ich Def.sequential Arbeit mit Eingabetasten machen, oder muss ich etwas mehr beteiligt tun?

Antwort