1 package com.atlassian.plugin;
2
3 import java.io.InputStream;
4 import java.net.URL;
5 import java.util.Collection;
6 import java.util.Comparator;
7 import java.util.Date;
8 import java.util.List;
9
10 public interface Plugin extends Resourced, Comparable
11 {
12 public static final Comparator NAME_COMPARATOR = new PluginNameComparator();
13
14 /**
15 * Gets the version of the plugins system to handle this plugin
16 * @return The plugins version. If undefined, assumed to be 1.
17 */
18 int getPluginsVersion();
19
20 /**
21 * Sets the version of the plugins system
22 * @param version The version
23 */
24 void setPluginsVersion(int version);
25
26 String getName();
27
28 void setName(String name);
29
30 String getI18nNameKey();
31
32 void setI18nNameKey(String i18nNameKey);
33
34 String getKey();
35
36 void setKey(String aPackage);
37
38 void addModuleDescriptor(ModuleDescriptor moduleDescriptor);
39
40 Collection getModuleDescriptors();
41
42 ModuleDescriptor getModuleDescriptor(String key);
43
44 List getModuleDescriptorsByModuleClass(Class aClass);
45
46 boolean isEnabledByDefault();
47
48 void setEnabledByDefault(boolean enabledByDefault);
49
50 PluginInformation getPluginInformation();
51
52 void setPluginInformation(PluginInformation pluginInformation);
53
54 void setResources(Resourced resources);
55
56 boolean isEnabled();
57
58 void setEnabled(boolean enabled);
59
60 /**
61 * Whether the plugin is a "system" plugin that shouldn't be made visible to the user
62 */
63 boolean isSystemPlugin();
64
65 boolean containsSystemModule();
66
67 void setSystemPlugin(boolean system);
68
69 /**
70 * Whether the plugin is a "bundled" plugin that can't be removed.
71 */
72 boolean isBundledPlugin();
73
74 /**
75 * The date this plugin was loaded into the system.
76 */
77 Date getDateLoaded();
78
79 /**
80 * Whether or not this plugin can be 'uninstalled'.
81 */
82 boolean isUninstallable();
83
84 /**
85 * Should the plugin file be deleted on unistall?
86 */
87 boolean isDeleteable();
88
89 /**
90 * Whether or not this plugin is loaded dynamically at runtime
91 */
92 boolean isDynamicallyLoaded();
93
94 /**
95 * Get the plugin to load a specific class.
96 *
97 * @param clazz The name of the class to be loaded
98 * @param callingClass The class calling the loading (used to help find a classloader)
99 * @return The loaded class.
100 * @throws ClassNotFoundException
101 */
102 Class loadClass(String clazz, Class callingClass) throws ClassNotFoundException;
103
104 /**
105 * Get the classloader for the plugin.
106 *
107 * @return The classloader used to load classes for this plugin
108 */
109 ClassLoader getClassLoader();
110
111 /**
112 * Retrieve the URL of the resource from the plugin.
113 *
114 * @param path the name of the resource to be loaded
115 * @return The URL to the resource, or null if the resource is not found
116 */
117 URL getResource(String path);
118
119 /**
120 * Load a given resource from the plugin. Plugins that are loaded dynamically will need
121 * to implement this in a way that loads the resource from the same context as the plugin.
122 * Static plugins can just pull them from their own classloader.
123 *
124 * @param name The name of the resource to be loaded.
125 * @return An InputStream for the resource, or null if the resource is not found.
126 */
127 InputStream getResourceAsStream(String name);
128
129 /**
130 * Free any resources held by this plugin. To be called during uninstallation of the {@link Plugin}.
131 */
132 void close();
133 }