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 StringCLI_PACKAGEAny23 Command Line Interface package.static StringPLUGIN_DIRS_LIST_SEPARATORList separator for the string declaring the plugin list.static StringPLUGIN_DIRS_PROPERTYProperty where look for plugins.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ExtractorGroupconfigureExtractors(File... pluginLocations)Configures a new list of extractors containing the extractors declared ininitialExtractorGroupand also the extractors detected in classpath specified bypluginLocations.ExtractorGroupconfigureExtractors(ExtractorGroup initialExtractorGroup)Configures a new list of extractors containing the extractors declared ininitialExtractorGroupand also the extractors detected in classpath specified by the default configuration.ExtractorGroupgetApplicableExtractors(ExtractorRegistry registry, File... pluginLocations)Returns an extractor group containing both the default extractors declared by theExtractorRegistryand theExtractorPlugins.Iterator<Tool>getApplicableTools(File... pluginLocations)Returns anIteratorof tools that have been detected within the given list of locations.Iterator<ExtractorFactory>getExtractors()List ofExtractorPluginclasses declared within the classpath.static Any23PluginManagergetInstance()<T> Iterator<T>getPlugins(Class<T> type)Returns all classes within the specifiedpackageNamesatisfying the given classfilter.Iterator<Tool>getTools()Returns the list of all theToolclasses declared within the classpath.booleanloadClassDir(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.booleanloadJAR(File jar)Loads a JAR file in the classpath.booleanloadJARDir(File jarDir)Loads all the JARs detected in a given directory.Throwable[]loadJARs(File... jars)Loads a list of JARs in the classpath.StringloadPlugins(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:
trueif the JAR is added for the first time to the classpath,falseotherwise.
-
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:
trueif the directory is added for the first time to the classpath,falseotherwise.
-
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:
trueif 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 specifiedpackageNamesatisfying 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 theToolclasses declared within the classpath.- Returns:
- not
nulllist of tool classes. - Throws:
IOException- if there is an error obtainingTool's from the classpath.
-
getExtractors
public Iterator<ExtractorFactory> getExtractors() throws IOException
List ofExtractorPluginclasses declared within the classpath.- Returns:
- not
nulllist 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 ininitialExtractorGroupand 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 ininitialExtractorGroupand 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 theExtractorRegistryand theExtractorPlugins.- Parameters:
registry- anExtractorRegistrypluginLocations- optional list of plugin locations.- Returns:
- a not
nulland 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 anIteratorof 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.
-
-