Merge branch 'main' into update/com.microsoft.java.debug.core-0.43.0
diff --git a/.asf.yaml b/.asf.yaml
index eb52000..16ec4da 100644
--- a/.asf.yaml
+++ b/.asf.yaml
@@ -14,7 +14,7 @@
# limitations under the License.
github:
- description: "VS Code extension for Apache Daffodil"
+ description: "Apache Daffodil™ Extension for Visual Studio Code"
homepage: https://daffodil.apache.org/
features:
wiki: true
diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml
index adde5c8..ce5b17f 100644
--- a/.github/workflows/CI.yml
+++ b/.github/workflows/CI.yml
@@ -54,11 +54,11 @@
uses: actions/setup-node@v3.3.0
with:
node-version: '16'
- - name: Setup Java 11
+ - name: Setup Java 8
uses: actions/setup-java@v3.4.1
with:
distribution: temurin
- java-version: 11
+ java-version: 8
- run: $SBT scalafmtCheck
- run: $SBT scalafmtSbtCheck
- run: yarn install
@@ -73,11 +73,11 @@
env:
SBT: sbt -J-Xms1024m -J-Xmx5120m -J-XX:ReservedCodeCacheSize=512m -J-XX:MaxMetaspaceSize=1024m ++2.12.15
steps:
- - name: Setup Java 11
+ - name: Setup Java 8
uses: actions/setup-java@v3.4.1
with:
distribution: temurin
- java-version: 11
+ java-version: 8
- name: Check out Repository
uses: actions/checkout@v3.0.2
with:
@@ -98,11 +98,11 @@
env:
SBT: sbt -J-Xms1024m -J-Xmx5120m -J-XX:ReservedCodeCacheSize=512m -J-XX:MaxMetaspaceSize=1024m ++2.12.15
steps:
- - name: Setup Java 11
+ - name: Setup Java 8
uses: actions/setup-java@v3.4.1
with:
distribution: temurin
- java-version: 11
+ java-version: 8
- uses: actions/checkout@v3.0.2
- name: Install Node.js
uses: actions/setup-node@v3.3.0
diff --git a/.gitignore b/.gitignore
index 0f8424b..d5261d7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -53,4 +53,7 @@
tmp.*
# ignore omega-edit scala server package file
-src/omega_edit/omega-edit-scala-server*
+omega-edit-scala-server*
+
+# ignore tests unzip daffodil-debugger
+daffodil-debugger-*
diff --git a/LICENSE b/LICENSE
index fa7e667..c1f4b8e 100644
--- a/LICENSE
+++ b/LICENSE
@@ -202,12 +202,12 @@
limitations under the License.
-APACHE DAFFODIL VS CODE EXTENSION SUBCOMPONENTS:
+APACHE DAFFODIL™ EXTENSION FOR VISUAL STUDIO CODE SUBCOMPONENTS:
-The Apache Daffodil VS Code Extension project contains subcomponents with
-separate copyright notices and license terms. Your use of the source code for
-these subcomponents is subject to the terms and conditions of the following
-licenses.
+The Apache Daffodil™ Extension for Visual Studio Code project contains
+subcomponents with separate copyright notices and license terms. Your use of
+the source code for these subcomponents is subject to the terms and
+conditions of the following licenses.
- images/arrow.svg
This product bundles the above files from the 'VS Code Mock Debug' extension.
diff --git a/NOTICE b/NOTICE
index 5a8e04f..fbcce24 100644
--- a/NOTICE
+++ b/NOTICE
@@ -1,4 +1,4 @@
-Apache Daffodil VS Code Extension
+Apache Daffodil™ Extension for Visual Studio Code
Copyright 2022 The Apache Software Foundation
This product includes software developed at
diff --git a/README.md b/README.md
index 6e28850..f8ff33c 100644
--- a/README.md
+++ b/README.md
@@ -20,15 +20,16 @@
<img src="https://daffodil.apache.org/assets/themes/apache/img/apache-daffodil-logo.png" height="85" alt="Apache Daffodil"/>
-# Apache Daffodil VS Code Extension
+# Apache Daffodil™ Extension for Visual Studio Code
[](https://github.com/apache/daffodil-vscode/actions/workflows/CI.yml)
</div>
-This is a VS Code extension which enables the interactive debugging of DFDL schema parsing using [Apache Daffodil](https://daffodil.apache.org/).
+This is an extension for Visual Studio Code (VS Code) which enables the interactive debugging of DFDL schema parsing using [Apache Daffodil](https://daffodil.apache.org/).
## Build Requirements
+
- Java Development Kit (JDK) 11 or higher
- SBT 0.13.8 or higher
- Node 10 or higher
@@ -38,13 +39,14 @@
Until the extension is available in the [VS Code Extension Marketplace](https://marketplace.visualstudio.com/vscode), please download the latest `.vsix` file from the [releases page](https://github.com/apache/daffodil-vscode/releases).
-
## Package VSIX and Debugger
+
:exclamation:**NOT necessary if using prebuilt VSIX**:exclamation:
:exclamation:**NOT necessary if running extension via VS Code without VSIX but a `yarn install` will be required**:exclamation:
Run full package
+
```bash
yarn package
```
@@ -95,7 +97,7 @@
## License
-Apache Daffodil VS Code Extension is licensed under the [Apache License, v2.0].
+Apache Daffodil™ Extension for Visual Studio Code is licensed under the [Apache License, v2.0].
[Apache License, v2.0]: https://www.apache.org/licenses/LICENSE-2.0
[GitHub Issues]: https://github.com/apache/daffodil-vscode/issues
diff --git a/build.sbt b/build.sbt
index 0ce6530..c46f1ab 100644
--- a/build.sbt
+++ b/build.sbt
@@ -78,7 +78,10 @@
name := "daffodil-debugger",
libraryDependencies ++= Seq(
"ch.qos.logback" % "logback-classic" % "1.2.11",
- "com.microsoft.java" % "com.microsoft.java.debug.core" % "0.43.0",
+ // NOTE: To support Java 8 this dependency can not go above version 0.34.0.
+ // scala-steward:off
+ "com.microsoft.java" % "com.microsoft.java.debug.core" % "0.34.0",
+ // scala-steward:on
"co.fs2" %% "fs2-io" % "3.2.10",
"com.monovore" %% "decline-effect" % "2.3.0",
"org.typelevel" %% "log4cats-slf4j" % "2.4.0"
diff --git a/build/package/.vscodeignore b/build/package/.vscodeignore
index 64bafdb..b07d292 100644
--- a/build/package/.vscodeignore
+++ b/build/package/.vscodeignore
@@ -28,5 +28,5 @@
!src/styles/styles.css
!src/omega_edit/omega_edit.js
!src/omega_edit/interface.html
-!src/omega_edit/omega-edit-scala-server*.zip
+!node_modules/omega-edit/omega-edit-scala-server*.zip
!src/language/providers/intellisense/DFDLGeneralFormat.dfdl.xsd
diff --git a/build/package/LICENSE b/build/package/LICENSE
index 915ab95..3a040af 100644
--- a/build/package/LICENSE
+++ b/build/package/LICENSE
@@ -202,12 +202,12 @@
limitations under the License.
-APACHE DAFFODIL VS CODE EXTENSION SUBCOMPONENTS:
+APACHE DAFFODIL™ EXTENSION FOR VISUAL STUDIO CODE EXTENSION SUBCOMPONENTS:
-The Apache Daffodil VS Code Extension project contains subcomponents with
-separate copyright notices and license terms. Your use of the source code for
-these subcomponents is subject to the terms and conditions of the following
-licenses.
+The Apache Daffodil™ Extension for Visual Studio Code project contains
+subcomponents with separate copyright notices and license terms. Your use of
+the source code for these subcomponents is subject to the terms and
+conditions of the following licenses.
- 'await-notify' in extension/dist/ext/extension.js
This product bundles 'Node Await Notify' from the above files.
diff --git a/build/package/NOLICENSE b/build/package/NOLICENSE
index c1a3e70..b46b9ee 100644
--- a/build/package/NOLICENSE
+++ b/build/package/NOLICENSE
@@ -1,4 +1,4 @@
-Apache Daffodil VS Code Extension
+Apache Daffodil™ Extension for Visual Studio Code
Copyright 2022 The Apache Software Foundation
This product includes software developed at
diff --git a/build/package/NONOTICE b/build/package/NONOTICE
index a7b3f5e..654cfb9 100644
--- a/build/package/NONOTICE
+++ b/build/package/NONOTICE
@@ -1,4 +1,4 @@
-Apache Daffodil VS Code Extension
+Apache Daffodil™ Extension for Visual Studio Code
Copyright 2022 The Apache Software Foundation
This product includes software developed at
diff --git a/build/package/NOTICE b/build/package/NOTICE
index 5838700..eca101e 100644
--- a/build/package/NOTICE
+++ b/build/package/NOTICE
@@ -1,4 +1,4 @@
-Apache Daffodil VS Code Extension
+Apache Daffodil™ Extension for Visual Studio Code
Copyright 2022 The Apache Software Foundation
This product includes software developed at
diff --git a/build/scripts/omega_edit_download.ts b/build/scripts/omega_edit_download.ts
deleted file mode 100644
index faa25f9..0000000
--- a/build/scripts/omega_edit_download.ts
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * 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.
- */
-
-// @ts-nocheck <-- This is needed as this file is basically a JavaScript script
-// but with some TypeScript niceness baked in
-const fs = require('fs')
-const os = require('os')
-const path = require('path')
-const HttpClient = require('typed-rest-client/HttpClient').HttpClient
-const crypto = require('crypto')
-const hashSum = crypto.createHash('sha512')
-
-/**
- * The below classes (Backend, Artifact) are defined similarly in src/classes/artifact.ts.
- * However for this script to work properly they needed to be redefined in a more JS style.
- */
-
-class Backend {
- constructor(owner, repo) {
- this.owner = owner
- this.repo = repo
- }
-}
-
-class Artifact {
- constructor(omegaEditVersion) {
- this.omegaEditVersion = omegaEditVersion
- this.name = `omega-edit-scala-server-${this.omegaEditVersion}`
- this.archive = `${this.name}.zip`
- this.archiveUrl = (backend) =>
- `https://github.com/${backend.owner}/${backend.repo}/releases/download/v${this.omegaEditVersion}/${this.archive}`
- this.scriptName = os.platform().toLowerCase().startsWith('win32')
- ? 'omega-edit-grpc-server.bat'
- : './omega-edit-grpc-server'
- }
-}
-
-// Method to get omega-edit version from a JSON file
-function getOmegaEditPackageVersion(filePath) {
- return JSON.parse(fs.readFileSync(filePath).toString())['dependencies'][
- 'omega-edit'
- ]
-}
-
-// Method to get omegaEditServerHash from a JSON file
-function getOmegaEditServerHash(filePath) {
- return JSON.parse(fs.readFileSync(filePath).toString())['omegaEditServerHash']
-}
-
-async function downloadServer() {
- // Get omegaEditVersion
- const omegaEditVersion = getOmegaEditPackageVersion('./package.json')
- const artifact = new Artifact(omegaEditVersion)
- const backend = new Backend('ctc-oss', 'omega-edit')
-
- let filePath = path.join('src/omega_edit', artifact.archive).toString()
-
- // Download and setup omega-edit server files
- if (!fs.existsSync(filePath)) {
- // Get omega-edit server of version entered using http client
- const client = new HttpClient('client')
- const artifactUrl = artifact.archiveUrl(backend)
- const response = await client.get(artifactUrl)
-
- if (response.message.statusCode !== 200) {
- const err = new Error(
- `Couldn't download the Ωedit sever backend from ${artifactUrl}.`
- )
- err['httpStatusCode'] = response.message.statusCode
- throw err
- }
-
- // Create zip from rest call
- const file = fs.createWriteStream(filePath)
-
- await new Promise((resolve, reject) => {
- file.on(
- 'error',
- (err) =>
- function () {
- throw err
- }
- )
- const stream = response.message.pipe(file)
-
- stream.on('close', () => {
- try {
- resolve(filePath)
- } catch (err) {
- reject(err)
- }
- })
- })
-
- hashSum.update(fs.readFileSync(filePath))
- if (
- hashSum.digest('hex').toString() !==
- getOmegaEditServerHash('./package.json')
- ) {
- fs.unlinkSync(filePath)
- throw new Error("[ERROR] omega-edit Scala server hashes didn't match")
- }
- }
-}
-
-module.exports = {
- downloadServer: downloadServer,
-}
diff --git a/build/scripts/package.ts b/build/scripts/package.ts
index ab4df08..4f90d98 100644
--- a/build/scripts/package.ts
+++ b/build/scripts/package.ts
@@ -42,7 +42,7 @@
// Setup package directory
function setup() {
if (fs.existsSync(pkg_dir)) {
- fs.rmdirSync(pkg_dir, { recursive: true })
+ fs.rmSync(pkg_dir, { recursive: true })
}
fs.mkdirSync(pkg_dir)
diff --git a/package.json b/package.json
index 0081bbf..9207c44 100644
--- a/package.json
+++ b/package.json
@@ -1,10 +1,9 @@
{
"name": "apache-daffodil-vscode",
- "displayName": "Apache Daffodil VS Code Extension",
- "description": "VS Code extension for Apache Daffodil DFDL schema debugging",
- "version": "1.2.0",
+ "displayName": "Apache Daffodil™ Extension for Visual Studio Code",
+ "description": "Apache Daffodil™ Extension for Visual Studio Code providing DFDL syntax highlighting, DFDL code completion, DFDL schema debugging, and data editor",
+ "version": "1.3.0-SNAPSHOT",
"daffodilVersion": "3.4.0",
- "omegaEditServerHash": "1c11c5711b6cd477023be71d04b070e1289312aaaef5f81fb9ded4e3884b7135ca13e2b2cf7b547e374142167c19789555eeb5d83dbed38ff6dde71c25db5fb7",
"publisher": "asf",
"author": "Apache Daffodil",
"license": "Apache-2.0",
@@ -24,18 +23,18 @@
"url": "https://github.com/apache/daffodil-vscode/issues"
},
"scripts": {
- "omega-edit-download": "node -e \"require('./build/scripts/omega_edit_download.ts').downloadServer()\"",
- "precompile": "node -p \"'export const LIB_VERSION = ' + JSON.stringify(require('./package.json').version) + ';'\" > src/version.ts",
- "compile": "tsc -p ./ && yarn omega-edit-download",
- "lint": "yarn run prettier src -c",
- "watch": "yarn omega-edit-download && webpack --watch --devtool nosources-source-map --config ./build/extension.webpack.config.js",
- "watch2": "tsc -watch -p ./",
+ "gen-version-ts": "node -p \"'export const LIB_VERSION = ' + JSON.stringify(require('./package.json').version) + ';'\" > src/version.ts",
+ "precompile": "yarn gen-version-ts",
+ "compile": "tsc -p ./ && yarn sbt",
+ "lint": "yarn prettier src -c",
+ "prewatch": "yarn gen-version-ts && yarn sbt",
+ "watch": "webpack --watch --devtool nosources-source-map --config ./build/extension.webpack.config.js",
"webpack": "webpack --mode production --config ./build/extension.webpack.config.js",
- "prepackage": "yarn sbt && yarn install && yarn compile && yarn webpack",
+ "prepackage": "yarn install && yarn compile && yarn webpack",
"package": "yarn package-setup && yarn package-create",
"package-setup": "node -e \"require('./build/scripts/package.ts').setup()\"",
"package-create": "node -e \"require('./build/scripts/package.ts').create()\"",
- "pretest": "yarn run compile && yarn run webpack",
+ "pretest": "yarn compile && yarn webpack",
"test": "node ./out/tests/runTest.js",
"sbt": "sbt universal:packageBin"
},
@@ -45,7 +44,7 @@
"child_process": "1.0.2",
"google-protobuf": "3.20.1",
"hexy": "0.3.4",
- "omega-edit": "0.9.24",
+ "omega-edit": "0.9.32",
"unzip-stream": "0.3.1",
"uuid": "^8.3.2",
"vscode-debugadapter": "1.51.0",
@@ -302,6 +301,11 @@
"description": "Absolute path to the input data file.",
"default": "${command:AskForDataName}"
},
+ "infosetFormat": {
+ "type": "string",
+ "description": "Infoset format type (xml/json)",
+ "default": "xml"
+ },
"infosetOutput": {
"type": "object",
"description": "Destination for final Infoset (file-path | 'console' | 'none')",
@@ -361,6 +365,7 @@
"program": "${command:AskForProgramName}",
"stopOnEntry": true,
"data": "${command:AskForDataName}",
+ "infosetFormat": "xml",
"infosetOutput": {
"type": "file",
"path": "${workspaceFolder}/infoset.xml"
@@ -383,6 +388,7 @@
"program": "^\"\\${command:AskForProgramName}\"",
"stopOnEntry": true,
"data": "^\"\\${command:AskForDataName}\"",
+ "infosetFormat": "xml",
"infosetOutput": {
"type": "file",
"path": "${workspaceFolder}/infoset.xml"
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 ad212c3..9ef9b0a 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
@@ -41,6 +41,7 @@
import org.apache.daffodil.processors.parsers._
import org.apache.daffodil.processors._
import org.apache.daffodil.sapi.infoset.XMLTextInfosetOutputter
+import org.apache.daffodil.sapi.infoset.JsonInfosetOutputter
import org.apache.daffodil.sapi.io.InputSourceDataInputStream
import org.apache.daffodil.util.Misc
import org.typelevel.log4cats.Logger
@@ -63,7 +64,8 @@
def apply(
schema: Path,
data: InputStream,
- debugger: Debugger
+ debugger: Debugger,
+ infosetFormat: String
): IO[Parse] =
for {
dp <- Compiler().compile(schema).map(p => p.withDebugger(debugger).withDebugging(true))
@@ -76,11 +78,16 @@
val stopper =
pleaseStop.get *> IO.canceled // will cancel the concurrent parse effect
+ val infosetOutputter = infosetFormat match {
+ case "xml" => new XMLTextInfosetOutputter(os, true)
+ case "json" => new JsonInfosetOutputter(os, true)
+ }
+
val parse =
IO.interruptibleMany {
dp.parse(
new InputSourceDataInputStream(data),
- new XMLTextInfosetOutputter(os, true)
+ infosetOutputter
) // WARNING: parse doesn't close the OutputStream, so closed below
}.guaranteeCase(outcome => Logger[IO].debug(s"parse finished: $outcome"))
.void
@@ -160,6 +167,7 @@
schemaPath: Path,
dataPath: Path,
stopOnEntry: Boolean,
+ infosetFormat: String,
infosetOutput: LaunchArgs.InfosetOutput
) extends Arguments {
def data: IO[InputStream] =
@@ -201,6 +209,11 @@
.getOrElse(true)
.asRight[String]
.toEitherNel,
+ Option(arguments.getAsJsonPrimitive("infosetFormat"))
+ .map(_.getAsString())
+ .getOrElse("xml")
+ .asRight[String]
+ .toEitherNel,
Option(arguments.getAsJsonObject("infosetOutput")) match {
case None => Right(LaunchArgs.InfosetOutput.Console).toEitherNel
case Some(infosetOutput) =>
@@ -257,13 +270,25 @@
infosetChanges = Stream
.fromQueueNoneTerminated(infoset)
.evalTap(latestInfoset.set)
- .evalTap(content => dapEvents.offer(Some(InfosetEvent(content, "text/xml"))))
+ .evalTap(content =>
+ dapEvents.offer(
+ Some(
+ InfosetEvent(
+ content,
+ args.infosetFormat match {
+ case "xml" => "text/xml"
+ case "json" => "application/json"
+ }
+ )
+ )
+ )
+ )
.onFinalizeCase(ec => Logger[IO].debug(s"infosetChanges (orig): $ec"))
events <- Resource.eval(Queue.bounded[IO, Option[Event]](10))
debugger <- DaffodilDebugger
- .resource(state, events, breakpoints, control, infoset)
- parse <- Resource.eval(args.data.flatMap(in => Parse(args.schemaPath, in, debugger)))
+ .resource(state, events, breakpoints, control, infoset, args.infosetFormat)
+ parse <- Resource.eval(args.data.flatMap(in => Parse(args.schemaPath, in, debugger, args.infosetFormat)))
parsing = args.infosetOutput match {
case Debugee.LaunchArgs.InfosetOutput.None =>
@@ -386,8 +411,7 @@
startElement.schemaLocation.lineNumber
.map(_.toInt)
.getOrElse(1), // line numbers start at 1 according to InitializeRequest
- 0, // column numbers start at 1 according to InitializeRequest, but set to 0 to ignore it; column calculation by Daffodil uses 1 tab = 2 spaces(?), but breakpoints use 1 character per tab
- null
+ 0 // column numbers start at 1 according to InitializeRequest, but set to 0 to ignore it; column calculation by Daffodil uses 1 tab = 2 spaces(?), but breakpoints use 1 character per tab
)
schemaScope <- schemaScope(schemaScopeId, startElement.state, variableRefs)
@@ -594,7 +618,13 @@
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,
+ infosetFormat: String,
+ infosetOutput: InfosetOutput
+ )
sealed trait InfosetOutput {
val `type`: String =
@@ -625,6 +655,7 @@
launchArgs.schemaPath.toString,
launchArgs.dataPath.toString(),
launchArgs.stopOnEntry,
+ launchArgs.infosetFormat,
InfosetOutput(launchArgs.infosetOutput)
),
BuildInfo(
@@ -731,7 +762,8 @@
breakpoints: Breakpoints,
control: Control,
events: QueueSink[IO, Option[Event]],
- infoset: QueueSink[IO, Option[String]]
+ infoset: QueueSink[IO, Option[String]],
+ infosetFormat: String
) extends Debugger {
implicit val logger: Logger[IO] = Slf4jLogger.getLogger
@@ -776,10 +808,14 @@
def infosetToString(ie: InfosetElement): String = {
val bos = new java.io.ByteArrayOutputStream()
- val xml = new XMLTextInfosetOutputter(bos, true)
+ val infosetOutputter = infosetFormat match {
+ case "xml" => new XMLTextInfosetOutputter(bos, true)
+ case "json" => new JsonInfosetOutputter(bos, true)
+ }
+
val iw = InfosetWalker(
ie.asInstanceOf[DIElement],
- xml,
+ infosetOutputter,
walkHidden = false,
ignoreBlocks = true,
releaseUnneededInfoset = false
@@ -818,7 +854,8 @@
events: QueueSink[IO, Option[Event]],
breakpoints: Breakpoints,
control: Control,
- infoset: QueueSink[IO, Option[String]]
+ infoset: QueueSink[IO, Option[String]],
+ infosetFormat: String
): Resource[IO, DaffodilDebugger] =
for {
dispatcher <- Dispatcher[IO]
@@ -828,7 +865,8 @@
breakpoints,
control,
events,
- infoset
+ infoset,
+ infosetFormat
)
}
}
diff --git a/src/adapter/activateDaffodilDebug.ts b/src/adapter/activateDaffodilDebug.ts
index 3f7e03f..75c8122 100644
--- a/src/adapter/activateDaffodilDebug.ts
+++ b/src/adapter/activateDaffodilDebug.ts
@@ -95,6 +95,7 @@
targetResource.fsPath,
false,
false,
+ 'xml',
{ type: 'file', path: '${workspaceFolder}/' + infosetFile }
),
{ noDebug: noDebug }
@@ -215,6 +216,7 @@
'${file}',
false,
false,
+ 'xml',
{ type: 'file', path: '${file}-infoset.xml' }
),
]
@@ -235,6 +237,7 @@
'${file}',
false,
false,
+ 'xml',
{ type: 'file', path: '${workspaceFolder}/' + infosetFile }
),
]
diff --git a/src/classes/artifact.ts b/src/classes/artifact.ts
index 13142c2..d802dfb 100644
--- a/src/classes/artifact.ts
+++ b/src/classes/artifact.ts
@@ -16,7 +16,7 @@
*/
import { LIB_VERSION } from '../version'
-import * as os from 'os'
+import { osCheck } from '../utils'
export class Backend {
constructor(readonly owner: string, readonly repo: string) {}
@@ -36,10 +36,7 @@
? `${type}-${this.version}-${LIB_VERSION}`
: `${type}-${this.version}`
this.archive = `${this.name}.zip`
- this.scriptName =
- os.platform() === 'win32'
- ? `${baseScriptName}.bat`
- : `./${baseScriptName}`
+ this.scriptName = osCheck(`${baseScriptName}.bat`, `./${baseScriptName}`)
}
archiveUrl = (backend: Backend) => {
diff --git a/src/daffodil.ts b/src/daffodil.ts
index 4587339..36b86d1 100644
--- a/src/daffodil.ts
+++ b/src/daffodil.ts
@@ -40,6 +40,7 @@
schemaPath: string
dataPath: string
stopOnEntry: boolean
+ infosetFormat: string
infosetOutput: InfosetOutput
}
diff --git a/src/daffodilDebugger.ts b/src/daffodilDebugger.ts
index a60bfb3..a6426d7 100644
--- a/src/daffodilDebugger.ts
+++ b/src/daffodilDebugger.ts
@@ -17,15 +17,17 @@
import * as vscode from 'vscode'
import * as fs from 'fs'
-import * as os from 'os'
-import * as child_process from 'child_process'
-import { deactivate } from './adapter/extension'
-import { LIB_VERSION } from './version'
import XDGAppPaths from 'xdg-app-paths'
import * as path from 'path'
-import { regexp, unzipFile, runScript } from './utils'
-import { getDaffodilVersion } from './daffodil'
-import { Artifact } from './classes/artifact'
+import { regexp, unzipFile } from './utils'
+import {
+ buildDebugger,
+ daffodilArtifact,
+ daffodilVersion,
+ runDebugger,
+ stopDebugger,
+ stopDebugging,
+} from './daffodilDebuggerUtils'
const xdgAppPaths = XDGAppPaths({ name: 'daffodil-dap' })
@@ -74,14 +76,8 @@
context: vscode.ExtensionContext,
config: vscode.DebugConfiguration
) {
- // Get daffodilVersion
- const daffodilVersion = getDaffodilVersion(
- context.asAbsolutePath('./package.json')
- )
- const artifact = new Artifact(
- 'daffodil-debugger',
- daffodilVersion,
- 'daffodil-debugger'
+ const artifact = daffodilArtifact(
+ daffodilVersion(context.asAbsolutePath('./package.json'))
)
// If useExistingServer var set to false make sure version of debugger entered is downloaded then ran
@@ -105,33 +101,13 @@
.toString()
// If debugging the extension without vsix installed make sure debugger is created
- if (!filePath.includes('.vscode/extension')) {
- if (!fs.existsSync(filePath)) {
- let baseFolder = context.asAbsolutePath('.')
- let command =
- os.platform() === 'win32'
- ? 'sbt universal:packageBin'
- : '/bin/bash --login -c "sbt universal:packageBin"' // Needed --login so it could resolve sbt command
- child_process.execSync(command, { cwd: baseFolder })
- }
- }
+ await buildDebugger(context.asAbsolutePath('.'), filePath)
// Unzip file
await unzipFile(filePath, rootPath)
}
- // Stop debugger if running
- if (os.platform() === 'win32') {
- // Windows stop debugger if already running
- child_process.execSync(
- 'tskill java 2>nul 1>nul || echo "Java not running"'
- )
- } else {
- // Linux/Mac stop debugger if already running and make sure script is executable
- child_process.exec(
- "kill -9 $(ps -ef | grep 'daffodil' | grep 'jar' | awk '{ print $2 }') || return 0"
- ) // ensure debugger server not running and
- }
+ await stopDebugger()
// Get program file before debugger starts to avoid timeout
if (config.program.includes('${command:AskForProgramName}')) {
@@ -146,7 +122,7 @@
config.data = ''
}
- return stopDebugging()
+ return await stopDebugging()
}
// Get data file before debugger starts to avoid timeout
@@ -157,7 +133,7 @@
}
if (config.data === '') {
- return stopDebugging()
+ return await stopDebugging()
}
let workspaceFolder = vscode.workspace.workspaceFolders
@@ -186,36 +162,11 @@
* being there will cause no issues.
*/
- let shellPath =
- os.platform() === 'win32' ? artifact.scriptName : '/bin/bash'
- let shellArgs =
- os.platform() === 'win32' ? [] : ['--login', '-c', artifact.scriptName]
-
- await runScript(
- `${rootPath}/daffodil-debugger-${daffodilVersion}-${LIB_VERSION}`,
- artifact,
- shellPath,
- shellArgs,
- {
- DAFFODIL_DEBUG_CLASSPATH: daffodilDebugClasspath,
- },
- 'daffodil'
+ await runDebugger(
+ rootPath,
+ daffodilDebugClasspath,
+ context.asAbsolutePath('./package.json')
)
}
}
-
- // Function for stopping debugging
- function stopDebugging() {
- vscode.debug.stopDebugging()
- deactivate()
- vscode.window.activeTerminal?.processId.then((id) => {
- if (id) {
- if (os.platform() === 'win32') {
- child_process.exec(`taskkill /F /PID ${id}`)
- } else {
- child_process.exec(`kill -9 ${id}`)
- }
- }
- })
- }
}
diff --git a/src/daffodilDebuggerUtils.ts b/src/daffodilDebuggerUtils.ts
new file mode 100644
index 0000000..df4d3ee
--- /dev/null
+++ b/src/daffodilDebuggerUtils.ts
@@ -0,0 +1,99 @@
+/*
+ * 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.
+ */
+
+import * as vscode from 'vscode'
+import * as fs from 'fs'
+import * as path from 'path'
+import * as child_process from 'child_process'
+import { LIB_VERSION } from './version'
+import { deactivate } from './adapter/extension'
+import { getDaffodilVersion } from './daffodil'
+import { Artifact } from './classes/artifact'
+import { osCheck, runScript } from './utils'
+
+export const daffodilVersion = (filePath: string): string => {
+ return getDaffodilVersion(filePath)
+}
+
+export const daffodilArtifact = (version: string): Artifact => {
+ return new Artifact('daffodil-debugger', version, 'daffodil-debugger')
+}
+
+export async function buildDebugger(baseFolder: string, filePath: string) {
+ if (!filePath.includes('.vscode/extension')) {
+ if (!fs.existsSync(filePath)) {
+ let command = osCheck(
+ 'sbt universal:packageBin',
+ '/bin/bash --login -c "sbt universal:packageBin"'
+ ) // Needed --login so it could resolve sbt command
+
+ child_process.execSync(command, { cwd: baseFolder })
+ }
+ }
+}
+
+export const stopDebugger = (id: number | undefined = undefined) =>
+ child_process.exec(osCheck(`taskkill /F /PID ${id}`, `kill -9 ${id}`))
+
+export const shellPath = (scriptName: string) =>
+ osCheck(scriptName, '/bin/bash')
+
+export const shellArgs = (scriptName: string, port: number) =>
+ osCheck(
+ ['--listenPort', `${port}`],
+ ['--login', '-c', `${scriptName} --listenPort ${port}`]
+ )
+
+export async function runDebugger(
+ rootPath: string,
+ daffodilDebugClasspath: string,
+ filePath: string,
+ serverPort: number = 4711
+): Promise<vscode.Terminal> {
+ const dfdlVersion = daffodilVersion(filePath)
+ const artifact = daffodilArtifact(dfdlVersion)
+ const scriptPath = path.join(
+ rootPath,
+ `daffodil-debugger-${dfdlVersion}-${LIB_VERSION}`
+ )
+
+ /*
+ * For Mac if /bin/bash --login -c not used errors about compiled version versus
+ * currently being used java version. Not sure if its needed for linux but it
+ * being there will cause no issues.
+ */
+
+ return await runScript(
+ scriptPath,
+ artifact.scriptName,
+ shellPath(artifact.scriptName),
+ shellArgs(artifact.scriptName, serverPort),
+ {
+ DAFFODIL_DEBUG_CLASSPATH: daffodilDebugClasspath,
+ },
+ 'daffodil'
+ )
+}
+
+// Function for stopping debugging
+export async function stopDebugging() {
+ vscode.debug.stopDebugging()
+ deactivate()
+ vscode.window.activeTerminal?.processId.then(async (id) => {
+ await stopDebugger(id)
+ })
+}
diff --git a/src/infoset.ts b/src/infoset.ts
index 2cdb240..8dcc2f2 100644
--- a/src/infoset.ts
+++ b/src/infoset.ts
@@ -46,8 +46,8 @@
switch (action) {
case 'Open':
- let xml = await vscode.workspace.openTextDocument(uri)
- await vscode.window.showTextDocument(xml, {
+ let infoset = await vscode.workspace.openTextDocument(uri)
+ await vscode.window.showTextDocument(infoset, {
preview: false,
viewColumn: vscode.ViewColumn.One,
})
@@ -173,7 +173,7 @@
})()
function tmp(sid: string): string {
- return `${tmpdir()}/infoset-${sid}.xml`
+ return `${tmpdir()}/infoset-${sid}.${getCurrentConfig().infosetFormat}`
}
function ensure(path: string): string {
diff --git a/src/launchWizard/launchWizard.js b/src/launchWizard/launchWizard.js
index 25c9b14..0fe98ca 100644
--- a/src/launchWizard/launchWizard.js
+++ b/src/launchWizard/launchWizard.js
@@ -97,6 +97,7 @@
: configSelectedValue
const data = document.getElementById('data').value
const debugServer = parseInt(document.getElementById('debugServer').value)
+ const infosetFormat = document.getElementById('infosetFormat').value
const infosetOutputFilePath = document.getElementById(
'infosetOutputFilePath'
).value
@@ -121,6 +122,7 @@
program: program,
data: data,
debugServer: debugServer,
+ infosetFormat: infosetFormat,
infosetOutput: {
type: infosetOutputType,
path: infosetOutputFilePath,
@@ -147,6 +149,9 @@
document.getElementById('name').value = config.name
document.getElementById('data').value = config.data
document.getElementById('debugServer').value = parseInt(config.debugServer)
+ document.getElementById('infosetFormat').value = config.infosetFormat
+ ? config.infosetFormat
+ : 'xml'
document.getElementById('infosetOutputFilePath').value = config.infosetOutput[
'path'
]
diff --git a/src/launchWizard/launchWizard.ts b/src/launchWizard/launchWizard.ts
index 697295c..f5eee8b 100644
--- a/src/launchWizard/launchWizard.ts
+++ b/src/launchWizard/launchWizard.ts
@@ -17,8 +17,7 @@
import * as vscode from 'vscode'
import * as fs from 'fs'
-import { getConfig } from '../utils'
-import * as os from 'os'
+import { getConfig, osCheck } from '../utils'
const defaultConf = getConfig('Wizard Config', 'launch', 'dfdl')
@@ -53,10 +52,10 @@
fs.mkdirSync(`${rootPath}/.vscode`)
}
- const launchPath =
- os.platform() === 'win32'
- ? `/${rootPath}/.vscode/launch.json`
- : `${rootPath}/.vscode/launch.json`
+ const launchPath = osCheck(
+ `/${rootPath}/.vscode/launch.json`,
+ `${rootPath}/.vscode/launch.json`
+ )
// Create launch.json if it doesn't exist already
if (!fs.existsSync(`${rootPath}/.vscode/launch.json`)) {
@@ -334,6 +333,18 @@
daffodilDebugClasspathAction !== 'append' ? 'checked' : ''
let appendCheck = daffodilDebugClasspathAction === 'append' ? 'checked' : ''
+ let infosetFormatSelect = ''
+ let infosetFormatTypes = ['xml', 'json']
+ let infosetFormat = defaultValues.infosetFormat
+
+ infosetFormatTypes.forEach((type) => {
+ if (type === infosetFormat) {
+ infosetFormatSelect += `<option selected value="${type}">${type}</option>`
+ } else {
+ infosetFormatSelect += `<option value="${type}">${type}</option>`
+ }
+ })
+
let infosetOutputTypeSelect = ''
let infosetOutputTypes = ['none', 'console', 'file']
let infosetOutputType = defaultValues.infosetOutput['type']
@@ -430,6 +441,14 @@
<input class="file-input" value="${defaultValues.debugServer}" id="debugServer"/>
</div>
+ <div id="infosetFormatDiv" class="setting-div">
+ <p>Infoset Format:</p>
+ <p class="setting-description">Desired format of infoset ('xml' | 'json')</p>
+ <select class="file-input" style="width: 200px;" id="infosetFormat">
+ ${infosetFormatSelect}
+ </select>
+ </div>
+
<div id="infosetOutputTypeDiv" class="setting-div">
<p>Infoset Output Type:</p>
<p class="setting-description">Destination for final Infoset (file | 'console' | 'none')</p>
diff --git a/src/omega_edit/client.ts b/src/omega_edit/client.ts
index 42725e5..935314b 100644
--- a/src/omega_edit/client.ts
+++ b/src/omega_edit/client.ts
@@ -20,12 +20,15 @@
import * as omegaEditSession from 'omega-edit/session'
import * as omegaEditViewport from 'omega-edit/viewport'
import * as omegaEditVersion from 'omega-edit/version'
-import { getServer, stopServer } from './server'
-import { viewportSubscribe } from './utils'
+import { startOmegaEditServer, viewportSubscribe } from './utils'
import { OmegaEdit } from './omega_edit'
import { v4 as uuidv4 } from 'uuid'
-
+import XDGAppPaths from 'xdg-app-paths'
+import { killProcess } from '../utils'
let serverRunning = false
+let serverTerminal: vscode.Terminal | undefined
+const xdgAppPaths = XDGAppPaths({ name: 'omega_edit' })
+let rootPath = xdgAppPaths.data()
// Method to get omega-edit version from a JSON file
export function getOmegaEditPackageVersion(filePath: fs.PathLike) {
@@ -44,6 +47,20 @@
await omegaEditSession.destroySession(sessionId)
}
+async function commonOmegaEdit(
+ ctx: vscode.ExtensionContext,
+ startServer: boolean,
+ omegaEditPackageVersion: string
+) {
+ if (!serverRunning && startServer) {
+ ;[serverTerminal, serverRunning] = await startOmegaEditServer(
+ ctx,
+ rootPath,
+ omegaEditPackageVersion
+ )
+ }
+}
+
export function activate(ctx: vscode.ExtensionContext) {
const omegaEditPackageVersion = getOmegaEditPackageVersion(
ctx.asAbsolutePath('./package.json')
@@ -53,11 +70,7 @@
vscode.commands.registerCommand(
'omega_edit.version',
async (startServer: boolean = true) => {
- if (!serverRunning && startServer) {
- await getServer(ctx, omegaEditPackageVersion)
- serverRunning = true
- }
-
+ await commonOmegaEdit(ctx, startServer, omegaEditPackageVersion)
return await omegaEditVersion.getVersion()
}
)
@@ -71,10 +84,7 @@
startServer: boolean = true,
subscribeToViewports: boolean = true
) => {
- if (!serverRunning && startServer) {
- await getServer(ctx, omegaEditPackageVersion)
- serverRunning = true
- }
+ await commonOmegaEdit(ctx, startServer, omegaEditPackageVersion)
return await createOmegaEditWebviewPanel(
ctx,
@@ -182,7 +192,9 @@
async () => {
await cleanupViewportSession(s, [vpAll, vp1, vp2, vp3])
panel.dispose()
- serverRunning = !(await stopServer())
+ await serverTerminal?.processId.then(async (id) => await killProcess(id))
+ serverRunning = false
+ vscode.window.showInformationMessage('omega-edit server stopped!')
},
undefined,
ctx.subscriptions
diff --git a/src/omega_edit/server.ts b/src/omega_edit/server.ts
deleted file mode 100644
index a2ea73e..0000000
--- a/src/omega_edit/server.ts
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * 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.
- */
-
-import * as vscode from 'vscode'
-import * as fs from 'fs'
-import * as path from 'path'
-import { Artifact } from '../classes/artifact'
-import XDGAppPaths from 'xdg-app-paths'
-import { runScript, unzipFile, killProcess } from '../utils'
-
-const xdgAppPaths = XDGAppPaths({ name: 'omega_edit' })
-
-export async function getServer(
- ctx: vscode.ExtensionContext,
- omegaEditVersion: string
-) {
- // Get omegaEditVersion
- const artifact = new Artifact(
- 'omega-edit-scala-server',
- omegaEditVersion,
- 'omega-edit-grpc-server'
- )
-
- if (vscode.workspace.workspaceFolders) {
- let rootPath = xdgAppPaths.data()
-
- // If data and app directories for holding omega server script do not exist create them
- if (!fs.existsSync(rootPath)) {
- fs.mkdirSync(rootPath, { recursive: true })
- }
-
- // Download and setup omega-edit server files
- if (!fs.existsSync(`${rootPath}/${artifact.name}`)) {
- const filePath = path.join(
- ctx.asAbsolutePath('./src/omega_edit/'),
- artifact.archive
- )
-
- // Unzip file and remove zip
- await unzipFile(filePath, rootPath)
- }
-
- await runScript(
- `${rootPath}/omega-edit-scala-server-${omegaEditVersion}`,
- artifact
- )
- }
-}
-
-// Function for stopping debugging
-export async function stopServer(terminal: vscode.Terminal | null = null) {
- if (terminal !== null) {
- terminal.processId.then(async (id) => await killProcess(id))
- return true
- } else {
- const action = await vscode.window.showInformationMessage(
- 'Stop Ωedit server?',
- 'Yes',
- 'No'
- )
-
- if (action === 'Yes') {
- vscode.window.activeTerminal?.processId.then(
- async (id) => await killProcess(id)
- )
- return true
- }
-
- return false
- }
-}
diff --git a/src/omega_edit/utils.ts b/src/omega_edit/utils.ts
index 7925024..3b2455f 100644
--- a/src/omega_edit/utils.ts
+++ b/src/omega_edit/utils.ts
@@ -23,6 +23,8 @@
ViewportDataRequest,
} from 'omega-edit/omega_edit_pb'
import { getClient, ALL_EVENTS } from 'omega-edit/settings'
+import * as omegaEditServer from 'omega-edit/server'
+import { runScript } from '../utils'
const client = getClient()
@@ -132,3 +134,18 @@
// data request not ran right away, so this ensures the views are populated
await setViewportDataForPanel(panel, vp2, commandViewport, commandHex)
}
+
+export async function startOmegaEditServer(
+ ctx: vscode.ExtensionContext,
+ rootPath: string,
+ omegaEditPackageVersion: string
+): Promise<[vscode.Terminal, boolean]> {
+ const [scriptName, scriptPath] = await omegaEditServer.setupServer(
+ rootPath,
+ omegaEditPackageVersion,
+ ctx.asAbsolutePath('./node_modules/omega-edit')
+ )
+
+ let terminal = await runScript(scriptPath, scriptName)
+ return [terminal, true]
+}
diff --git a/src/tests/data/test.dfdl.xsd b/src/tests/data/test.dfdl.xsd
index cb50f97..9900463 100644
--- a/src/tests/data/test.dfdl.xsd
+++ b/src/tests/data/test.dfdl.xsd
@@ -16,15 +16,49 @@
limitations under the License.
-->
-<xs:schema xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/"
- xmlns:xs="http://www.w3.org/2001/XMLSchema">
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/"
+ xmlns:daf="urn:ogf:dfdl:2013:imp:daffodil.apache.org:2018:ext"
+ xmlns:fn="http://www.w3.org/2005/xpath-functions">
- <xs:element name="name">
- <xs:simpleType>
- <xs:restriction base="xs:string">
- <xs:length value="25"/>
- </xs:restriction>
- </xs:simpleType>
- </xs:element>
+ <xs:annotation>
+ <xs:appinfo source="http://www.ogf.org/dfdl/">
+ <dfdl:defineFormat name="testFormat">
+ <dfdl:format alignmentUnits="bytes" lengthUnits="bits" representation="binary" binaryNumberRep="binary"
+ byteOrder="bigEndian" bitOrder="mostSignificantBitFirst" lengthKind="implicit" alignment="1" encodingErrorPolicy="replace"
+ binaryFloatRep="ieee" calendarPatternKind="implicit" documentFinalTerminatorCanBeMissing="yes"
+ emptyValueDelimiterPolicy="none" escapeSchemeRef="" fillByte="f" floating="no" ignoreCase="no"
+ initiatedContent="no" initiator="" leadingSkip="0" separator="" separatorSuppressionPolicy="anyEmpty"
+ textStandardZeroRep="0" textStandardInfinityRep="Inf" textStandardExponentRep="E"
+ textStandardNaNRep="NaN" textNumberPattern="#,##0.###;-#,##0.###" textNumberRounding="explicit"
+ textNumberRoundingMode="roundUnnecessary" textNumberRoundingIncrement="0" textStandardGroupingSeparator=","
+ separatorPosition="infix" sequenceKind="ordered" terminator="" textBidi="no" textNumberCheckPolicy="strict"
+ textNumberRep="standard" textPadKind="none" textStandardBase="10" textTrimKind="none" trailingSkip="0" truncateSpecifiedLengthString="no"
+ utf16Width="fixed" encoding="US-ASCII" nilKind="literalValue" nilValueDelimiterPolicy="none" occursCountKind="parsed"
+ textOutputMinLength="0" />
+ </dfdl:defineFormat>
+ <dfdl:format ref="testFormat"/>
+ </xs:appinfo>
+ </xs:annotation>
+
+ <xs:element name="element">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:sequence>
+ <xs:annotation>
+ <xs:appinfo source="http://www.ogf.org/dfdl/">
+ </xs:appinfo>
+ </xs:annotation>
+ </xs:sequence>
+ <xs:sequence dfdl:hiddenGroupRef="hiddenGroup" />
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+
+ <!-- NOTE: Intentionally empty. This is to make sure the file is a correctly defined schema file. -->
+ <xs:group name="hiddenGroup">
+ <xs:sequence>
+ </xs:sequence>
+ </xs:group>
</xs:schema>
diff --git a/src/tests/suite/adapter.test.ts b/src/tests/suite/adapter.test.ts
index 792f48c..f4d91d1 100644
--- a/src/tests/suite/adapter.test.ts
+++ b/src/tests/suite/adapter.test.ts
@@ -18,14 +18,10 @@
import * as assert from 'assert'
import * as path from 'path'
import { DebugClient } from 'vscode-debugadapter-testsupport'
+import { TEST_SCHEMA, PROJECT_ROOT } from './common'
suite('Daffodil Debug Adapter', () => {
- const DEBUG_ADAPTER = path.join(
- __dirname,
- '../../../out/adapter/debugAdapter.js'
- )
- const PROJECT_ROOT = path.join(__dirname, '../../../')
- const DATA_ROOT = path.join(PROJECT_ROOT, 'src/tests/data/')
+ const DEBUG_ADAPTER = path.join(PROJECT_ROOT, 'out/adapter/debugAdapter.js')
let client: DebugClient
@@ -79,22 +75,19 @@
suite('launch', () => {
test('should run program to the end', () => {
- const PROGRAM = path.join(DATA_ROOT, 'test.dfdl.xsd')
-
return Promise.all([
client.configurationSequence(),
- client.launch({ program: PROGRAM }),
+ client.launch({ program: TEST_SCHEMA }),
client.waitForEvent('terminated'),
])
})
test('should stop on entry', () => {
- const PROGRAM = path.join(DATA_ROOT, 'test.dfdl.xsd')
const ENTRY_LINE = 1
return Promise.all([
client.configurationSequence(),
- client.launch({ program: PROGRAM, stopOnEntry: true }),
+ client.launch({ program: TEST_SCHEMA, stopOnEntry: true }),
client.assertStoppedLocation('entry', { line: ENTRY_LINE }),
])
})
diff --git a/src/tests/suite/common.ts b/src/tests/suite/common.ts
new file mode 100644
index 0000000..c7c9c55
--- /dev/null
+++ b/src/tests/suite/common.ts
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+
+import * as path from 'path'
+
+export const PROJECT_ROOT = path.join(__dirname, '../../../')
+export const DATA_ROOT = path.join(PROJECT_ROOT, 'src/tests/data/')
+export const PACKAGE_PATH = path.join(PROJECT_ROOT, 'package.json')
+export const TEST_SCHEMA = path.join(DATA_ROOT, 'test.dfdl.xsd')
diff --git a/src/tests/suite/daffodil.test.ts b/src/tests/suite/daffodil.test.ts
index ec34609..0942d0e 100644
--- a/src/tests/suite/daffodil.test.ts
+++ b/src/tests/suite/daffodil.test.ts
@@ -20,18 +20,14 @@
import * as daffodil from '../../daffodil'
import * as fs from 'fs'
import * as path from 'path'
-import * as os from 'os'
import { Artifact } from '../../classes/artifact'
import { LIB_VERSION } from '../../version'
import { before, after } from 'mocha'
+import { PROJECT_ROOT, TEST_SCHEMA } from './common'
+import { osCheck } from '../../utils'
suite('Daffodfil', () => {
- const PROJECT_ROOT = path.join(__dirname, '../../../')
const packageFile = path.join(PROJECT_ROOT, 'package-test.json')
- const testDfdlFile = path.join(
- __dirname,
- '../../../src/tests/data/test.dfdl.xsd'
- )
// Create test package.json before anything else happens
before(() => {
@@ -53,16 +49,26 @@
assert.strictEqual(100, daffodilData.bytePos1b)
})
- test('InfosetEvent functions properly', () => {
+ test('InfosetEvent functions properly (xml)', () => {
let infosetEvent: daffodil.InfosetEvent = {
- content: 'This is content',
+ content: 'This is xml content',
mimeType: 'xml',
}
- assert.strictEqual('This is content', infosetEvent.content)
+ assert.strictEqual('This is xml content', infosetEvent.content)
assert.strictEqual('xml', infosetEvent.mimeType)
})
+ test('InfosetEvent functions properly (json)', () => {
+ let infosetEvent: daffodil.InfosetEvent = {
+ content: 'This is json content',
+ mimeType: 'json',
+ }
+
+ assert.strictEqual('This is json content', infosetEvent.content)
+ assert.strictEqual('json', infosetEvent.mimeType)
+ })
+
test('InfosetOutput functions properly', () => {
let infosetOutput: daffodil.InfosetOutput = {
type: 'console',
@@ -93,12 +99,14 @@
schemaPath: '/path/to/schema.xsd.xml',
dataPath: '/path/to/data.jpg',
stopOnEntry: true,
+ infosetFormat: 'json',
infosetOutput: infosetOutput,
}
assert.strictEqual('/path/to/schema.xsd.xml', launchArgs.schemaPath)
assert.strictEqual('/path/to/data.jpg', launchArgs.dataPath)
assert.strictEqual(true, launchArgs.stopOnEntry)
+ assert.strictEqual('json', launchArgs.infosetFormat)
assert.strictEqual(infosetOutput, launchArgs.infosetOutput)
})
@@ -116,6 +124,7 @@
schemaPath: '/path/to/schema.xsd.xml',
dataPath: '/path/to/data.jpg',
stopOnEntry: true,
+ infosetFormat: 'xml',
infosetOutput: infosetOutput,
}
@@ -216,9 +225,9 @@
assert.strictEqual(
await vscode.commands.executeCommand(
'extension.dfdl-debug.getProgramName',
- testDfdlFile
+ TEST_SCHEMA
),
- testDfdlFile
+ TEST_SCHEMA
)
})
@@ -238,9 +247,9 @@
assert.strictEqual(
await vscode.commands.executeCommand(
'extension.dfdl-debug.getDataName',
- testDfdlFile
+ TEST_SCHEMA
),
- testDfdlFile
+ TEST_SCHEMA
)
})
@@ -280,7 +289,7 @@
test('scriptName set properly', () => {
assert.strictEqual(
artifact.scriptName,
- os.platform() === 'win32' ? `${scriptName}.bat` : `./${scriptName}`
+ osCheck(`${scriptName}.bat`, `./${scriptName}`)
)
})
})
diff --git a/src/tests/suite/daffodilDebugger.test.ts b/src/tests/suite/daffodilDebugger.test.ts
new file mode 100644
index 0000000..edd640f
--- /dev/null
+++ b/src/tests/suite/daffodilDebugger.test.ts
@@ -0,0 +1,91 @@
+/*
+ * 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.
+ */
+
+import * as vscode from 'vscode'
+import * as assert from 'assert'
+import * as path from 'path'
+import * as fs from 'fs'
+import { PROJECT_ROOT, PACKAGE_PATH, TEST_SCHEMA } from './common'
+import { getConfig, killProcess, unzipFile } from '../../utils'
+import {
+ daffodilArtifact,
+ daffodilVersion,
+ runDebugger,
+ stopDebugging,
+} from '../../daffodilDebuggerUtils'
+import { before, after } from 'mocha'
+
+// Not using the debug adapter like adapter.test.ts as it will not fully connect the debugger
+suite('Daffodil Debugger', () => {
+ const dfdlVersion = daffodilVersion(PACKAGE_PATH)
+ const artifact = daffodilArtifact(dfdlVersion)
+
+ const SCALA_PATH = path.join(
+ PROJECT_ROOT,
+ 'server/core/target/universal',
+ artifact.archive
+ )
+ const EXTRACTED_FOLDER = path.join(PROJECT_ROOT, artifact.name)
+
+ // debugger options
+ const DATA = path.join(PROJECT_ROOT, 'images/daffodil.ico')
+ const XML_INFOSET_PATH = path.join(PROJECT_ROOT, 'testinfoset.xml')
+ const JSON_INFOSET_PATH = path.join(PROJECT_ROOT, 'testinfoset.json')
+ const debuggers: vscode.Terminal[] = []
+
+ before(async () => {
+ await unzipFile(SCALA_PATH, PROJECT_ROOT)
+ debuggers.push(await runDebugger(PROJECT_ROOT, '', PACKAGE_PATH))
+ debuggers.push(await runDebugger(PROJECT_ROOT, '', PACKAGE_PATH, 4712))
+ })
+
+ after(async () => {
+ await stopDebugging()
+ debuggers.forEach((d) => {
+ d.processId?.then(async (id) => await killProcess(id))
+ })
+ fs.rmSync(EXTRACTED_FOLDER, { recursive: true })
+ if (fs.existsSync(XML_INFOSET_PATH)) fs.rmSync(XML_INFOSET_PATH)
+ if (fs.existsSync(JSON_INFOSET_PATH)) fs.rmSync(JSON_INFOSET_PATH)
+ })
+
+ test('should output xml infoset', async () => {
+ await vscode.debug.startDebugging(
+ undefined,
+ getConfig('Run', 'launch', 'dfdl', TEST_SCHEMA, DATA, 4711, 'xml', {
+ type: 'file',
+ path: XML_INFOSET_PATH,
+ }),
+ { noDebug: true }
+ )
+
+ assert.strictEqual(fs.existsSync(XML_INFOSET_PATH), true)
+ })
+
+ test('should output json infoset', async () => {
+ await vscode.debug.startDebugging(
+ undefined,
+ getConfig('Run', 'launch', 'dfdl', TEST_SCHEMA, DATA, 4712, 'json', {
+ type: 'file',
+ path: JSON_INFOSET_PATH,
+ }),
+ { noDebug: true }
+ )
+
+ assert.strictEqual(fs.existsSync(JSON_INFOSET_PATH), true)
+ })
+})
diff --git a/src/tests/suite/index.ts b/src/tests/suite/index.ts
index 94efb89..fe47b76 100644
--- a/src/tests/suite/index.ts
+++ b/src/tests/suite/index.ts
@@ -30,7 +30,7 @@
const testsRoot = path.resolve(__dirname, '..')
return new Promise((c, e) => {
- glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
+ glob('**/*.test.js', { cwd: testsRoot }, (err, files) => {
if (err) {
return e(err)
}
diff --git a/src/tests/suite/omegaEdit.test.ts b/src/tests/suite/omegaEdit.test.ts
index 5e3c335..5c50b19 100644
--- a/src/tests/suite/omegaEdit.test.ts
+++ b/src/tests/suite/omegaEdit.test.ts
@@ -18,35 +18,32 @@
import * as vscode from 'vscode'
import * as assert from 'assert'
import * as path from 'path'
-import * as os from 'os'
import { Artifact, Backend } from '../../classes/artifact'
import * as omegaEditClient from '../../omega_edit/client'
-import { unzipFile, runScript, killProcess } from '../../utils'
+import { unzipFile, runScript, killProcess, osCheck } from '../../utils'
import { before, after } from 'mocha'
+import * as fs from 'fs'
+import { PROJECT_ROOT, PACKAGE_PATH, TEST_SCHEMA } from './common'
const wait_port = require('wait-port')
-const omegaEditPackagePath = path.join(__dirname, '../../../src/omega_edit')
+
+const omegaEditPackagePath = path.join(PROJECT_ROOT, 'node_modules/omega-edit')
+const omegaEditVersion =
+ omegaEditClient.getOmegaEditPackageVersion(PACKAGE_PATH)
const localArtifact = new Artifact(
'omega-edit-scala-server',
- omegaEditClient.getOmegaEditPackageVersion(
- path.join(__dirname, '../../../package.json')
- ),
+ omegaEditVersion,
'omega-edit-grpc-server'
)
-const testDfdlFile = path.join(
- __dirname,
- '../../../src/tests/data/test.dfdl.xsd'
-)
+const extractedFolder = path.join(PROJECT_ROOT, localArtifact.name)
export async function runServerForTests() {
- const extractedFolder = `${omegaEditPackagePath}/${localArtifact.name}`
-
- await unzipFile(
+ fs.copyFileSync(
`${omegaEditPackagePath}/${localArtifact.name}.zip`,
- omegaEditPackagePath
+ `${extractedFolder}.zip`
)
-
- return await runScript(`${extractedFolder}`, localArtifact)
+ await unzipFile(`${extractedFolder}.zip`, PROJECT_ROOT)
+ return await runScript(`${extractedFolder}`, localArtifact.scriptName)
}
suite('omega-edit Test Suite', () => {
@@ -58,6 +55,11 @@
after(async () => {
await terminal.processId.then(async (id) => await killProcess(id))
+ fs.rmSync(`${PROJECT_ROOT}/${localArtifact.name}.zip`)
+ fs.rmSync(`${PROJECT_ROOT}/${localArtifact.name}`, {
+ recursive: true,
+ force: true,
+ })
})
test('Test toggle.experimental', async () => {
@@ -106,7 +108,7 @@
test('scriptName set properly', () => {
assert.strictEqual(
artifact.scriptName,
- os.platform() === 'win32' ? `${scriptName}.bat` : `./${scriptName}`
+ osCheck(`${scriptName}.bat`, `./${scriptName}`)
)
})
@@ -139,17 +141,14 @@
assert.strictEqual(
version,
- 'v' +
- omegaEditClient.getOmegaEditPackageVersion(
- path.join(__dirname, '../../../package.json')
- )
+ 'v' + omegaEditClient.getOmegaEditPackageVersion(PACKAGE_PATH)
)
})
test('data editor opens', async () => {
const panel: vscode.WebviewPanel = await vscode.commands.executeCommand(
'data.edit',
- testDfdlFile,
+ TEST_SCHEMA,
false,
false
)
diff --git a/src/tests/suite/utils.test.ts b/src/tests/suite/utils.test.ts
index fa590a0..38c5822 100644
--- a/src/tests/suite/utils.test.ts
+++ b/src/tests/suite/utils.test.ts
@@ -30,6 +30,7 @@
program: '${command:AskForProgramName}',
data: '${command:AskForDataName}',
debugServer: 4711,
+ infosetFormat: 'xml',
infosetOutput: {
type: 'none',
path: '${workspaceFolder}/infoset.xml',
diff --git a/src/tests/suite/version.test.ts b/src/tests/suite/version.test.ts
index 0e306fc..c548d35 100644
--- a/src/tests/suite/version.test.ts
+++ b/src/tests/suite/version.test.ts
@@ -18,9 +18,9 @@
import * as assert from 'assert'
import * as fs from 'fs'
import * as path from 'path'
+import { PROJECT_ROOT } from './common'
suite('Daffodil Version', () => {
- const PROJECT_ROOT = path.join(__dirname, '../../../')
const versionFile = path.join(PROJECT_ROOT, 'src/version.ts')
const packageMapped = JSON.parse(
fs.readFileSync(path.join(PROJECT_ROOT, 'package.json')).toString()
diff --git a/src/utils.ts b/src/utils.ts
index 59b1a9e..07feb03 100644
--- a/src/utils.ts
+++ b/src/utils.ts
@@ -18,13 +18,13 @@
import * as vscode from 'vscode'
import * as fs from 'fs'
import * as unzip from 'unzip-stream'
-import { Artifact } from './classes/artifact'
import * as os from 'os'
import * as child_process from 'child_process'
+import path from 'path'
+
const wait_port = require('wait-port')
const defaultConf = vscode.workspace.getConfiguration()
-// const
let currentConfig: vscode.DebugConfiguration
export const regexp = {
@@ -86,6 +86,7 @@
program: string = '',
data: string | boolean = false,
debugServer: number | boolean = false,
+ infosetFormat: string | null = null,
infosetOutput: object | null = null,
stopOnEntry = false,
useExistingServer = false,
@@ -106,6 +107,7 @@
debugServer: debugServer
? debugServer
: defaultConf.get('debugServer', 4711),
+ infosetFormat: infosetFormat ? infosetFormat : 'xml',
infosetOutput: infosetOutput
? infosetOutput
: {
@@ -171,19 +173,40 @@
return terminal
}
+/*
+ * Check if OS is windows, if so return windows option else return the mac and linux option.
+ * This method is used to elimate a lot duplicated code we had check if the os was windows related.
+ */
+export function osCheck(winOption: any, macLinOption: any): any {
+ return os.platform().toLowerCase().startsWith('win')
+ ? winOption
+ : macLinOption
+}
+
export async function killProcess(id: number | undefined) {
if (id) {
- if (os.platform() === 'win32') {
- child_process.exec(`taskkill /F /PID ${id}`)
- } else {
- child_process.exec(`kill -9 ${id} 2>&1 || echo 0`)
- }
+ child_process.exec(
+ osCheck(`taskkill /F /PID ${id}`, `kill -9 ${id} 2>&1 || echo 0`)
+ )
+ }
+}
+
+export const delay = (ms: number) => new Promise((res) => setTimeout(res, ms))
+
+export function chmodScript(scriptPath: string, scriptName: string) {
+ if (!os.platform().toLowerCase().startsWith('win')) {
+ child_process.execSync(
+ `chmod +x ${scriptPath.replace(' ', '\\ ')}/bin/${scriptName.replace(
+ './',
+ ''
+ )}`
+ )
}
}
export async function runScript(
scriptPath: string,
- artifact: Artifact,
+ scriptName: string,
shellPath: string | null = null,
shellArgs: string[] = [],
env:
@@ -194,23 +217,14 @@
type: string = '',
hideTerminal: boolean = false
) {
- const delay = (ms: number) => new Promise((res) => setTimeout(res, ms))
-
- if (!os.platform().toLowerCase().startsWith('win')) {
- child_process.execSync(
- `chmod +x ${scriptPath.replace(
- ' ',
- '\\ '
- )}/bin/${artifact.scriptName.replace('./', '')}`
- )
- }
+ chmodScript(scriptPath, scriptName)
// Start server in terminal based on scriptName
let terminal = vscode.window.createTerminal({
- name: artifact.scriptName,
- cwd: `${scriptPath}/bin`,
+ name: scriptName,
+ cwd: path.join(scriptPath, 'bin'),
hideFromUser: false,
- shellPath: shellPath !== null ? shellPath : artifact.scriptName,
+ shellPath: shellPath !== null ? shellPath : scriptName,
shellArgs: shellArgs,
env: env,
})
diff --git a/yarn.lock b/yarn.lock
index dba147c..5ec0c53 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -1658,10 +1658,10 @@
resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.12.2.tgz#c0641f26394532f28ab8d796ab954e43c009a8ea"
integrity sha512-z+cPxW0QGUp0mcqcsgQyLVRDoXFQbXOwBaqyF7VIgI4TWNQsDHrBpUQslRmIfAoYWdYzs6UlKJtB2XJpTaNSpQ==
-omega-edit@0.9.24:
- version "0.9.24"
- resolved "https://registry.yarnpkg.com/omega-edit/-/omega-edit-0.9.24.tgz#b7c40e320ec06416d02afc1134a51095b39ecedd"
- integrity sha512-myPLWkc1TVSOXIiqhIn3WdvCUdvSb9LDmYFM63E6naK6dphbGKM3ClFBx0mQsQ6XKSBkrJ9Gxcw09dnS+CUViA==
+omega-edit@0.9.32:
+ version "0.9.32"
+ resolved "https://registry.yarnpkg.com/omega-edit/-/omega-edit-0.9.32.tgz#29006dcb23843f644f15e9b1919a2c756e231a7b"
+ integrity sha512-zRwvq/+t6hKJafKjA9WUk76cc0SZP/CLjcLmFCi8Kx7orPxA3jRtCYWwYbgrhri3sQ3Xz0kxPFBDd+dCz47tHw==
dependencies:
"@grpc/grpc-js" "^1.7.1"
"@types/google-protobuf" "^3.15.5"