Package edu.umd.cs.findbugs
Class PluginLoader
java.lang.Object
edu.umd.cs.findbugs.PluginLoader
- All Implemented Interfaces:
AutoCloseable
Loader for a FindBugs plugin. A plugin is a jar file containing two metadata
files, "findbugs.xml" and "messages.xml". Those files specify
- the bug pattern Detector classes,
- the bug patterns detected (including all text for displaying detected instances of those patterns), and
- the "bug codes" which group together related bug instances
The PluginLoader creates a Plugin object to store the Detector factories and metadata.
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescription(package private) boolean
private ClassLoader
private final ClassLoader
private final boolean
private List
<URLClassLoader> (package private) boolean
private final String
(package private) static boolean
private final URL
private final URI
private static final org.slf4j.Logger
private static int
private boolean
(package private) String
plugin Id for parent plugin(package private) static LinkedList
<PluginLoader> private final Plugin
private static final String
private static final String
private static final String
private static final String
-
Constructor Summary
ConstructorsModifierConstructorDescriptionDeprecated.PluginLoader
(boolean fake, URL url) Deprecated.PluginLoader
(URL url) Deprecated.PluginLoader
(URL url, ClassLoader parent) Deprecated.private
PluginLoader
(URL url, URI uri, ClassLoader parent, boolean isInitial, boolean optional) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprivate static void
addClassPathFromManifest
(URL url, List<URL> urls, Manifest mf) private void
addCollection
(List<org.dom4j.Document> messageCollectionList, String filename) private URLClassLoader
buildURLClassLoader
(URL[] urls) Creates a newURLClassLoader
and adds it to the list of classloaders we need to close if we close the corresponding pluginprivate URLClassLoader
buildURLClassLoader
(URL[] urls, ClassLoader parent) Creates a newURLClassLoader
and adds it to the list of classloaders we need to close if we close the corresponding pluginvoid
close()
Closes the class loaders created in thisPluginLoader
private static URL
private Plugin
constructMinimalPlugin
(org.dom4j.Document pluginDescriptor, List<org.dom4j.Document> messageCollectionList) private static URL[]
createClassloaderUrls
(URL url) Patch for issue 3429143: allow plugins load classes/resources from 3rd party jarsprivate static org.dom4j.Node
findMessageNode
(List<org.dom4j.Document> messageCollectionList, String xpath, String missingMsg) private static String
findMessageText
(List<org.dom4j.Document> messageCollectionList, String xpath, String missingMsg) private static void
private static String
getChildText
(org.dom4j.Node node, String childName) private static <T> Class
<? extends T> getClass
(ClassLoader loader, String className, Class<T> type) private DetectorFactorySelector
getConstraintSelector
(org.dom4j.Element constraintElement, Plugin plugin, String singleDetectorElementName) static PluginLoader
(package private) static URL
getCoreResource
(String name) private static URL
private static String
getJarName
(URL url) private List
<org.dom4j.Document> org.dom4j.Document
static PluginLoader
getPluginLoader
(URL url, ClassLoader parent, boolean isInitial, boolean optional) getResource
(String name) Get a resource using the URLClassLoader classLoader.getURI()
getURL()
private static URL
getUrlBase
(URL pluginListProperties) private static File
guessManifest
(File parent) Trying to find the manifest of "exploded plugin" in the current dir, "standard jar" manifest location or "standard" Eclipse location (sibling to the current classpath)boolean
private Plugin
init()
(package private) static void
(package private) static void
(package private) static void
boolean
private <T> void
loadComponentPlugin
(Plugin plugin, Class<T> componentKind, String componentClassname, String filterId, boolean disabled, String description, String details, PropertyBundle properties) private static void
static URL
loadFromFindBugsEtcDir
(String name) static URL
private static void
loadInitialPlugin
(URL u, boolean initial, boolean optional) (package private) static void
Get the Plugin.private void
private static void
loadPlugins
(File home) private static void
loadPluginsInDir
(File pluginDir, boolean optional) private static Date
private static org.dom4j.Document
private static URL
resourceFromFindbugsJar
(String slashedResourceName) Try to load resource from JAR file of Findbugs core plugin.private static URL
resourceFromPlugin
(URL u, String args) toString()
private static URI
static PluginLoader.Summary
-
Field Details
-
XPATH_PLUGIN_SHORT_DESCRIPTION
- See Also:
-
XPATH_PLUGIN_WEBSITE
- See Also:
-
XPATH_PLUGIN_PROVIDER
- See Also:
-
XPATH_PLUGIN_PLUGINID
- See Also:
-
LOG
private static final org.slf4j.Logger LOG -
lazyInitialization
static boolean lazyInitialization -
partiallyInitialized
-
nextUnknownId
private static int nextUnknownId -
classLoader
-
classLoaderForResources
-
plugin
-
corePlugin
private final boolean corePlugin -
initialPlugin
boolean initialPlugin -
cannotDisable
boolean cannotDisable -
optionalPlugin
private boolean optionalPlugin -
loadedFrom
-
jarName
-
loadedFromUri
-
createdClassLoaders
-
parentId
String parentIdplugin Id for parent plugin -
loadedPluginIds
-
-
Constructor Details
-
PluginLoader
Deprecated.Constructor.- Parameters:
url
- the URL of the plugin Jar file- Throws:
PluginException
- if the plugin cannot be fully loaded
-
PluginLoader
Deprecated.Constructor.- Parameters:
url
- the URL of the plugin Jar fileparent
- the parent classloader- Throws:
PluginException
-
PluginLoader
private PluginLoader(@Nonnull URL url, URI uri, ClassLoader parent, boolean isInitial, boolean optional) throws PluginException Constructor.- Parameters:
url
- the URL of the plugin Jar fileuri
-parent
- the parent classloaderisInitial
- is this plugin loaded from one of the standard locations for pluginsoptional
- is this an optional plugin- Throws:
PluginException
-
PluginLoader
Deprecated.Constructor. Loads a plugin using the caller's class loader. This constructor should only be used to load the "core" findbugs detectors, which are built into findbugs.jar.- Throws:
PluginException
-
PluginLoader
Deprecated.Fake plugin.
-
-
Method Details
-
hasParent
public boolean hasParent() -
finishLazyInitialization
private static void finishLazyInitialization() -
buildURLClassLoader
Creates a newURLClassLoader
and adds it to the list of classloaders we need to close if we close the corresponding plugin- Parameters:
urls
- the URLs from which to load classes and resources- Returns:
- a new
URLClassLoader
-
buildURLClassLoader
Creates a newURLClassLoader
and adds it to the list of classloaders we need to close if we close the corresponding plugin- Parameters:
urls
- the URLs from which to load classes and resourcesparent
- the parent class loader for delegation- Returns:
- a new
URLClassLoader
-
close
Closes the class loaders created in thisPluginLoader
- Specified by:
close
in interfaceAutoCloseable
- Throws:
IOException
- if a class loader fails to close, in that case the other classloaders won't be closed
-
createClassloaderUrls
Patch for issue 3429143: allow plugins load classes/resources from 3rd party jars- Parameters:
url
- plugin jar location as url- Returns:
- non empty list with url to be used for loading classes from given plugin. If plugin jar contains standard Java manifest file, all entries of its "Class-Path" attribute will be translated to the jar-relative url's and added to the returned list. If plugin jar does not contains a manifest, or manifest does not have "Class-Path" attribute, the given argument will be the only entry in the array.
- Throws:
PluginException
-
addClassPathFromManifest
private static void addClassPathFromManifest(@Nonnull URL url, @Nonnull List<URL> urls, @Nonnull Manifest mf) throws MalformedURLException - Throws:
MalformedURLException
-
guessManifest
Trying to find the manifest of "exploded plugin" in the current dir, "standard jar" manifest location or "standard" Eclipse location (sibling to the current classpath) -
computeCoreUrl
-
getURL
-
getURI
-
toUri
- Throws:
PluginException
-
getJarName
-
getClassLoader
-
loadPlugin
Get the Plugin.- Throws:
PluginException
- if the plugin cannot be fully loaded
-
getPlugin
-
resourceFromPlugin
- Throws:
MalformedURLException
-
getResource
Get a resource using the URLClassLoader classLoader. We try findResource first because (based on experiment) we can trust it to prefer resources in the jarfile to resources on the filesystem. Simply calling classLoader.getResource() allows the filesystem to override the jarfile, which can mess things up if, for example, there is a findbugs.xml or messages.xml in the current directory.- Parameters:
name
- resource to get- Returns:
- URL for the resource, or null if it could not be found
-
getCoreResource
-
resourceFromFindbugsJar
Try to load resource from JAR file of Findbugs core plugin.- Parameters:
slashedResourceName
- Name of resource to load- Returns:
- URL which points resource in jar file, or null if JAR file not found
-
getFindbugsJar
- Returns:
- URL of findbugs.jar, or null if found no jar file which contains FindBugs.class
- Throws:
MalformedURLException
-
loadFromFindBugsEtcDir
-
loadFromFindBugsPluginDir
-
getClass
private static <T> Class<? extends T> getClass(ClassLoader loader, @DottedClassName String className, Class<T> type) throws PluginException - Throws:
PluginException
-
init
- Throws:
PluginException
-
loadPluginComponents
- Throws:
PluginException
-
constructMinimalPlugin
private Plugin constructMinimalPlugin(org.dom4j.Document pluginDescriptor, List<org.dom4j.Document> messageCollectionList) throws DuplicatePluginIdError - Throws:
DuplicatePluginIdError
-
getPluginDescriptor
- Throws:
PluginException
-
getPotentialMessageFiles
-
getMessageDocuments
- Throws:
PluginException
-
loadComponentPlugin
private <T> void loadComponentPlugin(Plugin plugin, Class<T> componentKind, @DottedClassName String componentClassname, String filterId, boolean disabled, String description, String details, PropertyBundle properties) throws PluginException - Throws:
PluginException
-
parseDate
-
getConstraintSelector
private DetectorFactorySelector getConstraintSelector(org.dom4j.Element constraintElement, Plugin plugin, String singleDetectorElementName) throws PluginException - Throws:
PluginException
-
addCollection
private void addCollection(List<org.dom4j.Document> messageCollectionList, String filename) throws PluginException - Throws:
PluginException
-
findMessageNode
private static org.dom4j.Node findMessageNode(List<org.dom4j.Document> messageCollectionList, String xpath, String missingMsg) throws PluginException - Throws:
PluginException
-
findMessageText
-
getChildText
- Throws:
PluginException
-
getPluginLoader
public static PluginLoader getPluginLoader(URL url, ClassLoader parent, boolean isInitial, boolean optional) throws PluginException - Throws:
PluginException
-
getCorePluginLoader
-
isCorePlugin
public boolean isCorePlugin() -
installStandardPlugins
static void installStandardPlugins() -
loadPlugins
-
installUserInstalledPlugins
static void installUserInstalledPlugins() -
loadPluginsInDir
-
loadInitialPlugins
static void loadInitialPlugins() -
loadCorePlugin
private static void loadCorePlugin() -
loadInitialPlugin
-
installWebStartPlugins
static void installWebStartPlugins() -
getUrlBase
- Throws:
MalformedURLException
-
toString
-
validate
- Throws:
IllegalArgumentException
-
parseDocument
private static org.dom4j.Document parseDocument(@WillClose InputStream in) throws org.dom4j.DocumentException, IOException - Throws:
org.dom4j.DocumentException
IOException
-
PluginLoader(URL,URI,ClassLoader,boolean,boolean)
instead