Package net.sf.okapi.common.plugins
Class PluginsManager
- java.lang.Object
-
- net.sf.okapi.common.plugins.PluginsManager
-
public class PluginsManager extends Object
Provides a way to discover and list plug-ins for a given location or file.
-
-
Constructor Summary
Constructors Constructor Description PluginsManager()Create a PluginsManager that uses the current thread's context ClassLoader when loading plugins.PluginsManager(ClassLoader parentClassLoader)Create a PluginsManager that uses the specified ClassLoader when loading plugins.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static booleancleanupJarFileFactory(String... jarNames)cleanup jar file factory cache http://loracular.blogspot.com/2009/12/dynamic-class-loader-with.htmlstatic voidcloseOpenJars(ClassLoader classLoader)Workaround for non-released jar file lock by URLClassLoader http://loracular.blogspot.com/2009/12/dynamic-class-loader-with.htmlvoiddiscover(File pluginsDir, boolean append)Explores the given file or directory for plug-ins and add them to this manager.URLClassLoadergetClassLoader()Gets the URLClassLoader to use for creating new instance of the components listed in this manager.List<PluginItem>getList()Gets the list of all the plug-ins currently in this manager.List<String>getList(int type)Gets the list of the class names of all available plug-ins of a given type currently available in this manager.FilegetPluginsDir()Gets the directory where the plug-ins are located.ArrayList<URL>getURLs()Gets the list of URLs of the jars containing plug-ins currently in this manager.voidreleaseClassLoader()
-
-
-
Constructor Detail
-
PluginsManager
public PluginsManager()
Create a PluginsManager that uses the current thread's context ClassLoader when loading plugins.
-
PluginsManager
public PluginsManager(ClassLoader parentClassLoader)
Create a PluginsManager that uses the specified ClassLoader when loading plugins.- Parameters:
parentClassLoader- ClassLoader to be used as the parent of any ClassLoaders used to load plugins.
-
-
Method Detail
-
discover
public void discover(File pluginsDir, boolean append)
Explores the given file or directory for plug-ins and add them to this manager.- Parameters:
pluginsDir- the directory where the plugins are located.append- true to preserve any plug-ins already existing in this manager, false to reset and start with no plug-in.
-
getList
public List<String> getList(int type)
Gets the list of the class names of all available plug-ins of a given type currently available in this manager. The methoddiscover(File, boolean)must be called once before calling this method.- Parameters:
type- the type of plug-ins to list.- Returns:
- the list of available plug-ins for the given type.
-
getList
public List<PluginItem> getList()
Gets the list of all the plug-ins currently in this manager.- Returns:
- the list of all the plug-ins currently in this manager.
-
getURLs
public ArrayList<URL> getURLs()
Gets the list of URLs of the jars containing plug-ins currently in this manager.- Returns:
- the list of URLs.
-
getClassLoader
public URLClassLoader getClassLoader()
Gets the URLClassLoader to use for creating new instance of the components listed in this manager. The methoddiscover(File, boolean)must be called once before calling this method.- Returns:
- the URLClassLoader for this manager.
-
getPluginsDir
public File getPluginsDir()
Gets the directory where the plug-ins are located.- Returns:
- directory path.
-
releaseClassLoader
public void releaseClassLoader()
-
closeOpenJars
public static void closeOpenJars(ClassLoader classLoader)
Workaround for non-released jar file lock by URLClassLoader http://loracular.blogspot.com/2009/12/dynamic-class-loader-with.html- Parameters:
classLoader- theClassLoaderto use.
-
cleanupJarFileFactory
public static boolean cleanupJarFileFactory(String... jarNames)
cleanup jar file factory cache http://loracular.blogspot.com/2009/12/dynamic-class-loader-with.html- Parameters:
jarNames- the names of the jar files.- Returns:
- true if successful, false otherwise.
-
-