Thom Smith
Thom Smith

Reputation: 14086

Get a list of available components

I'm writing an admin tool for a ColdFusion app, and I'd like to provide an autocomplete feature for a field for entering component names. In order to do this, I'd need a list of all of the components in the application. I have the following code to get a list of mappings:

public function getComponentNames() {
    var ServiceFactory = CreateObject('java', 'coldfusion.server.ServiceFactory');
    return ServiceFactory.runtimeService.getMappings();
}

Is there any better way to get a list of components than crawling the filesystem looking for .cfc files under these paths?

EDIT: This is currently working, but painfully slowly for just a couple of thousand components:

public function getComponents() {
    var ServiceFactory = CreateObject('java', 'coldfusion.server.ServiceFactory');
    var mappings = ServiceFactory.runtimeService.getMappings();

    for (m in mappings) {
        var components = DirectoryList(mappings[m], true, 'path', '*.cfc');
        writeDump(components);
    }
}

Upvotes: 1

Views: 223

Answers (1)

Adam Cameron
Adam Cameron

Reputation: 29870

In CFML the sense of an "application" is pretty loose. It's more a bunch of files that interact with each other.

As well as scanning all the mappings, you'd also need to scan any directories within the subdirectory structure of the site as well.

Are you not better off - perhaps - writing an extension for Sublime Text or Eclipse or something? You can then leverage their idea of "projects", and you can let the IDE handle the file indexing. You can then just "do stuff" with the file listing the IDE will expose to you via the API. I've never written an IDE extension, so can't be more "helpful" than that, I'm afraid.

Upvotes: 2

Related Questions