1 package com.atlassian.plugin.osgi.factory;
2
3 import com.atlassian.plugin.module.ContainerAccessor;
4 import org.osgi.framework.Bundle;
5 import org.osgi.util.tracker.ServiceTracker;
6
7 import java.io.InputStream;
8 import java.net.URL;
9 import java.util.Set;
10
11 /**
12 * Helper for the {@link OsgiPlugin} to abstract how key operations are handled in different states, represented
13 * by implementations of this interface.
14 *
15 * @since 2.2.0
16 */
17 interface OsgiPluginHelper
18 {
19 /**
20 * @return the OSGi bundle
21 */
22 Bundle getBundle();
23
24 /**
25 * Loads a class from the bundle
26 *
27 * @param clazz The class name to load
28 * @param callingClass The calling class
29 * @param <T> The type of class to load
30 * @return An instance of the class
31 * @throws ClassNotFoundException If the class cannot be found
32 */
33 <T> Class<T> loadClass(String clazz, Class<?> callingClass) throws ClassNotFoundException;
34
35 /**
36 * Gets a resource from the bundle
37 * @param name The resource name
38 * @return The resource
39 */
40 URL getResource(final String name);
41
42 /**
43 * Gets a resource as a stream from the bundle
44 * @param name The resource name
45 * @return The input stream
46 */
47 InputStream getResourceAsStream(final String name);
48
49 /**
50 * Gets the classloader for this bundle
51 * @return The class loader instance
52 */
53 ClassLoader getClassLoader();
54
55 /**
56 * Installs the bundle
57 * @return The created bundle
58 */
59 Bundle install();
60
61 /**
62 * Notification the bundle has been enabled
63 *
64 * @param serviceTrackers The service trackers to associate with the bundle
65 */
66 void onEnable(ServiceTracker... serviceTrackers);
67
68 /**
69 * Notification that the plugin has been disabled
70 */
71 void onDisable();
72
73 /**
74 * Notification the bundle has been uninstalled
75 */
76 void onUninstall();
77
78 /**
79 * @return a list of required plugins
80 */
81 Set<String> getRequiredPlugins();
82
83 /**
84 * @param container the plugin container (likely a spring context)
85 */
86 void setPluginContainer(Object container);
87
88 ContainerAccessor getContainerAccessor();
89
90 ContainerAccessor getRequiredContainerAccessor();
91
92 /**
93 * Tells whether this plugin is a remote plugin or not, by looking up the manifest header.
94 * @return {@code true} if it is a remote plugin
95 *
96 * @since 3.0
97 */
98 boolean isRemotePlugin();
99 }