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 9e74273  Support version specific configuration files
9e74273 is described below

commit 9e7427317a6beaafdc1a771e31c96bff1b83cf8c
Author: Steve Lawrence <slawre...@apache.org>
AuthorDate: Mon Jun 30 20:35:32 2025 -0400

    Support version specific configuration files
    
    Different versions of Daffodil support different tunables and tunable
    values. This can make it difficult in some cases to have a single
    configuration file when multiple versions of Daffodil are specified in
    packageDaffodilBinVersions.
    
    To make this easier, if the config option is specified and a file exists
    at the same path but with a Daffodil version as the secondary extension,
    then that config file will be used when building saved parsers for that
    Daffodil version. If version specific path does not exist, the original
    config option is used.
    
    Fixes #112
---
 README.md                                          |  7 +++++++
 .../scala/org/apache/daffodil/DaffodilPlugin.scala | 22 +++++++++++++++++++---
 .../sbt-daffodil/saved-parsers-03/build.sbt        |  2 +-
 .../saved-parsers-03/src/main/resources/test.cfg   |  1 +
 .../resources/{test.cfg => test.daffodil350.cfg}   |  0
 .../sbt-daffodil/saved-parsers-03/test.script      |  4 ++--
 6 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/README.md b/README.md
index 2a5afae..f9456e5 100644
--- a/README.md
+++ b/README.md
@@ -111,6 +111,13 @@ Path to a configuration file used during compilation, 
currently only used to
 specify tunables. If specified, it should usually use SBT settings to create
 the path. Defaults to `None` if not provided.
 
+If a file exists with the same name as the config option, but with a Daffodil
+version as the secondary extension (e.g. `config.daffodil390.xml`), then that
+file will be used instead of the original config file, but only when creating
+saved parsers for that specific version of Daffodil. This can be useful when
+multiple versions are specified in `daffodilPackageBinVersions` but those
+versions have configuration incompatibilities.
+
 Example:
 
 If the configuration file is in `src/main/resources/`, then use:
diff --git a/src/main/scala/org/apache/daffodil/DaffodilPlugin.scala 
b/src/main/scala/org/apache/daffodil/DaffodilPlugin.scala
index b227cdb..35e4ccb 100644
--- a/src/main/scala/org/apache/daffodil/DaffodilPlugin.scala
+++ b/src/main/scala/org/apache/daffodil/DaffodilPlugin.scala
@@ -429,8 +429,8 @@ object DaffodilPlugin extends AutoPlugin {
         val targetFiles = daffodilPackageBinVersions.value.flatMap { 
daffodilVersion =>
           // get all the Daffodil jars and dependencies for the version of 
Daffodil associated with
           // this ivy config
-          val cfg = ivyConfigs.find { _.name == ivyConfigName(daffodilVersion) 
}.get
-          val daffodilJars = Classpaths.managedJars(cfg, classpathTypesVal, 
updateVal).files
+          val ivyCfg = ivyConfigs.find { _.name == 
ivyConfigName(daffodilVersion) }.get
+          val daffodilJars = Classpaths.managedJars(ivyCfg, classpathTypesVal, 
updateVal).files
 
           // Note that order matters here. The projectClasspath might have 
daffodil jars on it if
           // Daffodil is a compile dependency, which could be a different 
version from the version
@@ -464,6 +464,22 @@ object DaffodilPlugin extends AutoPlugin {
             val internalApiVersion =
               filterVersions(daffodilVersion, 
daffodilInternalApiVersionMapping).head
 
+            // If a file exists with the same name as the config option but 
with the ivy config
+            // name as a secondary extension (e.g. config.daffodil390.xml) 
then use that as the
+            // config file. Otherwise use the unmodified config setting. This 
is useful when
+            // different version of Daffodil require different configs.
+            val cfgOption = dbi.config
+              .map { cfg =>
+                val curName = cfg.getName
+                val index = curName.lastIndexOf(".")
+                val (baseName, ext) = if (index >= 1) curName.splitAt(index) 
else (curName, "")
+                val versionedName = baseName + "." + ivyCfg.name + ext
+                val versionedCfg = new File(cfg.getParentFile, versionedName)
+                if (versionedCfg.exists) versionedCfg else cfg
+              }
+              .map { _.toString }
+              .getOrElse("")
+
             val args = jvmArgs ++ Seq(
               "-classpath",
               classpathFiles.mkString(File.pathSeparator),
@@ -472,7 +488,7 @@ object DaffodilPlugin extends AutoPlugin {
               dbi.schema,
               targetFile.toString,
               dbi.root.getOrElse(""),
-              dbi.config.map { _.toString }.getOrElse("")
+              cfgOption
             )
 
             // SBT has the concept of an "export stream"--this is a stream 
that an SBT task can
diff --git a/src/sbt-test/sbt-daffodil/saved-parsers-03/build.sbt 
b/src/sbt-test/sbt-daffodil/saved-parsers-03/build.sbt
index 163bce5..230e9d5 100644
--- a/src/sbt-test/sbt-daffodil/saved-parsers-03/build.sbt
+++ b/src/sbt-test/sbt-daffodil/saved-parsers-03/build.sbt
@@ -31,6 +31,6 @@ daffodilPackageBinInfos := {
   )
 }
 
-daffodilPackageBinVersions := Seq("3.6.0", "3.5.0")
+daffodilPackageBinVersions := Seq("3.11.0", "3.5.0")
 
 daffodilVersion := daffodilPackageBinVersions.value.head
diff --git 
a/src/sbt-test/sbt-daffodil/saved-parsers-03/src/main/resources/test.cfg 
b/src/sbt-test/sbt-daffodil/saved-parsers-03/src/main/resources/test.cfg
index 7545ee2..8f0dae4 100644
--- a/src/sbt-test/sbt-daffodil/saved-parsers-03/src/main/resources/test.cfg
+++ b/src/sbt-test/sbt-daffodil/saved-parsers-03/src/main/resources/test.cfg
@@ -23,6 +23,7 @@
       encodingErrorPolicyError
       facetExplicitLengthOutOfRange
       multipleChoiceBranches
+      multipleChildElementsWithSameName
     </daf:suppressSchemaDefinitionWarnings>
   </daf:tunables>
 </daf:dfdlConfig>
diff --git 
a/src/sbt-test/sbt-daffodil/saved-parsers-03/src/main/resources/test.cfg 
b/src/sbt-test/sbt-daffodil/saved-parsers-03/src/main/resources/test.daffodil350.cfg
similarity index 100%
copy from src/sbt-test/sbt-daffodil/saved-parsers-03/src/main/resources/test.cfg
copy to 
src/sbt-test/sbt-daffodil/saved-parsers-03/src/main/resources/test.daffodil350.cfg
diff --git a/src/sbt-test/sbt-daffodil/saved-parsers-03/test.script 
b/src/sbt-test/sbt-daffodil/saved-parsers-03/test.script
index 76a79ef..f84fc9a 100644
--- a/src/sbt-test/sbt-daffodil/saved-parsers-03/test.script
+++ b/src/sbt-test/sbt-daffodil/saved-parsers-03/test.script
@@ -18,6 +18,6 @@
 
 > packageDaffodilBin
 $ exists target/test-0.1-daffodil350.bin
-$ exists target/test-0.1-daffodil360.bin
+$ exists target/test-0.1-daffodil3110.bin
 $ exists target/test-0.1-two-daffodil350.bin
-$ exists target/test-0.1-two-daffodil360.bin
+$ exists target/test-0.1-two-daffodil3110.bin

Reply via email to