Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cbt_build.cbt
import cbt._
import cbt_internal._

class Build(val context: Context) extends Shared with Scalariform with PublishLocal with CommandLineOverrides{
class Build(val context: Context) extends Shared with Scalariform with PublishLocal with CommandLineOverrides with Ensime {
override def name: String = "cbt"
override def version: String = "0.9-SNAPSHOT"
override def description: String = "Fast, intuitive Build Tool for Scala"
Expand Down
6 changes: 6 additions & 0 deletions doc/plugin-author-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,9 @@ representing the operation, e.g. `compile` or `doc`. If there
is only one inner case class inside of anothe case class,
call it `config`, give it a name representing the operation,
e.g. `compile` or `doc`.

### Finalizing your plugin

Add your plugin to stage2/plugins.scala

Create a test project, and then test it in test/test.scala
8 changes: 8 additions & 0 deletions examples/scalaxb-example/build/build.scala
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
}
}
6 changes: 6 additions & 0 deletions examples/scalaxb-example/build/build/build.scala
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
}

10 changes: 10 additions & 0 deletions examples/scalaxb-example/src/main/scala/usage.scala
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)
}
11 changes: 11 additions & 0 deletions examples/scalaxb-example/src/main/xsd/address.xsd
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>
116 changes: 58 additions & 58 deletions nailgun_launcher/EarlyDependencies.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

public class EarlyDependencies{

public static String scalaVersion = "2.11.8";
public static String scalaVersion = "2.11.11";
public static String scalaXmlVersion = "1.0.6";
public static String zincVersion = "0.3.13";
public static String zincVersion = "0.3.15";

/** ClassLoader for stage1 */
ClassLoader classLoader;
Expand All @@ -29,20 +29,20 @@ public class EarlyDependencies{
public EarlyDependencies(
String mavenCache, String mavenUrl, ClassLoaderCache classLoaderCache, ClassLoader rootClassLoader
) throws Throwable {
String scalaReflect_2_11_8_File = mavenCache + "/org/scala-lang/scala-reflect/2.11.8/scala-reflect-2.11.8.jar";
String scalaCompiler_2_11_8_File = mavenCache + "/org/scala-lang/scala-compiler/2.11.8/scala-compiler-2.11.8.jar";
String scalaReflect_2_11_11_File = mavenCache + "/org/scala-lang/scala-reflect/2.11.11/scala-reflect-2.11.11.jar";
String scalaCompiler_2_11_11_File = mavenCache + "/org/scala-lang/scala-compiler/2.11.11/scala-compiler-2.11.11.jar";
String scalaXml_1_0_6_File = mavenCache + "/org/scala-lang/modules/scala-xml_2.11/1.0.6/scala-xml_2.11-1.0.6.jar";
String scalaLibrary_2_11_8_File = mavenCache + "/org/scala-lang/scala-library/2.11.8/scala-library-2.11.8.jar";
String zinc_0_3_13_File = mavenCache + "/com/typesafe/zinc/zinc/0.3.13/zinc-0.3.13.jar";
String incrementalCompiler_0_13_13_File = mavenCache + "/com/typesafe/sbt/incremental-compiler/0.13.13/incremental-compiler-0.13.13.jar";
String compilerInterface_0_13_13_File = mavenCache + "/com/typesafe/sbt/compiler-interface/0.13.13/compiler-interface-0.13.13-sources.jar";
String scalaLibrary_2_11_11_File = mavenCache + "/org/scala-lang/scala-library/2.11.11/scala-library-2.11.11.jar";
String zinc_0_3_15_File = mavenCache + "/com/typesafe/zinc/zinc/0.3.15/zinc-0.3.15.jar";
String incrementalCompiler_0_13_15_File = mavenCache + "/com/typesafe/sbt/incremental-compiler/0.13.15/incremental-compiler-0.13.15.jar";
String compilerInterface_0_13_15_File = mavenCache + "/com/typesafe/sbt/compiler-interface/0.13.15/compiler-interface-0.13.15-sources.jar";
String scalaCompiler_2_10_6_File = mavenCache + "/org/scala-lang/scala-compiler/2.10.6/scala-compiler-2.10.6.jar";
String sbtInterface_0_13_13_File = mavenCache + "/com/typesafe/sbt/sbt-interface/0.13.13/sbt-interface-0.13.13.jar";
String sbtInterface_0_13_15_File = mavenCache + "/com/typesafe/sbt/sbt-interface/0.13.15/sbt-interface-0.13.15.jar";
String scalaReflect_2_10_6_File = mavenCache + "/org/scala-lang/scala-reflect/2.10.6/scala-reflect-2.10.6.jar";
String scalaLibrary_2_10_6_File = mavenCache + "/org/scala-lang/scala-library/2.10.6/scala-library-2.10.6.jar";

download(new URL(mavenUrl + "/org/scala-lang/scala-reflect/2.11.8/scala-reflect-2.11.8.jar"), Paths.get(scalaReflect_2_11_8_File), "b74530deeba742ab4f3134de0c2da0edc49ca361");
download(new URL(mavenUrl + "/org/scala-lang/scala-compiler/2.11.8/scala-compiler-2.11.8.jar"), Paths.get(scalaCompiler_2_11_8_File), "fe1285c9f7b58954c5ef6d80b59063569c065e9a");
download(new URL(mavenUrl + "/org/scala-lang/scala-reflect/2.11.11/scala-reflect-2.11.11.jar"), Paths.get(scalaReflect_2_11_11_File), "2addc7e09cf2e77e2243a5772bd0430c32c2b410");
download(new URL(mavenUrl + "/org/scala-lang/scala-compiler/2.11.11/scala-compiler-2.11.11.jar"), Paths.get(scalaCompiler_2_11_11_File), "2f1568549280da6d0a332846cb7c27edae76fd10");

// org.scala-lang:scala-library:2.10.6
String[] scalaLibrary_2_10_6_ClasspathArray = new String[]{scalaLibrary_2_10_6_File};
Expand All @@ -66,92 +66,92 @@ public EarlyDependencies(
scalaReflect_2_10_6_ClasspathArray
);

// com.typesafe.sbt:sbt-interface:0.13.13
String[] sbtInterface_0_13_13_ClasspathArray = new String[]{sbtInterface_0_13_13_File, scalaLibrary_2_10_6_File, scalaReflect_2_10_6_File};
ClassLoader sbtInterface_0_13_13_ = loadDependency(
mavenUrl + "/com/typesafe/sbt/sbt-interface/0.13.13/sbt-interface-0.13.13.jar",
sbtInterface_0_13_13_File,
"9367c5c7a835f9505774fc3b7c3a8146a1396f85",
// com.typesafe.sbt:sbt-interface:0.13.15
String[] sbtInterface_0_13_15_ClasspathArray = new String[]{sbtInterface_0_13_15_File, scalaLibrary_2_10_6_File, scalaReflect_2_10_6_File};
ClassLoader sbtInterface_0_13_15_ = loadDependency(
mavenUrl + "/com/typesafe/sbt/sbt-interface/0.13.15/sbt-interface-0.13.15.jar",
sbtInterface_0_13_15_File,
"93fe450d5f5efb111397a34bc1fba0d50368a265",
classLoaderCache,
scalaReflect_2_10_6_,
sbtInterface_0_13_13_ClasspathArray
sbtInterface_0_13_15_ClasspathArray
);

// org.scala-lang:scala-compiler:2.10.6
String[] scalaCompiler_2_10_6_ClasspathArray = new String[]{sbtInterface_0_13_13_File, scalaCompiler_2_10_6_File, scalaLibrary_2_10_6_File, scalaReflect_2_10_6_File};
String[] scalaCompiler_2_10_6_ClasspathArray = new String[]{sbtInterface_0_13_15_File, scalaCompiler_2_10_6_File, scalaLibrary_2_10_6_File, scalaReflect_2_10_6_File};
ClassLoader scalaCompiler_2_10_6_ = loadDependency(
mavenUrl + "/org/scala-lang/scala-compiler/2.10.6/scala-compiler-2.10.6.jar",
scalaCompiler_2_10_6_File,
"9b15174852f5b6bb1edbf303d5722286a0a54011",
classLoaderCache,
sbtInterface_0_13_13_,
sbtInterface_0_13_15_,
scalaCompiler_2_10_6_ClasspathArray
);

// com.typesafe.sbt:compiler-interface:0.13.13
String[] compilerInterface_0_13_13_ClasspathArray = new String[]{compilerInterface_0_13_13_File, sbtInterface_0_13_13_File, scalaCompiler_2_10_6_File, scalaLibrary_2_10_6_File, scalaReflect_2_10_6_File};
ClassLoader compilerInterface_0_13_13_ = loadDependency(
mavenUrl + "/com/typesafe/sbt/compiler-interface/0.13.13/compiler-interface-0.13.13-sources.jar",
compilerInterface_0_13_13_File,
"691bf88813bb34771c0ca4418d579bb652e1526f",
// com.typesafe.sbt:compiler-interface:0.13.15
String[] compilerInterface_0_13_15_ClasspathArray = new String[]{compilerInterface_0_13_15_File, sbtInterface_0_13_15_File, scalaCompiler_2_10_6_File, scalaLibrary_2_10_6_File, scalaReflect_2_10_6_File};
ClassLoader compilerInterface_0_13_15_ = loadDependency(
mavenUrl + "/com/typesafe/sbt/compiler-interface/0.13.15/compiler-interface-0.13.15-sources.jar",
compilerInterface_0_13_15_File,
"bad996ed4fc3e83b872525e9cd7b80d81b98a324",
classLoaderCache,
scalaCompiler_2_10_6_,
compilerInterface_0_13_13_ClasspathArray
compilerInterface_0_13_15_ClasspathArray
);

// com.typesafe.sbt:incremental-compiler:0.13.13
String[] incrementalCompiler_0_13_13_ClasspathArray = new String[]{compilerInterface_0_13_13_File, incrementalCompiler_0_13_13_File, sbtInterface_0_13_13_File, scalaCompiler_2_10_6_File, scalaLibrary_2_10_6_File, scalaReflect_2_10_6_File};
ClassLoader incrementalCompiler_0_13_13_ = loadDependency(
mavenUrl + "/com/typesafe/sbt/incremental-compiler/0.13.13/incremental-compiler-0.13.13.jar",
incrementalCompiler_0_13_13_File,
"65008fb90b965ea44d0959b8a2e214df206cda6e",
// com.typesafe.sbt:incremental-compiler:0.13.15
String[] incrementalCompiler_0_13_15_ClasspathArray = new String[]{compilerInterface_0_13_15_File, incrementalCompiler_0_13_15_File, sbtInterface_0_13_15_File, scalaCompiler_2_10_6_File, scalaLibrary_2_10_6_File, scalaReflect_2_10_6_File};
ClassLoader incrementalCompiler_0_13_15_ = loadDependency(
mavenUrl + "/com/typesafe/sbt/incremental-compiler/0.13.15/incremental-compiler-0.13.15.jar",
incrementalCompiler_0_13_15_File,
"95e20d00b25a7aae19838009c11578b7e6b258ad",
classLoaderCache,
compilerInterface_0_13_13_,
incrementalCompiler_0_13_13_ClasspathArray
compilerInterface_0_13_15_,
incrementalCompiler_0_13_15_ClasspathArray
);

// com.typesafe.zinc:zinc:0.3.13
String[] zinc_0_3_13_ClasspathArray = new String[]{compilerInterface_0_13_13_File, incrementalCompiler_0_13_13_File, sbtInterface_0_13_13_File, zinc_0_3_13_File, scalaCompiler_2_10_6_File, scalaLibrary_2_10_6_File, scalaReflect_2_10_6_File};
ClassLoader zinc_0_3_13_ = loadDependency(
mavenUrl + "/com/typesafe/zinc/zinc/0.3.13/zinc-0.3.13.jar",
zinc_0_3_13_File,
"ae0dcd6105d6e87ece2d181c5f0f7a79a966775a",
// com.typesafe.zinc:zinc:0.3.15
String[] zinc_0_3_15_ClasspathArray = new String[]{compilerInterface_0_13_15_File, incrementalCompiler_0_13_15_File, sbtInterface_0_13_15_File, zinc_0_3_15_File, scalaCompiler_2_10_6_File, scalaLibrary_2_10_6_File, scalaReflect_2_10_6_File};
ClassLoader zinc_0_3_15_ = loadDependency(
mavenUrl + "/com/typesafe/zinc/zinc/0.3.15/zinc-0.3.15.jar",
zinc_0_3_15_File,
"12e1f782684f2702e847faa0994eed4711270687",
classLoaderCache,
incrementalCompiler_0_13_13_,
zinc_0_3_13_ClasspathArray
incrementalCompiler_0_13_15_,
zinc_0_3_15_ClasspathArray
);

// org.scala-lang:scala-library:2.11.8
String[] scalaLibrary_2_11_8_ClasspathArray = new String[]{scalaLibrary_2_11_8_File};
ClassLoader scalaLibrary_2_11_8_ = loadDependency(
mavenUrl + "/org/scala-lang/scala-library/2.11.8/scala-library-2.11.8.jar",
scalaLibrary_2_11_8_File,
"ddd5a8bced249bedd86fb4578a39b9fb71480573",
// org.scala-lang:scala-library:2.11.11
String[] scalaLibrary_2_11_11_ClasspathArray = new String[]{scalaLibrary_2_11_11_File};
ClassLoader scalaLibrary_2_11_11_ = loadDependency(
mavenUrl + "/org/scala-lang/scala-library/2.11.11/scala-library-2.11.11.jar",
scalaLibrary_2_11_11_File,
"e283d2b7fde6504f6a86458b1f6af465353907cc",
classLoaderCache,
rootClassLoader,
scalaLibrary_2_11_8_ClasspathArray
scalaLibrary_2_11_11_ClasspathArray
);

// org.scala-lang.modules:scala-xml_2.11:1.0.6
String[] scalaXml_1_0_6_ClasspathArray = new String[]{scalaXml_1_0_6_File, scalaLibrary_2_11_8_File};
String[] scalaXml_1_0_6_ClasspathArray = new String[]{scalaXml_1_0_6_File, scalaLibrary_2_11_11_File};
ClassLoader scalaXml_1_0_6_ = loadDependency(
mavenUrl + "/org/scala-lang/modules/scala-xml_2.11/1.0.6/scala-xml_2.11-1.0.6.jar",
scalaXml_1_0_6_File,
"4ebd108453e6455351c0ec50d32509ae1154fdb1",
classLoaderCache,
scalaLibrary_2_11_8_,
scalaLibrary_2_11_11_,
scalaXml_1_0_6_ClasspathArray
);

classLoader = scalaXml_1_0_6_;
classpathArray = scalaXml_1_0_6_ClasspathArray;

zinc = zinc_0_3_13_;
zinc = zinc_0_3_15_;

scalaCompiler_File = scalaCompiler_2_11_8_File;
scalaLibrary_File = scalaLibrary_2_11_8_File;
scalaReflect_File = scalaReflect_2_11_8_File;
sbtInterface_File = sbtInterface_0_13_13_File;
compilerInterface_File = compilerInterface_0_13_13_File;
scalaCompiler_File = scalaCompiler_2_11_11_File;
scalaLibrary_File = scalaLibrary_2_11_11_File;
scalaReflect_File = scalaReflect_2_11_11_File;
sbtInterface_File = sbtInterface_0_13_15_File;
compilerInterface_File = compilerInterface_0_13_15_File;
}
}
138 changes: 138 additions & 0 deletions plugins/scalaxb/ScalaXB.scala
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
}
}
Copy link
Owner

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?

Copy link
Author

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.

Copy link
Owner

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


9 changes: 9 additions & 0 deletions plugins/scalaxb/build/build.scala
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)
)
}
1 change: 1 addition & 0 deletions stage2/plugins.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class plugins( context: Context, scalaVersion: String ) {
final lazy val scalafmt = plugin( "scalafmt" )
final lazy val scalaJs = plugin( "scalajs" )
final lazy val scalapb = plugin( "scalapb" )
final lazy val scalaxb = plugin( "scalaxb" )
final lazy val scalariform = plugin( "scalariform" )
final lazy val scalastyle = plugin( "scalastyle" )
final lazy val sonatypeRelease = plugin( "sonatype-release" )
Expand Down
Loading