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