4

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?

Peter Boughton
  • 110,170
  • 32
  • 120
  • 176
blank
  • 17,852
  • 20
  • 105
  • 159

6 Answers6

10

Ben Nadel has a method to examine the live stack trace from a running template. It seems to me that you could easily plop this into your application and log the results to a database. Once you've done that, you've got a good idea of what's in use and what's not.

I think the easiest way, however, is to enable debugging (standard caveat here about development server, etc). The standard ColdFusion debugger will give you a complete list of every file used during the execution of a single page. ColdFire will do the same thing in a handy Firebug extension (click ColdFusion then click Exec Times).

It should be pointed out that the built-in debugger even shows you the files included from CFC calls, and the files included from within those calls as well. It is all inclusive.

Ben Nadel on Stack Traces

Ray Camden's ColdFire

Sample of CF Debugging from a live page:
alt text

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
JWHardcastle
  • 131
  • 4
6

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
  • 110,170
  • 32
  • 120
  • 176
  • I wish I could give this more than +1. Don't wait until it's "clean" to put it in version control. Just do it now - ideally a direct copy of your production code. Don't import stuff from a development server until you've got the production code imported - it probably has all kinds of junk in it that was never deployed. – bpanulla May 10 '11 at 22:37
5

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
  • 332,285
  • 67
  • 532
  • 628
1

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
  • 1,958
  • 3
  • 14
  • 14
  • 1
    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 May 26 '09 at 15:22
  • 1
    OnRequest is per-request, not per-script. – Peter Boughton May 27 '09 at 12:43
  • I think you could get pretty close with this method and an audit of instances of in your code base. It won't be 100% definitive but would get you most of the way there. You could then drop bugs in the files that you still have questions about. – bpanulla May 10 '11 at 22:43
0

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
  • 38,186
  • 16
  • 91
  • 120
0

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.

Adrian J. Moreno
  • 14,350
  • 1
  • 37
  • 44