tags:

views:

254

answers:

6

I'm starting some work on an existing ColdFusion application with no version control and what look like unused cfm files (test.cfm, test2.cfm etc.). I'd like to get a picture of what files are actually part of the application so I can get it into git or subversion in a manageable state.

How would you go about this? A regex and some methods to find and map cfinclude and cfcomponent tags? Is there some existing tool that does this?

A: 

cfinclude won't tell you if a url is supposed to load the file directly. I've seen system where some files are not included via an index.cfm even when the framework expects it. I have it in my own work where index.cfm loads most code but reset.cfm bypasses the framework to reset configs and session data.

SpliFF
+3  A: 

A regex is not advisable. Since ColdFusion is quite flexible in the way files can be included or referenced, there will be no way to determine the definitive list of dependencies from the source code alone.

You could insert a <cflog> into each file and build a log from the running application. Examine the log after the application was active for a while and all functionality had been accessed at least once.

Tomalak
+2  A: 

Put it into git first! Then, if you screw up, you can easily roll back.
(If you're concerned about having a 'clean' repository, when you're finished and fully tested, you have the option to just remove the single .git folder and create a new one.)

Then, as Tomalak suggests, use cflog on every file. Infact I'd say maybe even log twice, at the top and bottom of each script, could potentially help you to map out how the application runs.

Peter Boughton
A: 

Don't bother instrumenting each file, just cflog the page name in OnRequest inside application.cfc - the target page is an argument.

Of course then the issue becomes code coverage and the ability to fully excercise the app.

<cffunction name="onRequest" returnType="void">
  <cfargument name="targetPage" type="String" required=true/>
  <cflog file="Usedpage" text="#Arguments.targetPage#">
  <cfinclude template="#Arguments.targetPage#">
   ...
</cffunction>
kevink
It occurs to me that this may not help with cfcs, I am not sure they get called though onrequest but it should at least help with base .cfms.
kevink
OnRequest is per-request, not per-script.
Peter Boughton
+8  A: 
Toxf
A: 

Download a trial of Dreamweaver and define a ColdFusion site. DW can create a site map and tell you which files are not included, linked, cfmoduled and so forth. I don't know if it can figure out unused CFCs, but CFMs should be easy. Note that I haven't used DW for years, but it had this functionality around CF 4/5.

iKnowKungFoo