blob: ca02f1b27d1d9fbb55486b160ca4bde236359513 [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
lazy val genManaged = taskKey[Unit]("Generate managed sources and resources")
lazy val genProps = taskKey[Seq[File]]("Generate properties scala source")
lazy val genSchemas = taskKey[Seq[File]]("Generated DFDL schemas")
lazy val daffodil = Project("daffodil", file(".")).configs(IntegrationTest)
.enablePlugins(JavaUnidocPlugin, ScalaUnidocPlugin)
.aggregate(macroLib, propgen, lib, io, runtime1, runtime1Unparser, core, japi, sapi, tdmlLib, tdmlProc, cli, udf, test, testIBM1, tutorials, testStdLayout)
.settings(commonSettings, nopublish, ratSettings, unidocSettings)
lazy val macroLib = Project("daffodil-macro-lib", file("daffodil-macro-lib")).configs(IntegrationTest)
.settings(commonSettings, nopublish)
.settings(libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value)
lazy val propgen = Project("daffodil-propgen", file("daffodil-propgen")).configs(IntegrationTest)
.settings(commonSettings, nopublish)
lazy val lib = Project("daffodil-lib", file("daffodil-lib")).configs(IntegrationTest)
.dependsOn(macroLib % "compile-internal, test-internal")
.settings(commonSettings, libManagedSettings, usesMacros)
lazy val io = Project("daffodil-io", file("daffodil-io")).configs(IntegrationTest)
.dependsOn(lib, macroLib % "compile-internal, test-internal")
.settings(commonSettings, usesMacros)
lazy val runtime1 = Project("daffodil-runtime1", file("daffodil-runtime1")).configs(IntegrationTest)
.dependsOn(io, lib % "test->test", udf, macroLib % "compile-internal, test-internal")
.settings(commonSettings, usesMacros)
lazy val runtime1Unparser = Project("daffodil-runtime1-unparser", file("daffodil-runtime1-unparser")).configs(IntegrationTest)
.dependsOn(runtime1, lib % "test->test", runtime1 % "test->test")
.settings(commonSettings)
lazy val core = Project("daffodil-core", file("daffodil-core")).configs(IntegrationTest)
.dependsOn(runtime1Unparser, udf, lib % "test->test", runtime1 % "test->test")
.settings(commonSettings)
lazy val japi = Project("daffodil-japi", file("daffodil-japi")).configs(IntegrationTest)
.dependsOn(core)
.settings(commonSettings)
lazy val sapi = Project("daffodil-sapi", file("daffodil-sapi")).configs(IntegrationTest)
.dependsOn(core)
.settings(commonSettings)
lazy val tdmlLib = Project("daffodil-tdml-lib", file("daffodil-tdml-lib")).configs(IntegrationTest)
.dependsOn(macroLib % "compile-internal", lib, io, io % "test->test")
.settings(commonSettings)
lazy val tdmlProc = Project("daffodil-tdml-processor", file("daffodil-tdml-processor")).configs(IntegrationTest)
.dependsOn(tdmlLib, core)
.settings(commonSettings)
lazy val cli = Project("daffodil-cli", file("daffodil-cli")).configs(IntegrationTest)
.dependsOn(tdmlProc, sapi, japi, udf % "it->test") // causes sapi/japi to be pulled in to the helper zip/tar
.settings(commonSettings, nopublish)
.settings(libraryDependencies ++= Dependencies.cli)
lazy val udf = Project("daffodil-udf", file("daffodil-udf")).configs(IntegrationTest)
.settings(commonSettings)
lazy val test = Project("daffodil-test", file("daffodil-test")).configs(IntegrationTest)
.dependsOn(tdmlProc, udf % "test->test")
.settings(commonSettings, nopublish)
//
// Uncomment the following line to run these tests
// against IBM DFDL using the Cross Tester
//
//.settings(IBMDFDLCrossTesterPlugin.settings)
lazy val testIBM1 = Project("daffodil-test-ibm1", file("daffodil-test-ibm1")).configs(IntegrationTest)
.dependsOn(tdmlProc)
.settings(commonSettings, nopublish)
//
// Uncomment the following line to run these tests
// against IBM DFDL using the Cross Tester
//
//.settings(IBMDFDLCrossTesterPlugin.settings)
lazy val tutorials = Project("daffodil-tutorials", file("tutorials")).configs(IntegrationTest)
.dependsOn(tdmlProc)
.settings(commonSettings, nopublish)
lazy val testStdLayout = Project("daffodil-test-stdLayout", file("test-stdLayout")).configs(IntegrationTest)
.dependsOn(tdmlProc)
.settings(commonSettings, nopublish)
lazy val commonSettings = Seq(
organization := "org.apache.daffodil",
version := "3.0.0",
scalaVersion := "2.12.11",
crossScalaVersions := Seq("2.12.11"),
scalacOptions ++= Seq(
"-feature",
"-deprecation",
"-language:experimental.macros",
"-unchecked",
"-Xfatal-warnings",
"-Xxml:-coalescing",
"-Xfuture"
),
// add scalac options that are version specific
scalacOptions ++= scalacCrossOptions(scalaVersion.value),
// Workaround issue that some options are valid for javac, not javadoc.
// These javacOptions are for code compilation only. (Issue sbt/sbt#355)
javacOptions in Compile in compile ++= Seq(
"-Werror",
"-Xlint:deprecation"
),
logBuffered := true,
transitiveClassifiers := Seq("sources", "javadoc"),
retrieveManaged := true,
useCoursier := false, // disabled because it breaks retrieveManaged (sbt issue #5078)
exportJars := true,
exportJars in Test := false,
publishMavenStyle := true,
publishArtifact in Test := false,
pomIncludeRepository in ThisBuild := { _ => false },
scmInfo := Some(
ScmInfo(
browseUrl = url("https://gitbox.apache.org/repos/asf/incubator-daffodil.git"),
connection = "scm:git:https://gitbox.apache.org/repos/asf/incubator-daffodil.git"
)
),
licenses := Seq("Apache License, Version 2.0" -> url("https://www.apache.org/licenses/LICENSE-2.0")),
mappings in (Compile, packageBin) += baseDirectory.value / ".." / "DISCLAIMER" -> "META-INF/DISCLAIMER",
homepage := Some(url("https://daffodil.apache.org")),
unmanagedBase := baseDirectory.value / "lib" / "jars",
sourceManaged := baseDirectory.value / "src_managed",
resourceManaged := baseDirectory.value / "resource_managed",
libraryDependencies ++= Dependencies.common,
parallelExecution in IntegrationTest := false,
testOptions += Tests.Argument(TestFrameworks.JUnit, "-q", "-v"),
) ++ Defaults.itSettings
def scalacCrossOptions(scalaVersion: String) =
CrossVersion.partialVersion(scalaVersion) match {
case Some((2, 12)) => Seq(
"-Ywarn-unused:imports"
)
case _ => Seq.empty
}
lazy val nopublish = Seq(
publish := {},
publishLocal := {},
publishM2 := {},
skip in publish := true
)
lazy val usesMacros = Seq(
// copies classe and source files into the project that uses macros. Note
// that for packageBin, we only copy directories and class files--this
// ignores files such a META-INFA/LICENSE and NOTICE that are duplicated and
// would otherwise cause a conflict
mappings in (Compile, packageBin) ++= mappings.in(macroLib, Compile, packageBin).value.filter { case (f, _) => f.isDirectory || f.getPath.endsWith(".class") },
mappings in (Compile, packageSrc) ++= mappings.in(macroLib, Compile, packageSrc).value
)
lazy val libManagedSettings = Seq(
genManaged := {
(genProps in Compile).value
(genSchemas in Compile).value
()
},
genProps in Compile := {
val cp = (dependencyClasspath in Runtime in propgen).value
val inSrc = (sources in Compile in propgen).value
val inRSrc = (resources in Compile in propgen).value
val stream = (streams in propgen).value
val outdir = (sourceManaged in Compile).value
val filesToWatch = (inSrc ++ inRSrc).toSet
val cachedFun = FileFunction.cached(stream.cacheDirectory / "propgen") { (in: Set[File]) =>
val mainClass = "org.apache.daffodil.propGen.PropertyGenerator"
val out = new java.io.ByteArrayOutputStream()
val forkOpts = ForkOptions()
.withOutputStrategy(Some(CustomOutput(out)))
.withBootJars(cp.files.toVector)
val ret = new Fork("java", Some(mainClass)).fork(forkOpts, Seq(outdir.toString)).exitValue()
if (ret != 0) {
sys.error("Failed to generate code")
}
val bis = new java.io.ByteArrayInputStream(out.toByteArray)
val isr = new java.io.InputStreamReader(bis)
val br = new java.io.BufferedReader(isr)
val iterator = Iterator.continually(br.readLine()).takeWhile(_ != null)
val files = iterator.map { f =>
stream.log.info("generated %s".format(f))
new File(f)
}.toSet
files
}
cachedFun(filesToWatch).toSeq
},
genSchemas in Compile := {
val inRSrc = (resources in Compile in propgen).value
val stream = (streams in propgen).value
val outdir = (resourceManaged in Compile).value
val filesToWatch = inRSrc.filter{_.isFile}.toSet
val cachedFun = FileFunction.cached(stream.cacheDirectory / "schemasgen") { (schemas: Set[File]) =>
schemas.map { schema =>
val out = outdir / "org" / "apache" / "daffodil" / "xsd" / schema.getName
IO.copyFile(schema, out)
stream.log.info("generated %s".format(out))
out
}
}
cachedFun(filesToWatch).toSeq
},
sourceGenerators in Compile += (genProps in Compile).taskValue,
resourceGenerators in Compile += (genSchemas in Compile).taskValue
)
lazy val ratSettings = Seq(
ratLicenses := Seq(
("BSD2 ", Rat.BSD2_LICENSE_NAME, Rat.LICENSE_TEXT_PASSERA)
),
ratLicenseFamilies := Seq(
Rat.BSD2_LICENSE_NAME
),
ratExcludes := Rat.excludes
)
lazy val unidocSettings = Seq(
unidocProjectFilter in (ScalaUnidoc, unidoc) := inProjects(sapi, udf),
scalacOptions in (ScalaUnidoc, unidoc) := Seq(
"-doc-title", "Apache Daffodil (incubating) " + version.value + " Scala API",
"-doc-root-content", (baseDirectory in sapi).value + "/root-doc.txt"
),
unidocProjectFilter in (JavaUnidoc, unidoc) := inProjects(japi, udf),
javacOptions in (JavaUnidoc, unidoc) := Seq(
"-windowtitle", "Apache Daffodil (incubating) " + version.value + " Java API",
"-doctitle", "<h1>Apache Daffodil (incubating) " + version.value + " Java API</h1>",
"-notimestamp"
),
unidocAllSources in (JavaUnidoc, unidoc) := (unidocAllSources in (JavaUnidoc, unidoc)).value.map { sources =>
sources.filterNot { source =>
source.toString.contains("$") || source.toString.contains("packageprivate")
}
},
)
//
// To create a set of eclipse projects (one for each subproject of daffodil), you
// need the sbtEclipse plugin and this task below which is run after 'sbt eclipse'.
// Directions for setup are on the Daffodil Wiki.
//
lazy val updateEclipseClasspaths = taskKey[Unit]("Updates eclipse classpaths with daffodil-macro-lib. Used after sbt eclipse.")
updateEclipseClasspaths := UpdateEclipseClasspaths.main()