stevedlawrence commented on code in PR #1452: URL: https://github.com/apache/daffodil-vscode/pull/1452#discussion_r2417020160
########## src/daffodilDebugger/daffodilJars.ts: ########## @@ -0,0 +1,64 @@ +/* + * 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' +import * as fs from 'fs' +import * as unzip from 'unzip-stream' +import * as os from 'os' +import { pipeline } from 'stream/promises' + +import { outputChannel } from '../adapter/activateDaffodilDebug' + +async function downloadAndExtractDaffodilCLIJars( + url: string, + targetDir: string +): Promise<void> { + outputChannel.appendLine( + `[INFO] Daffodil CLI JARs don't exist. Downloading and extracting...` + ) + + const res = await fetch(url) + if (!res.ok || !res.body) { + throw new Error( + `Failed to download ${url}: ${res.status} ${res.statusText}` + ) + } + + // Pipe the response body stream into unzip-stream and wait for completion + await pipeline(res.body as any, unzip.Extract({ path: targetDir })) +} + +export async function checkIfDaffodilJarsNeeded(daffodilVersion: string) { + const destFolder = path.join(os.homedir(), '.cache', 'daffodil-debugger') Review Comment: Suggest this wants to be VS Code extension global storage and not a users home directory. ########## package.json: ########## @@ -3,7 +3,11 @@ "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.4.2-SNAPSHOT", - "daffodilVersion": "3.11.0", + "daffodilScalaVersions": { + "<=3.10.0,<3.11.0": "2.12", Review Comment: Is the `<3.11.0` needed here? Does the <=3.10.0 ensure it's <3.11.0? ########## debugger/src/main/scala-3/org.apache.daffodil.debugger.dap/Support.scala: ########## @@ -0,0 +1,64 @@ +/* + * 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. + */ + +/** This file contains support code for making a majority of Scala shareable between different versions of Scala and + * Daffodil. The main difference comes in package names, converting certain variables, etc. This file has all the + * helper code for that for Scala 3. + */ + +package org.apache.daffodil.debugger.dap + +import java.io._ +import java.nio.file.Path +import org.apache.daffodil.api._ +import org.apache.daffodil.io.InputSourceDataInputStream +import scala.jdk.CollectionConverters._ + +object Support { + /* Daffodil DataProcessor wrapper methods */ + def dataProcessorWithDebugger(p: DataProcessor, debugger: Debugger, variables: Map[String, String]): DataProcessor = + p.withDebugger(debugger) + .withExternalVariables(variables.asJava) + .withValidation("daffodil") + + /* Daffodil InputSourceDataInputStream wrapper methods */ + def getInputSourceDataInputStream(data: InputStream): InputSourceDataInputStream = InputSourceDataInputStream(data) + + /* Daffodil ProcessorFactory wrapper methods */ + def getProcessorFactory( + schema: Path, + rootName: Option[String], + rootNamespace: Option[String], + tunables: Map[String, String] + ): ProcessorFactory = { + val compiler = Daffodil + .compiler() + .withTunables(tunables.asJava) + + (rootName, rootNamespace) match { + case (Some(name), Some(ns)) => compiler.compileFile(schema.toFile(), name, ns) + case (Some(name), None) => compiler.compileFile(schema.toFile(), name) + case _ => compiler.compileFile(schema.toFile()) + } Review Comment: the compileFile supports nulls, so this match/case should be able be replaced with: ```scala compiler.compileFile(schema.toFile(), name.orNull, ns.orNull) ``` ########## debugger/src/main/scala/org.apache.daffodil.debugger.dap/DAPodil.scala: ########## @@ -434,29 +436,55 @@ object DAPodil extends IOApp { .withDefault(4711), Opts .option[Duration]("listenTimeout", "duration to wait for a DAP client connection (default: 10s)") - .withDefault(10.seconds) - ).mapN(Options) + .withDefault(10.seconds), + Opts + .option[String]("daffodilVersion", "version of Daffodil to use (default: 3.11.0)") + .withDefault("3.11.0") + ).mapN(Options.apply) implicit val logger: Logger[IO] = Slf4jLogger.getLogger - val header = - s"""| - |****************************************************** - |A DAP server for debugging Daffodil schema processors. - | - |Build info: - | version: ${BuildInfo.version} - | daffodilVersion: ${BuildInfo.daffodilVersion} - | scalaVersion: ${BuildInfo.scalaVersion} - | sbtVersion: ${BuildInfo.sbtVersion} - |Runtime info: - | JVM version: ${System.getProperty("java.version")} (${System.getProperty("java.home")}) - |******************************************************""".stripMargin + def getHeader(daffodilVersion: Option[String]): String = { + val header = + s"""| + |****************************************************** + |A DAP server for debugging Daffodil schema processors. + | + |Build info: + | version: ${BuildInfo.version} + | scalaVersion: ${BuildInfo.scalaVersion} + | sbtVersion: ${BuildInfo.sbtVersion} + |Runtime info: + | JVM version: ${System.getProperty("java.version")} (${System.getProperty("java.home")}) + |******************************************************""".stripMargin + + daffodilVersion match { + case Some(version) => + header.replace( + s"Runtime info:", + s"Runtime info:\n Daffodil Version: ${version}" + ) + case None => header + } + } + + def getDaffodilCLIJars(daffodilVersion: String): Unit = { + val url = + s"https://www.apache.org/dyn/closer.lua/download/daffodil/${daffodilVersion}/bin/apache-daffodil-${daffodilVersion}-bin.zip" + val dest = Paths.get(sys.props("user.home"), ".cache", "daffodil-debugger") Review Comment: This probably isn't the right directory for windows? I'm not sure what it woudld be, but I don't think windows really uses hidden directories in users home dirs. Feels to me like the VS Code extension global global storage is the place for these. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
