Skip to content

Commit

Permalink
FT Variable Substitution - Parser changed from ltx to xmldom (#11401)
Browse files Browse the repository at this point in the history
Parser changed from ltx to xmldom
  • Loading branch information
eaarora-ms authored and leantk committed Dec 23, 2019
1 parent 3f8beba commit 4d31596
Show file tree
Hide file tree
Showing 17 changed files with 227 additions and 107 deletions.
2 changes: 1 addition & 1 deletion Tasks/AzureMysqlDeploymentV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"version": {
"Major": 1,
"Minor": 156,
"Patch": 10
"Patch": 11
},
"demands": [],
"minimumAgentVersion": "1.100.0",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureMysqlDeploymentV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"version": {
"Major": 1,
"Minor": 156,
"Patch": 10
"Patch": 11
},
"demands": [],
"minimumAgentVersion": "1.100.0",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureRmWebAppDeploymentV4/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 4,
"Minor": 157,
"Patch": 4
"Patch": 5
},
"releaseNotes": "What's new in version 4.*<br />Supports Zip Deploy, Run From Package, War Deploy [Details here](https://aka.ms/appServiceDeploymentMethods)<br />Supports App Service Environments<br />Improved UI for discovering different App service types supported by the task<br/>Run From Package is the preferred deployment method, which makes files in wwwroot folder read-only<br/>Click [here](https://aka.ms/azurermwebdeployreadme) for more information.",
"minimumAgentVersion": "2.104.1",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureRmWebAppDeploymentV4/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 4,
"Minor": 157,
"Patch": 4
"Patch": 5
},
"releaseNotes": "ms-resource:loc.releaseNotes",
"minimumAgentVersion": "2.104.1",
Expand Down
81 changes: 81 additions & 0 deletions Tasks/Common/webdeployment-common-v2/npmdomutility.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
2 changes: 1 addition & 1 deletion Tasks/Common/webdeployment-common-v2/variableutility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
219 changes: 125 additions & 94 deletions Tasks/Common/webdeployment-common-v2/xmlvariablesubstitutionutility.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Tasks/FileTransformV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 1,
"Minor": 156,
"Patch": 3
"Patch": 4
},
"instanceNameFormat": "File Transform: $(Package)",
"groups": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/FileTransformV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 1,
"Minor": 156,
"Patch": 3
"Patch": 4
},
"instanceNameFormat": "ms-resource:loc.instanceNameFormat",
"groups": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/FileTransformV2/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 2,
"Minor": 0,
"Patch": 1
"Patch": 2
},
"preview": "true",
"releaseNotes": "More optimized task fields that allow users to enable any/all of the transformation (XML), variable substitution (JSON and XML) features in a single task instance.</br>Task fails when any of the configured transformation/substitution is NOT applied or when the task is no-op.",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/FileTransformV2/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 2,
"Minor": 0,
"Patch": 1
"Patch": 2
},
"preview": "true",
"releaseNotes": "ms-resource:loc.releaseNotes",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/IISWebAppDeploymentOnMachineGroupV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"version": {
"Major": 0,
"Minor": 156,
"Patch": 3
"Patch": 4
},
"demands": [],
"minimumAgentVersion": "2.104.1",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/IISWebAppDeploymentOnMachineGroupV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"version": {
"Major": 0,
"Minor": 156,
"Patch": 3
"Patch": 4
},
"demands": [],
"minimumAgentVersion": "2.104.1",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/MysqlDeploymentOnMachineGroupV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"version": {
"Major": 1,
"Minor": 156,
"Patch": 4
"Patch": 5
},
"demands": [],
"minimumAgentVersion": "1.100.0",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/MysqlDeploymentOnMachineGroupV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"version": {
"Major": 1,
"Minor": 156,
"Patch": 4
"Patch": 5
},
"demands": [],
"minimumAgentVersion": "1.100.0",
Expand Down
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,8 @@
"typed-rest-client": "1.0.9",
"typescript": "2.3.4",
"validator": "3.33.0"
},
"dependencies": {
"xmldom": "^0.1.27"
}
}

0 comments on commit 4d31596

Please sign in to comment.