You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by "tuxji (via GitHub)" <gi...@apache.org> on 2024/03/18 03:39:27 UTC

Re: [PR] De-personalize Diagnostic File URLs in Compiled Schemas [daffodil]

tuxji commented on code in PR #1065:
URL: https://github.com/apache/daffodil/pull/1065#discussion_r1527749980


##########
daffodil-lib/src/main/scala/org/apache/daffodil/lib/exceptions/SchemaFileLocatable.scala:
##########
@@ -35,24 +32,42 @@ trait HasSchemaFileLocation extends LookupLocation {
 }
 
 object SchemaFileLocation {
-  def apply(context: SchemaFileLocatable, tunables: DaffodilTunables) =
+  def apply(context: SchemaFileLocatable) =
     new SchemaFileLocation(
       context.lineNumber,
       context.columnNumber,
       context.uriString,
+      context.diagnosticFilepath,
       context.toString,
       context.diagnosticDebugName,
-      tunables.maxParentDirectoriesForDiagnostics,
     )
+
+  def apply(
+    lineNumber: Option[String],
+    columnNumber: Option[String],
+    uriString: String,
+    diagnosticFilepath: String,
+    contextToString: String,
+    diagnosticDebugName: String,
+  ) = {
+    new SchemaFileLocation(
+      lineNumber,
+      columnNumber,
+      uriString,
+      diagnosticFilepath,
+      contextToString,
+      diagnosticDebugName,
+    )
+  }

Review Comment:
   I think your comment is already resolved, Steve.  This PR defines a new custom XercesSchemaFileLocatable and passes it to this new apply() constructor.  The places where the apply() constructor is called already looks very similar to your code except for the addition of a second parameter.  The second parameter looks important and shouldn't be omitted.
   
   ```scala
       val xsfl = new XercesSchemaFileLocatable(err, "")
       val newSchemaLocation = SchemaFileLocation(
         xsfl,
         schemaFileLocation,
       )
       new SchemaDefinitionError(
         newSchemaLocation,
         "Error loading schema due to %s",
         errMessage,
       )
   ```



##########
daffodil-japi/src/test/java/org/apache/daffodil/example/TestJavaAPI.java:
##########
@@ -122,7 +122,7 @@ public void testJavaAPI1() throws IOException, ClassNotFoundException {
         DebuggerRunnerForJAPITest debugger = new DebuggerRunnerForJAPITest();
 
         org.apache.daffodil.japi.Compiler c = Daffodil.compiler();
-        java.io.File schemaFile = getResource("/test/japi/mySchema1.dfdl.xsd");
+        java.io.File schemaFile = new File("daffodil-japi/src/test/resources/test/japi/mySchema1.dfdl.xsd");

Review Comment:
   What is the reason for replacing getResource (was it a function we defined ourselves?  I thought Java's getResource returned an URI or null, not a File) with new File?



##########
daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/IIBase.scala:
##########
@@ -195,15 +196,32 @@ abstract class IIBase(
   protected final lazy val resolvedSchemaLocation: Option[DaffodilSchemaSource] =
     LV('resolvedSchemaLocation) {
       val res = schemaLocationProperty.flatMap { slText =>
-        val enclosingSchemaURI = schemaFile.map { _.schemaSource.uriForLoading }
-        val optURI = XMLUtils.resolveSchemaLocation(slText, enclosingSchemaURI)
-        val optSource = optURI.map { case (uri, relToAbs) =>
+        val enclosingSchemaURIAndDFP = schemaFile.map { sf =>
+          (sf.schemaSource.diagnosticFilepath, sf.schemaSource.uriForLoading)
+        }
+        val enclosingSchemaURISchemaSource = enclosingSchemaURIAndDFP
+          .map { case (dfp, uri) =>
+            URISchemaSource(dfp, uri)
+          }
+        val optURISchemaSource =
+          XMLUtils.resolveSchemaLocation(slText, enclosingSchemaURISchemaSource)
+        val optSource = optURISchemaSource.map { case (uriSchemaSource, relToAbs) =>
           schemaDefinitionWarningWhen(
             WarnID.DeprecatedRelativeSchemaLocation,
             relToAbs,
             s"Resolving relative schemaLocations absolutely is deprecated. Did you mean /$slText",
           )
-          URISchemaSource(uri)
+          // if isBootStrapSD is true, we assume we are using the fakeXMLSchemaDocument, which means
+          // we will be passing in and receiving back an absolute diagnosticFilepath from resolveSchemaLocation.
+          // In just this case, we want to ignore that absolute filepath and use the diagnosticFilepath
+          // from main, which is the XMLSchemaDocument diagnosticFilepath
+          val finalUriSchemaSource = if (xsdArg.isBootStrapSD) {

Review Comment:
   What do the letters "SD" stand for in "isBootStrapSD"?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@daffodil.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org