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

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


The following commit(s) were added to refs/heads/main by this push:
     new 9177397  Bump extension daffodilVersion to 3.2.1:
9177397 is described below

commit 9177397df5e6e3a2043c34bcee526e7b20d735a4
Author: Shane Dell <[email protected]>
AuthorDate: Wed Jan 19 13:16:54 2022 -0500

    Bump extension daffodilVersion to 3.2.1:
    
    - Add "daffodilVersion" entry to package.json
    - Update build.sbt to get daffodilVersion by reading the package.json
    - Update the extension to have a method for getting the daffodilVersion 
from the package.json
    - Create unit test for extension that it gets the proper daffodilVersion 
given a file path
    - Fix bash and bat templates to not hard code the app classpath
      - Had to make new variable inside of the templates, that would be sent 
for the adding of debug classpaths to the app classpath. As app classpath is a 
READ only variable
    
    Closes #74
    Closes #75
---
 build.sbt                               |  5 ++++-
 package.json                            |  1 +
 project/plugins.sbt                     |  1 +
 server/core/src/templates/bash-template |  9 +++++----
 server/core/src/templates/bat-template  | 10 +++++-----
 src/daffodil.ts                         |  6 ++++++
 src/daffodilDebugger.ts                 | 10 +++++++---
 src/tests/daffodil.test.ts              | 23 +++++++++++++++++++++++
 8 files changed, 52 insertions(+), 13 deletions(-)

diff --git a/build.sbt b/build.sbt
index dda8f9f..6761d60 100644
--- a/build.sbt
+++ b/build.sbt
@@ -15,7 +15,10 @@
  * limitations under the License.
  */
 
-lazy val daffodilVer = "3.2.1"
+import play.api.libs.json._
+
+lazy val packageData = 
Json.parse(scala.io.Source.fromFile("./package.json").mkString).as[JsObject]
+lazy val daffodilVer = packageData("daffodilVersion").as[String]
 
 lazy val commonSettings = {
   Seq(
diff --git a/package.json b/package.json
index 250fec3..460076a 100644
--- a/package.json
+++ b/package.json
@@ -3,6 +3,7 @@
   "displayName": "Apache Daffodil Schema Debugger",
   "description": "VS Code extension for Apache Daffodil DFDL schema debugging",
   "version": "1.0.0-SNAPSHOT",
+  "daffodilVersion": "3.2.1",
   "publisher": "asf",
   "author": "Apache Daffodil",
   "license": "Apache-2.0",
diff --git a/project/plugins.sbt b/project/plugins.sbt
index 72ea9e4..741b8d5 100644
--- a/project/plugins.sbt
+++ b/project/plugins.sbt
@@ -20,3 +20,4 @@ addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % 
"1.8.1")
 addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.1.17")
 addSbtPlugin("org.musigma" % "sbt-rat" % "0.7.0")
 addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.3")
+addSbtPlugin("com.github.battermann" % "sbt-json" % "0.5.0")
diff --git a/server/core/src/templates/bash-template 
b/server/core/src/templates/bash-template
index e150be7..dbf7ba1 100644
--- a/server/core/src/templates/bash-template
+++ b/server/core/src/templates/bash-template
@@ -264,14 +264,16 @@ run() {
   fi
 
   if [[ "$DAFFODIL_DEBUG_CLASSPATH" != "" ]]; then
-    app_classpath="$app_classpath:$DAFFODIL_DEBUG_CLASSPATH"
+    new_classpath="$app_classpath:$DAFFODIL_DEBUG_CLASSPATH"
+  else
+    new_classpath="$app_classpath"
   fi
 
   # run sbt
   execRunner "$java_cmd" \
     ${java_opts[@]} \
     "${java_args[@]}" \
-    -cp "$(fix_classpath "$app_classpath")" \
+    -cp "$(fix_classpath "$new_classpath")" \
     "${mainclass[@]}" \
     "${app_commands[@]}" \
     "${residual_args[@]}"
@@ -365,8 +367,7 @@ declare -r app_home="$(realpath "$(dirname 
"$real_script_path")")"
 declare -r lib_dir="$(realpath "${app_home}/../lib")"
 declare -a app_mainclass=(org.apache.daffodil.debugger.dap.DAPodil)
 
-declare -r script_conf_file="${app_home}/../conf/application.ini"
-declare -a 
app_classpath="$lib_dir/org.apache.daffodil.daffodil-debugger-1.0.0-SNAPSHOT.jar:$lib_dir/org.scala-lang.scala-library-2.12.13.jar:$lib_dir/org.apache.daffodil.daffodil-sapi_2.12-3.1.0.jar:$lib_dir/org.apache.daffodil.daffodil-runtime1_2.12-3.1.0.jar:$lib_dir/ch.qos.logback.logback-classic-1.2.3.jar:$lib_dir/com.microsoft.java.com.microsoft.java.debug.core-0.31.1.jar:$lib_dir/co.fs2.fs2-io_2.12-3.0.4.jar:$lib_dir/com.monovore.decline-effect_2.12-2.1.0.jar:$lib_dir/org.typeleve
 [...]
+${{template_declares}}
 
 # java_cmd is overrode in process_args when -java-home is used
 declare java_cmd=$(get_java_cmd)
diff --git a/server/core/src/templates/bat-template 
b/server/core/src/templates/bat-template
index 35b06f8..1c21cf7 100644
--- a/server/core/src/templates/bat-template
+++ b/server/core/src/templates/bat-template
@@ -55,9 +55,7 @@ rem "-J" is stripped, "-D" is left as is, and everything is 
appended to JAVA_OPT
 set _JAVA_PARAMS=
 set _APP_ARGS=
 
-set 
"APP_CLASSPATH=%APP_LIB_DIR%\org.apache.daffodil.daffodil-debugger-1.0.0-SNAPSHOT.jar;%APP_LIB_DIR%\org.scala-lang.scala-library-2.12.13.jar;%APP_LIB_DIR%\org.apache.daffodil.daffodil-sapi_2.12-3.1.0.jar;%APP_LIB_DIR%\org.apache.daffodil.daffodil-runtime1_2.12-3.1.0.jar;%APP_LIB_DIR%\ch.qos.logback.logback-classic-1.2.3.jar;%APP_LIB_DIR%\com.microsoft.java.com.microsoft.java.debug.core-0.31.1.jar;%APP_LIB_DIR%\co.fs2.fs2-io_2.12-3.0.4.jar;%APP_LIB_DIR%\com.monovore.decline-effect_2.1
 [...]
-set "APP_MAIN_CLASS=org.apache.daffodil.debugger.dap.DAPodil"
-set "SCRIPT_CONF_FILE=%APP_HOME%\conf\application.ini"
+@@APP_DEFINES@@
 
 rem Bundled JRE has priority over standard environment variables
 if defined BUNDLED_JVM (
@@ -117,12 +115,14 @@ if defined CUSTOM_MAIN_CLASS (
 )
 
 if defined DAFFODIL_DEBUG_CLASSPATH (
-    set APP_CLASSPATH="%APP_CLASSPATH%;%DAFFODIL_DEBUG_CLASSPATH%"
+    set NEW_CLASSPATH="%APP_CLASSPATH%;%DAFFODIL_DEBUG_CLASSPATH%"
+) else (
+    set NEW_CLASSPATH="%APP_CLASSPATH%"
 )
 
 
 rem Call the application and pass all arguments unchanged.
-"%_JAVACMD%" !_JAVA_OPTS! !DAFFODIL_DEBUGGER_OPTS! -cp "%APP_CLASSPATH%" 
%MAIN_CLASS% !_APP_ARGS!
+"%_JAVACMD%" !_JAVA_OPTS! !DAFFODIL_DEBUGGER_OPTS! -cp "%NEW_CLASSPATH%" 
%MAIN_CLASS% !_APP_ARGS!
 
 @endlocal
 
diff --git a/src/daffodil.ts b/src/daffodil.ts
index 3fc13f2..4587339 100644
--- a/src/daffodil.ts
+++ b/src/daffodil.ts
@@ -15,6 +15,8 @@
  * limitations under the License.
  */
 
+import * as fs from 'fs'
+
 export const dataEvent = 'daffodil.data'
 export interface DaffodilData {
   bytePos1b: number
@@ -50,3 +52,7 @@ export interface BuildInfo {
   daffodilVersion: string
   scalaVersion: string
 }
+
+export function getDaffodilVersion(filePath: fs.PathLike) {
+  return JSON.parse(fs.readFileSync(filePath).toString())['daffodilVersion']
+}
diff --git a/src/daffodilDebugger.ts b/src/daffodilDebugger.ts
index 9929392..957f505 100644
--- a/src/daffodilDebugger.ts
+++ b/src/daffodilDebugger.ts
@@ -25,6 +25,7 @@ import { LIB_VERSION } from './version'
 import XDGAppPaths from 'xdg-app-paths'
 import * as path from 'path'
 import { regexp } from './utils'
+import { getDaffodilVersion } from './daffodil'
 
 const xdgAppPaths = XDGAppPaths({ name: 'daffodil-dap' })
 
@@ -41,9 +42,6 @@ class Artifact {
     os.platform() === 'win32' ? 'daffodil-debugger.bat' : './daffodil-debugger'
 }
 
-const daffodilVersion = '3.1.0' // TODO: will become a runtime parameter 
driven by config or artifacts in the releases repo
-const artifact = new Artifact(daffodilVersion)
-
 // Class for getting release data
 export class Release {
   name: string
@@ -89,6 +87,12 @@ export async function getDebugger(
   context: vscode.ExtensionContext,
   config: vscode.DebugConfiguration
 ) {
+  // Get daffodilVersion
+  const daffodilVersion = getDaffodilVersion(
+    context.asAbsolutePath('./package.json')
+  )
+  const artifact = new Artifact(daffodilVersion)
+
   // If useExistingServer var set to false make sure version of debugger 
entered is downloaded then ran
   if (!config.useExistingServer) {
     const delay = (ms: number) => new Promise((res) => setTimeout(res, ms))
diff --git a/src/tests/daffodil.test.ts b/src/tests/daffodil.test.ts
index dbab8f3..a6a7e9a 100644
--- a/src/tests/daffodil.test.ts
+++ b/src/tests/daffodil.test.ts
@@ -17,8 +17,24 @@
 
 import * as assert from 'assert'
 import * as daffodil from '../daffodil'
+import * as fs from 'fs'
+import * as path from 'path'
+import { before, after } from 'mocha'
 
 suite('Daffodfil', () => {
+  const PROJECT_ROOT = path.join(__dirname, '../../')
+  const packageFile = path.join(PROJECT_ROOT, 'package-test.json')
+
+  // Create test package.json before anything else happens
+  before(() => {
+    fs.writeFileSync(packageFile, JSON.stringify({ daffodilVersion: '0.0.0' }))
+  })
+
+  // Delete test package.json after all tests are done
+  after(() => {
+    fs.unlinkSync(packageFile)
+  })
+
   // suite to test all functions work properly
   suite('interfaces', () => {
     test('DaffodilData functions properly', () => {
@@ -119,4 +135,11 @@ suite('Daffodfil', () => {
       assert.strictEqual(daffodil.configEvent, 'daffodil.config')
     })
   })
+
+  suite('getDaffodilVersion', () => {
+    test('getDaffodilVersion returns same version as file', () => {
+      var daffodilVersion = daffodil.getDaffodilVersion(packageFile)
+      assert.strictEqual(daffodilVersion, '0.0.0')
+    })
+  })
 })

Reply via email to