Package org.apache.any23.plugin
Class Any23PluginManager
- java.lang.Object
-
- org.apache.any23.plugin.Any23PluginManager
-
public class Any23PluginManager extends Object
The Any23PluginManager is responsible for inspecting dynamically the classpath and retrieving useful classes.- Author:
- Michele Mostarda (mostarda@fbk.eu)
-
-
Field Summary
Fields Modifier and Type Field Description static String
CLI_PACKAGE
Any23 Command Line Interface package.static String
PLUGIN_DIRS_LIST_SEPARATOR
List separator for the string declaring the plugin list.static String
PLUGIN_DIRS_PROPERTY
Property where look for plugins.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ExtractorGroup
configureExtractors(File... pluginLocations)
Configures a new list of extractors containing the extractors declared ininitialExtractorGroup
and also the extractors detected in classpath specified bypluginLocations
.ExtractorGroup
configureExtractors(ExtractorGroup initialExtractorGroup)
Configures a new list of extractors containing the extractors declared ininitialExtractorGroup
and also the extractors detected in classpath specified by the default configuration.ExtractorGroup
getApplicableExtractors(ExtractorRegistry registry, File... pluginLocations)
Returns an extractor group containing both the default extractors declared by theExtractorRegistry
and theExtractorPlugin
s.Iterator<Tool>
getApplicableTools(File... pluginLocations)
Returns anIterator
of tools that have been detected within the given list of locations.Iterator<ExtractorFactory>
getExtractors()
List ofExtractorPlugin
classes declared within the classpath.static Any23PluginManager
getInstance()
<T> Iterator<T>
getPlugins(Class<T> type)
Returns all classes within the specifiedpackageName
satisfying the given classfilter
.Iterator<Tool>
getTools()
Returns the list of all theTool
classes declared within the classpath.boolean
loadClassDir(File classDir)
Loads a classes directory in the classpath.Throwable[]
loadClassDirs(File... classDirs)
Loads a list of class dirs in the classpath.Throwable[]
loadFiles(File... files)
Loads a generic list of files, trying to determine the type of every file.boolean
loadJAR(File jar)
Loads a JAR file in the classpath.boolean
loadJARDir(File jarDir)
Loads all the JARs detected in a given directory.Throwable[]
loadJARs(File... jars)
Loads a list of JARs in the classpath.String
loadPlugins(File... pluginLocations)
Loads plugins from a list of specified locations.
-
-
-
Field Detail
-
CLI_PACKAGE
public static final String CLI_PACKAGE
Any23 Command Line Interface package.
-
PLUGIN_DIRS_PROPERTY
public static final String PLUGIN_DIRS_PROPERTY
Property where look for plugins.- See Also:
- Constant Field Values
-
PLUGIN_DIRS_LIST_SEPARATOR
public static final String PLUGIN_DIRS_LIST_SEPARATOR
List separator for the string declaring the plugin list.- See Also:
- Constant Field Values
-
-
Method Detail
-
getInstance
public static Any23PluginManager getInstance()
- Returns:
- a singleton instance of
Any23PluginManager
.
-
loadJAR
public boolean loadJAR(File jar)
Loads a JAR file in the classpath.- Parameters:
jar
- the JAR file to be loaded.- Returns:
true
if the JAR is added for the first time to the classpath,false
otherwise.
-
loadJARs
public Throwable[] loadJARs(File... jars)
Loads a list of JARs in the classpath.- Parameters:
jars
- list of JARs to be loaded.- Returns:
- list of exceptions raised during the loading.
-
loadClassDir
public boolean loadClassDir(File classDir)
Loads a classes directory in the classpath.- Parameters:
classDir
- the directory to be loaded.- Returns:
true
if the directory is added for the first time to the classpath,false
otherwise.
-
loadClassDirs
public Throwable[] loadClassDirs(File... classDirs)
Loads a list of class dirs in the classpath.- Parameters:
classDirs
- list of class dirs to be loaded.- Returns:
- list of exceptions raised during the loading.
-
loadJARDir
public boolean loadJARDir(File jarDir)
Loads all the JARs detected in a given directory.- Parameters:
jarDir
- directory containing the JARs to be loaded. Example '/usr/local/apache-tomcat-7.0.72/webapps/apache-any23-service-2.2-SNAPSHOT/WEB-INF/lib/apache-any23-openie'- Returns:
true
if all JARs in dir are loaded.
-
loadFiles
public Throwable[] loadFiles(File... files)
Loads a generic list of files, trying to determine the type of every file.- Parameters:
files
- list of files to be loaded.- Returns:
- list of errors occurred during loading.
-
getPlugins
public <T> Iterator<T> getPlugins(Class<T> type) throws IOException
Returns all classes within the specifiedpackageName
satisfying the given classfilter
. The search is performed on the static classpath (the one the application started with) and the dynamic classpath (the one specified using the load methods).- Type Parameters:
T
- type of filtered class.- Parameters:
type
- of filtered class.- Returns:
- list of matching classes.
- Throws:
IOException
- if there is an error obtaining plugins.
-
getTools
public Iterator<Tool> getTools() throws IOException
Returns the list of all theTool
classes declared within the classpath.- Returns:
- not
null
list of tool classes. - Throws:
IOException
- if there is an error obtainingTool
's from the classpath.
-
getExtractors
public Iterator<ExtractorFactory> getExtractors() throws IOException
List ofExtractorPlugin
classes declared within the classpath.- Returns:
- not
null
list of plugin classes. - Throws:
IOException
- if there is an error obtaining Extractors.
-
loadPlugins
public String loadPlugins(File... pluginLocations)
Loads plugins from a list of specified locations.- Parameters:
pluginLocations
- list of locations.- Returns:
- a report about the loaded plugins.
-
configureExtractors
public ExtractorGroup configureExtractors(File... pluginLocations) throws IOException, IllegalAccessException, InstantiationException
Configures a new list of extractors containing the extractors declared ininitialExtractorGroup
and also the extractors detected in classpath specified bypluginLocations
.- Parameters:
pluginLocations
- path locations of plugins.- Returns:
- full list of extractors.
- Throws:
IOException
- if there is an error locating the plugin(s).IllegalAccessException
- if there are access permissions for plugin(s).InstantiationException
- if there is an error instantiating plugin(s).
-
configureExtractors
public ExtractorGroup configureExtractors(ExtractorGroup initialExtractorGroup) throws IOException, InstantiationException, IllegalAccessException
Configures a new list of extractors containing the extractors declared ininitialExtractorGroup
and also the extractors detected in classpath specified by the default configuration.- Parameters:
initialExtractorGroup
- initial list of extractors.- Returns:
- full list of extractors.
- Throws:
IOException
- if there is an error locating the extractor(s).IllegalAccessException
- if there are access permissions for extractor(s).InstantiationException
- if there is an error instantiating extractor(s).
-
getApplicableExtractors
public ExtractorGroup getApplicableExtractors(ExtractorRegistry registry, File... pluginLocations) throws IOException, IllegalAccessException, InstantiationException
Returns an extractor group containing both the default extractors declared by theExtractorRegistry
and theExtractorPlugin
s.- Parameters:
registry
- anExtractorRegistry
pluginLocations
- optional list of plugin locations.- Returns:
- a not
null
and not empty extractor group. - Throws:
IOException
- if there is an error locating the extractor group.IllegalAccessException
- if there are access permissions for the extractor group.InstantiationException
- if there is an error instantiating the extractor group.
-
getApplicableTools
public Iterator<Tool> getApplicableTools(File... pluginLocations) throws IOException
Returns anIterator
of tools that have been detected within the given list of locations.- Parameters:
pluginLocations
- list of plugin locations.- Returns:
- set of detected tools.
- Throws:
IOException
- if there is an error acessingTool
's.
-
-