Talend is Eclipse based and uses plugins to extend its capabilities. This means we can build a plugin to contain all of our components to make them easily installable.
Benefits of building a plugin for Talend:
- Keep all your components together
- Easier to share and deliver
- Self-contained
- Easier to centralize common resources (jar,images,..)
- Advanced customizations (javajet)
Understand Plugins through Reverse Engineering
Probably the best way to understand how plugins work in Talend’s context is to open one of the existing plugins. You can find all the plugins in the folder:
[JETL_INSTALL_DIR]/plugins
One good example of a plugin for providing components is org.talend.designer.esb.components.rs.consumer_5.5.1.r118616 (name may change depending on your JETLversion). This plugin contains the tRestClient component.
If you are curious you can also have a look to this folder: org.talend.designer.components.localprovider_5.5.1.r118616. It contains all the basic components of JETL.
Talend Designer ESB Tooling REST Service consumer plug-in
Browse the folder : You should see this structure:
|
Create a Plugin project
As Talend doesn't expose Eclipse feature to build plugins so we’ll need to use a proper Eclipse instance to build one.
Open an Eclipse instance (not JETL)
Click on the menu File > New.. > Other
Select Plug-in Project
Configure the new project name and setting
Configure Advanced plugin properties
- Id: Make sure to use a relevant Id, this will be used to reference your plugin from component’s xml configuration (as example to import a common jar stored in the plugin)
- Execution Environment: This should match the design Environment, so where TOS is installed. Anyway is always best to use the minimum java version needed for your custom code to run, especially if you will share the plugin (of course you will J)
- Activator Class: this class is very important, so choose a meaningful package name. We’ll need to work on it later on. You can also call this “MyOwnPlugin”.
Uncheck “Create a plug-in using one of the templates
Click Finish
Import the Talend core plugin
In order to build a talend plugin we need to define some dependencies with talend plugins in our brand new one. To do so we need to have these plugins in our Eclipse.
In Eclipse select from menu File > Import…
In the Import From section select Directory and browse the plugins folder of TOS
Click Next
In the plugin selection you can use the field to filter for strings like “talend.core”
Select the plugin: org.talend.core from the left area and click “Add”
Click on Finish
Create Java classes for Talend extension points
Activator class
The Activator class was automatically generated from the wizard. We just need to add another method:
Activator.getStatus(String message, Throwable e)
public static IStatus getStatus(String message, Throwable e) { String msg = e.getMessage() != null ? e.getMessage() : message != null ? message : e.getClass().getName(); return new Status(4, getDefault().getBundle().getSymbolicName(), msg, e); }[/code]
So at the end your class should look something like this:
MyCustomPlugin.java
package org.mycompany.talend.component;import org.eclipse.core.runtime.IStatus;import org.eclipse.core.runtime.Status;import org.eclipse.ui.plugin.AbstractUIPlugin;import org.osgi.framework.BundleContext;public class MyCustomPlugin extends AbstractUIPlugin { public static MyCustomPlugin getDefault() { return plugin; } // The plug-in ID public static final String PLUGIN_ID = "MyPluginProjectId"; //$NON-NLS-1$ // The shared instance private static MyCustomPlugin plugin; /** * The constructor */ public MyCustomPlugin() { } /* * (non-Javadoc) * * @see * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext * ) */ public void start(BundleContext context) throws Exception { super.start(context); plugin = this; } /* * (non-Javadoc) * * @see * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext * ) */ public void stop(BundleContext context) throws Exception { plugin = null; super.stop(context); } public static IStatus getStatus(String message, Throwable e) { String msg = e.getMessage() != null ? e.getMessage() : message != null ? message : e.getClass().getName(); return new Status(4, getDefault().getBundle().getSymbolicName(), msg, e); }}[/code]
Component Provider
The main purpose of this class is to point eclipse platform to the location of our custom components within the plugin. It extends org.talend.core.model.components.AbstractComponentsProvider.
This abstract class is part of the talend core plugin. In order to have your project build in eclipse you’ll need to add the jar [JETL_INSTALL_DIR]/plugins/org.talend.core_5.4.1.r111943.jar to the project’s BuildPath
Below a simple implementation:
MyCustomComponentsProvider.java
package org.mycompany.talend.component;import java.io.File;import java.net.URL;import org.eclipse.core.runtime.FileLocator;import org.eclipse.core.runtime.Path;import org.talend.core.model.components.AbstractComponentsProvider;public class MyCustomComponentsProvider extends AbstractComponentsProvider{ private File providedLocation = null; protected File getExternalComponentsLocation() { if (this.providedLocation == null) { MyCustomPlugin plugin = MyCustomPlugin.getDefault(); try { URL url = FileLocator.find(plugin.getBundle(), new Path("components"), null); url = FileLocator.toFileURL(url); this.providedLocation = new File(url.getPath()); } catch (Exception e) { plugin.getLog().log(MyCustomPlugin.getStatus(null, e)); } } return this.providedLocation; } public String getFamilyTranslation(String paramString) { return null; }}[/code]
Recommended Comments
There are no comments to display.