1 package com.atlassian.plugin;
2
3 import com.atlassian.plugin.predicate.ModuleDescriptorPredicate;
4 import com.atlassian.plugin.predicate.PluginPredicate;
5
6 import java.io.InputStream;
7 import java.util.Collection;
8 import java.util.List;
9
10 /**
11 * Allows access to the current plugin system state
12 */
13 public interface PluginAccessor
14 {
15 /**
16 * Gets all of the currently installed plugins.
17 * @return a collection of installed {@link Plugin}s.
18 */
19 Collection<Plugin> getPlugins();
20
21 /**
22 * Gets all installed plugins that match the given predicate.
23 * @param pluginPredicate the {@link PluginPredicate} to match.
24 * @return a collection of {@link Plugin}s that match the given predicate.
25 * @since 0.17
26 */
27 Collection<Plugin> getPlugins(final PluginPredicate pluginPredicate);
28
29 /**
30 * Get all of the currently enabled plugins.
31 * @return a collection of installed and enabled {@link Plugin}s.
32 */
33 Collection<Plugin> getEnabledPlugins();
34
35 /**
36 * Gets all installed modules that match the given predicate.
37 * @param moduleDescriptorPredicate the {@link com.atlassian.plugin.predicate.ModuleDescriptorPredicate} to match.
38 * @return a collection of modules as per {@link ModuleDescriptor#getModule()} that match the given predicate.
39 * @since 0.17
40 */
41 <T> Collection<T> getModules(final ModuleDescriptorPredicate<T> moduleDescriptorPredicate);
42
43 /**
44 * Gets all module descriptors of installed modules that match the given predicate.
45 * @param moduleDescriptorPredicate the {@link com.atlassian.plugin.predicate.ModuleDescriptorPredicate} to match.
46 * @return a collection of {@link ModuleDescriptor}s that match the given predicate.
47 * @since 0.17
48 */
49 <T> Collection<ModuleDescriptor<T>> getModuleDescriptors(final ModuleDescriptorPredicate<T> moduleDescriptorPredicate);
50
51 /**
52 * Retrieve a given plugin (whether enabled or not).
53 * @return The enabled plugin, or null if that plugin does not exist.
54 */
55 Plugin getPlugin(String key);
56
57 /**
58 * Retrieve a given plugin if it is enabled.
59 * @return The enabled plugin, or null if that plugin does not exist or is disabled.
60 */
61 Plugin getEnabledPlugin(String pluginKey);
62
63 /**
64 * Retrieve any plugin module by complete module key.
65 * <p>
66 * Note: the module may or may not be disabled.
67 */
68 ModuleDescriptor getPluginModule(String completeKey);
69
70 /**
71 * Retrieve an enabled plugin module by complete module key.
72 */
73 ModuleDescriptor getEnabledPluginModule(String completeKey);
74
75 /**
76 * Whether or not a given plugin is currently enabled.
77 */
78 boolean isPluginEnabled(String key);
79
80 /**
81 * Whether or not a given plugin module is currently enabled. This also checks
82 * if the plugin it is contained within is enabled also
83 * @see #isPluginEnabled(String)
84 */
85 boolean isPluginModuleEnabled(String completeKey);
86
87 /**
88 * Retrieve all plugin modules that implement or extend a specific class.
89 *
90 * @return List of modules that implement or extend the given class.
91 */
92 <T> List<T> getEnabledModulesByClass(Class<T> moduleClass);
93
94 /**
95 * Retrieve all plugin modules that implement or extend a specific class, and has a descriptor class
96 * as one of descriptorClazz
97 *
98 * @param descriptorClazz @NotNull
99 * @param moduleClass @NotNull
100 * @return List of modules that implement or extend the given class. Empty list if none found
101 * @deprecated since 0.17, use {@link #getModules(com.atlassian.plugin.predicate.ModuleDescriptorPredicate)} with an appropriate predicate instead.
102 */
103 <T> List<T> getEnabledModulesByClassAndDescriptor(Class<ModuleDescriptor<T>>[] descriptorClazz, Class<T> moduleClass);
104
105 /**
106 * Retrieve all plugin modules that implement or extend a specific class, and has a descriptor class
107 * as the descriptorClazz
108 *
109 * @param descriptorClazz @NotNull
110 * @param moduleClass @NotNull
111 * @return List of modules that implement or extend the given class. Empty list if none found
112 * @deprecated since 0.17, use {@link #getModules(com.atlassian.plugin.predicate.ModuleDescriptorPredicate)} with an appropriate predicate instead.
113 */
114 <T> List<T> getEnabledModulesByClassAndDescriptor(Class<ModuleDescriptor<T>> descriptorClazz, Class<T> moduleClass);
115
116 /**
117 * Get all enabled module descriptors that have a specific descriptor class.
118 *
119 * @param descriptorClazz module descriptor class
120 * @return List of {@link ModuleDescriptor}s that implement or extend the given class.
121 */
122 <T extends ModuleDescriptor> List<T> getEnabledModuleDescriptorsByClass(Class<T> descriptorClazz);
123
124 /**
125 * Get all enabled module descriptors that have a specific descriptor class.
126 *
127 * @param descriptorClazz module descriptor class
128 * @param verbose log verbose messages flag
129 * @return List of {@link ModuleDescriptor}s that implement or extend the given class.
130 */
131 <T extends ModuleDescriptor> List<T> getEnabledModuleDescriptorsByClass(Class<T> descriptorClazz, boolean verbose);
132
133 /**
134 * Get all enabled module descriptors that have a specific descriptor type.
135 *
136 * @return List of {@link ModuleDescriptor}s that are of a given type.
137 * @deprecated since 0.17, use {@link #getModuleDescriptors(com.atlassian.plugin.predicate.ModuleDescriptorPredicate)} with an appropriate predicate instead.
138 */
139 <T extends ModuleDescriptor> List<T> getEnabledModuleDescriptorsByType(String type) throws PluginParseException;
140
141 /**
142 * Retrieve a resource from a currently loaded (and active) dynamically loaded plugin. Will return the first resource
143 * found, so plugins with overlapping resource names will behave eratically.
144 *
145 * @param resourcePath the path to the resource to retrieve
146 * @return the dynamically loaded resource that matches that path, or null if no such resource is found
147 */
148 InputStream getDynamicResourceAsStream(String resourcePath);
149
150 /**
151 * Retrieve a resource from a currently loaded (and active) plugin. For statically loaded plugins, this just means
152 * pulling the resource from the PluginManager's classloader. For dynamically loaded plugins, this means retrieving
153 * the resource from the plugin's private classloader.
154 * @deprecated since 0.21 this method is not used, use
155 * {@link #getPlugin(String)}.{@link Plugin#getClassLoader() getClassLoader()}.{@link ClassLoader#getResourceAsStream(String) getResourceAsStream(String)}
156 */
157 InputStream getPluginResourceAsStream(String pluginKey, String resourcePath);
158
159 /**
160 * Retrieve a class from a currently loaded (and active) dynamically loaded plugin. Will return the first class
161 * found, so plugins with overlapping class names will behave eratically.
162 *
163 * @param className the name of the class to retrieve
164 * @return the dynamically loaded class that matches that name
165 * @throws ClassNotFoundException thrown if no classes by that name could be found in any of the enabled dynamic plugins
166 * @deprecated since 0.21 this method is not used, use
167 * {@link #getPlugin(String)}.{@link Plugin#getClassLoader() getClassLoader()}.{@link ClassLoader#loadClass(String) loadClass(String)}
168 */
169 Class<?> getDynamicPluginClass(String className) throws ClassNotFoundException;
170
171 /**
172 * Retrieve the class loader responsible for loading classes and resources from plugins.
173 * @return the class loader
174 * @since 0.21
175 */
176 ClassLoader getClassLoader();
177
178 /**
179 * @return true if the plugin is a system plugin.
180 */
181 boolean isSystemPlugin(String key);
182 }