-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
145 lines (125 loc) · 3.8 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
const {
toXML
} = require('jstoxml');
const fs = require('fs');
var jsonFail = require('./failure_cause.js').kb
function uuid() {
var chars = '0123456789abcdef'.split('');
var uuid = [],
rnd = Math.random,
r;
uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
uuid[14] = '4'; // version 4
for (var i = 0; i < 36; i++) {
if (!uuid[i]) {
r = 0 | rnd() * 16;
uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r & 0xf];
}
}
return uuid.join('');
}
let result = new Object([])
for (let el of jsonFail) {
try {
delete el.lastOccurred
delete el._id
delete el._removed
delete el.modifications
delete el.comment
//fix indications
for (let ind of el.indications) {
ind._name = ind['@class']
delete ind['@class']
ind._content = {
_name: 'pattern',
_content: ind.pattern
}
delete(ind.pattern)
}
} catch (e) {
console.error(e)
}
//rework category so it generated
// <categories class="java.util.Arrays$ArrayList">
// <a class="string-array">
// <string>BQ5</string>
// <string>B5</string>
// </a>
// </categories>
let tempArray = []
//retransform everthing
for (let key in el){
if(key == 'categories') {
let resultCategory = {}
resultCategory._content = {
_name: 'a',
_attrs: {class: 'string-array'},
_content: {
_name: 'string',
_content: el.categories
}
}
resultCategory._name = 'categories'
tempArray.push({ _name: 'categories',
_attrs: {'class':'java.util.Arrays$ArrayList'},
_content: {
_name: 'a',
_attrs: {class: 'string-array'},
_content: {
_name: 'string',
_content: el.categories
}
}
})
} else {
tempArray.push({ _name: key,
_content: el[key]
})
}
}
//uuid
let temp = tempArray
// let temp = Object.assign(el)
let id = uuid()
temp.id = id
//structure
result.push({
_name: 'entry',
_content: [
{
string: id
},
{ _name: 'com.sonyericsson.jenkins.plugins.bfa.model.FailureCause',
_content: temp
}
]
})
}
let resultForReal = {
_name: 'causes',
_content: result
}
const xmlOptions = {
header: false,
indent: ' '
};
var xml = toXML(resultForReal, xmlOptions)
var header = `<?xml version='1.1' encoding='UTF-8'?>
<com.sonyericsson.jenkins.plugins.bfa.PluginImpl plugin="[email protected]">
<noCausesMessage>No problems were identified. If you know why this problem occurred, please add a suitable Cause for it.</noCausesMessage>
<doNotAnalyzeAbortedJob>false</doNotAnalyzeAbortedJob>
<knowledgeBase class="com.sonyericsson.jenkins.plugins.bfa.db.LocalFileKnowledgeBase">`
var footer = `
</knowledgeBase>
<nrOfScanThreads>3</nrOfScanThreads>
<maxLogSize>0</maxLogSize>
<testResultCategories></testResultCategories>
<sodVariables>
<minimumSodWorkerThreads>0</minimumSodWorkerThreads>
<maximumSodWorkerThreads>0</maximumSodWorkerThreads>
<sodThreadKeepAliveTime>0</sodThreadKeepAliveTime>
<sodWaitForJobShutdownTimeout>0</sodWaitForJobShutdownTimeout>
<sodCorePoolNumberOfThreads>0</sodCorePoolNumberOfThreads>
</sodVariables>
</com.sonyericsson.jenkins.plugins.bfa.PluginImpl>`
fs.writeFileSync('./result.xml', header + xml + footer)