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:08 UTC

[daffodil-vscode] 04/28: - Initial stab at adding TDMLConfig to launch args - Build fixes - Remove generated files from tracked files

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 980b7bab3d18ed877c8302b9f140c36134eff554
Author: Michael Hoke <mi...@nteligen.com>
AuthorDate: Tue Jun 28 13:31:26 2022 -0400

    - Initial stab at adding TDMLConfig to launch args
    - Build fixes
    - Remove generated files from tracked files
---
 .gitignore                                         |   1 +
 bindings.xjb                                       |   5 +-
 build.sbt                                          |   4 +-
 package.json                                       |  57 ++++++++++++
 .../org.apache.daffodil.debugger.dap/Parse.scala   | 100 ++++++++++++++++++++-
 src/adapter/activateDaffodilDebug.ts               |  58 +++++++++++-
 src/daffodilDebugger.ts                            |  14 +++
 src/utils.ts                                       |  12 +++
 8 files changed, 240 insertions(+), 11 deletions(-)

diff --git a/.gitignore b/.gitignore
index a62109c..8a489fe 100644
--- a/.gitignore
+++ b/.gitignore
@@ -25,6 +25,7 @@ node_modules
 # sbt
 target
 .bsp
+.bloop
 
 # npm install file
 package-lock.json
diff --git a/bindings.xjb b/bindings.xjb
index 826b0b5..e9f65d1 100644
--- a/bindings.xjb
+++ b/bindings.xjb
@@ -3,6 +3,9 @@
           xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
           xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/"
           xmlns:xs="http://www.w3.org/2001/XMLSchema">
+    <jxb:globalBindings>
+        <jxb:serializable uid="1" />
+    </jxb:globalBindings>
     <jxb:bindings schemaLocation="resources/xsd/DFDL_part3_model.xsd" version="1.0">
         <jxb:bindings node="//xs:attributeGroup[@name='SetVariableAG']/xs:attribute[@name='value']">
             <jxb:property name="ValueAttribute"/>
@@ -52,4 +55,4 @@
             <jxb:typesafeEnumClass name="PropertyNameTypeX"/>
         </jxb:bindings>
     </jxb:bindings>
-</jxb:bindings>
\ No newline at end of file
+</jxb:bindings>
diff --git a/build.sbt b/build.sbt
index 62ba03f..1ca2d57 100644
--- a/build.sbt
+++ b/build.sbt
@@ -71,8 +71,6 @@ lazy val `daffodil-debugger` = project
   .settings(publish / skip := true)
   .dependsOn(core)
   .aggregate(core)
-  .dependsOn(sbtXjcProject)
-  .aggregate(sbtXjcProject)
 
 lazy val core = project
   .in(file("server/core"))
@@ -91,6 +89,8 @@ lazy val core = project
     packageName := s"${name.value}-$daffodilVer"
   )
   .enablePlugins(commonPlugins: _*)
+  .dependsOn(sbtXjcProject)
+  .aggregate(sbtXjcProject)
 
 lazy val sbtXjcProject = project
   .in(file("server/sbtXjc"))
diff --git a/package.json b/package.json
index 8c1afa3..270e30e 100644
--- a/package.json
+++ b/package.json
@@ -86,6 +86,9 @@
     "onCommand:extension.dfdl-debug.getDataName",
     "onCommand:extension.dfdl-debug.runEditorContents",
     "onCommand:extension.dfdl-debug.debugEditorContents",
+    "onCommand:extension.dfdl-debug.generateTDML",
+    "onCommand:extension.dfdl-debug.getTDMLName",
+    "onCommand:extension.dfdl-debug.getTDMLDescription",
     "onCommand:launch.config",
     "onCommand:data.edit",
     "onCommand:omega_edit.version",
@@ -144,6 +147,10 @@
         {
           "command": "extension.dfdl-debug.debugEditorContents",
           "when": "resourceLangId == dfdl"
+        },
+        {
+          "command": "extension.dfdl-debug.generateTDML",
+          "when": "resourceLangId == dfdl"
         }
       ],
       "commandPalette": [
@@ -155,6 +162,10 @@
           "command": "extension.dfdl-debug.runEditorContents",
           "when": "resourceLangId == dfdl"
         },
+        {
+          "command": "extension.dfdl-debug.generateTDML",
+          "when": "resourceLangId == dfdl"
+        },
         {
           "command": "data.edit",
           "enablement": "experimentalFeaturesEnabled"
@@ -189,6 +200,12 @@
         "enablement": "!inDebugMode",
         "icon": "$(play)"
       },
+      {
+        "command": "extension.dfdl-debug.generateTDML",
+        "title": "Generate TDML",
+        "category": "Daffodil Debug",
+        "enablement": "!inDebugMode"
+      },
       {
         "command": "extension.dfdl-debug.toggleFormatting",
         "title": "Toggle between decimal and hex formatting",
@@ -300,6 +317,15 @@
                   "path": "${workspaceFolder}/infoset.xml"
                 }
               },
+              "tdmlConfig": {
+                "type": "object",
+                "description": "Configuration for TDML Actions",
+                "default": {
+                  "action": "none",
+                  "name": "Default Test Case",
+                  "description": "Generated by DFDL VSCode Extension"
+                }
+              },
               "stopOnEntry": {
                 "type": "boolean",
                 "description": "Automatically stop after launch.",
@@ -355,6 +381,11 @@
               "type": "file",
               "path": "${workspaceFolder}/infoset.xml"
             },
+            "tdmlConfig": {
+              "action": "none",
+              "name": "Default Test Case",
+              "description": "Generated by DFDL VSCode Extension"
+            },
             "debugServer": 4711,
             "openHexView": false,
             "openInfosetView": false,
@@ -377,6 +408,11 @@
                 "type": "file",
                 "path": "${workspaceFolder}/infoset.xml"
               },
+              "tdmlConfig": {
+                "action": "none",
+                "name": "Default Test Case",
+                "description": "Generated by DFDL VSCode Extension"
+              },
               "debugServer": 4711,
               "openHexView": false,
               "openInfosetView": false,
@@ -409,6 +445,27 @@
             "description": "Absolute path to the input data file.",
             "default": "${command:AskForDataName}"
           },
+          "tdmlAction": {
+            "type": "string",
+            "description": "TDML Action to take (generate | append | execute | none)",
+            "enum": [
+              "generate",
+              "append",
+              "execute",
+              "none"
+            ],
+            "default": "none"
+          },
+          "tdmlName": {
+            "type": "string",
+            "description": "Name of the TDML Test Case",
+            "default": "${command:AskForTDMLName}"
+          },
+          "tdmlDescription": {
+            "type": "string",
+            "description": "Description of the TDML Test Case",
+            "default": "${command:AskForTDMLDescription}"
+          },
           "infosetOutputType": {
             "type": "string",
             "description": "Destination for final Infoset (file | 'console' | 'none')",
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 e613ca4..b2aebff 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,6 +47,9 @@ 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._
+import javax.xml.bind.JAXBContext
+import org.apache.commons.io.FilenameUtils
 
 trait Parse {
 
@@ -159,7 +162,8 @@ object Parse {
         schemaPath: Path,
         dataPath: Path,
         stopOnEntry: Boolean,
-        infosetOutput: LaunchArgs.InfosetOutput
+        infosetOutput: LaunchArgs.InfosetOutput,
+        tdmlConfig: LaunchArgs.TDMLConfig
     ) extends Arguments {
       def data: IO[InputStream] =
         IO.blocking(FileUtils.readFileToByteArray(dataPath.toFile))
@@ -168,6 +172,7 @@ object Parse {
 
     object LaunchArgs {
       sealed trait InfosetOutput
+      sealed trait TDMLConfig
 
       object InfosetOutput {
         case object None extends InfosetOutput
@@ -175,6 +180,13 @@ object Parse {
         case class File(path: Path) extends InfosetOutput
       }
 
+      object TDMLConfig {
+        case class Generate(name: String, description: String) extends TDMLConfig
+        case class Append(name: String, description: String) extends TDMLConfig
+        case class Execute(name: String, description: String) extends TDMLConfig
+        case object None extends TDMLConfig
+      }
+
       def parse(arguments: JsonObject): EitherNel[String, LaunchArgs] =
         (
           Option(arguments.getAsJsonPrimitive("program"))
@@ -226,6 +238,30 @@ object Parse {
                       Left(s"invalid 'infosetOutput.type': '$invalidType', must be 'none', 'console', or 'file'").toEitherNel
                   }
               }
+          },
+          Option(arguments.getAsJsonObject("tdmlConfig")) match {
+            case None => Right(LaunchArgs.TDMLConfig.None).toEitherNel
+            case Some(tdmlConfig) =>
+              Option(tdmlConfig.getAsJsonPrimitive("action")) match {
+                case None => Right(LaunchArgs.TDMLConfig.None).toEitherNel
+                case Some(action) =>
+                  action.getAsString() match {
+                    case "none" => Right(LaunchArgs.TDMLConfig.None).toEitherNel
+                    case "generate" | "append" | "execute" =>
+                      Option(tdmlConfig.getAsJsonPrimitive("name"))
+                        .map(_.getAsString())
+                        .getOrElse("Default Test Case")
+                        .asRight[String]
+                        .toEitherNel
+                      Option(tdmlConfig.getAsJsonPrimitive("description"))
+                        .map(_.getAsString())
+                        .getOrElse("Generated by DFDL VSCode Extension")
+                        .asRight[String]
+                        .toEitherNel
+                    case invalidType =>
+                      Left(s"invalid 'tdmlConfig.action': '$invalidType', must be 'none', 'generate', 'append', or 'execute'").toEitherNel
+                  }
+              }
           }
         ).parMapN(LaunchArgs.apply)
     }
@@ -326,7 +362,37 @@ object Parse {
                   } { outStream =>
                     IO(outStream.close()).handleErrorWith(_ => IO.unit)
                   } */
-                  IO(new FileOutputStream(path.toFile()))
+                  val factory = new ObjectFactory()
+
+                  val dfdlInfoset = factory.createDfdlInfosetType()
+                  dfdlInfoset.setType("file")
+                  dfdlInfoset.getContent().add(path)
+
+                  val infoset = factory.createInfosetType()
+                  infoset.setDfdlInfoset(dfdlInfoset)
+
+                  val docPart = factory.createDocumentPartType()
+                  docPart.setType(DocumentPartTypeEnum.FILE)
+                  docPart.setValue(args.dataPath.toString())
+
+                  val doc = factory.createDocumentType()
+                  doc.getContent().add(docPart)
+
+                  val testCase = factory.createParserTestCaseType()
+                  testCase.setName(FilenameUtils.getBaseName(args.schemaPath.toString()))
+                  testCase.setRoot("file")
+                  testCase.setModel(args.schemaPath.getFileName().toString())
+                  testCase.setDescription("Generated by DFDL VSCode Extension")
+                  testCase.setRoundTrip(RoundTripType.ONE_PASS)
+                  testCase.getTutorialOrDocumentOrInfoset().add(doc)
+
+                  val testSuite = factory.createTestSuite()
+                  testSuite.setSuiteName(FilenameUtils.getBaseName(args.schemaPath.toString()))
+                  testSuite.setDefaultRoundTrip(RoundTripType.ONE_PASS)
+                  testSuite.getTutorialOrParserTestCaseOrDefineSchema().add(testCase)
+                  
+                  IO(JAXBContext.newInstance(classOf[TestSuite]).createMarshaller().marshal(testSuite, new FileOutputStream(path.toFile())))
+                  
                   // path.toString()
                 case _ =>
                   /* Resource.make {
@@ -603,7 +669,7 @@ object Parse {
   case class ConfigEvent(launchArgs: ConfigEvent.LaunchArgs, buildInfo: ConfigEvent.BuildInfo)
       extends Events.DebugEvent("daffodil.config")
   object ConfigEvent {
-    case class LaunchArgs(schemaPath: String, dataPath: String, stopOnEntry: Boolean, infosetOutput: InfosetOutput)
+    case class LaunchArgs(schemaPath: String, dataPath: String, stopOnEntry: Boolean, infosetOutput: InfosetOutput, tdmlConfig: TDMLConfig)
 
     sealed trait InfosetOutput {
       val `type`: String =
@@ -613,6 +679,17 @@ object Parse {
           case InfosetOutput.File(_) => "file"
         }
     }
+    sealed trait TDMLConfig {
+      val `action`: String = 
+        this match {
+          case TDMLConfig.None => "none"
+          case TDMLConfig.Generate(_, _) => "generate"
+          case TDMLConfig.Append(_, _) => "append"
+          case TDMLConfig.Execute(_, _) => "execute"
+        }
+      val `name`: String = "Default Test Case Name"
+      val `description`: String = "Generated by DFDL VSCode Extension"
+    }
     object InfosetOutput {
       case object None extends InfosetOutput
       case object Console extends InfosetOutput
@@ -625,6 +702,20 @@ object Parse {
           case Debugee.LaunchArgs.InfosetOutput.File(path) => File(path.toString)
         }
     }
+    object TDMLConfig {
+      case class Generate(name: String, description: String) extends TDMLConfig
+      case class Append(name: String, description: String) extends TDMLConfig
+      case class Execute(name: String, description: String) extends TDMLConfig
+      case object None extends TDMLConfig
+
+      def apply(that: Debugee.LaunchArgs.TDMLConfig): TDMLConfig =
+        that match {
+          case Debugee.LaunchArgs.TDMLConfig.None => None
+          case Debugee.LaunchArgs.TDMLConfig.Generate(name, description) => Generate(name, description)
+          case Debugee.LaunchArgs.TDMLConfig.Append(name, description) => Append(name, description)
+          case Debugee.LaunchArgs.TDMLConfig.Execute(name, description) => Execute(name, description)
+        }
+    }
 
     case class BuildInfo(version: String, daffodilVersion: String, scalaVersion: String)
 
@@ -634,7 +725,8 @@ object Parse {
           launchArgs.schemaPath.toString,
           launchArgs.dataPath.toString(),
           launchArgs.stopOnEntry,
-          InfosetOutput(launchArgs.infosetOutput)
+          InfosetOutput(launchArgs.infosetOutput),
+          TDMLConfig(launchArgs.tdmlConfig)
         ),
         BuildInfo(
           DAPBuildInfo.version,
diff --git a/src/adapter/activateDaffodilDebug.ts b/src/adapter/activateDaffodilDebug.ts
index e2f714a..f3efa7f 100644
--- a/src/adapter/activateDaffodilDebug.ts
+++ b/src/adapter/activateDaffodilDebug.ts
@@ -25,7 +25,11 @@ import * as omegaEditClient from '../omega_edit/client'
 import * as dfdlLang from '../language/dfdl'
 
 // Function for setting up the commands for Run and Debug file
-function createDebugRunFileConfigs(resource: vscode.Uri, runOrDebug: String) {
+function createDebugRunFileConfigs(
+  resource: vscode.Uri,
+  runOrDebug: String,
+  tdmlConfig: TDMLConfig | undefined
+) {
   let targetResource = resource
   let noDebug = runOrDebug === 'run' ? true : false
 
@@ -47,7 +51,8 @@ function createDebugRunFileConfigs(resource: vscode.Uri, runOrDebug: String) {
         targetResource.fsPath,
         false,
         false,
-        { type: 'file', path: '${workspaceFolder}/' + infosetFile }
+        { type: 'file', path: '${workspaceFolder}/' + infosetFile },
+        tdmlConfig
       ),
       { noDebug: noDebug }
     )
@@ -76,13 +81,19 @@ export function activateDaffodilDebug(
     vscode.commands.registerCommand(
       'extension.dfdl-debug.runEditorContents',
       (resource: vscode.Uri) => {
-        createDebugRunFileConfigs(resource, 'run')
+        createDebugRunFileConfigs(resource, 'run', undefined)
       }
     ),
     vscode.commands.registerCommand(
       'extension.dfdl-debug.debugEditorContents',
       (resource: vscode.Uri) => {
-        createDebugRunFileConfigs(resource, 'debug')
+        createDebugRunFileConfigs(resource, 'debug', undefined)
+      }
+    ),
+    vscode.commands.registerCommand(
+      'extension.dfdl-debug.generateTDML',
+      (resource: vscode.Uri) => {
+        null // TODO
       }
     ),
     vscode.commands.registerCommand(
@@ -166,6 +177,38 @@ export function activateDaffodilDebug(
     )
   )
 
+  context.subscriptions.push(
+    vscode.commands.registerCommand(
+      'extension.dfdl-debug.getTMDLName',
+      async (_) => {
+        return await vscode.window
+          .showInputBox({
+            prompt: 'Test Case Name: ',
+            placeHolder: 'Default Test Case',
+          })
+          .then((value) => {
+            return value
+          })
+      }
+    )
+  )
+
+  context.subscriptions.push(
+    vscode.commands.registerCommand(
+      'extension.dfdl-debug.getTMDLDescription',
+      async (_) => {
+        return await vscode.window
+          .showInputBox({
+            prompt: 'Test Case Description: ',
+            placeHolder: 'Generated by DFDL VSCode Extension',
+          })
+          .then((value) => {
+            return value
+          })
+      }
+    )
+  )
+
   // register a configuration provider for 'dfdl' debug type
   const provider = new DaffodilConfigurationProvider(context)
   context.subscriptions.push(
@@ -394,3 +437,10 @@ class InlineDebugAdapterFactory
     )
   }
 }
+
+export interface TDMLConfig {
+  generate: boolean
+  append: boolean
+  name: string
+  description: string
+}
diff --git a/src/daffodilDebugger.ts b/src/daffodilDebugger.ts
index c14add3..f0482d3 100644
--- a/src/daffodilDebugger.ts
+++ b/src/daffodilDebugger.ts
@@ -185,6 +185,20 @@ export async function getDebugger(
         return stopDebugging()
       }
 
+      if (config.tdmlConfig.action !== 'none') {
+        if (config.tdmlName === '') {
+          config.tdmlName = await vscode.commands.executeCommand(
+            'extension.dfdl-debug.getTDMLName'
+          )
+        }
+
+        if (config.tdmlDescription === '') {
+          config.tdmlDescription = await vscode.commands.executeCommand(
+            'extension.dfdl-debug.getTDMLDescription'
+          )
+        }
+      }
+
       let workspaceFolder = vscode.workspace.workspaceFolders
         ? vscode.workspace.workspaceFolders[0].uri.fsPath
         : vscode.Uri.parse('').fsPath
diff --git a/src/utils.ts b/src/utils.ts
index 2dc333e..8a5891a 100644
--- a/src/utils.ts
+++ b/src/utils.ts
@@ -16,6 +16,7 @@
  */
 
 import * as vscode from 'vscode'
+import { TDMLConfig } from './adapter/activateDaffodilDebug'
 
 const defaultConf = vscode.workspace.getConfiguration()
 let currentConfig: vscode.ProviderResult<vscode.DebugConfiguration>
@@ -80,6 +81,7 @@ export function getConfig(
   data = false,
   debugServer = false,
   infosetOutput: object | null = null,
+  tdmlConfig: TDMLConfig | null = null,
   stopOnEntry = false,
   useExistingServer = false,
   trace = false,
@@ -108,6 +110,16 @@ export function getConfig(
             '${workspaceFolder}/infoset.xml'
           ),
         },
+    tdmlConfig: tdmlConfig
+      ? tdmlConfig
+      : {
+          action: defaultConf.get('tdmlAction', 'none'),
+          name: defaultConf.get('tdmlName', 'Default Test Case'),
+          description: defaultConf.get(
+            'tdmlDescription',
+            'Generated by DFDL VSCode Extension'
+          ),
+        },
     stopOnEntry: stopOnEntry
       ? stopOnEntry
       : defaultConf.get('stopOnEntry', true),