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 504da56  Warn whe daffodilFlatLayout is true, but the layout does not 
look flat
504da56 is described below

commit 504da5627d1ec9554ca69584e5ae05a7081b7b23
Author: Steve Lawrence <[email protected]>
AuthorDate: Thu Oct 31 14:45:50 2024 -0400

    Warn whe daffodilFlatLayout is true, but the layout does not look flat
    
    Setting `daffodilFlatLayout := true` in a project where the layout is
    not flat will cause weird behavior and things will fail in unintuitive
    ways, making it hard to figure out the problem.
    
    If the setting is true, we now try to detect non-flat layouts and output
    warnings, helping to avoid these difficult to track down errors.
    
    Closes #70
---
 .../scala/org/apache/daffodil/DaffodilPlugin.scala | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/src/main/scala/org/apache/daffodil/DaffodilPlugin.scala 
b/src/main/scala/org/apache/daffodil/DaffodilPlugin.scala
index f1b5cd7..df36566 100644
--- a/src/main/scala/org/apache/daffodil/DaffodilPlugin.scala
+++ b/src/main/scala/org/apache/daffodil/DaffodilPlugin.scala
@@ -526,11 +526,17 @@ object DaffodilPlugin extends AutoPlugin {
   def flatLayoutSettings(dir: String) = Seq(
     unmanagedSourceDirectories := {
       if (!daffodilFlatLayout.value) unmanagedSourceDirectories.value
-      else Seq(baseDirectory.value / dir)
+      else {
+        nonFlatWarning(Keys.sLog.value, unmanagedSourceDirectories.value)
+        Seq(baseDirectory.value / dir)
+      }
     },
     unmanagedResourceDirectories := {
       if (!daffodilFlatLayout.value) unmanagedResourceDirectories.value
-      else unmanagedSourceDirectories.value
+      else {
+        nonFlatWarning(Keys.sLog.value, unmanagedResourceDirectories.value)
+        unmanagedSourceDirectories.value
+      }
     },
     unmanagedSources / includeFilter := {
       if (!daffodilFlatLayout.value) (unmanagedSources / includeFilter).value
@@ -542,4 +548,16 @@ object DaffodilPlugin extends AutoPlugin {
     },
   )
 
+  /**
+   * Before changing the unmanagedSource/ResourceDirectories settings to be 
flat, we should call
+   * this function passing in the current non-flat setting value. This will 
detect if any of the
+   * directories in a non-flat layout exist, and if so warn. This helps to 
avoid cases where
+   * daffodilFlatLayout is true but the layout isn't actually flat.
+   */
+  private def nonFlatWarning(logger: Logger, dirsThatShouldNotExist: 
Seq[File]): Unit = {
+    dirsThatShouldNotExist.filter(_.exists).foreach { dir =>
+      logger.warn("daffodilFlatLayout is true, but the layout does not look 
flat: " + dir)
+    }
+  }
+
 }

Reply via email to