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 9ef64c4  Add daffodilBuildsCharset setting
9ef64c4 is described below

commit 9ef64c41e1150402db127acd69d7e917eba5fb56
Author: Steve Lawrence <[email protected]>
AuthorDate: Mon Jul 8 09:03:24 2024 -0400

    Add daffodilBuildsCharset setting
    
    Closes #32
---
 README.md                                          | 22 +++++++++--------
 .../scala/org/apache/daffodil/DaffodilPlugin.scala | 17 ++++++++++++-
 .../sbt-daffodil/builds-charset-01/build.sbt       | 28 ++++++++++++++++++++++
 .../builds-charset-01/project/plugins.sbt          | 20 ++++++++++++++++
 .../src/main/scala/com/example/charset.scala       | 26 ++++++++++++++++++++
 .../sbt-daffodil/builds-charset-01/test.script     | 26 ++++++++++++++++++++
 6 files changed, 128 insertions(+), 11 deletions(-)

diff --git a/README.md b/README.md
index 5e28866..ca33eb7 100644
--- a/README.md
+++ b/README.md
@@ -144,27 +144,29 @@ IntelliJ, do not trigger during builds. So you must 
either run `sbt Test/compile
 to manually trigger the resource generator, or let SBT handle builds by
 enabling the "Use SBT shell for builds" option.
 
-### Layers and User Defined Functions
+### Charsets, 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:
+If your schema project builds a Daffodil charset, layer, or user defined
+function, then set the `daffodilBuildsCharset`, `daffodilBuildsLayer`, or
+`daffodilBuildsUDF` setting to true, respectively. For example:
 
 ```scala
+daffodilBuildsCharset := true
+
 daffodilBuildsLayer := true
 
 daffodilBuildsUDF := true
 ```
 
-Setting either of these values to true adds additional dependencies needed to
+Setting any 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:
+the Scala version to be included in the jar file name, since charsets, layers,
+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
+charsets/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
diff --git a/src/main/scala/org/apache/daffodil/DaffodilPlugin.scala 
b/src/main/scala/org/apache/daffodil/DaffodilPlugin.scala
index 11a109d..821e355 100644
--- a/src/main/scala/org/apache/daffodil/DaffodilPlugin.scala
+++ b/src/main/scala/org/apache/daffodil/DaffodilPlugin.scala
@@ -39,6 +39,9 @@ object DaffodilPlugin extends AutoPlugin {
     val daffodilVersion = settingKey[String](
       "Version of daffodil to add as a dependency",
     )
+    val daffodilBuildsCharset = settingKey[Boolean](
+      "Whether or not the project builds a charset",
+    )
     val daffodilBuildsLayer = settingKey[Boolean](
       "Whether or not the project builds a layer",
     )
@@ -165,6 +168,7 @@ object DaffodilPlugin extends AutoPlugin {
     /**
      * Disable uncommon features by default, schema projects must explicitly 
enable them to use
      */
+    daffodilBuildsCharset := false,
     daffodilBuildsLayer := false,
     daffodilBuildsUDF := false,
     daffodilTdmlUsesPackageBin := false,
@@ -193,6 +197,17 @@ object DaffodilPlugin extends AutoPlugin {
       dependencies
     },
 
+    /**
+     * Add Charset compile dependencies if enabled
+     */
+    libraryDependencies ++= {
+      if (daffodilBuildsCharset.value) {
+        Seq("org.apache.daffodil" %% "daffodil-io" % daffodilVersion.value)
+      } else {
+        Seq()
+      }
+    },
+
     /**
      * Add layer compile dependencies if enabled
      */
@@ -223,7 +238,7 @@ object DaffodilPlugin extends AutoPlugin {
      * projects can override this and change the setting to false if they 
don't want the scala
      * version in the jar name.
      */
-    crossPaths := (daffodilBuildsLayer.value || daffodilBuildsUDF.value),
+    crossPaths := (daffodilBuildsCharset.value || daffodilBuildsLayer.value || 
daffodilBuildsUDF.value),
 
     /**
      * Enable verbose logging for junit tests
diff --git a/src/sbt-test/sbt-daffodil/builds-charset-01/build.sbt 
b/src/sbt-test/sbt-daffodil/builds-charset-01/build.sbt
new file mode 100644
index 0000000..2313b65
--- /dev/null
+++ b/src/sbt-test/sbt-daffodil/builds-charset-01/build.sbt
@@ -0,0 +1,28 @@
+/*
+ * 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.
+ */
+
+version := "0.1"
+
+name := "test"
+
+organization := "com.example"
+
+enablePlugins(DaffodilPlugin)
+
+daffodilVersion := "3.6.0"
+
+daffodilBuildsCharset := true
diff --git a/src/sbt-test/sbt-daffodil/builds-charset-01/project/plugins.sbt 
b/src/sbt-test/sbt-daffodil/builds-charset-01/project/plugins.sbt
new file mode 100644
index 0000000..eaf249b
--- /dev/null
+++ b/src/sbt-test/sbt-daffodil/builds-charset-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/builds-charset-01/src/main/scala/com/example/charset.scala
 
b/src/sbt-test/sbt-daffodil/builds-charset-01/src/main/scala/com/example/charset.scala
new file mode 100644
index 0000000..2441a32
--- /dev/null
+++ 
b/src/sbt-test/sbt-daffodil/builds-charset-01/src/main/scala/com/example/charset.scala
@@ -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.
+ */
+
+package com.example
+
+import org.apache.daffodil.io.processors.charset.BitsCharsetDefinition
+
+// this is not a real charset, but the above import will fail to compile if 
daffodil-io (which
+// contains the Daffodil charset API is not on the compile classpath
+class TestCharset {
+}
+
diff --git a/src/sbt-test/sbt-daffodil/builds-charset-01/test.script 
b/src/sbt-test/sbt-daffodil/builds-charset-01/test.script
new file mode 100644
index 0000000..854d1d6
--- /dev/null
+++ b/src/sbt-test/sbt-daffodil/builds-charset-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 charsets are scala version specific
+> package
+$ exists target/scala-2.12/test_2.12-0.1.jar
+
+# expect compilation to fail without this setting
+> set daffodilBuildsCharset := false
+-> compile

Reply via email to