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 b087a1d  Support schema projects that build layers and UDFs
b087a1d is described below

commit b087a1d6777b28514777333d2bbad1f2374584ab
Author: Steve Lawrence <[email protected]>
AuthorDate: Wed Jan 24 12:02:15 2024 -0500

    Support schema projects that build layers and UDFs
    
    - Add daffodilBuildsLayer and daffodilBuildsUDF settings, which if set
      to true adds dependencies and modifies crossPaths for projects that
      builds layers and UDFs, respectively. Defaults to false since most
      projects will not use these.
    
    Closes #11
---
 README.md                                          | 26 +++++++++++++
 .../scala/org/apache/daffodil/DaffodilPlugin.scala | 44 ++++++++++++++++++++--
 .../build.sbt                                      | 11 +-----
 .../builds-layer-01/project/plugins.sbt            | 20 ++++++++++
 .../src/main/scala/com/example/layer.scala}        | 19 +++-------
 .../sbt-daffodil/builds-layer-01/test.script       | 26 +++++++++++++
 .../{saved-parsers-01 => builds-udf-01}/build.sbt  | 11 +-----
 .../sbt-daffodil/builds-udf-01/project/plugins.sbt | 20 ++++++++++
 .../src/main/scala/com/example/udf.scala}          | 19 +++-------
 .../sbt-daffodil/builds-udf-01/test.script         | 26 +++++++++++++
 .../sbt-daffodil/saved-parsers-01/build.sbt        |  2 -
 11 files changed, 175 insertions(+), 49 deletions(-)

diff --git a/README.md b/README.md
index 86630ac..b1d8fa4 100644
--- a/README.md
+++ b/README.md
@@ -94,6 +94,32 @@ If used, one may want to use the first value of this setting 
to configure
 daffodilVersion := daffodilPackageBinVersions.value.head
 ```
 
+## Layers and User Defined Functions
+
+If your schema project builds a Daffodil layer or user defined function, then
+set the `daffodilBuildsLayer` or `daffodilBuildsUDF` setting to true,
+respectively. For example:
+
+```scala
+daffodilBuildsLayer := true
+
+daffodilBuildsUDF := true
+```
+
+Setting either of these values to true adds additional dependencies needed to
+build the component.
+
+Note that this also sets the SBT `crossPaths` setting to `true`, which causes
+the Scala version to be included in the jar file name, since layer and UDF jars
+may be implemented in Scala and are specific to the Scala version used to build
+them. However, if your schema project implements layers/UDFs using only Java,
+you can override this in build.sbt and remove the Scala version from the jar
+name, for example:
+
+```scala
+crossPaths := false
+```
+
 ## Flat Directory Layout
 
 Instead of using the standard `src/{main,test}/{scala,resources}/` directory
diff --git a/src/main/scala/org/apache/daffodil/DaffodilPlugin.scala 
b/src/main/scala/org/apache/daffodil/DaffodilPlugin.scala
index 3bc06ef..a03d519 100644
--- a/src/main/scala/org/apache/daffodil/DaffodilPlugin.scala
+++ b/src/main/scala/org/apache/daffodil/DaffodilPlugin.scala
@@ -39,6 +39,12 @@ object DaffodilPlugin extends AutoPlugin {
     val daffodilVersion = settingKey[String](
       "Version of daffodil to add as a dependency",
     )
+    val daffodilBuildsLayer = settingKey[Boolean](
+      "Whether or not the project builds a layer",
+    )
+    val daffodilBuildsUDF = settingKey[Boolean](
+      "Whether or not the project builds a user defined function",
+    )
     val daffodilFlatLayout = settingKey[Boolean](
       "Whether or not to use a flat schema project layout that uses src/ and 
test/ root directories containing a mix of sources and resources",
     )
@@ -68,6 +74,12 @@ object DaffodilPlugin extends AutoPlugin {
      */
     daffodilVersion := "3.6.0",
 
+    /**
+     * Assume schemas do not include layers or UDFs, projects can override 
these if they do
+     */
+    daffodilBuildsLayer := false,
+    daffodilBuildsUDF := false,
+
     /**
      * Add Daffodil and version specific test dependencies
      */
@@ -97,10 +109,36 @@ object DaffodilPlugin extends AutoPlugin {
     },
 
     /**
-     * DFDL schemas are are not scala version specific since they just contain 
resources,
-     * disable crossPaths so published jars do not contain a scala version
+     * Add layer compile dependencies if enabled
+     */
+    libraryDependencies ++= {
+      if (daffodilBuildsLayer.value) {
+        Seq("org.apache.daffodil" %% "daffodil-runtime1-layers" % 
daffodilVersion.value)
+      } else {
+        Seq()
+      }
+    },
+
+    /**
+     * Add UDF compile dependencies if enabled
+     */
+    libraryDependencies ++= {
+      if (daffodilBuildsUDF.value) {
+        Seq("org.apache.daffodil" %% "daffodil-udf" % daffodilVersion.value)
+      } else {
+        Seq()
+      }
+    },
+
+    /**
+     * DFDL schemas are not scala version specific since they just contain 
resources, so we
+     * disable crossPaths so that published jars do not contain a scala 
version. However, if a
+     * project builds layers or UDFs, then we do need to enable crossPaths 
since those might be
+     * implemented in Scala and so is version dependent. If they are 
implemented purely in Java,
+     * projects can override this and change the setting to false if they 
don't want the scala
+     * version in the jar name.
      */
-    crossPaths := false,
+    crossPaths := (daffodilBuildsLayer.value || daffodilBuildsUDF.value),
 
     /**
      * Enable verbose logging for junit tests
diff --git a/src/sbt-test/sbt-daffodil/saved-parsers-01/build.sbt 
b/src/sbt-test/sbt-daffodil/builds-layer-01/build.sbt
similarity index 77%
copy from src/sbt-test/sbt-daffodil/saved-parsers-01/build.sbt
copy to src/sbt-test/sbt-daffodil/builds-layer-01/build.sbt
index 90c54b8..50d500e 100644
--- a/src/sbt-test/sbt-daffodil/saved-parsers-01/build.sbt
+++ b/src/sbt-test/sbt-daffodil/builds-layer-01/build.sbt
@@ -21,13 +21,6 @@ name := "test"
 
 organization := "com.example"
 
-crossPaths := false
+daffodilVersion := "3.6.0"
 
-daffodilPackageBinInfos := Seq(
-  ("/test.dfdl.xsd", None, None),
-  ("/test.dfdl.xsd", Some("test02"), Some("two")),
-)
-
-daffodilPackageBinVersions := Seq("3.6.0", "3.5.0")
-
-daffodilVersion := daffodilPackageBinVersions.value.head
+daffodilBuildsLayer := true
diff --git a/src/sbt-test/sbt-daffodil/builds-layer-01/project/plugins.sbt 
b/src/sbt-test/sbt-daffodil/builds-layer-01/project/plugins.sbt
new file mode 100644
index 0000000..eaf249b
--- /dev/null
+++ b/src/sbt-test/sbt-daffodil/builds-layer-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/saved-parsers-01/build.sbt 
b/src/sbt-test/sbt-daffodil/builds-layer-01/src/main/scala/com/example/layer.scala
similarity index 72%
copy from src/sbt-test/sbt-daffodil/saved-parsers-01/build.sbt
copy to 
src/sbt-test/sbt-daffodil/builds-layer-01/src/main/scala/com/example/layer.scala
index 90c54b8..9d82359 100644
--- a/src/sbt-test/sbt-daffodil/saved-parsers-01/build.sbt
+++ 
b/src/sbt-test/sbt-daffodil/builds-layer-01/src/main/scala/com/example/layer.scala
@@ -15,19 +15,12 @@
  * limitations under the License.
  */
 
-version := "0.1"
+package com.example
 
-name := "test"
+import org.apache.daffodil.runtime1.layers.LayerCompiler
 
-organization := "com.example"
+// this is not a real layer, but the above import will fail to compile if
+// daffodil-runtime1-layers is not on the compile classpath
+class TestLayer {
+}
 
-crossPaths := false
-
-daffodilPackageBinInfos := Seq(
-  ("/test.dfdl.xsd", None, None),
-  ("/test.dfdl.xsd", Some("test02"), Some("two")),
-)
-
-daffodilPackageBinVersions := Seq("3.6.0", "3.5.0")
-
-daffodilVersion := daffodilPackageBinVersions.value.head
diff --git a/src/sbt-test/sbt-daffodil/builds-layer-01/test.script 
b/src/sbt-test/sbt-daffodil/builds-layer-01/test.script
new file mode 100644
index 0000000..8ffa18b
--- /dev/null
+++ b/src/sbt-test/sbt-daffodil/builds-layer-01/test.script
@@ -0,0 +1,26 @@
+## 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.
+## 
+
+
+# builds jar, with _2.12 in the name beause layers are scala version specific
+> package
+$ exists target/scala-2.12/test_2.12-0.1.jar
+
+# expect compilation to fail without this setting
+> set daffodilBuildsLayer := false
+-> compile
diff --git a/src/sbt-test/sbt-daffodil/saved-parsers-01/build.sbt 
b/src/sbt-test/sbt-daffodil/builds-udf-01/build.sbt
similarity index 77%
copy from src/sbt-test/sbt-daffodil/saved-parsers-01/build.sbt
copy to src/sbt-test/sbt-daffodil/builds-udf-01/build.sbt
index 90c54b8..e4d70f4 100644
--- a/src/sbt-test/sbt-daffodil/saved-parsers-01/build.sbt
+++ b/src/sbt-test/sbt-daffodil/builds-udf-01/build.sbt
@@ -21,13 +21,6 @@ name := "test"
 
 organization := "com.example"
 
-crossPaths := false
+daffodilVersion := "3.6.0"
 
-daffodilPackageBinInfos := Seq(
-  ("/test.dfdl.xsd", None, None),
-  ("/test.dfdl.xsd", Some("test02"), Some("two")),
-)
-
-daffodilPackageBinVersions := Seq("3.6.0", "3.5.0")
-
-daffodilVersion := daffodilPackageBinVersions.value.head
+daffodilBuildsUDF := true
diff --git a/src/sbt-test/sbt-daffodil/builds-udf-01/project/plugins.sbt 
b/src/sbt-test/sbt-daffodil/builds-udf-01/project/plugins.sbt
new file mode 100644
index 0000000..eaf249b
--- /dev/null
+++ b/src/sbt-test/sbt-daffodil/builds-udf-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/saved-parsers-01/build.sbt 
b/src/sbt-test/sbt-daffodil/builds-udf-01/src/main/scala/com/example/udf.scala
similarity index 72%
copy from src/sbt-test/sbt-daffodil/saved-parsers-01/build.sbt
copy to 
src/sbt-test/sbt-daffodil/builds-udf-01/src/main/scala/com/example/udf.scala
index 90c54b8..8d820e6 100644
--- a/src/sbt-test/sbt-daffodil/saved-parsers-01/build.sbt
+++ 
b/src/sbt-test/sbt-daffodil/builds-udf-01/src/main/scala/com/example/udf.scala
@@ -15,19 +15,12 @@
  * limitations under the License.
  */
 
-version := "0.1"
+package com.example
 
-name := "test"
+import org.apache.daffodil.udf.UserDefinedFunction
 
-organization := "com.example"
+// this is not a real udf, but the above import will fail to compile if 
daffodil-udf is not on
+// the compile classpath
+class TestUDF {
+}
 
-crossPaths := false
-
-daffodilPackageBinInfos := Seq(
-  ("/test.dfdl.xsd", None, None),
-  ("/test.dfdl.xsd", Some("test02"), Some("two")),
-)
-
-daffodilPackageBinVersions := Seq("3.6.0", "3.5.0")
-
-daffodilVersion := daffodilPackageBinVersions.value.head
diff --git a/src/sbt-test/sbt-daffodil/builds-udf-01/test.script 
b/src/sbt-test/sbt-daffodil/builds-udf-01/test.script
new file mode 100644
index 0000000..3b88fbe
--- /dev/null
+++ b/src/sbt-test/sbt-daffodil/builds-udf-01/test.script
@@ -0,0 +1,26 @@
+## 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.
+## 
+
+
+# builds jar, with _2.12 in the name beause UDFs are scala version specific
+> package
+$ exists target/scala-2.12/test_2.12-0.1.jar
+
+# expect compilation to fail without this setting
+> set daffodilBuildsUDF := false
+-> compile
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 90c54b8..97b7895 100644
--- a/src/sbt-test/sbt-daffodil/saved-parsers-01/build.sbt
+++ b/src/sbt-test/sbt-daffodil/saved-parsers-01/build.sbt
@@ -21,8 +21,6 @@ name := "test"
 
 organization := "com.example"
 
-crossPaths := false
-
 daffodilPackageBinInfos := Seq(
   ("/test.dfdl.xsd", None, None),
   ("/test.dfdl.xsd", Some("test02"), Some("two")),

Reply via email to