1 package com.atlassian.plugin.impl;
2
3 import com.atlassian.plugin.Plugin;
4 import com.atlassian.plugin.ModuleDescriptor;
5 import com.atlassian.plugin.descriptors.UnloadableModuleDescriptor;
6
7 import java.util.List;
8 import java.util.ArrayList;
9 import java.util.Iterator;
10
11
12
13
14 public final class UnloadablePluginFactory
15 {
16
17
18
19
20
21
22 public static UnloadablePlugin createUnloadablePlugin(Plugin oldPlugin)
23 {
24 return createUnloadablePlugin(oldPlugin, null);
25 }
26
27
28
29
30
31
32
33
34
35
36
37 public static UnloadablePlugin createUnloadablePlugin(Plugin oldPlugin, UnloadableModuleDescriptor unloadableDescriptor)
38 {
39 UnloadablePlugin newPlugin = new UnloadablePlugin();
40
41 newPlugin.setName(oldPlugin.getName());
42 newPlugin.setKey(oldPlugin.getKey());
43 newPlugin.setI18nNameKey(oldPlugin.getI18nNameKey());
44 newPlugin.setUninstallable(oldPlugin.isUninstallable());
45 newPlugin.setDeletable(oldPlugin.isDeleteable());
46
47
48 newPlugin.setSystemPlugin(false);
49
50 newPlugin.setPluginInformation(oldPlugin.getPluginInformation());
51
52 List moduleDescriptors = new ArrayList(oldPlugin.getModuleDescriptors());
53 Iterator descriptorIterator = moduleDescriptors.iterator();
54
55
56 while (descriptorIterator.hasNext())
57 {
58 ModuleDescriptor descriptor = (ModuleDescriptor) descriptorIterator.next();
59
60
61 if (unloadableDescriptor != null && descriptor.getKey().equals(unloadableDescriptor.getKey()))
62 continue;
63
64 newPlugin.addModuleDescriptor(descriptor);
65 }
66
67
68 if (unloadableDescriptor != null)
69 newPlugin.addModuleDescriptor(unloadableDescriptor);
70
71 return newPlugin;
72 }
73 }