Skip to content

Instantly share code, notes, and snippets.

@eed3si9n
Created March 1, 2012 05:13
Show Gist options
  • Save eed3si9n/1947457 to your computer and use it in GitHub Desktop.
Save eed3si9n/1947457 to your computer and use it in GitHub Desktop.
Using scalaxb within multiple configs
import sbt._
object Builds extends Build {
import sbtscalaxb.Plugin._
import ScalaxbKeys._
val Xsd = config("xsd") extend(Compile)
val Wsdl = config("wsdl") extend(Compile)
val Soap11 = config("soap11") extend(Compile)
val Soap12 = config("soap12") extend(Compile)
lazy val cli = Project("app", file("cli"), settings = cliSettings)
lazy val buildSettings = Defaults.defaultSettings ++ customLsSettings ++ Seq(
version := "0.6.9-SNAPSHOT",
organization := "org.scalaxb"
)
lazy val cliSettings = buildSettings ++ Seq(
name := "scalaxb",
unmanagedSourceDirectories in Compile <+= baseDirectory( _ / "src_managed" )) ++ codeGenSettings
def customScalaxbSettings(base: String): Seq[Project.Setting[_]] = Seq(
sources <<= xsdSource map { xsd => Seq(xsd / (base + ".xsd")) },
sourceManaged <<= baseDirectory / "src_managed",
packageName := base,
protocolFileName := base + "_xmlprotocol.scala",
classPrefix := Some("X")
)
def soapSettings(base: String): Seq[Project.Setting[_]] = Seq(
sources <<= xsdSource map { xsd => Seq(xsd / (base + ".xsd")) },
sourceManaged <<= sourceDirectory(_ / "main" / "resources"),
packageName := base,
protocolFileName := base + "_xmlprotocol.scala",
packageDir := false,
generate <<= (generate) map { files =>
val renamed = files map { file => new File(file.getParentFile, file.getName + ".template") }
IO.move(files zip renamed)
renamed
})
def codeGenSettings: Seq[Project.Setting[_]] =
inConfig(Xsd)(baseScalaxbSettings ++ inTask(scalaxb)(customScalaxbSettings("xmlschema"))) ++
inConfig(Wsdl)(baseScalaxbSettings ++ inTask(scalaxb)(customScalaxbSettings("wsdl11"))) ++
inConfig(Soap11)(baseScalaxbSettings ++ inTask(scalaxb)(soapSettings("soapenvelope11"))) ++
inConfig(Soap12)(baseScalaxbSettings ++ inTask(scalaxb)(soapSettings("soapenvelope12")))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment