Action at plugin installation

Hi, i’m writing an openfire plugin, and I would like to do things at plugin installation.

I wrote the plugin, implemented the plugin interface, and overrided the two methods

initializePlugin and destroyPlugin.

I put my things to do in initializePlugin, but it seems that this function is called everytime openfire restart.

Can anyone confirm ?

If yes, how could I do to execute my “things” only at plugin installation ?

Thanks,

MarC.

There’s no real distinction that you can make use of. One mechanism that you might re-use, is the database installation stuff that’s being provided. Basically, what it does is:

  • check what version of the database scripts is installed (which is stored in the ofVersion database table);
  • check what version of the database scripts is required (which is defined in the plugin.xml file);
  • if the values differ, execute every update script, until the two values match.

Every update script should, of course, increase the value for the ‘installed’ database version.

You might do something similar: when loading your plugin, query the database (or any other form of persistant storage) for a specific identifier. If that identifier is not set (or not set to the value that you define), do your one-time initialization, and set the identifier.

I put my things to do in initializePlugin, but it seems that this function is called everytime openfire restart.

Can anyone confirm?

Yes.

If yes, how could I do to execute my “things” only at plugin installation ?
What about this?

static final String PROPERTY_LAST_VERSION = "plugin.YOURPLUGIN.lastversion"; // ... String version = pluginManager.getVersion(this);
String lastversion = JiveGlobals.getProperty(PROPERTY_LAST_VERSION, "");
if (lastversion.equals("")) {
    // first start...do something....
}
else {
    int cmp = version.compareTo(lastversion);
    switch (cmp) {
        case -1: // do something....
            break;
        case 1: // do something....
            break;
        default: // same version as last time...
    }
}
JiveGlobals.setProperty(PROPERTY_LAST_VERSION, version);

However, an plugin MUST restore all changes that could harm working of Openfire when destroyPlugin is called. It MUST be always save to remove an plugin! Also you should check if your changes are still present, when your plugins starts a second time.

Thank you guys for your answers.

I will do what you both suggest me.

Thanks again,

Regards,

MarC.