-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathvarScoper.cfm
262 lines (221 loc) · 9.08 KB
/
varScoper.cfm
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
<!---
varscoper.cfm
Author: Mike Schierberl
Change log:
7/14/2006 - initial revision
11/1/2007 - support for ColdFusion MX - 8
Fixes:
-changed processDirectory() not to be dependant on the resultset that cfdirectory returns for ColdFusion 7 - 8
--->
<cffunction name="processDirectory" hint="used to traverse a directory structure">
<cfargument name="startingDirectory" type="string" required="true">
<cfargument name="recursive" type="boolean" required="false" default="false">
<cfset var fileQuery = "" />
<cfset var scoperFileName = "" />
<cfset var xmlDoc = "" />
<cfset var xmlDocData = "" />
<cfset var directoryexcludelistXML = arrayNew(1) />
<cfset var directoryexcludelist = "" />
<cfset var fileexcludelistXML = arrayNew(1) />
<cfset var fileexcludelist = "" />
<cfset var pathsep = "/" />
<!--- get properties --->
<cfif fileExists("#getDirectoryFromPath(getCurrentTemplatePath())#properties.xml")>
<!--- read xml file --->
<cffile action="read" file="#getDirectoryFromPath(getCurrentTemplatePath())#properties.xml" variable="xmlDocData">
<!--- get file to parse --->
<cfset xmlDoc = XmlParse(xmlDocData) />
<!--- get directory exclusion list --->
<cfset directoryexcludelistXML = XmlSearch(xmlDoc, "/properties/directoryexcludelist") />
<!--- if array size GT 0 the get the value --->
<cfif arrayLen(directoryexcludelistXML) GT 0>
<cfset directoryexcludelist = trim(directoryexcludelistXML[1].XmlText) />
</cfif>
<!--- get file exclusion list --->
<cfset fileexcludelistXML = XmlSearch(xmlDoc, "/properties/fileexcludelist") />
<!--- if array size GT 0 the get the value --->
<cfif arrayLen(fileexcludelistXML) GT 0>
<cfset fileexcludelist = trim(fileexcludelistXML[1].XmlText) />
</cfif>
</cfif>
<cfdirectory directory="#arguments.startingDirectory#" name="fileQuery" >
<cfloop query="fileQuery">
<!--- check to see if we want to exclude the diretory or file (from properties file) --->
<cfif NOT listFindNoCase(directoryExcludeList, listLast(replace(arguments.startingDirectory, "\", "/", "ALL"), pathsep))
AND NOT listFindNoCase(fileExcludeList, "#name#")
>
<cfset scoperFileName = "#arguments.startingDirectory##pathsep##name#" />
<cfif listFind("cfc,cfm",right(fileQuery.name,3)) NEQ 0 and type IS "file">
<cfset variables.totalFiles = variables.totalFiles + 1 />
<cfinclude template="varScoperDisplay.cfm">
<cfelseif type IS "Dir" and arguments.recursive >
<cfset processDirectory(startingDirectory:scoperFileName, recursive:true) />
</cfif>
</cfif>
</cfloop>
</cffunction>
<cfif isDefined("URL.displayFormat") and url.displayFormat IS "unit">
<cfset url.filePath="testCaseCFC.cfc">
<cfset URL.parseCfscript = true />
</cfif>
<cfif isdefined("url.filePath")>
<cfset scoperFileName=url.filePath>
<cfelse>
<cfset scoperFileName="testCaseCFC.cfc">
</cfif>
<html>
<head>
<style>
body, input{
font-family: verdana, arial, helvetica, sans-serif;
font-size:12px;
}
.scoperTable{
font-family: verdana, arial, helvetica, sans-serif;
font-size: 10px;
border-color: #0000cc;
border-width: 2px;
border-style: solid;
}
.fileTitle{
font-size: 18px;
background-color:#4444cc;
color: #ffffff;
}
.functionCell{
font-size: 14px;
background-color:#ccddff;
border-width: 2px 0px 0px 0px;
border-style: solid;
}
.varNameCell{
font-size: 12px;
border-width: 2px 2px 0px 0px;
background-color:#ebebeb;
border-style: solid;
}
.contextCell{
border-width: 2px 0px 0px 0px;
border-style: solid;
}
.summary{
font-family: verdana, arial, helvetica, sans-serif;
font-size: 14px;
font-weight: bold;
}
.codeCell{
font-size: 12px;
padding-left:4ex;
border-width: 2px 0px 0px 0px;
border-style: solid;
}
th.codeCell{
padding:0px;
background-color:#ebebeb;
border-width: 2px 2px 0px 0px;
vertical-align:top;
}
.smallFunctionCell{
font-size: 10px;
background-color:#ccddff;
color:#999999;
border-width: 2px 0px 0px 0px;
border-style: solid;
}
</style>
<title>varscoper</title>
</head>
<body>
<cfsetting showdebugoutput="false">
<cfparam name="displayFormat" default="">
<form action="varScoper.cfm" method="get" name="scoperForm" id="scoperForm" <!--- onsubmit="document.scoperForm.submitButton.disabled=true;" --->>
absolute path:
<cfoutput>
<input type="text" name="filePath" id="filePath" size="75" value="#htmlEditFormat(scoperFileName)#" />
</cfoutput>
<input type="submit" value="start" name="submitButton" id="submitButton" /><br>
output:
<input type="radio" name="displayFormat" value="screen" <cfif displayFormat is "" or displayFormat IS "screen">checked</cfif>> screen
<input type="radio" name="displayFormat" value="csv" <cfif displayFormat IS "csv">checked</cfif>> csv
<input type="radio" name="displayFormat" value="xml" <cfif displayFormat IS "xml">checked</cfif>> xml
<input type="radio" name="displayFormat" value="unit" <cfif displayFormat IS "unit">checked</cfif>> unit test
<input type="radio" name="displayFormat" value="dump" <cfif displayFormat IS "dump">checked</cfif>> dump (debug)
<br>
<input type="checkbox" name="showDuplicates" value="true" <cfif isDefined("URL.showDuplicates") and URL.showDuplicates>checked</cfif>> show duplicates (useful if some setters are in comments)
<!--- <input type="checkbox" name="hideLineNumbers" value="true" <cfif isDefined("URL.hideLineNumbers") and URL.hideLineNumbers>checked</cfif>> hide line numbers --->
<br>
<input type="hidden" name="recursiveDirectory" value="disabled" />
<input type="checkbox" name="recursiveDirectory" value="true" <cfif NOT isDefined("URL.recursiveDirectory") or findNoCase('true',URL.recursiveDirectory)>checked</cfif>> include sub-folders<br>
<input type="hidden" name="parseCFScript" value="disabled" />
<input type="checkbox" name="parseCfscript" value="true" <cfif NOT isDefined("URL.parseCfscript") OR findNoCase('true',URL.parseCfscript) >checked</cfif>> parse cfscript. note: this will NOT return correct line numbers
</form>
<cfif isdefined("url.filePath") and trim(url.filePath) IS NOT "">
<cfif isDefined("URL.displayFormat") AND URL.displayFormat IS "CSV">
<cfscript>
function CSVFormat(col){
/* Look for quotes */
if (Find("""", col)) {
return_string = """" & Replace(col, """", """""", "All") & """";
} //if
/* Look for spaces */
else if (Find(" ", col)) {
return_string = """" & col & """";
} //else if
/* Look for commans */
else if (Find(",", col)) {
return_string = """" & col & """";
} //else if
else {
return_string = col;
} //else
return return_String;
}
newLine = Chr(13)&Chr(10);
</cfscript>
<cfset request.allCSVData = '"Filename","Function Name","Function Line","Variable Name","Variable Line","Context"#Chr(13)##Chr(10)#'>
</cfif>
<cfif fileExists("#url.filePath#") or fileExists(expandPath(url.filePath))>
<cfif fileExists(url.filePath)>
<cfset scoperFileName=url.filePath>
<cfelse>
<cfset scoperFileName=expandPath(url.filePath)>
</cfif>
<cfset variables.totalMethods = 0 />
<cfset directoryStart = getTickCount() />
<cfoutput><script>fileLines = new Array(); </script></cfoutput>
<cfinclude template="varScoperDisplay.cfm">
<cfset directoryEnd = getTickCount() />
<cfoutput><br><br><span class="summary">Processed 1 file and #variables.totalMethods# cffunctions in #directoryEnd-directoryStart#ms</span></cfoutput>
<cfelseif directoryExists("#url.filePath#") OR directoryExists(expandPath(url.filePath))>
<cfif directoryExists(url.filePath)>
<cfset startingDirectory = url.filePath>
<cfelse>
<cfset startingDirectory = expandPath(url.filePath)>
</cfif>
<cfif NOT isDefined("URL.recursiveDirectory") or findNoCase('true',URL.recursiveDirectory)>
<cfset recursive=true>
<cfelse>
<cfset recursive=false>
</cfif>
<cfset variables.totalFiles = 0 />
<cfset variables.totalMethods = 0 />
<cfset directoryStart = getTickCount() />
<cfoutput><script>fileLines = new Array(); </script></cfoutput>
<cfset processDirectory(startingDirectory:startingDirectory,recursive:recursive)>
<cfset directoryEnd = getTickCount() />
<cfoutput><br><br><span class="summary">Processed #variables.totalFiles# files and #variables.totalMethods# cffunctions in #directoryEnd-directoryStart#ms</span></cfoutput>
<cfelse>
<cfoutput>No file or directory exists for the path specified (#htmlEditFormat(url.filePath)#)</cfoutput>
</cfif>
<cfif isDefined("URL.displayFormat") AND URL.displayFormat IS "CSV">
<cfsetting enablecfoutputonly="true" showdebugoutput="false">
<cfset fileName="unscoped_variables.csv" />
<cfheader name="Content-Disposition" value="attachment; filename=#FileName#">
<cfheader name="Expires" value="#Now()#">
<cfcontent type="application/octet-stream" reset="true"> <!--- vnd.ms-excel --->
<cfcontent reset="true"><cfoutput>#request.allCSVData#</cfoutput><cfabort>
</cfif>
</cfif>
</body>
</html>