/** * Load the class with a certain name using the class loader of certain plugin. * * @param plugin The plugin for which we want to use the class loader * @param classType The type of class to load * @return the name of the class * @throws KettlePluginException In case there is something wrong */ @SuppressWarnings( "unchecked" ) public <T> T getClass( PluginInterface plugin, T classType ) throws KettlePluginException { String className = plugin.getClassMap().get( classType ); return (T) getClass( plugin, className ); }
/** * @return a unique list of all the step plugin package names */ public List<String> getPluginPackages( Class<? extends PluginTypeInterface> pluginType ) { Set<String> list = new TreeSet<>(); for ( PluginInterface plugin : getPlugins( pluginType ) ) { for ( String className : plugin.getClassMap().values() ) { int lastIndex = className.lastIndexOf( "." ); if ( lastIndex > -1 ) { list.add( className.substring( 0, lastIndex ) ); } } } return new ArrayList<>( list ); }
/** * @param fragment A plugin interface to merge with */ default void merge( PluginInterface fragment ) { if ( fragment != null ) { Optional.ofNullable( fragment.getClassMap() ).ifPresent( this.getClassMap()::putAll ); Optional.ofNullable( fragment.getImageFile() ).ifPresent( this::setImageFile ); Optional.ofNullable( fragment.getLibraries() ).ifPresent( this.getLibraries()::addAll ); Optional.ofNullable( fragment.getErrorHelpFile() ).ifPresent( this::setErrorHelpFile ); Optional.ofNullable( fragment.getDocumentationUrl() ).ifPresent( this::setDocumentationUrl ); Optional.ofNullable( fragment.getCasesUrl() ).ifPresent( this::setCasesUrl ); Optional.ofNullable( fragment.getForumUrl() ).ifPresent( this::setForumUrl ); Optional.ofNullable( fragment.getClassLoaderGroup() ).ifPresent( this::setClassLoaderGroup ); } } }
/** * Find the plugin ID based on the class * * @param pluginType the type of plugin * @param pluginClass The class to look for * @return The ID of the plugin to which this class belongs (checks the plugin class maps) or null if nothing was * found. */ public String getPluginId( Class<? extends PluginTypeInterface> pluginType, Object pluginClass ) { String className = pluginClass.getClass().getName(); PluginInterface plugin = getPlugins( pluginType ).stream() .filter( p -> p.getClassMap().values().contains( className ) ) .findFirst() .orElse( null ); if ( plugin != null ) { return plugin.getIds()[0]; } return extensions.stream() .map( ext -> ext.getPluginId( pluginType, pluginClass ) ) .filter( Objects::nonNull ) .findFirst() .orElse( null ); }
ucl.loadClass( plugin.getClassMap().values().iterator().next() ); } catch ( ClassNotFoundException ignored ) { ucl.loadClass( plugin.getClassMap().values().iterator().next() ); } catch ( ClassNotFoundException ignored ) {
@BeforeClass public static void setUpBeforeClass() throws Exception { KettleClientEnvironment.init(); dbMap.put( DatabaseInterface.class, DBMockIface.class.getName() ); dbMap.put( InfobrightDatabaseMeta.class, InfobrightDatabaseMeta.class.getName() ); PluginRegistry preg = PluginRegistry.getInstance(); mockDbPlugin = mock( PluginInterface.class ); when( mockDbPlugin.matches( anyString() ) ).thenReturn( true ); when( mockDbPlugin.isNativePlugin() ).thenReturn( true ); when( mockDbPlugin.getMainType() ).thenAnswer( (Answer<Class<?>>) invocation -> DatabaseInterface.class ); when( mockDbPlugin.getPluginType() ).thenAnswer( (Answer<Class<? extends PluginTypeInterface>>) invocation -> DatabasePluginType.class ); when( mockDbPlugin.getIds() ).thenReturn( new String[] { "Oracle", "mock-db-id" } ); when( mockDbPlugin.getName() ).thenReturn( "mock-db-name" ); when( mockDbPlugin.getClassMap() ).thenReturn( dbMap ); preg.registerPlugin( DatabasePluginType.class, mockDbPlugin ); }
String dialogClassName = plugin.getClassMap().get( StepDialogInterface.class ); if ( dialogClassName == null ) {
List<GUIOption<Object>> leditables = new ArrayList<GUIOption<Object>>(); for ( PluginInterface plugin : plugins ) { if ( !plugin.getClassMap().keySet().contains( GUIOption.class ) ) { continue;
public JobEntryDialogInterface getJobEntryDialog( JobEntryInterface jobEntryInterface, JobMeta jobMeta ) { Class<?>[] paramClasses = new Class<?>[] { Shell.class, JobEntryInterface.class, Repository.class, JobMeta.class }; Object[] paramArgs = new Object[] { spoon.getShell(), jobEntryInterface, spoon.getRepository(), jobMeta }; PluginRegistry registry = PluginRegistry.getInstance(); PluginInterface plugin = registry.getPlugin( JobEntryPluginType.class, jobEntryInterface ); String dialogClassName = plugin.getClassMap().get( JobEntryDialogInterface.class ); if ( dialogClassName == null ) { // try the deprecated way log.logDebug( "Use of JobEntryInterface#getDialogClassName is deprecated, use PluginDialog annotation instead." ); dialogClassName = jobEntryInterface.getDialogClassName(); } try { Class<JobEntryDialogInterface> dialogClass = registry.getClass( plugin, dialogClassName ); Constructor<JobEntryDialogInterface> dialogConstructor = dialogClass.getConstructor( paramClasses ); JobEntryDialogInterface entryDialogInterface = dialogConstructor.newInstance( paramArgs ); entryDialogInterface.setMetaStore( spoon.getMetaStore() ); return entryDialogInterface; } catch ( Throwable t ) { t.printStackTrace(); String errorTitle = BaseMessages.getString( PKG, "Spoon.Dialog.ErrorCreatingJobDialog.Title" ); String errorMsg = BaseMessages.getString( PKG, "Spoon.Dialog.ErrorCreatingJobEntryDialog.Message", dialogClassName ); spoon.getLog().logError( spoon.toString(), errorMsg ); new ErrorDialog( spoon.getShell(), errorTitle, errorMsg, t ); return null; } }
/** * @param pluginType the type of plugin to get information for * @return a row buffer containing plugin information for the given plugin type * @throws KettlePluginException */ public RowBuffer getPluginInformation( Class<? extends PluginTypeInterface> pluginType ) throws KettlePluginException { RowBuffer rowBuffer = new RowBuffer( getPluginInformationRowMeta() ); for ( PluginInterface plugin : getPlugins( pluginType ) ) { Object[] row = new Object[getPluginInformationRowMeta().size()]; int rowIndex = 0; row[rowIndex++] = getPluginType( plugin.getPluginType() ).getName(); row[rowIndex++] = plugin.getIds()[0]; row[rowIndex++] = plugin.getName(); row[rowIndex++] = Const.NVL( plugin.getDescription(), "" ); row[rowIndex++] = Utils.isEmpty( plugin.getLibraries() ) ? "" : plugin.getLibraries().toString(); row[rowIndex++] = Const.NVL( plugin.getImageFile(), "" ); row[rowIndex++] = plugin.getClassMap().values().toString(); row[rowIndex] = Const.NVL( plugin.getCategory(), "" ); rowBuffer.getBuffer().add( row ); } return rowBuffer; }
String className = plugin.getClassMap().get( pluginClass ); if ( className == null ) {