From b4692e1fbdf2f6ae7cf922156fcba312e2beab24 Mon Sep 17 00:00:00 2001
From: Eavanshi Arora <52486630+eaarora-ms@users.noreply.github.com>
Date: Fri, 11 Oct 2019 13:30:04 +0530
Subject: [PATCH] FT Variable Substitution - Parser changed from ltx to xmldom
(#11401)
Parser changed from ltx to xmldom
---
Tasks/AzureMysqlDeploymentV1/task.json | 2 +-
Tasks/AzureMysqlDeploymentV1/task.loc.json | 2 +-
Tasks/AzureRmWebAppDeploymentV4/task.json | 2 +-
Tasks/AzureRmWebAppDeploymentV4/task.loc.json | 2 +-
.../webdeployment-common-v2/npmdomutility.ts | 81 +++++++
.../variableutility.ts | 2 +-
.../xmlvariablesubstitutionutility.ts | 219 ++++++++++--------
Tasks/FileTransformV1/task.json | 2 +-
Tasks/FileTransformV1/task.loc.json | 2 +-
Tasks/FileTransformV2/task.json | 2 +-
Tasks/FileTransformV2/task.loc.json | 2 +-
.../task.json | 2 +-
.../task.loc.json | 2 +-
.../MysqlDeploymentOnMachineGroupV1/task.json | 2 +-
.../task.loc.json | 2 +-
package-lock.json | 5 +
package.json | 3 +
17 files changed, 227 insertions(+), 107 deletions(-)
create mode 100644 Tasks/Common/webdeployment-common-v2/npmdomutility.ts
diff --git a/Tasks/AzureMysqlDeploymentV1/task.json b/Tasks/AzureMysqlDeploymentV1/task.json
index d1d705f189d8..6c96ad3f4aa9 100644
--- a/Tasks/AzureMysqlDeploymentV1/task.json
+++ b/Tasks/AzureMysqlDeploymentV1/task.json
@@ -17,7 +17,7 @@
"version": {
"Major": 1,
"Minor": 156,
- "Patch": 10
+ "Patch": 11
},
"demands": [],
"minimumAgentVersion": "1.100.0",
diff --git a/Tasks/AzureMysqlDeploymentV1/task.loc.json b/Tasks/AzureMysqlDeploymentV1/task.loc.json
index 9cfe02563b65..903d4be60174 100644
--- a/Tasks/AzureMysqlDeploymentV1/task.loc.json
+++ b/Tasks/AzureMysqlDeploymentV1/task.loc.json
@@ -17,7 +17,7 @@
"version": {
"Major": 1,
"Minor": 156,
- "Patch": 10
+ "Patch": 11
},
"demands": [],
"minimumAgentVersion": "1.100.0",
diff --git a/Tasks/AzureRmWebAppDeploymentV4/task.json b/Tasks/AzureRmWebAppDeploymentV4/task.json
index 2b3b757e9327..aa9ca41e5d91 100644
--- a/Tasks/AzureRmWebAppDeploymentV4/task.json
+++ b/Tasks/AzureRmWebAppDeploymentV4/task.json
@@ -18,7 +18,7 @@
"version": {
"Major": 4,
"Minor": 157,
- "Patch": 4
+ "Patch": 5
},
"releaseNotes": "What's new in version 4.*
Supports Zip Deploy, Run From Package, War Deploy [Details here](https://aka.ms/appServiceDeploymentMethods)
Supports App Service Environments
Improved UI for discovering different App service types supported by the task
Run From Package is the preferred deployment method, which makes files in wwwroot folder read-only
Click [here](https://aka.ms/azurermwebdeployreadme) for more information.",
"minimumAgentVersion": "2.104.1",
diff --git a/Tasks/AzureRmWebAppDeploymentV4/task.loc.json b/Tasks/AzureRmWebAppDeploymentV4/task.loc.json
index 5d621b033767..ca8481553bb5 100644
--- a/Tasks/AzureRmWebAppDeploymentV4/task.loc.json
+++ b/Tasks/AzureRmWebAppDeploymentV4/task.loc.json
@@ -18,7 +18,7 @@
"version": {
"Major": 4,
"Minor": 157,
- "Patch": 4
+ "Patch": 5
},
"releaseNotes": "ms-resource:loc.releaseNotes",
"minimumAgentVersion": "2.104.1",
diff --git a/Tasks/Common/webdeployment-common-v2/npmdomutility.ts b/Tasks/Common/webdeployment-common-v2/npmdomutility.ts
new file mode 100644
index 000000000000..4fbe86e1951a
--- /dev/null
+++ b/Tasks/Common/webdeployment-common-v2/npmdomutility.ts
@@ -0,0 +1,81 @@
+var varUtility = require("./variableutility.js");
+var DOMParser = require('xmldom').DOMParser;
+
+export class NpmDomUtility {
+
+ private xmlDomLookUpTable = {};
+ private xmlDom;
+
+ public constructor(xmlContent) {
+ this.xmlDomLookUpTable = {};
+ this.xmlDom = new DOMParser().parseFromString(xmlContent,"text/xml");
+ this.buildLookUpTable(this.xmlDom);
+ }
+
+ public getXmlDom() {
+ return this.xmlDom;
+ }
+
+ public getContentWithHeader(xmlDom) {
+ return xmlDom ? xmlDom.toString() : "";
+ }
+
+ /**
+ * Define method to create a lookup for DOM
+ */
+ private buildLookUpTable(node) {
+ if(node){
+ let nodeName = node.nodeName;
+ if(nodeName){
+ nodeName = nodeName.toLowerCase();
+ let listOfNodes = this.xmlDomLookUpTable[nodeName];
+ if(listOfNodes == null || !(Array.isArray(listOfNodes))) {
+ this.xmlDomLookUpTable[nodeName] = [];
+ }
+ (this.xmlDomLookUpTable[nodeName]).push(node);
+ if(node.hasChildNodes()) {
+ let children = node.childNodes;
+ for(let i=0 ; i < children.length; i++) {
+ this.buildLookUpTable(children[i]);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Returns array of nodes which match with the tag name.
+ */
+ public getElementsByTagName(nodeName) {
+ if(varUtility.isEmpty(nodeName))
+ return [];
+ let selectedElements = this.xmlDomLookUpTable[nodeName.toLowerCase()];
+ if(!selectedElements){
+ selectedElements = [];
+ }
+ return selectedElements;
+ }
+
+ /**
+ * Search in subtree with provided node name
+ */
+ public getChildElementsByTagName(node, tagName) {
+ if(!varUtility.isObject(node) )
+ return [];
+ var liveNodes = [];
+ if(node.hasChildNodes()){
+ var children = node.childNodes;
+ for(let i=0; i < children.length; i++ ){
+ let childName = children[i].nodeName;
+ if( !varUtility.isEmpty(childName) && tagName == childName){
+ liveNodes.push(children[i]);
+ }
+ let liveChildNodes = this.getChildElementsByTagName(children[i], tagName);
+ if(liveChildNodes && liveChildNodes.length > 0){
+ liveNodes = liveNodes.concat(liveChildNodes);
+ }
+ }
+ }
+ return liveNodes;
+ }
+}
diff --git a/Tasks/Common/webdeployment-common-v2/variableutility.ts b/Tasks/Common/webdeployment-common-v2/variableutility.ts
index cfbf989df143..2cd878c06a26 100644
--- a/Tasks/Common/webdeployment-common-v2/variableutility.ts
+++ b/Tasks/Common/webdeployment-common-v2/variableutility.ts
@@ -11,7 +11,7 @@ export function isPredefinedVariable(variable: string): boolean {
}
export function isEmpty(object){
- if(object == null || object == "")
+ if(object == null || object == "" || (object.toString()).trim() == null || (object.toString()).trim() == "")
return true;
return false;
}
diff --git a/Tasks/Common/webdeployment-common-v2/xmlvariablesubstitutionutility.ts b/Tasks/Common/webdeployment-common-v2/xmlvariablesubstitutionutility.ts
index 78a93c9da99b..ccca8b9f4e33 100644
--- a/Tasks/Common/webdeployment-common-v2/xmlvariablesubstitutionutility.ts
+++ b/Tasks/Common/webdeployment-common-v2/xmlvariablesubstitutionutility.ts
@@ -1,28 +1,37 @@
-import Q = require('q');
import tl = require('azure-pipelines-task-lib/task');
import fs = require('fs');
import path = require('path');
-var ltx = require("ltx");
var varUtility = require ('./variableutility.js');
var ltxdomutility = require("./ltxdomutility.js");
+var npmdomutility = require("./npmdomutility.js");
var fileEncoding = require('./fileencoding.js');
function getReplacableTokenFromTags(xmlNode, variableMap) {
var parameterSubValue = {};
- for (var childNode of xmlNode.children) {
- if(!varUtility.isObject(childNode)) {
- continue;
- }
- for(var nodeAttribute in childNode.attrs) {
- if (childNode.attrs[nodeAttribute].startsWith('$(ReplacableToken_') && variableMap[childNode.attrs['name']]) {
- var indexOfReplaceToken = '$(ReplacableToken_'.length;
- var lastIndexOf_ = childNode.attrs[nodeAttribute].lastIndexOf('_');
- if(lastIndexOf_ <= indexOfReplaceToken) {
- tl.debug('Attribute value is in incorrect format ! ' + childNode.attrs[nodeAttribute]);
- continue;
+ if(xmlNode.hasChildNodes()) {
+ var children = xmlNode.childNodes;
+ for (let childs = 0; childs < children.length; childs ++) {
+ let childNode = children[childs];
+ if ((varUtility.isObject(childNode)) && (!varUtility.isEmpty(childNode))) {
+ if(childNode.attributes) {
+ let childNodeAttributes = childNode.attributes;
+ let childNodeAttributeName;
+ for (let nodeAttribute=0 ; nodeAttributeTask fails when any of the configured transformation/substitution is NOT applied or when the task is no-op.",
diff --git a/Tasks/FileTransformV2/task.loc.json b/Tasks/FileTransformV2/task.loc.json
index fb2ee5f843d9..80e9680327d6 100644
--- a/Tasks/FileTransformV2/task.loc.json
+++ b/Tasks/FileTransformV2/task.loc.json
@@ -18,7 +18,7 @@
"version": {
"Major": 2,
"Minor": 0,
- "Patch": 1
+ "Patch": 2
},
"preview": "true",
"releaseNotes": "ms-resource:loc.releaseNotes",
diff --git a/Tasks/IISWebAppDeploymentOnMachineGroupV0/task.json b/Tasks/IISWebAppDeploymentOnMachineGroupV0/task.json
index d50c7546f5ce..5de085fb4c41 100644
--- a/Tasks/IISWebAppDeploymentOnMachineGroupV0/task.json
+++ b/Tasks/IISWebAppDeploymentOnMachineGroupV0/task.json
@@ -17,7 +17,7 @@
"version": {
"Major": 0,
"Minor": 156,
- "Patch": 3
+ "Patch": 4
},
"demands": [],
"minimumAgentVersion": "2.104.1",
diff --git a/Tasks/IISWebAppDeploymentOnMachineGroupV0/task.loc.json b/Tasks/IISWebAppDeploymentOnMachineGroupV0/task.loc.json
index ce55cf27ee25..6766666e444c 100644
--- a/Tasks/IISWebAppDeploymentOnMachineGroupV0/task.loc.json
+++ b/Tasks/IISWebAppDeploymentOnMachineGroupV0/task.loc.json
@@ -17,7 +17,7 @@
"version": {
"Major": 0,
"Minor": 156,
- "Patch": 3
+ "Patch": 4
},
"demands": [],
"minimumAgentVersion": "2.104.1",
diff --git a/Tasks/MysqlDeploymentOnMachineGroupV1/task.json b/Tasks/MysqlDeploymentOnMachineGroupV1/task.json
index b81650459086..a226bd1b05ea 100644
--- a/Tasks/MysqlDeploymentOnMachineGroupV1/task.json
+++ b/Tasks/MysqlDeploymentOnMachineGroupV1/task.json
@@ -17,7 +17,7 @@
"version": {
"Major": 1,
"Minor": 156,
- "Patch": 4
+ "Patch": 5
},
"demands": [],
"minimumAgentVersion": "1.100.0",
diff --git a/Tasks/MysqlDeploymentOnMachineGroupV1/task.loc.json b/Tasks/MysqlDeploymentOnMachineGroupV1/task.loc.json
index 24728f53c10a..4b59dfa49e31 100644
--- a/Tasks/MysqlDeploymentOnMachineGroupV1/task.loc.json
+++ b/Tasks/MysqlDeploymentOnMachineGroupV1/task.loc.json
@@ -17,7 +17,7 @@
"version": {
"Major": 1,
"Minor": 156,
- "Patch": 4
+ "Patch": 5
},
"demands": [],
"minimumAgentVersion": "1.100.0",
diff --git a/package-lock.json b/package-lock.json
index 040e9ad55c70..38be5acfca30 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -896,6 +896,11 @@
"resolved": "https://registry.npmjs.org/xml/-/xml-1.0.1.tgz",
"integrity": "sha1-eLpyAgApxbyHuKgaPPzXS0ovweU=",
"dev": true
+ },
+ "xmldom": {
+ "version": "0.1.27",
+ "resolved": "https://registry.npmjs.org/xmldom/-/xmldom-0.1.27.tgz",
+ "integrity": "sha1-1QH5ezvbQDr4757MIFcxh6rawOk="
}
}
}
diff --git a/package.json b/package.json
index 3c7ac1701f84..990749eb9823 100644
--- a/package.json
+++ b/package.json
@@ -45,5 +45,8 @@
"typed-rest-client": "1.0.9",
"typescript": "2.3.4",
"validator": "3.33.0"
+ },
+ "dependencies": {
+ "xmldom": "^0.1.27"
}
}