CarbonLaunchExtension
The CarbonLaunchExtension
 interface allows developers to write custom extensions that perform tasks that need to be executed just before launching the Carbon server. The single perform() method in the interface takes no parameters. Extended classes need to implement the perform() method with customized operations that need to be called when launching the Carbon server. All the current implementations of the interface can be found under the org.wso2.carbon.server.extensions
 package.
Few of the existing implementations are as follows:
org.wso2.carbon.server.extensions.DefaultBundleCreator: Creates regular OSGi bundles out of regular JAR files.
org.wso2.carbon.server.extensions.DropinsBundleDeployer: Deploys bundles found inside the
<PRODUCT_HOME>/repository/components/dropins
 directory.org.wso2.carbon.server.extensions.PatchInstaller: Copies all the patches found in the
<PRODUCT_HOME>/repository/components/patchesÂ
directory to the<PRODUCT_HOME>/repository/components/plugins
 directory in a recursive manner.org.wso2.carbon.server.extensions.SystemBundleExtensionCreator: Reads the extension folder and create extension bundles.
Given below is an implementation of an extension (org.wso2.carbon.server.extensions.DefaultBundleCreator) used for creating OSGi bundles during the server launch process. The main functionality goes inside the perform() method that gets executed within the Main method.
/** * Creates regular OSGi bundles out of regular jar files */ public class DefaultBundleCreator implements CarbonLaunchExtension { private static final String JARS_DIR = "repository" + File.separator + "components" + File.separator + "lib"; public void perform() { File dropinsFolder = new File(Utils.getCarbonComponentRepo(), "dropins"); File dir = Utils.getBundleDirectory(JARS_DIR); File[] files = dir.listFiles(new Utils.JarFileFilter()); if (files != null) { for (File file : files) { try { Manifest mf = new Manifest(); Attributes attribs = mf.getMainAttributes(); attribs.putValue(LauncherConstants.DYNAMIC_IMPORT_PACKAGE, "*"); Utils.createBundle(file, dropinsFolder, mf, ""); } catch (Throwable e) { System.err.println("Cannot create bundle from jar file " + file.getAbsolutePath()); e.printStackTrace(); } } } } }
Developers can write their own implementations for the CarbonLaunchExtension interface, adding the custom operations inside the perform() method that need to be called while launching the Carbon server. Those extensions can then be called within the Main method that launches the Carbon server.
Given below is the existing implementation in Carbon where all the extensions are called before starting the OSGi framework. The perform() method of each CarbonLaunchExtension implementation is called in this process. Developers can call the perform() method of their implementation in the location given below. If you need to add a new extension to the implementation given below, you can send a pull request with the changes. Note that this is only available for developers and cannot be extended externally.
public static void invokeExtensions() { //converting jars found under components/lib and putting them in components/dropins dir new DefaultBundleCreator().perform(); new SystemBundleExtensionCreator().perform(); new Log4jPropFileFragmentBundleCreator().perform(); new LibraryFragmentBundleCreator().perform(); <Add your custom implementation here> //Add bundles in the dropins directory to the bundles.info file. new DropinsBundleDeployer().perform(); //copying patched jars to components/plugins dir new PatchInstaller().perform(); //rewriting the eclipse.ini file new EclipseIniRewriter().perform(); }