1 package it.com.atlassian.plugin.osgi.performance;
2
3 import com.atlassian.plugin.DefaultModuleDescriptorFactory;
4 import com.atlassian.plugin.hostcontainer.DefaultHostContainer;
5 import com.atlassian.plugin.test.PluginJarBuilder;
6
7 import it.com.atlassian.plugin.osgi.performance.FrameworkRestartTestBase;
8 import org.apache.commons.io.FileUtils;
9
10 import java.io.File;
11 import java.util.Random;
12
13
14
15
16 public class TestOsgiNoCacheFrameworkRestart extends FrameworkRestartTestBase
17 {
18 private final Random rnd = new Random(System.currentTimeMillis());
19
20 protected void addPlugin(File dir, int pluginId) throws Exception
21 {
22 System.out.println("building plugin " + pluginId);
23 PluginJarBuilder builder = new PluginJarBuilder("restart-test", null);
24
25 StringBuilder apxml = new StringBuilder();
26 apxml.append("<atlassian-plugin name='Test' key='test.plugin" + pluginId + "' pluginsVersion='2'>\n" +
27 " <plugin-info>\n" +
28 " <version>1.0</version>\n" +
29 " </plugin-info>\n" +
30
31 " <dummy key='dum1'/>\n");
32
33 for (int x=0; x<50; x++)
34 {
35 String pkg = pkg(pluginId, x);
36 builder.addFormattedJava(pkg + ".MyInterface",
37 "package " + pkg + ";",
38 "public interface MyInterface {}");
39 builder.addFormattedJava(pkg + ".MyComponent",
40 "package " + pkg + ";",
41 "public class MyComponent implements MyInterface {",
42 " public MyComponent() {}",
43 "}");
44 apxml.append(" <component key='comp" + x + "' interface='" + pkg + ".MyInterface' class='" + pkg + ".MyComponent' ");
45 if (x < 10)
46 {
47 apxml.append("public='true'");
48 }
49 apxml.append("/>\n");
50 }
51 if (pluginId != 49)
52 {
53
54 for (int x=0; x<10; x++)
55 {
56 int refid;
57 do
58 {
59 refid = 50 - rnd.nextInt(50 - pluginId) - 1;
60 }
61 while (refid == pluginId);
62
63 apxml.append(" <component-import key='ref" + x + "' interface='" + pkg(refid, x) + ".MyInterface'/>\n");
64 }
65 }
66 apxml.append("</atlassian-plugin>");
67 builder.addFormattedResource("atlassian-plugin.xml", apxml.toString());
68 builder.build(dir);
69 System.out.println("plugin " + pluginId + " built");
70 }
71
72 private String pkg(int pluginId, int x)
73 {
74 return "plugin" + pluginId + ".component" + x;
75 }
76 }