-
Notifications
You must be signed in to change notification settings - Fork 59
Create a ScalaXB Plugin #556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import cbt._ | ||
|
|
||
| class Build(val context: Context) extends BaseBuild with ScalaXB { | ||
| override def compile = taskCache[Build]("compile").memoize{ | ||
| generateScalaXBSources().defaultConfig.apply | ||
| super.compile | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import cbt._ | ||
|
|
||
| class Build(val context: Context) extends BuildBuild { | ||
| override def dependencies = super.dependencies :+ plugins.scalaxb | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import www.example.com.IPO | ||
|
|
||
| object Usage extends App { | ||
| val shipTo = scalaxb.fromXML[IPO.Address](<shipTo> | ||
| <name>foo</name> | ||
| <street>1537 Paper Street</street> | ||
| <city>Wilmington</city> | ||
| </shipTo>) | ||
| println(shipTo.toString) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <schema targetNamespace="http://www.example.com/IPO" | ||
| xmlns="http://www.w3.org/2001/XMLSchema" | ||
| xmlns:ipo="http://www.example.com/IPO"> | ||
| <complexType name="Address"> | ||
| <sequence> | ||
| <element name="name" type="string"/> | ||
| <element name="street" type="string"/> | ||
| <element name="city" type="string"/> | ||
| </sequence> | ||
| </complexType> | ||
| </schema> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| package cbt | ||
|
|
||
| import java.io.File | ||
| import scalaxb.{compiler => sc} | ||
| import scalaxb.compiler.{Config => ScConfig} | ||
| import sc.ConfigEntry._ | ||
| import cbt.ScalaXB._ | ||
|
|
||
| trait ScalaXB extends BaseBuild { | ||
| private val targetDirectory = projectDirectory / "target" | ||
|
|
||
| def generateScalaXBSources(outputDirectory: File = (targetDirectory / "src_managed"), verbose: Boolean = false) = | ||
| ScalaXB.GenerateScalaXBSources(sources, projectDirectory, outputDirectory, verbose) | ||
| } | ||
|
|
||
| object ScalaXB { | ||
| case class GenerateScalaXBSources(sources: Seq[File], projectRoot: File, outputDirectory: File, verbose: Boolean = false) { | ||
| def defaultConfig: Config = | ||
| Config( | ||
| xsdSourceDir = projectRoot / "src" / "main" / "xsd", | ||
| wsdlSourceDir = projectRoot / "src" / "main" / "wsdl", | ||
| generatedPackageName = "generated", | ||
| generatedPackageNames = Map(), | ||
| autoPackages = false, | ||
| classPrefix = None, | ||
| paramPrefix = None, | ||
| attributePrefix = None, | ||
| prependFamily = false, | ||
| wrapContents = Nil, | ||
| contentSizeLimit = Int.MaxValue, | ||
| chunkSize = 10, | ||
| namedAttributes = false, | ||
| packageDir = true, | ||
| generateRuntime = true, | ||
| generateClients = List(Dispatch(ScConfig.defaultDispatchVersion.value), Async), | ||
| ignoreUnknown = false, | ||
| vararg = false, | ||
| generateVisitor = false, | ||
| generateMutable = false, | ||
| protocolFileName = sc.Defaults.protocolFileName, | ||
| protocolPackageName = None, | ||
| laxAny = false, | ||
| additionalCombinedPackageNames = Map() | ||
| ) | ||
|
|
||
| case class Config ( | ||
| xsdSourceDir: File, | ||
| wsdlSourceDir: File, | ||
| generatedPackageName: String, | ||
| generatedPackageNames: Map[String, String], | ||
| autoPackages: Boolean, | ||
| classPrefix: Option[String], | ||
| paramPrefix: Option[String], | ||
| attributePrefix: Option[String], | ||
| prependFamily: Boolean, | ||
| wrapContents: List[String], | ||
| contentSizeLimit: Int, | ||
| chunkSize: Int, | ||
| namedAttributes: Boolean, | ||
| packageDir: Boolean, | ||
| generateRuntime: Boolean, | ||
| protocolFileName: String, | ||
| protocolPackageName: Option[String], | ||
| generateMutable: Boolean, | ||
| generateVisitor: Boolean, | ||
| laxAny: Boolean, | ||
| additionalCombinedPackageNames: Map[Option[String], Option[String]], | ||
| generateClients: List[HttpClient], | ||
| ignoreUnknown: Boolean, | ||
| vararg: Boolean | ||
| ) { | ||
|
|
||
| def apply = { | ||
| def compile: Seq[File] = | ||
| sources.headOption map { src => | ||
| import sc._ | ||
| sc.Log.configureLogger(verbose) | ||
| val module = Module.moduleByFileName(src) | ||
| module.processFiles(sources.toVector, scConfig.update(Outdir(outputDirectory))) | ||
| } getOrElse {Nil} | ||
|
|
||
| compile | ||
| } | ||
|
|
||
| def combinedPackageNames: Map[Option[String], Option[String]] = | ||
| generatedPackageNames.map { case (k, v) => ((Option(k.toString), Some(v))) }.updated(None, Some(generatedPackageName)) | ||
|
|
||
| def scConfig: ScConfig = | ||
| ScConfig( | ||
| Vector(PackageNames(combinedPackageNames)) ++ | ||
| (if (packageDir) Vector(GeneratePackageDir) else Vector()) ++ | ||
| classPrefix.map(ClassPrefix(_)).toVector ++ | ||
| paramPrefix.map(ParamPrefix(_)).toVector ++ | ||
| attributePrefix.map(AttributePrefix(_)).toVector ++ | ||
| Vector(ScConfig.defaultOutdir) ++ | ||
| (if (prependFamily.value) Vector(PrependFamilyName) else Vector()) ++ | ||
| Vector(WrappedComplexTypes(wrapContents)) ++ | ||
| Vector(SeperateProtocol) ++ | ||
| Vector(ProtocolFileName(protocolFileName)) ++ | ||
| Vector(ProtocolPackageName(protocolPackageName)) ++ | ||
| Vector(ScConfig.defaultDefaultNamespace) ++ | ||
| (if (generateRuntime) Vector(GenerateRuntime) else Vector()) ++ | ||
| (generateClients.toVector.flatMap { | ||
| case Dispatch(version, true) => Vector(GenerateDispatchClient, DispatchVersion(version), GenerateDispatchAs) | ||
| case Dispatch(version, false) => Vector(GenerateDispatchClient, DispatchVersion(version)) | ||
| case Gigahorse(version, Gigahorse.OkHttp) => Vector(GenerateGigahorseClient, GigahorseVersion(version), GigahorseBackend("okhttp")) | ||
| case Gigahorse(version, Gigahorse.AHC) => Vector(GenerateGigahorseClient, GigahorseVersion(version), GigahorseBackend("asynchttpclient")) | ||
| case Async => Vector(GenerateAsync) | ||
| }) ++ | ||
| Vector(ContentsSizeLimit(contentSizeLimit)) ++ | ||
| Vector(SequenceChunkSize(chunkSize)) ++ | ||
| (if (namedAttributes) Vector(NamedAttributes) else Vector()) ++ | ||
| (if (laxAny) Vector(LaxAny) else Vector()) ++ | ||
| (if (ignoreUnknown) Vector(IgnoreUnknown) else Vector()) ++ | ||
| (if (vararg && !generateMutable) Vector(VarArg) else Vector()) ++ | ||
| (if (generateMutable) Vector(GenerateMutable) else Vector()) ++ | ||
| (if (generateVisitor) Vector(GenerateVisitor) else Vector()) ++ | ||
| (if (autoPackages) Vector(AutoPackages) else Vector()) | ||
| ) | ||
|
|
||
| } | ||
| } | ||
|
|
||
|
|
||
| object ScalaXBConfig { | ||
| } | ||
|
|
||
| sealed trait HttpClient | ||
| case class Dispatch(version: String, generateAs: Boolean = false) extends HttpClient | ||
| case class Gigahorse(version: String, backend: Gigahorse.Backend) extends HttpClient | ||
| case object Async extends HttpClient | ||
| object Gigahorse { | ||
| sealed trait Backend | ||
| case object OkHttp extends Backend | ||
| case object AHC extends Backend | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import cbt._ | ||
|
|
||
| class Build(val context: Context) extends Plugin with Ensime { | ||
| def scalaXBVersion = "1.5.2" | ||
|
|
||
| override def dependencies = super.dependencies ++ Resolver(mavenCentral).bind( | ||
| ScalaDependency("org.scalaxb", "scalaxb", scalaXBVersion) | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we take the Gigahorse stuff out of the cbt package?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can, but it's built in to scalaxb, so the binaries will still be floating around in there.. scalaxb has a tight coupling to it's backends from what I understand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, can we move inside of a scalaxb plugin specific object or package? Just so it doesn't lie around in cbt's global namespace