Sep 8th, 2010, 06:49 PM
Addons calling other addons - best practice?
I'm working on a few addons that basically enhance some of the standard Roo addons for our internal use. Ie, I am creating an addon that configures a project's security setup to use our LDAP server and specific Spring Security settings we use.
I'm wondering what the best approach is for dealing with a situation where I want another addon's command to run before mine. I see a few ways this could work:
1) Inject the component from the addon I want to use and call the code directly
This is what I'm doing now, and it works, but I'm a little worried about maintenance. I am worried that the addons I depend on may change down the road and cause problems for those trying to use my addon. Probably not a huge deal, since this is for internal use, though.
2) Invoke another command somehow
Is there a generic way to invoke, say "security setup"? This wouldn't totally solve the maintenance issue, but it would at least make the code itself decoupled.
3) Don't do anything, require the user to run "security setup" first
This is the most reliable, but it requires more documentation and extra work on the part of the end-user. There are also cases where the user may try to run one of our commands, find it unavailable, and not know why (I have a patch for this in Roo's JIRA, but I'm not sure if it will be used or not).
Any ideas on what the best practice should be?
Sep 18th, 2010, 01:50 AM
I'd suggest using the mechanism described in https://jira.springframework.org/browse/ROO-1343 to monitor when "security setup" is successfully executed and then complete your extra work then.
Dec 5th, 2010, 02:01 PM
i agree here, I also need a way to create bigger addons which interm call existing addons.
I want to call following addons in my addon (which is a complete security solution for a web site - registration, captcha , user login, forgot password, remember me)
1. entity addon
2. security setup
3. controller addon
Can we not get an object of roo shell and run commands on it "entity -class ~.model.User --test automatically" ?
Also, once I have done that, I would like to monitor the objects created ( I think there is a way of doing that, but any documentation on that would be great).
There should be some way of doing this.
Dec 5th, 2010, 02:05 PM
In short I am talking about implement what is mentioned in this jira - https://jira.springsource.org/browse/ROO-532
Dec 5th, 2010, 03:08 PM
I was going through Spring Roo existing addons and saw this
shell.executeCommand("osgi start --url " + url);
I believe I may be able to do as follows
shell.executeCommand("entity -class ~.model.WebUser --testAutomatically")
Will update here once I am one with my investigation.
Dec 7th, 2010, 05:28 PM
I would not recommend to use the shell.executeCommand approach. This would be quite fragile in case someone changes a command (remember with this approach you have no type safety). A much better approach is to get hold of the relevant *Operations interface and invoke the relevant methods there. So all you need to do is to create a dependency on the relevant add-on in your pom.xml and use the Felix @Reference annotation.
Also, you should only really depend on core add-ons (the add-ons that Roo ships) since the user may not have other third party add-ons installed (unless you make it very clear to him that you need that add-on installed for yours to work).