This is an automated email from the ASF dual-hosted git repository.
slawrence pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/daffodil-sbt.git
The following commit(s) were added to refs/heads/main by this push:
new 45cd845 Configure common settings for DFDL schema project
45cd845 is described below
commit 45cd845caf6a3ef948498787f46fef7e9f9fa976
Author: Steve Lawrence <[email protected]>
AuthorDate: Tue Jan 23 11:17:28 2024 -0500
Configure common settings for DFDL schema project
- Add new "daffodilVersion" setting, used to specify which version of
Daffodil "sbt test" should build and run against. This is used to add
dependencies like daffodil-tdml-processor, junit, and loggers if
needed
- Set crossPaths to false--schema projects jars do not depend on
specific versions of Scala since they just contain resources. This
makes it so the _2.12 is not included in jar file names.
- Set testOptions for verbose logging with SBT JUnit interface
- Change daffodilPackageBinVersion from a Set to a Seq. This makes it so
order is deterministic and schema projects can do things like:
daffodilVersion := daffodilPackageBinVersions.head
- Remove sbtPlugin := true setting--that is already set by enabling the
SbtPlugin plugin
- Update scripted test to use new settings and remove settings the
plugin now provides.
- Ignore project/build.properties in scripted tests--when running
scripted tests manually sbt creates these files and we don't want them
Closes #9
---
.gitignore | 1 +
README.md | 21 ++++++++-
build.sbt | 4 +-
.../scala/org/apache/daffodil/DaffodilPlugin.scala | 51 +++++++++++++++++++++-
.../build.sbt} | 8 +++-
.../common-settings-01/project/plugins.sbt | 20 +++++++++
.../src/main/resources/com/example/test.dfdl.xsd | 37 ++++++++++++++++
.../src/test/resources/com/example/test.tdml | 34 +++++++++++++++
.../src/test/scala/com/example/test.scala} | 22 +++++-----
.../sbt-daffodil/common-settings-01/test.script | 20 +++++++++
.../sbt-daffodil/saved-parsers-01/build.sbt | 3 +-
11 files changed, 203 insertions(+), 18 deletions(-)
diff --git a/.gitignore b/.gitignore
index 839f323..56f4f79 100644
--- a/.gitignore
+++ b/.gitignore
@@ -15,3 +15,4 @@
.bsp
target
+src/sbt-test/**/build.properties
diff --git a/README.md b/README.md
index 183d2e5..2cc0906 100644
--- a/README.md
+++ b/README.md
@@ -29,6 +29,18 @@ addSbtPlugin("org.apache.daffodil" % "sbt-daffodil" %
"<version>")
## Features
+### Common Settings
+
+This plugin configures a number of SBT settings to have better defaults for
+DFDL schema projects. This includes setting dependencies for testing (e.g.
+daffodil-tdml-processor, junit), juint test options, and more. This requires
+that the plugin knows which version of Daffodil to use, which is set by adding
+the `daffodilVersion` setting to build.sbt, for example:
+
+```scala
+daffodilVersion := "3.6.0"
+```
+
### Saved Parsers
This plugin adds the ability to create and publish saved parsers of a schema.
@@ -53,7 +65,7 @@ parsers using the `daffodilPackageBinVersions` setting. For
example, to build
saved parsers for Daffodil 3.6.0 and 3.5.0:
```scala
-daffodilPackageBinVersions := Set("3.6.0", "3.5.0")
+daffodilPackageBinVersions := Seq("3.6.0", "3.5.0")
```
Then run `sbt packageDaffodilBin` to generate saved parsers in the `target/`
@@ -75,6 +87,13 @@ The `publish`, `publishLocal`, `publishM2` and related
publish tasks are
modified to automatically build and publish the saved parsers as a new
artifacts.
+If used, one may want to use the first value of this setting to configure
+`daffodilVersion`, e.g.:
+
+```scala
+daffodilVersion := daffodilPackageBinVersions.value.head
+```
+
# License
Apache Daffodil SBT Plugin is licensed under the [Apache License, v2.0].
diff --git a/build.sbt b/build.sbt
index ee09706..f08b629 100644
--- a/build.sbt
+++ b/build.sbt
@@ -15,8 +15,6 @@
* limitations under the License.
*/
-enablePlugins(SbtPlugin)
-
name := "sbt-daffodil"
organization := "org.apache.daffodil"
@@ -31,7 +29,7 @@ scalacOptions ++= Seq(
// SBT Plugin settings
-sbtPlugin := true
+enablePlugins(SbtPlugin)
crossSbtVersions := Seq("1.8.0")
diff --git a/src/main/scala/org/apache/daffodil/DaffodilPlugin.scala
b/src/main/scala/org/apache/daffodil/DaffodilPlugin.scala
index c76f4ef..7e17f86 100644
--- a/src/main/scala/org/apache/daffodil/DaffodilPlugin.scala
+++ b/src/main/scala/org/apache/daffodil/DaffodilPlugin.scala
@@ -30,12 +30,15 @@ object DaffodilPlugin extends AutoPlugin {
val daffodilPackageBinInfos = settingKey[Seq[(String, Option[String],
Option[String])]](
"Sequence of 3-tuple defining the main schema resource, optional root
element, and optional name",
)
- val daffodilPackageBinVersions = settingKey[Set[String]](
+ val daffodilPackageBinVersions = settingKey[Seq[String]](
"Versions of daffodil to create saved parsers for",
)
val packageDaffodilBin = taskKey[Seq[File]](
"Package daffodil saved parsers",
)
+ val daffodilVersion = settingKey[String](
+ "Version of daffodil to add as a dependency",
+ )
}
import autoImport._
@@ -57,11 +60,55 @@ object DaffodilPlugin extends AutoPlugin {
}
override lazy val projectSettings: Seq[Setting[_]] = Seq(
+ /**
+ * Default Daffodil version
+ */
+ daffodilVersion := "3.6.0",
+
+ /**
+ * Add Daffodil and version specific test dependencies
+ */
+ libraryDependencies ++= {
+ // Seq of 2-tuples, where each tuple is a Seq of version specifiers and
a list of
+ // dependencies to add if the daffodilVersion matches all of those
specifiers. If the
+ // version specifier Seq is empty, the associated dependencies are added
regardless of
+ // Daffodil version
+ val versionedDeps = Seq(
+ // always add Daffodil and junit test dependencies
+ Nil -> Seq(
+ "org.apache.daffodil" %% "daffodil-tdml-processor" %
daffodilVersion.value % "test",
+ "junit" % "junit" % "4.13.2" % "test",
+ "com.github.sbt" % "junit-interface" % "0.13.2" % "test",
+ ),
+ // Add log4j with older versions of Daffodil to silence warnings about
missing loggers
+ Seq(">=3.2.0", "<=3.4.0") -> Seq(
+ "org.apache.logging.log4j" % "log4j-core" % "2.20.0" % "test",
+ ),
+ )
+
+ val dafVer = VersionNumber(daffodilVersion.value)
+ val dependencies = versionedDeps
+ .filter { case (vers, _) => vers.forall { v =>
SemanticSelector(v).matches(dafVer) } }
+ .flatMap { case (_, deps) => deps }
+ dependencies
+ },
+
+ /**
+ * DFDL schemas are are not scala version specific since they just contain
resources,
+ * disable crossPaths so published jars do not contain a scala version
+ */
+ crossPaths := false,
+
+ /**
+ * Enable verbose logging for junit tests
+ */
+ testOptions += Tests.Argument(TestFrameworks.JUnit, "-v"),
+
/**
* Default to building no saved parsers and supporting no versions of
daffodil
*/
daffodilPackageBinInfos := Seq(),
- daffodilPackageBinVersions := Set(),
+ daffodilPackageBinVersions := Seq(),
/**
* define and configure a custom Ivy configuration with dependencies to
the Daffodil
diff --git
a/src/sbt-test/sbt-daffodil/saved-parsers-01/project/build.properties
b/src/sbt-test/sbt-daffodil/common-settings-01/build.sbt
similarity index 89%
rename from src/sbt-test/sbt-daffodil/saved-parsers-01/project/build.properties
rename to src/sbt-test/sbt-daffodil/common-settings-01/build.sbt
index 92ae7e1..e831eac 100644
--- a/src/sbt-test/sbt-daffodil/saved-parsers-01/project/build.properties
+++ b/src/sbt-test/sbt-daffodil/common-settings-01/build.sbt
@@ -15,4 +15,10 @@
* limitations under the License.
*/
-sbt.version=1.9.8
+version := "0.1"
+
+name := "test"
+
+organization := "com.example"
+
+daffodilVersion := "3.6.0"
diff --git a/src/sbt-test/sbt-daffodil/common-settings-01/project/plugins.sbt
b/src/sbt-test/sbt-daffodil/common-settings-01/project/plugins.sbt
new file mode 100644
index 0000000..eaf249b
--- /dev/null
+++ b/src/sbt-test/sbt-daffodil/common-settings-01/project/plugins.sbt
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+addSbtPlugin("org.apache.daffodil" % "sbt-daffodil" %
sys.props("plugin.version"))
diff --git
a/src/sbt-test/sbt-daffodil/common-settings-01/src/main/resources/com/example/test.dfdl.xsd
b/src/sbt-test/sbt-daffodil/common-settings-01/src/main/resources/com/example/test.dfdl.xsd
new file mode 100644
index 0000000..dbab88c
--- /dev/null
+++
b/src/sbt-test/sbt-daffodil/common-settings-01/src/main/resources/com/example/test.dfdl.xsd
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+
+<schema
+ xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/"
+ xmlns:ex="http://example.com"
+ targetNamespace="http://example.com"
+ elementFormDefault="unqualified">
+
+ <include
schemaLocation="/org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd"/>
+
+ <annotation>
+ <appinfo source="http://www.ogf.org/dfdl/">
+ <dfdl:format ref="ex:GeneralFormat" />
+ </appinfo>
+ </annotation>
+
+ <element name="test01" type="xs:string" dfdl:lengthKind="delimited" />
+
+</schema>
diff --git
a/src/sbt-test/sbt-daffodil/common-settings-01/src/test/resources/com/example/test.tdml
b/src/sbt-test/sbt-daffodil/common-settings-01/src/test/resources/com/example/test.tdml
new file mode 100644
index 0000000..fd78b68
--- /dev/null
+++
b/src/sbt-test/sbt-daffodil/common-settings-01/src/test/resources/com/example/test.tdml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+
+<testSuite
+ xmlns="http://www.ibm.com/xmlns/dfdl/testData"
+ xmlns:tdml="http://www.ibm.com/xmlns/dfdl/testData"
+ xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/"
+ xmlns:ex="http://example.com">
+
+ <parserTestCase name="test01" root="test01"
model="com/example/test.dfdl.xsd">
+ <document>test data</document>
+ <infoset>
+ <dfdlInfoset>
+ <ex:test01>test data</ex:test01>
+ </dfdlInfoset>
+ </infoset>
+ </parserTestCase>
+
+</testSuite>
diff --git a/src/sbt-test/sbt-daffodil/saved-parsers-01/build.sbt
b/src/sbt-test/sbt-daffodil/common-settings-01/src/test/scala/com/example/test.scala
similarity index 70%
copy from src/sbt-test/sbt-daffodil/saved-parsers-01/build.sbt
copy to
src/sbt-test/sbt-daffodil/common-settings-01/src/test/scala/com/example/test.scala
index 59f61b6..85e2848 100644
--- a/src/sbt-test/sbt-daffodil/saved-parsers-01/build.sbt
+++
b/src/sbt-test/sbt-daffodil/common-settings-01/src/test/scala/com/example/test.scala
@@ -15,18 +15,20 @@
* limitations under the License.
*/
-version := "0.1"
+package com.example
-name := "test"
+import org.junit.Test
+import org.apache.daffodil.tdml.Runner
+import org.junit.AfterClass
-organization := "com.example"
+object TestExample {
+ lazy val runner = Runner("/com/example/", "test.tdml")
-crossPaths := false
+ @AfterClass def shutdown: Unit = { runner.reset }
+}
-daffodilPackageBinInfos := Seq(
- ("/test.dfdl.xsd", None, None),
- ("/test.dfdl.xsd", Some("test02"), Some("two")),
-)
-
-daffodilPackageBinVersions := Set("3.6.0", "3.5.0")
+class TestExample {
+ import TestExample._
+ @Test def test_test01() { runner.runOneTest("test01") }
+}
diff --git a/src/sbt-test/sbt-daffodil/common-settings-01/test.script
b/src/sbt-test/sbt-daffodil/common-settings-01/test.script
new file mode 100644
index 0000000..8d94745
--- /dev/null
+++ b/src/sbt-test/sbt-daffodil/common-settings-01/test.script
@@ -0,0 +1,20 @@
+## 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.
+##
+
+> compile
+> test
diff --git a/src/sbt-test/sbt-daffodil/saved-parsers-01/build.sbt
b/src/sbt-test/sbt-daffodil/saved-parsers-01/build.sbt
index 59f61b6..90c54b8 100644
--- a/src/sbt-test/sbt-daffodil/saved-parsers-01/build.sbt
+++ b/src/sbt-test/sbt-daffodil/saved-parsers-01/build.sbt
@@ -28,5 +28,6 @@ daffodilPackageBinInfos := Seq(
("/test.dfdl.xsd", Some("test02"), Some("two")),
)
-daffodilPackageBinVersions := Set("3.6.0", "3.5.0")
+daffodilPackageBinVersions := Seq("3.6.0", "3.5.0")
+daffodilVersion := daffodilPackageBinVersions.value.head