Search in sources :

Example 66 with PluginInterface

use of org.pentaho.di.core.plugins.PluginInterface in project pentaho-kettle by pentaho.

the class ValueMetaAndDataTest method testLoadXML.

@Test
@PrepareForTest({ EnvUtil.class })
public void testLoadXML() throws KettleValueException, KettlePluginException, ParseException {
    PowerMockito.mockStatic(EnvUtil.class);
    Mockito.when(EnvUtil.getSystemProperty(Const.KETTLE_DEFAULT_DATE_FORMAT)).thenReturn("yyyy-MM-dd HH:mm:ss.SSS");
    ValueMetaAndData valueMetaAndData = new ValueMetaAndData(Mockito.mock(ValueMetaInterface.class), new Object());
    List<PluginInterface> pluginTypeList = new ArrayList<>();
    PluginInterface plugin = Mockito.mock(PluginInterface.class);
    Mockito.when(plugin.getName()).thenReturn("3");
    String[] ids = { "3" };
    Mockito.when(plugin.getIds()).thenReturn(ids);
    pluginTypeList.add(plugin);
    Mockito.when(pluginRegistry.getPlugins(ValueMetaPluginType.class)).thenReturn(pluginTypeList);
    ValueMetaFactory.pluginRegistry = pluginRegistry;
    NodeList nodeList = Mockito.mock(NodeList.class);
    Mockito.when(nodeList.getLength()).thenReturn(2);
    Node node = Mockito.mock(Node.class);
    Mockito.when(node.getChildNodes()).thenReturn(nodeList);
    Node childNodeText = Mockito.mock(Node.class);
    Mockito.when(childNodeText.getNodeName()).thenReturn("text");
    Mockito.when(nodeList.item(0)).thenReturn(childNodeText);
    Node nodeValue = Mockito.mock(Node.class);
    Mockito.when(childNodeText.getFirstChild()).thenReturn(nodeValue);
    String testData = "2010/01/01 00:00:00.000";
    Mockito.when(nodeValue.getNodeValue()).thenReturn(testData);
    Node childNodeType = Mockito.mock(Node.class);
    Mockito.when(childNodeType.getNodeName()).thenReturn("type");
    Mockito.when(nodeList.item(1)).thenReturn(childNodeType);
    Node nodeTypeValue = Mockito.mock(Node.class);
    Mockito.when(childNodeType.getFirstChild()).thenReturn(nodeTypeValue);
    Mockito.when(nodeTypeValue.getNodeValue()).thenReturn("3");
    valueMetaAndData.loadXML(node);
    Assert.assertEquals(valueMetaAndData.getValueData(), new SimpleDateFormat(ValueMetaBase.COMPATIBLE_DATE_FORMAT_PATTERN).parse(testData));
}
Also used : PluginInterface(org.pentaho.di.core.plugins.PluginInterface) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) SimpleDateFormat(java.text.SimpleDateFormat) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 67 with PluginInterface

use of org.pentaho.di.core.plugins.PluginInterface in project pentaho-kettle by pentaho.

the class SwingGUIResource method loadEntryImages.

private Map<String, SwingUniversalImage> loadEntryImages() {
    Map<String, SwingUniversalImage> map = new HashMap<>();
    for (PluginInterface plugin : PluginRegistry.getInstance().getPlugins(JobEntryPluginType.class)) {
        try {
            if (JobMeta.STRING_SPECIAL.equals(plugin.getIds()[0])) {
                continue;
            }
            SwingUniversalImage image = getUniversalImageIcon(plugin);
            if (image == null) {
                throw new KettleException("Unable to find image file: " + plugin.getImageFile() + " for plugin: " + plugin);
            }
            map.put(plugin.getIds()[0], image);
        } catch (Exception e) {
            log.logError("Unable to load job entry icon image for plugin: " + plugin.getName() + " (id=" + plugin.getIds()[0] + ")", e);
        }
    }
    return map;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) HashMap(java.util.HashMap) PluginInterface(org.pentaho.di.core.plugins.PluginInterface) SwingUniversalImage(org.pentaho.di.core.SwingUniversalImage) KettleException(org.pentaho.di.core.exception.KettleException) FileNotFoundException(java.io.FileNotFoundException)

Example 68 with PluginInterface

use of org.pentaho.di.core.plugins.PluginInterface in project pentaho-kettle by pentaho.

the class LifecycleSupport method loadPlugins.

/**
 * Instantiate the main plugin class types for the plugin type provided from the set of registered plugins via
 * {@link PluginRegistry}.
 *
 * @param pluginType
 *          Type of plugin whose main class types should be instanticated
 * @return Set of plugin main class instances (a.k.a. plugins)
 */
static <T> Set<T> loadPlugins(Class<? extends PluginTypeInterface> pluginType, Class<T> mainPluginClass) {
    Set<T> pluginInstances = new HashSet<T>();
    List<PluginInterface> plugins = registry.getPlugins(pluginType);
    for (PluginInterface plugin : plugins) {
        try {
            pluginInstances.add(registry.loadClass(plugin, mainPluginClass));
        } catch (Throwable e) {
            LogChannel.GENERAL.logError("Unexpected error loading class for plugin " + plugin.getName(), e);
        }
    }
    return pluginInstances;
}
Also used : PluginInterface(org.pentaho.di.core.plugins.PluginInterface) HashSet(java.util.HashSet)

Example 69 with PluginInterface

use of org.pentaho.di.core.plugins.PluginInterface in project pentaho-kettle by pentaho.

the class CompressionProviderFactory method getCompressionProviderNames.

@Override
public String[] getCompressionProviderNames() {
    ArrayList<String> providerNames = new ArrayList<String>();
    List<PluginInterface> providers = getPlugins();
    if (providers != null) {
        for (PluginInterface plugin : providers) {
            try {
                CompressionProvider provider = PluginRegistry.getInstance().loadClass(plugin, CompressionProvider.class);
                if (provider != null) {
                    providerNames.add(provider.getName());
                }
            } catch (Exception e) {
            // Do nothing here, if we can't load the provider, don't add it to the list
            }
        }
    }
    return providerNames.toArray(new String[providerNames.size()]);
}
Also used : PluginInterface(org.pentaho.di.core.plugins.PluginInterface) ArrayList(java.util.ArrayList)

Example 70 with PluginInterface

use of org.pentaho.di.core.plugins.PluginInterface in project pentaho-kettle by pentaho.

the class CompressionProviderFactory method getCompressionProviders.

@Override
public Collection<CompressionProvider> getCompressionProviders() {
    Collection<CompressionProvider> providerClasses = new ArrayList<CompressionProvider>();
    List<PluginInterface> providers = getPlugins();
    if (providers != null) {
        for (PluginInterface plugin : providers) {
            try {
                providerClasses.add(PluginRegistry.getInstance().loadClass(plugin, CompressionProvider.class));
            } catch (Exception e) {
            // Do nothing here, if we can't load the provider, don't add it to the list
            }
        }
    }
    return providerClasses;
}
Also used : PluginInterface(org.pentaho.di.core.plugins.PluginInterface) ArrayList(java.util.ArrayList)

Aggregations

PluginInterface (org.pentaho.di.core.plugins.PluginInterface)99 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)45 KettleException (org.pentaho.di.core.exception.KettleException)24 ArrayList (java.util.ArrayList)17 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)14 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)12 TransMeta (org.pentaho.di.trans.TransMeta)11 StepMeta (org.pentaho.di.trans.step.StepMeta)11 JobEntryCopy (org.pentaho.di.job.entry.JobEntryCopy)10 Test (org.junit.Test)9 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)9 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)8 Point (org.pentaho.di.core.gui.Point)8 JobMeta (org.pentaho.di.job.JobMeta)8 KettlePluginException (org.pentaho.di.core.exception.KettlePluginException)7 TransHopMeta (org.pentaho.di.trans.TransHopMeta)7 TreeItem (org.eclipse.swt.widgets.TreeItem)6 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)6 LongObjectId (org.pentaho.di.repository.LongObjectId)6 ObjectId (org.pentaho.di.repository.ObjectId)6