This is an automated email from the ASF dual-hosted git repository.

mmcgann pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/daffodil.git


The following commit(s) were added to refs/heads/main by this push:
     new cc5d546d4 Add WarnID to Schema Definition Warning messages
cc5d546d4 is described below

commit cc5d546d44777862fdbd3fdcad4a8a3fc624b673
Author: Mike McGann <[email protected]>
AuthorDate: Thu Mar 2 16:04:22 2023 -0500

    Add WarnID to Schema Definition Warning messages
    
    Warnings in Daffodil can be suppressed by using an identifier but this
    can be difficult to obtain as the identifier is not displayed to the end
    user. This change adds this identifier to the message, when available,
    and contains instructions on how to suppress the warning.
    
    DAFFODIL-2634
---
 .../codegen/c/DaffodilCCodeGenerator.scala         |  4 ++-
 .../apache/daffodil/core/dsom/DFDLSchemaFile.scala |  7 +++-
 .../resources/org/apache/daffodil/xsd/dafext.xsd   |  3 ++
 .../org/apache/daffodil/runtime1/dsom/SDE.scala    | 12 ++++---
 .../runtime1/processors/ProcessorStateBases.scala  |  8 +----
 .../runtime1/processors/VariableMap1.scala         |  6 ++--
 .../apache/daffodil/runtime1/dsom/TestSDW.scala    | 37 ++++++++++++++++++++++
 7 files changed, 62 insertions(+), 15 deletions(-)

diff --git 
a/daffodil-codegen-c/src/main/scala/org/apache/daffodil/codegen/c/DaffodilCCodeGenerator.scala
 
b/daffodil-codegen-c/src/main/scala/org/apache/daffodil/codegen/c/DaffodilCCodeGenerator.scala
index 83a187daa..3f438fc5f 100644
--- 
a/daffodil-codegen-c/src/main/scala/org/apache/daffodil/codegen/c/DaffodilCCodeGenerator.scala
+++ 
b/daffodil-codegen-c/src/main/scala/org/apache/daffodil/codegen/c/DaffodilCCodeGenerator.scala
@@ -57,6 +57,7 @@ import 
org.apache.daffodil.core.grammar.primitives.ScalarOrderedSequenceChild
 import org.apache.daffodil.core.grammar.primitives.SpecifiedLengthExplicit
 import org.apache.daffodil.core.grammar.primitives.SpecifiedLengthImplicit
 import org.apache.daffodil.lib.api.Diagnostic
+import org.apache.daffodil.lib.api.WarnID
 import org.apache.daffodil.lib.util.Misc
 import org.apache.daffodil.runtime1.api.DFDL
 import org.apache.daffodil.runtime1.dsom.SchemaDefinitionError
@@ -216,7 +217,8 @@ class DaffodilCCodeGenerator(root: Root) extends 
DFDL.CodeGenerator {
    * Adds a warning message to the diagnostics
    */
   private def warning(formatString: String, args: Any*): Unit = {
-    val sde = new SchemaDefinitionWarning(None, None, formatString, args: _*)
+    val sde =
+      new SchemaDefinitionWarning(WarnID.CodeGenerator, None, None, 
formatString, args: _*)
     diagnostics :+= sde
   }
 
diff --git 
a/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/DFDLSchemaFile.scala
 
b/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/DFDLSchemaFile.scala
index 92faae2b6..9873fffb9 100644
--- 
a/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/DFDLSchemaFile.scala
+++ 
b/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/DFDLSchemaFile.scala
@@ -50,7 +50,12 @@ class DFDLSchemaFileLoadErrorHandler(schemaFileLocation: 
SchemaFileLocation)
   }
 
   private def loaderSDWs: Seq[Diagnostic] = loaderWarnings.map {
-    new SchemaDefinitionWarning(schemaFileLocation, "Warning loading schema 
due to %s", _)
+    new SchemaDefinitionWarning(
+      WarnID.XmlParser,
+      schemaFileLocation,
+      "Warning loading schema due to %s",
+      _,
+    )
   }
 
   def loadingDiagnostics = loaderSDEs ++ loaderSDWs
diff --git 
a/daffodil-propgen/src/main/resources/org/apache/daffodil/xsd/dafext.xsd 
b/daffodil-propgen/src/main/resources/org/apache/daffodil/xsd/dafext.xsd
index 3fdb5dfc5..274822c46 100644
--- a/daffodil-propgen/src/main/resources/org/apache/daffodil/xsd/dafext.xsd
+++ b/daffodil-propgen/src/main/resources/org/apache/daffodil/xsd/dafext.xsd
@@ -672,6 +672,7 @@
           <xs:enumeration value="appinfoDFDLSourceWrong" />
           <xs:enumeration value="appinfoNoSource" />
           <xs:enumeration value="choiceInsideHiddenGroup" />
+          <xs:enumeration value="codeGenerator" />
           <xs:enumeration value="deprecatedBigIntegerBits" />
           <xs:enumeration value="deprecatedBuiltInFormats" />
           <xs:enumeration value="deprecatedEncodingNameUSASCII7BitPacked" />
@@ -710,6 +711,8 @@
           <xs:enumeration value="unsupportedAttributeFinalDefault" />
           <xs:enumeration value="unsupportedAttributeFormDefault" />
           <xs:enumeration value="unsupportedAttributeSchemaLocation" />
+          <xs:enumeration value="variableSet" />
+          <xs:enumeration value="xmlParser" />
         </xs:restriction>
       </xs:simpleType>
     </xs:list>
diff --git 
a/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/dsom/SDE.scala 
b/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/dsom/SDE.scala
index 3567693d8..3367b784c 100644
--- 
a/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/dsom/SDE.scala
+++ 
b/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/dsom/SDE.scala
@@ -87,6 +87,7 @@ class RuntimeSchemaDefinitionError(
 }
 
 class RuntimeSchemaDefinitionWarning(
+  warnID: WarnID,
   schemaContext: SchemaFileLocation,
   runtimeContext: ParseOrUnparseState,
   kind: String,
@@ -96,7 +97,7 @@ class RuntimeSchemaDefinitionWarning(
     Some(runtimeContext),
     None,
     Nope,
-    Maybe(kind),
+    Maybe(kind + s" (id: ${warnID})"),
     args: _*,
   ) {
 
@@ -106,6 +107,7 @@ class RuntimeSchemaDefinitionWarning(
 }
 
 class SchemaDefinitionWarning(
+  warnID: WarnID,
   schemaContext: Option[SchemaFileLocation],
   annotationContext: Option[SchemaFileLocation],
   kind: String,
@@ -115,15 +117,16 @@ class SchemaDefinitionWarning(
     None,
     annotationContext,
     Nope,
-    Maybe(kind),
+    Maybe(kind + s" (id: ${warnID})"),
     args: _*,
   ) {
 
-  def this(sc: SchemaFileLocation, kind: String, args: Any*) =
-    this(Some(sc), None, kind, args: _*)
+  def this(w: WarnID, sc: SchemaFileLocation, kind: String, args: Any*) =
+    this(w, Some(sc), None, kind, args: _*)
 
   override def isError = false
   def modeName = "Schema Definition"
+
 }
 
 class ValidationError(
@@ -255,6 +258,7 @@ trait ImplementsThrowsOrSavesSDE extends 
ImplementsThrowsSDE with SavesErrorsAnd
   def SDW(warnID: WarnID, fmt: String, args: Any*): Unit = {
     if (tunable.notSuppressedWarning(warnID)) {
       val sdw = new SchemaDefinitionWarning(
+        warnID,
         Some(schemaFileLocation),
         NoAnnotationContext,
         fmt,
diff --git 
a/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/processors/ProcessorStateBases.scala
 
b/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/processors/ProcessorStateBases.scala
index 5d8639541..8bea3bb1c 100644
--- 
a/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/processors/ProcessorStateBases.scala
+++ 
b/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/processors/ProcessorStateBases.scala
@@ -561,17 +561,11 @@ abstract class ParseOrUnparseState protected (
     diagnostics = rsde :: diagnostics
   }
 
-  final def SDW(str: String, args: Any*) = {
-    val ctxt = getContext()
-    val rsdw = new RuntimeSchemaDefinitionWarning(ctxt.schemaFileLocation, 
this, str, args: _*)
-    diagnostics = rsdw :: diagnostics
-  }
-
   final def SDW(warnID: WarnID, str: String, args: Any*) = {
     if (tunable.notSuppressedWarning(warnID)) {
       val ctxt = getContext()
       val rsdw =
-        new RuntimeSchemaDefinitionWarning(ctxt.schemaFileLocation, this, str, 
args: _*)
+        new RuntimeSchemaDefinitionWarning(warnID, ctxt.schemaFileLocation, 
this, str, args: _*)
       diagnostics = rsdw :: diagnostics
     }
   }
diff --git 
a/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/processors/VariableMap1.scala
 
b/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/processors/VariableMap1.scala
index 177a682b9..f00949393 100644
--- 
a/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/processors/VariableMap1.scala
+++ 
b/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/processors/VariableMap1.scala
@@ -21,6 +21,7 @@ import scala.collection.mutable.ArrayBuffer
 import scala.collection.mutable.Map
 
 import org.apache.daffodil.lib.api.ThinDiagnostic
+import org.apache.daffodil.lib.api.WarnID
 import org.apache.daffodil.lib.exceptions.Assert
 import org.apache.daffodil.lib.exceptions.ThrowsSDE
 import org.apache.daffodil.lib.externalvars.Binding
@@ -450,6 +451,7 @@ class VariableMap private (vTable: Map[GlobalQName, 
ArrayBuffer[VariableInstance
            * the way we evaluate escapeSchemes it could lead us to setting the
            * variable read too early */
           pstate.SDW(
+            WarnID.VariableSet,
             "Cannot set variable %s after reading the default value. State 
was: %s. Existing value: %s",
             variable.rd.globalQName,
             VariableSet,
@@ -463,8 +465,8 @@ class VariableMap private (vTable: Map[GlobalQName, 
ArrayBuffer[VariableInstance
           vrd.direction match {
             /**
              * Due to potential race conditions regarding the setting of
-             * variables via setVariable and default values in cominbation with
-             * suspesions during unparsing, we only allow the use of either
+             * variables via setVariable and default values in combination with
+             * suspensions during unparsing, we only allow the use of either
              * setVariable statements or a default value when unparsing a
              * variable.
              */
diff --git 
a/daffodil-runtime1/src/test/scala/org/apache/daffodil/runtime1/dsom/TestSDW.scala
 
b/daffodil-runtime1/src/test/scala/org/apache/daffodil/runtime1/dsom/TestSDW.scala
new file mode 100644
index 000000000..1c0836dbc
--- /dev/null
+++ 
b/daffodil-runtime1/src/test/scala/org/apache/daffodil/runtime1/dsom/TestSDW.scala
@@ -0,0 +1,37 @@
+/*
+ * 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 org.apache.daffodil.runtime1.dsom
+
+import org.apache.daffodil.lib.api.WarnID
+
+import org.junit.Assert._
+import org.junit.Test
+
+class TestSDW {
+
+  @Test def testSDWMessage() = {
+    val sdw = new SchemaDefinitionWarning(
+      WarnID.DeprecatedBuiltInFormats,
+      None,
+      None,
+      "test message",
+    )
+    val expected = "Schema Definition Warning: test message (id: 
deprecatedBuiltInFormats)"
+    assertEquals(expected, sdw.getMessage)
+  }
+}

Reply via email to