You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by ar...@apache.org on 2022/08/05 17:38:23 UTC

[daffodil-vscode] 19/28: Small updates to TDML/JAXB interface

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

arosien pushed a commit to branch daffodil-vscode-tdml
in repository https://gitbox.apache.org/repos/asf/daffodil-vscode.git

commit a05706f29028955385a210e349adafd082b62280
Author: Michael Hoke <mi...@nteligen.com>
AuthorDate: Fri Jul 22 16:48:09 2022 -0400

    Small updates to TDML/JAXB interface
---
 .../org.apache.daffodil.debugger.dap/Parse.scala   | 10 +++---
 .../main/scala/org.apache.daffodil.tdml/TDML.scala | 40 ++++++++++++++++++----
 2 files changed, 39 insertions(+), 11 deletions(-)

diff --git a/server/core/src/main/scala/org.apache.daffodil.debugger.dap/Parse.scala b/server/core/src/main/scala/org.apache.daffodil.debugger.dap/Parse.scala
index 97903e1..b55def1 100644
--- a/server/core/src/main/scala/org.apache.daffodil.debugger.dap/Parse.scala
+++ b/server/core/src/main/scala/org.apache.daffodil.debugger.dap/Parse.scala
@@ -47,7 +47,7 @@ import org.typelevel.log4cats.Logger
 import org.typelevel.log4cats.slf4j.Slf4jLogger
 import scala.util.Try
 // import org.apache.commons.io.output.NullOutputStream
-// import org.apache.daffodil.tdml.TDML
+import org.apache.daffodil.tdml.TDML
 
 trait Parse {
 
@@ -355,12 +355,12 @@ object Parse {
               dapEvents.offer(None) // ensure dapEvents is terminated when the parse is terminated
             ) ++ Stream.eval(
               args.tdmlConfig match {
-                case Debugee.LaunchArgs.TDMLConfig.Config(action, _, _, _) =>
+                case Debugee.LaunchArgs.TDMLConfig.Config(action, name, description, tdmlPath) =>
                   if (action == "generate")
                     args.infosetOutput match {
-                      case Debugee.LaunchArgs.InfosetOutput.File(_) =>
-                        Logger[IO].debug("Makes it into the generate")
-                        // TDML.generate(path.toString(), args.dataPath.toString(), args.schemaPath.toString(), name, description, tdmlPath)
+                      case Debugee.LaunchArgs.InfosetOutput.File(path) =>
+                        // Logger[IO].debug("Getting ready to generate")
+                        IO(TDML.generate(path.toString(), args.dataPath.toString(), args.schemaPath.toString(), name, description, tdmlPath))
                       case _ =>
                         Logger[IO].debug("Non-file InfosetOutput")
                         // IO(new PrintStream(NullOutputStream.NULL_OUTPUT_STREAM))
diff --git a/server/core/src/main/scala/org.apache.daffodil.tdml/TDML.scala b/server/core/src/main/scala/org.apache.daffodil.tdml/TDML.scala
index c36ff88..c311527 100644
--- a/server/core/src/main/scala/org.apache.daffodil.tdml/TDML.scala
+++ b/server/core/src/main/scala/org.apache.daffodil.tdml/TDML.scala
@@ -4,9 +4,14 @@ import javax.xml.bind.JAXBContext
 import java.io.FileOutputStream
 import cats.effect.IO
 import java.io.File
+import javax.xml.bind.Marshaller
+
+// import org.typelevel.log4cats.Logger
+// import org.typelevel.log4cats.slf4j.Slf4jLogger
 
 // TODO: Put TDML path in class definition?
 object TDML {
+  // implicit val logger: Logger[IO] = Slf4jLogger.getLogger
   // Create a ParserTestCaseType object that can be put into a TestSuite
   // These types are generated when JAXB is executed on the TDML schema
   // 
@@ -28,7 +33,7 @@ object TDML {
   // tdmlDescription: Description for the DFDL operation
   // 
   // Returns the ParserTestCase object created with the applied paths
-  def createTestCase(infosetPath: String, dataPath: String, schemaPath: String, tdmlName: String, tdmlDescription: String) = {
+  def createTestCase(infosetPath: String, dataPath: String, schemaPath: String, tdmlName: String, tdmlDescription: String): ParserTestCaseType = {
     val factory = new ObjectFactory()
 
     val dfdlInfoset = factory.createDfdlInfosetType()
@@ -40,7 +45,8 @@ object TDML {
 
     val docPart = factory.createDocumentPartType()
     docPart.setType(DocumentPartTypeEnum.FILE)
-    docPart.setValue(dataPath.toString())
+    // The following line causes the output of the marshalling to be empty
+    docPart.setValue(dataPath)
 
     val doc = factory.createDocumentType()
     doc.getContent().add(docPart)
@@ -53,6 +59,8 @@ object TDML {
     testCase.setRoundTrip(RoundTripType.ONE_PASS)
     testCase.getTutorialOrDocumentOrInfoset().add(doc)
     testCase.getTutorialOrDocumentOrInfoset().add(infoset)
+
+    return testCase
   }
 
   // Generate a new TDML file.
@@ -68,7 +76,8 @@ object TDML {
   // 
   // There is a suiteName attribute in the root element of the document. This is set to $tdmlName
   // TODO: I think the return type here should just be Unit
-  def generate(infosetPath: String, dataPath: String, schemaPath: String, tdmlName: String, tdmlDescription: String, tdmlPath: String): IO[Unit] = {
+  def generate(infosetPath: String, dataPath: String, schemaPath: String, tdmlName: String, tdmlDescription: String, tdmlPath: String): Unit = {
+    // Logger[IO].debug("Generating")
     val factory = new ObjectFactory()
 
     val testSuite = factory.createTestSuite()
@@ -76,7 +85,15 @@ object TDML {
     testSuite.setDefaultRoundTrip(RoundTripType.ONE_PASS)
     testSuite.getTutorialOrParserTestCaseOrDefineSchema().add(createTestCase(infosetPath, dataPath, schemaPath, tdmlName, tdmlDescription))
 
-    IO(JAXBContext.newInstance(classOf[TestSuite]).createMarshaller().marshal(testSuite, new FileOutputStream(tdmlPath)))
+    // Logger[IO].debug("Getting ready to send XML to file")
+    // val marshaller = JAXBContext.newInstance(classOf[TestSuite]).createMarshaller()
+    // marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true)
+    // marshaller.marshal(testSuite, new FileOutputStream(tdmlPath))
+    // JAXBContext.newInstance(classOf[TestSuite]).createMarshaller().marshal(testSuite, fos)
+    // val fos = new FileOutputStream(tdmlPath)
+    val marshaller = JAXBContext.newInstance(classOf[TestSuite]).createMarshaller()
+    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true)
+    marshaller.marshal(testSuite, new java.io.File(tdmlPath))
   }
 
   // Append a new test case to an existing TDML file.
@@ -115,7 +132,18 @@ object TDML {
       // var foundInfoset = ""
 
       // TODO: Do I really have to cast to instances every time? I've already checked that they are...
-      if (tc.isInstanceOf[ParserTestCaseType]) {
+      tc match {
+        case ptc: ParserTestCaseType =>
+          if (ptc.getName() == tdmlName && ptc.getDescription() == tdmlDescription) {
+            ptc.getTutorialOrDocumentOrInfoset().forEach { dis =>
+              dis match {
+                case doc: DocumentType =>
+                  return (ptc.getModel(), doc.getContent().indexOf(0).asInstanceOf[DocumentPartType].getValue())
+              }
+            }
+          }
+      }
+      /*if (tc.isInstanceOf[ParserTestCaseType]) {
         // Match name and description of potential test case
         if (tc.asInstanceOf[ParserTestCaseType].getName() == tdmlName && tc.asInstanceOf[ParserTestCaseType].getDescription() == tdmlDescription) {
           tc.asInstanceOf[ParserTestCaseType].getTutorialOrDocumentOrInfoset().forEach { dis =>
@@ -134,7 +162,7 @@ object TDML {
             // }
           }
         }
-      }
+      }*/
     }
 
     // If there is no test case in the TDML file meeting the name/description criteria, return empty