forked from gretard/sonar-ps-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregenerateRulesDefinition.ps1
89 lines (69 loc) · 3.11 KB
/
regenerateRulesDefinition.ps1
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
$reportFile = Join-path $PSScriptRoot "sonar-ps-plugin\src\main\resources\powershell-rules.xml"
$profileFile = Join-path $PSScriptRoot "sonar-ps-plugin\src\main\resources\powershell-profile.xml"
$xmlProfileWriter = New-Object System.XMl.XmlTextWriter($profileFile , $Null);
# Set The Formatting
$xmlProfileWriter.Formatting = "Indented"
$xmlProfileWriter.Indentation = "4"
# Write the XML Declaration
$xmlProfileWriter.WriteStartDocument();
# Start Issues XML Element
$xmlProfileWriter.WriteStartElement("profile");
$xmlProfileWriter.WriteElementString("name", "Sonar way");
$xmlProfileWriter.WriteElementString("language", "ps");
$xmlProfileWriter.WriteStartElement("rules");
# Create The Document
$xmlWriter = New-Object System.XMl.XmlTextWriter($reportFile , $Null);
# Set The Formatting
$xmlWriter.Formatting = "Indented"
$xmlWriter.Indentation = "4"
# Write the XML Declaration
$xmlWriter.WriteStartDocument();
# Start Issues XML Element
$xmlWriter.WriteStartElement("psrules");
$powershellRules = Get-ScriptAnalyzerRule;
foreach ($rule in $powershellRules)
{
$xmlProfileWriter.WriteStartElement("rule");
$xmlProfileWriter.WriteElementString("key", $rule.RuleName);
$xmlProfileWriter.WriteElementString("repositoryKey", "ps-psanalyzer");
$xmlProfileWriter.WriteEndElement();
$xmlWriter.WriteStartElement("rule");
$xmlWriter.WriteElementString("key", $rule.RuleName)
$xmlWriter.WriteElementString("internalKey", $rule.RuleName)
$xmlWriter.WriteElementString("name", $rule.CommonName)
$xmlWriter.WriteElementString("description", $rule.Description)
$xmlWriter.WriteElementString("cardinality", "SINGLE")
$xmlWriter.WriteElementString("remediationFunction", "LINEAR")
$xmlWriter.WriteElementString("descriptionFormat", "MARKDOWN")
$xmlWriter.WriteElementString("remediationFunctionBaseEffort", "")
$remediationDefaultTime = "2min";
$severity = "INFO";
if ($rule.Severity -eq "Information") {
$severity = "INFO";
$remediationDefaultTime = "2min";
}
if ($rule.Severity -eq "Warning") {
$severity = "MAJOR";
$remediationDefaultTime = "5min";
}
if ($rule.Severity -eq "ERROR") {
$severity = "BLOCKER";
$remediationDefaultTime = "15min";
}
$xmlWriter.WriteElementString("debtRemediationFunctionCoefficient", $remediationDefaultTime);
$xmlWriter.WriteElementString("severity", $severity);
$xmlWriter.WriteEndElement();
}
# End Issues XML element
$xmlWriter.WriteEndElement();
# End the XML Document
$xmlWriter.WriteEndDocument();
# Finish The Document
$xmlWriter.Finalize
$xmlWriter.Flush
$xmlWriter.Close();
$xmlProfileWriter.WriteEndDocument();
# Finish The Document
$xmlProfileWriter.Finalize
$xmlProfileWriter.Flush
$xmlProfileWriter.Close();