From 75d377b8896272ac385bc5ce28346abca34a8b9c Mon Sep 17 00:00:00 2001 From: Venelin Bakalov Date: Fri, 31 May 2024 15:09:24 +0300 Subject: [PATCH] Update XML parser usage to match new interfaces --- extension/src/client/lint/rule/ToolchainVersionRule.ts | 8 ++++---- extension/src/client/provider/content/RemoteDocument.ts | 6 +++--- extension/src/client/system/ConfigurationManager.ts | 8 ++++---- packages/node/vrdt-common/src/maven/PomFile.ts | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/extension/src/client/lint/rule/ToolchainVersionRule.ts b/extension/src/client/lint/rule/ToolchainVersionRule.ts index d9e2afbf..a7137277 100644 --- a/extension/src/client/lint/rule/ToolchainVersionRule.ts +++ b/extension/src/client/lint/rule/ToolchainVersionRule.ts @@ -3,9 +3,9 @@ * SPDX-License-Identifier: MIT */ -import * as xmlParser from "fast-xml-parser" -import * as semver from "semver" import { Logger, PomFile } from "@vmware/vrdt-common" +import { XMLParser, XMLValidator } from "fast-xml-parser" +import * as semver from "semver" import * as vscode from "vscode" import { Patterns } from "../../constants" @@ -20,7 +20,7 @@ export class ToolchainVersionRule extends PomLintRule { apply(document: vscode.TextDocument): vscode.Diagnostic[] { const pomXmlContent = document.getText() - if (!xmlParser.validate(pomXmlContent)) { + if (!XMLValidator.validate(pomXmlContent)) { this.logger.info("Not valid XML") return [] } @@ -59,7 +59,7 @@ export class ToolchainVersionRule extends PomLintRule { } private extractParentVersion(pomXmlContent: string): string | null { - const pomXml = xmlParser.parse(pomXmlContent) + const pomXml = new XMLParser().parse(pomXmlContent) if (!pomXml.project || !pomXml.project.parent) { this.logger.warn("Missing parent tag") diff --git a/extension/src/client/provider/content/RemoteDocument.ts b/extension/src/client/provider/content/RemoteDocument.ts index ef98968e..398ef8c4 100644 --- a/extension/src/client/provider/content/RemoteDocument.ts +++ b/extension/src/client/provider/content/RemoteDocument.ts @@ -6,10 +6,10 @@ import * as path from "path" import { Logger, VroRestClient } from "@vmware/vrdt-common" -import * as vscode from "vscode" import * as AdmZip from "adm-zip" +import { XMLParser } from "fast-xml-parser" import * as fs from "fs-extra" -import * as xmlParser from "fast-xml-parser" +import * as vscode from "vscode" import { ContentLocation } from "./ContentLocation" @@ -105,7 +105,7 @@ export class RemoteDocument { "@t": string "#text": string } - let xml = xmlParser.parse(source, { ignoreAttributes: false, attributeNamePrefix: "@" }) + let xml = new XMLParser({ ignoreAttributes: false, attributeNamePrefix: "@" }).parse(source) xml = xml["dunes-script-module"] let js = "/**\n" diff --git a/extension/src/client/system/ConfigurationManager.ts b/extension/src/client/system/ConfigurationManager.ts index 0cd60dcb..5e06d7da 100644 --- a/extension/src/client/system/ConfigurationManager.ts +++ b/extension/src/client/system/ConfigurationManager.ts @@ -5,9 +5,6 @@ import * as path from "path" -import * as chokidar from "chokidar" -import * as xmlParser from "fast-xml-parser" -import * as fs from "fs-extra" import { AutoWire, BaseConfiguration, @@ -16,6 +13,9 @@ import { MavenProfileWrapper, VrealizeSettings } from "@vmware/vrdt-common" +import * as chokidar from "chokidar" +import { XMLParser } from "fast-xml-parser" +import * as fs from "fs-extra" import * as vscode from "vscode" import { BuiltInCommands } from "../constants" @@ -105,7 +105,7 @@ export class ConfigurationManager extends BaseConfiguration implements Registrab return } - const settingsJson = xmlParser.parse(settingsXmlContent.toString("utf8")) + const settingsJson = new XMLParser().parse(settingsXmlContent.toString("utf8")) const allProfiles = settingsJson?.settings?.profiles?.profile const vroProfiles: MavenProfilesMap = {} diff --git a/packages/node/vrdt-common/src/maven/PomFile.ts b/packages/node/vrdt-common/src/maven/PomFile.ts index e8f864b6..6741ccfc 100644 --- a/packages/node/vrdt-common/src/maven/PomFile.ts +++ b/packages/node/vrdt-common/src/maven/PomFile.ts @@ -3,7 +3,7 @@ * SPDX-License-Identifier: MIT */ -import * as xmlParser from "fast-xml-parser" +import { XMLParser } from "fast-xml-parser" import * as fs from "fs-extra" export class PomFile { @@ -56,7 +56,7 @@ export class PomFile { constructor(public readonly filePath: string) { const pomContent = fs.readFileSync(filePath, { encoding: "utf8" }) - this.jsonContent = xmlParser.parse(pomContent) + this.jsonContent = new XMLParser().parse(pomContent) if (!this.jsonContent.project || !this.jsonContent.project.parent) { throw new Error(`Missing parent tag [file = ${filePath}]`)