-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsourceanalyzer.sh
268 lines (227 loc) · 8.78 KB
/
sourceanalyzer.sh
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
#!/bin/bash
#Bash completion for SCA and tools - http://github.com/andersonshatch/sca-bash-completion
#Copyright (c) 2018 Josh Anderson
#See attached LICENSE or visit above URL
_sourceanalyzer()
{
local cur prev opts
COMPREPLY=() #Output array
cur="${COMP_WORDS[COMP_CWORD]}" #Current word
prev="${COMP_WORDS[COMP_CWORD-1]}" #Previous word
opts="-64 -append -autoheap -b -build-label -build-project -build-version -cp -classpath -clean -clobber-log"
opts="$opts -debug -debug-verbose -disable-default-rule-type -disable-language -disable-source-bundling -dotnet-sources"
opts="$opts -enable-language -encoding -exclude -exit-code-level -export-build-session -f -filter -findbugs -format"
opts="$opts -h -help -import-build-session -incremental -incremental-base -j -libdirs -list-options -logfile -mt"
opts="$opts -no-default-issue-rules -no-default-rules -no-default-source-rules -no-default-sink-rules"
opts="$opts -php-source-root -php-version -python-path -python-version -quick -quiet -ruby-path -rubygem-path -rules"
opts="$opts -scan -show-files -show-build-ids -show-build-tree -show-build-warnings -show-loc -source -sql-language"
opts="$opts -verbose -version -vsversion -Xms -Xmx -Xss -?"
local completions=()
if [[ ${prev} == "-b" ]] ; then
#Complete from known build IDs
local fortifyDir="$HOME/.fortify/sca"
if [[ -n $COMSPEC ]] ; then
#Windows, assume cygwin
local fortifyDir=`cygpath $LOCALAPPDATA/fortify/sca`
fi
#Find the character index of the version number in the fortify directory
local sortPoint=$(( ${#fortifyDir} + 1 ))
#Sort the part of the path after sca, i.e. the version number -- ensures that e.g. 16.10 will properly be higher than 6.4
local buildDir=`ls -d $fortifyDir*/build 2> /dev/null | sort -k 1."$sortPoint"n | tail -n 1`
completions=`find $buildDir -name "*.scasession" -exec basename {} .scasession \;`
elif [[ ${prev} == "-import-build-session" ]] ; then
#Filename completion - .mbs
_filedir 'mbs'
return 0
elif [[ ${prev} == "-disable-language" ]] || [[ ${prev} == "-enable-language" ]] ; then
#language completion
completions="abap apex actionscript asp cfml cobol configuration cpp dotnet java javascript jsp objc php plsql python ruby scala sql swift tsql typescript vb"
elif [[ ${prev} == "-exit-code-level" ]] ; then
#exit code level completion
completions="errors nothing no_output_file warnings"
elif [[ ${prev} == "-rules" ]] ; then
#Filename completion - .xml and .bin
_filedir '@(xml|bin)'
return 0
elif [[ ${prev} == "-php-version" ]] ; then
#PHP version completion
completions=`echo 4 5.{0..6} 7.{0..1}`
elif [[ ${prev} == "-python-version" ]] ; then
#Python version completion
completions="2 3"
elif [[ ${prev} == "-source" ]] ; then
#Complete supported JDK versions
completions=`echo 1.{3..9}`
elif [[ ${prev} == "-sql-language" ]] ; then
#Complete SQL dialects
completions="PLSQL TSQL"
elif [[ ${prev} == "-vsversion" ]] ; then
#Complete VS versions
completions=`echo 7.1 {8..12}.0`
elif [[ ${cur} == -* ]] ; then
#Complete from the list if current word starts with a -
completions=$opts
else
#Fallback to file/folder completions
_filedir
return 0
fi
COMPREPLY=( $(compgen -W "${completions}" -- ${cur}) )
return 0
}
complete -F _sourceanalyzer sourceanalyzer sourceanalyzer.exe
_fortifyclient()
{
local cur prev keywords switches
COMPREPLY=() #Output array
cur="${COMP_WORDS[COMP_CWORD]}" #Current word
prev="${COMP_WORDS[COMP_CWORD-1]}" #Previous word
keywords="archiveRuntimeEvents checkPermission"
keywords="$keywords deleteRuntimeEventArchive downloadAttachment downloadFPR downloadRuntimeEventArchive"
keywords="$keywords import invalidatetoken listProjectVersions listRuntimeApplications listRuntimeEventArchives listtokens"
keywords="$keywords purgeProjectVersion restoreRuntimeEventArchive"
keywords="$keywords token uploadFPR uploadSource"
switches="-applicationIds -archiveId -attachmentId -authtoken -bundle -daysToLive -debug"
switches="$switches -endDate -entityId -f -file -force -gettoken -help"
switches="$switches -includeSource -invalidate -invalidateById -invalidateForUser"
switches="$switches -machineoutput -password -permissionName -project -projectVersionID -proxyurl"
switches="$switches -scanDate -startDate -url -user -version"
local completions=()
if [[ $(($COMP_CWORD-1)) == 0 ]] ; then
#Keyword completion
completions=$keywords
elif [[ ${prev} == "-f" ]] || [[ ${prev} == "-file" ]] || [[ ${prev} == "-bundle" ]] ; then
#File completion
_filedir
return 0
elif [[ ${prev} == "-url" ]] ; then
#Complete from user specified SSC URL
completions=$SSC_URL
elif [[ ${prev} == "-user" ]] ; then
if [[ -n $SSC_USER ]] ; then
#Complete user specified SSC username
completions=$SSC_USER
else
#Complete guessed usernames (just admin and current username)
completions="admin $USER"
fi
elif [[ ${prev} == "-gettoken" ]] ; then
#Complete default token types
completions="AnalysisDownloadToken AnalysisUploadToken AuditToken CIToken CloudCtrlToken DownloadFileTransferToken JenkinsToken"
completions="$completions ReportToken ReportFileTransferToken UnifiedLoginToken UploadFileTransferToken"
else
#Switch completion
completions=$switches
fi
COMPREPLY=( $(compgen -W "${completions}" -- ${cur} ) )
return 0
}
complete -F _fortifyclient fortifyclient fortifyclient.bat
_fprutility()
{
local cur prev switches
COMPREPLY=() #Output array
cur="${COMP_WORDS[COMP_CWORD]}" #Current word
prev="${COMP_WORDS[COMP_CWORD-1]}" #Previous word
switches="-analyzerIssueCounts -categoryIssueCounts -errors -extract -f -forceMigration"
switches="$switches -iidmigratorOptions -information -mappings -merge -mergeArchive -migrate -project"
switches="$switches -query -search -settings -signature -source -sourceArchive"
switches="$switches -useMigrationFile -useSourceProjectTemplate"
if [[ ${prev} == "-project" ]] || [[ ${prev} == "-source" ]] ; then
#Filename completion - .fpr and .fsa
_filedir '@(fpr|fsa)'
elif [[ ${prev} == "-f" ]] ; then
#Filename completion - all
_filedir
else
#Switch completion
COMPREPLY=( $(compgen -W "${switches}" -- ${cur} ) )
fi
return 0
}
complete -F _fprutility FPRUtility FPRUtility.bat
_fortifyupdate()
{
local cur prev switches
COMPREPLY=() #Output array
cur="${COMP_WORDS[COMP_CWORD]}" #Current word
prev="${COMP_WORDS[COMP_CWORD-1]}" #Previous word
switches="-acceptKey -coreDir -h -help -import -locale"
switches="$switches -proxyhost -proxyPassword -proxyport -proxyUsername"
switches="$switches -showInstalledExternalMetadata -showInstalledRules -url"
if [[ ${prev} == "-import" ]] ; then
#Filename completion - .zip
_filedir 'zip'
elif [[ ${prev} == "-coreDir" ]] ; then
#Directory completion
_filedir -d
else
#Switch completion
COMPREPLY=( $(compgen -W "${switches}" -- ${cur} ) )
fi
return 0
}
complete -F _fortifyupdate fortifyupdate fortifyupdate.cmd
_reportgenerator()
{
local cur prev switches
COMPREPLY=() #Output array
cur="${COMP_WORDS[COMP_CWORD]}" #Current word
prev="${COMP_WORDS[COMP_CWORD-1]}" #Previous word
switches="-f -filterSet -format -showHidden -showRemoved -showSuppressed -source"
switches="$switches -template -user -verbose"
completions=()
if [[ ${prev} == "-format" ]] ; then
#Output format completion
completions="pdf rtf xml"
elif [[ ${prev} == "-source" ]] ; then
#Filename completion - .fpr
_filedir 'fpr'
return 0
elif [[ ${prev} == "-f" ]] || [[ ${prev} == "-template" ]] ; then
#Filename completion - all
_filedir
return 0
else
#Switch completion
completions=$switches
fi
COMPREPLY=( $(compgen -W "${completions}" -- ${cur} ) )
return 0
}
complete -F _reportgenerator ReportGenerator ReportGenerator.bat
_scastate()
{
local cur prev switches
COMPREPLY=() #Output array
cur="${COMP_WORDS[COMP_CWORD]}" #Current word
prev="${COMP_WORDS[COMP_CWORD-1]}" #Previous word
switches="-a --all -debug -ftd --full-thread-dump -h -help -hd --heap-dump -liveprogress"
#skip -pi (short for --program-info) as -pid will be more commonly used
switches="$switches -nogui --program-info -pid -progress -properties"
switches="$switches -scaversion -td --thread-dump -timers -version -vminfo"
if [[ $prev == "-pid" ]] ; then
#Process ID completion
_pids
elif [[ $prev == "--heap-dump" ]] || [[ $prev == "-hd" ]] ; then
#Filename completion - all
_filedir
return 0
else
#Switch completion
COMPREPLY=( $(compgen -W "${switches}" -- ${cur} ) )
fi
return 0
}
complete -F _scastate SCAState SCAState.cmd
_auditworkbench()
{
local cur prev
COMPREPLY=() #Output array
cur="${COMP_WORDS[COMP_CWORD]}" #Current word
prev="${COMP_WORDS[COMP_CWORD-1]}" #Previous word
#Complete openable types
_filedir '@(fpr|fvdl)'
return 0
}
complete -F _auditworkbench auditworkbench auditworkbench.cmd