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) booleanprivate ClassLoaderprivate final ClassLoaderprivate final booleanprivate List<URLClassLoader> (package private) booleanprivate final String(package private) static booleanprivate final URLprivate final URIprivate static final org.slf4j.Loggerprivate static intprivate boolean(package private) Stringplugin Id for parent plugin(package private) static LinkedList<PluginLoader> private final Pluginprivate static final Stringprivate static final Stringprivate static final Stringprivate static final String -
Constructor Summary
ConstructorsModifierConstructorDescriptionDeprecated.PluginLoader(boolean fake, URL url) Deprecated.PluginLoader(URL url) Deprecated.PluginLoader(URL url, ClassLoader parent) Deprecated.privatePluginLoader(URL url, URI uri, ClassLoader parent, boolean isInitial, boolean optional) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidaddClassPathFromManifest(URL url, List<URL> urls, Manifest mf) private voidaddCollection(List<org.dom4j.Document> messageCollectionList, String filename) private URLClassLoaderbuildURLClassLoader(URL[] urls) Creates a newURLClassLoaderand adds it to the list of classloaders we need to close if we close the corresponding pluginprivate URLClassLoaderbuildURLClassLoader(URL[] urls, ClassLoader parent) Creates a newURLClassLoaderand adds it to the list of classloaders we need to close if we close the corresponding pluginvoidclose()Closes the class loaders created in thisPluginLoaderprivate static URLprivate PluginconstructMinimalPlugin(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.NodefindMessageNode(List<org.dom4j.Document> messageCollectionList, String xpath, String missingMsg) private static StringfindMessageText(List<org.dom4j.Document> messageCollectionList, String xpath, String missingMsg) private static voidprivate static StringgetChildText(org.dom4j.Node node, String childName) private static <T> Class<? extends T> getClass(ClassLoader loader, String className, Class<T> type) private DetectorFactorySelectorgetConstraintSelector(org.dom4j.Element constraintElement, Plugin plugin, String singleDetectorElementName) static PluginLoader(package private) static URLgetCoreResource(String name) private static URLprivate static StringgetJarName(URL url) private List<org.dom4j.Document> org.dom4j.Documentstatic PluginLoadergetPluginLoader(URL url, ClassLoader parent, boolean isInitial, boolean optional) getResource(String name) Get a resource using the URLClassLoader classLoader.getURI()getURL()private static URLgetUrlBase(URL pluginListProperties) private static FileguessManifest(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)booleanprivate Plugininit()(package private) static void(package private) static void(package private) static voidbooleanprivate <T> voidloadComponentPlugin(Plugin plugin, Class<T> componentKind, String componentClassname, String filterId, boolean disabled, String description, String details, PropertyBundle properties) private static voidstatic URLloadFromFindBugsEtcDir(String name) static URLprivate static voidloadInitialPlugin(URL u, boolean initial, boolean optional) (package private) static voidGet the Plugin.private voidprivate static voidloadPlugins(File home) private static voidloadPluginsInDir(File pluginDir, boolean optional) private static Dateprivate static org.dom4j.Documentprivate static URLresourceFromFindbugsJar(String slashedResourceName) Try to load resource from JAR file of Findbugs core plugin.private static URLresourceFromPlugin(URL u, String args) toString()private static URIstatic 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
-
-
Method Details
-
hasParent
public boolean hasParent() -
finishLazyInitialization
private static void finishLazyInitialization() -
buildURLClassLoader
Creates a newURLClassLoaderand 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 newURLClassLoaderand 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:
closein 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
-
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
-
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.DocumentExceptionIOException
-
PluginLoader(URL,URI,ClassLoader,boolean,boolean)instead