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));
}
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;
}
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;
}
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()]);
}
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;
}
Aggregations