1 package com.atlassian.plugin;
2
3
4 import java.io.InputStream;
5 import java.util.ArrayList;
6 import java.util.Collection;
7 import java.util.List;
8 import java.util.function.Predicate;
9 import java.util.stream.Collectors;
10
11
12
13
14 public class MockPluginAccessor implements PluginAccessor {
15 private Collection<Plugin> allPlugins = new ArrayList<>();
16
17 public Collection<Plugin> getPlugins() {
18 return allPlugins;
19 }
20
21 public void addPlugin(Plugin plugin) {
22 allPlugins.add(plugin);
23 }
24
25 public Collection<Plugin> getPlugins(final Predicate<Plugin> predicate) {
26 throw new UnsupportedOperationException();
27 }
28
29 public Collection<Plugin> getEnabledPlugins() {
30 return allPlugins.stream()
31 .filter(plugin -> plugin.getPluginState() == PluginState.ENABLED)
32 .collect(Collectors.toList());
33 }
34
35 public <M> Collection<M> getModules(final Predicate<ModuleDescriptor<M>> predicate) {
36 throw new UnsupportedOperationException();
37 }
38
39 public <M> Collection<ModuleDescriptor<M>> getModuleDescriptors(final Predicate<ModuleDescriptor<M>> predicate) {
40 throw new UnsupportedOperationException();
41 }
42
43 public Plugin getPlugin(final String key) {
44 for (Plugin plugin : allPlugins) {
45 if (key.equals(plugin.getKey())) {
46 return plugin;
47 }
48 }
49 return null;
50 }
51
52 public Plugin getEnabledPlugin(final String pluginKey) {
53 throw new UnsupportedOperationException();
54 }
55
56 public ModuleDescriptor<?> getPluginModule(final String completeKey) {
57 throw new UnsupportedOperationException();
58 }
59
60 public ModuleDescriptor<?> getEnabledPluginModule(final String completeKey) {
61 throw new UnsupportedOperationException();
62 }
63
64 public boolean isPluginEnabled(final String key) {
65 return getPlugin(key).getPluginState() == PluginState.ENABLED;
66 }
67
68 public boolean isPluginModuleEnabled(final String completeKey) {
69 return false;
70 }
71
72 public <M> List<M> getEnabledModulesByClass(final Class<M> moduleClass) {
73 throw new UnsupportedOperationException();
74 }
75
76 public <M> List<M> getEnabledModulesByClassAndDescriptor(final Class<ModuleDescriptor<M>>[] descriptorClazz, final Class<M> moduleClass) {
77 throw new UnsupportedOperationException();
78 }
79
80 public <M> List<M> getEnabledModulesByClassAndDescriptor(final Class<ModuleDescriptor<M>> descriptorClass, final Class<M> moduleClass) {
81 throw new UnsupportedOperationException();
82 }
83
84 public <D extends ModuleDescriptor<?>> List<D> getEnabledModuleDescriptorsByClass(final Class<D> descriptorClazz) {
85 throw new UnsupportedOperationException();
86 }
87
88 @Override
89 public <D extends ModuleDescriptor<?>> List<D> getActiveModuleDescriptorsByClass(Class<D> descriptorClazz) {
90 throw new UnsupportedOperationException("Not implemented");
91 }
92
93 public <M> List<ModuleDescriptor<M>> getEnabledModuleDescriptorsByType(final String type)
94 throws PluginParseException {
95 throw new UnsupportedOperationException();
96 }
97
98 public InputStream getDynamicResourceAsStream(final String resourcePath) {
99 throw new UnsupportedOperationException();
100 }
101
102 public InputStream getPluginResourceAsStream(final String pluginKey, final String resourcePath) {
103 throw new UnsupportedOperationException();
104 }
105
106 public Class<?> getDynamicPluginClass(final String className) {
107 throw new UnsupportedOperationException();
108 }
109
110 public ClassLoader getClassLoader() {
111 throw new UnsupportedOperationException();
112 }
113
114 public boolean isSystemPlugin(final String key) {
115 return false;
116 }
117
118 public PluginRestartState getPluginRestartState(final String key) {
119 throw new UnsupportedOperationException();
120 }
121
122 public Iterable<ModuleDescriptor<?>> getDynamicModules(final Plugin plugin) {
123 throw new UnsupportedOperationException();
124 }
125 }