View Javadoc

1   package com.atlassian.plugin.osgi.factory.transform.stage;
2   
3   import com.atlassian.plugin.JarPluginArtifact;
4   import com.atlassian.plugin.PluginAccessor;
5   import com.atlassian.plugin.PluginParseException;
6   import com.atlassian.plugin.osgi.factory.OsgiPlugin;
7   import com.atlassian.plugin.osgi.factory.transform.TransformContext;
8   import com.atlassian.plugin.osgi.factory.transform.model.SystemExports;
9   import com.atlassian.plugin.osgi.hostcomponents.HostComponentRegistration;
10  import com.atlassian.plugin.osgi.container.OsgiContainerManager;
11  import com.atlassian.plugin.test.PluginJarBuilder;
12  import com.atlassian.plugin.util.PluginUtils;
13  import junit.framework.TestCase;
14  import static org.mockito.Matchers.contains;
15  import static org.mockito.Mockito.mock;
16  import static org.mockito.Mockito.verify;
17  import static org.mockito.Mockito.when;
18  import org.osgi.framework.Constants;
19  import org.osgi.framework.ServiceReference;
20  import org.apache.log4j.spi.Filter;
21  
22  import javax.print.attribute.AttributeSet;
23  import java.io.ByteArrayInputStream;
24  import java.io.File;
25  import java.io.IOException;
26  import java.util.Arrays;
27  import java.util.Collection;
28  import java.util.Collections;
29  import java.util.jar.Attributes;
30  import java.util.jar.Manifest;
31  
32  public class TestGenerateManifestStage extends TestCase
33  {
34      private GenerateManifestStage stage;
35      private OsgiContainerManager osgiContainerManager;
36  
37      @Override
38      public void setUp()
39      {
40          stage = new GenerateManifestStage();
41          osgiContainerManager = mock(OsgiContainerManager.class);
42          when(osgiContainerManager.getRegisteredServices()).thenReturn(new ServiceReference[0]);
43      }
44  
45  
46      public void testGenerateManifest() throws Exception
47      {
48          final File file = new PluginJarBuilder()
49                  .addFormattedResource(
50                          "atlassian-plugin.xml",
51                          "<atlassian-plugin key='com.atlassian.plugins.example' name='Example Plugin'>",
52                          "  <plugin-info>",
53                          "    <description>",
54                          "      A sample plugin for demonstrating the file format.",
55                          "    </description>",
56                          "    <version>1.1</version>",
57                          "    <vendor name='Atlassian Software Systems Pty Ltd' url='http://www.atlassian.com'/>",
58                          "  </plugin-info>",
59                          "</atlassian-plugin>")
60                  .addFormattedJava(
61                          "com.mycompany.myapp.Foo",
62                          "package com.mycompany.myapp; public class Foo {}")
63                  .build();
64  
65          final TransformContext context = new TransformContext(Collections.<HostComponentRegistration> emptyList(), SystemExports.NONE, new JarPluginArtifact(file),
66              null, PluginAccessor.Descriptor.FILENAME, osgiContainerManager);
67          context.setShouldRequireSpring(true);
68  
69          final Attributes attrs = executeStage(context);
70  
71          assertEquals("1.1", attrs.getValue(Constants.BUNDLE_VERSION));
72          assertEquals("com.atlassian.plugins.example", attrs.getValue(Constants.BUNDLE_SYMBOLICNAME));
73          assertEquals("A sample plugin for demonstrating the file format.", attrs.getValue(Constants.BUNDLE_DESCRIPTION));
74          assertEquals("Atlassian Software Systems Pty Ltd", attrs.getValue(Constants.BUNDLE_VENDOR));
75          assertEquals("http://www.atlassian.com", attrs.getValue(Constants.BUNDLE_DOCURL));
76          assertEquals(null, attrs.getValue(Constants.EXPORT_PACKAGE));
77          assertEquals(".", attrs.getValue(Constants.BUNDLE_CLASSPATH));
78          assertEquals("com.atlassian.plugins.example", attrs.getValue(OsgiPlugin.ATLASSIAN_PLUGIN_KEY));
79          assertEquals("*;timeout:=60", attrs.getValue("Spring-Context"));
80          assertEquals(null, attrs.getValue(Constants.IMPORT_PACKAGE));
81  
82      }
83  
84      public void testGenerateManifestWithProperInferredImports() throws Exception
85      {
86  
87          final File file = new PluginJarBuilder().addPluginInformation("someKey", "someName", "1.0").build();
88          final TransformContext context = new TransformContext(null, SystemExports.NONE, new JarPluginArtifact(file), null, PluginAccessor.Descriptor.FILENAME, osgiContainerManager);
89          context.getExtraImports().add(AttributeSet.class.getPackage().getName());
90          final Attributes attrs = executeStage(context);
91  
92          assertTrue(attrs.getValue(Constants.IMPORT_PACKAGE).contains(AttributeSet.class.getPackage().getName()));
93  
94      }
95  
96      public void testGenerateManifestWithCustomTimeout() throws Exception
97      {
98          try
99          {
100             System.setProperty(PluginUtils.ATLASSIAN_PLUGINS_ENABLE_WAIT, "333");
101             stage = new GenerateManifestStage();
102             final File file = new PluginJarBuilder().addPluginInformation("someKey", "someName", "1.0").build();
103             final TransformContext context = new TransformContext(null, SystemExports.NONE, new JarPluginArtifact(file), null, PluginAccessor.Descriptor.FILENAME, osgiContainerManager);
104             context.setShouldRequireSpring(true);
105             final Attributes attrs = executeStage(context);
106 
107             assertEquals("*;timeout:=333", attrs.getValue("Spring-Context"));
108         }
109         finally
110         {
111             System.clearProperty(PluginUtils.ATLASSIAN_PLUGINS_ENABLE_WAIT);
112         }
113 
114     }
115 
116     public void testGenerateManifestWithExistingSpringContextTimeout() throws Exception
117     {
118         try
119         {
120             System.setProperty(PluginUtils.ATLASSIAN_PLUGINS_ENABLE_WAIT, "333");
121             stage = new GenerateManifestStage();
122             final File file = new PluginJarBuilder().addPluginInformation("someKey", "someName", "1.0")
123                     .addFormattedResource("META-INF/MANIFEST.MF",
124                         "Manifest-Version: 1.0",
125                             "Spring-Context: *;timeout:=60",
126                             "Bundle-Version: 4.2.0.jira40",
127                         "Bundle-SymbolicName: my.foo.symbolicName")
128                     .build();
129             final TransformContext context = new TransformContext(null, SystemExports.NONE, new JarPluginArtifact(file), null, PluginAccessor.Descriptor.FILENAME, osgiContainerManager);
130             context.setShouldRequireSpring(true);
131             final Attributes attrs = executeStage(context);
132 
133             assertEquals("*;timeout:=333", attrs.getValue("Spring-Context"));
134         }
135         finally
136         {
137             System.clearProperty(PluginUtils.ATLASSIAN_PLUGINS_ENABLE_WAIT);
138         }
139     }
140 
141     public void testGenerateManifestWithExistingSpringContextTimeoutNoSystemProperty() throws Exception
142     {
143         stage = new GenerateManifestStage();
144         final File file = new PluginJarBuilder().addPluginInformation("someKey", "someName", "1.0")
145                 .addFormattedResource("META-INF/MANIFEST.MF",
146                         "Manifest-Version: 1.0",
147                         "Spring-Context: *;timeout:=60",
148                         "Bundle-Version: 4.2.0.jira40",
149                         "Bundle-SymbolicName: my.foo.symbolicName")
150                 .build();
151         final TransformContext context = new TransformContext(null, SystemExports.NONE, new JarPluginArtifact(file), null, PluginAccessor.Descriptor.FILENAME, osgiContainerManager);
152         context.setShouldRequireSpring(true);
153         final Attributes attrs = executeStage(context);
154 
155         assertEquals("*;timeout:=60", attrs.getValue("Spring-Context"));
156     }
157 
158     public void testGenerateManifestSpringContextTimeoutNoTimeoutInHeader() throws Exception
159     {
160         try
161         {
162             System.setProperty(PluginUtils.ATLASSIAN_PLUGINS_ENABLE_WAIT, "789");
163             stage = new GenerateManifestStage();
164             final File file = new PluginJarBuilder().addPluginInformation("someKey", "someName", "1.0")
165                     .addFormattedResource("META-INF/MANIFEST.MF",
166                             "Manifest-Version: 1.0",
167                             "Spring-Context: *;create-asynchronously:=false",
168                             "Bundle-Version: 4.2.0.jira40",
169                             "Bundle-SymbolicName: my.foo.symbolicName")
170                     .build();
171             final TransformContext context = new TransformContext(null, SystemExports.NONE, new JarPluginArtifact(file), null, PluginAccessor.Descriptor.FILENAME, osgiContainerManager);
172             context.setShouldRequireSpring(true);
173             final Attributes attrs = executeStage(context);
174             assertEquals("*;create-asynchronously:=false;timeout:=789", attrs.getValue("Spring-Context"));
175         }
176         finally
177         {
178             System.clearProperty(PluginUtils.ATLASSIAN_PLUGINS_ENABLE_WAIT);
179         }
180     }
181 
182     public void testGenerateManifestSpringContextTimeoutTimeoutAtTheBeginning() throws Exception
183     {
184         try
185         {
186             System.setProperty(PluginUtils.ATLASSIAN_PLUGINS_ENABLE_WAIT, "789");
187             stage = new GenerateManifestStage();
188             final File file = new PluginJarBuilder().addPluginInformation("someKey", "someName", "1.0")
189                     .addFormattedResource("META-INF/MANIFEST.MF",
190                             "Manifest-Version: 1.0",
191                             "Spring-Context: timeout:=123;config/account-data-context.xml;create-asynchrously:=false",
192                             "Bundle-Version: 4.2.0.jira40",
193                             "Bundle-SymbolicName: my.foo.symbolicName")
194                     .build();
195             final TransformContext context = new TransformContext(null, SystemExports.NONE, new JarPluginArtifact(file), null, PluginAccessor.Descriptor.FILENAME, osgiContainerManager);
196             context.setShouldRequireSpring(true);
197             final Attributes attrs = executeStage(context);
198             assertEquals("timeout:=789;config/account-data-context.xml;create-asynchrously:=false", attrs.getValue("Spring-Context"));
199         }
200         finally
201         {
202             System.clearProperty(PluginUtils.ATLASSIAN_PLUGINS_ENABLE_WAIT);
203         }
204     }
205 
206     public void testGenerateManifestSpringContextTimeoutTimeoutInTheMiddle() throws Exception
207     {
208         try
209         {
210             System.setProperty(PluginUtils.ATLASSIAN_PLUGINS_ENABLE_WAIT, "789");
211             stage = new GenerateManifestStage();
212             final File file = new PluginJarBuilder().addPluginInformation("someKey", "someName", "1.0")
213                     .addFormattedResource("META-INF/MANIFEST.MF",
214                             "Manifest-Version: 1.0",
215                             "Spring-Context: config/account-data-context.xml;timeout:=123;create-asynchrously:=false",
216                             "Bundle-Version: 4.2.0.jira40",
217                             "Bundle-SymbolicName: my.foo.symbolicName")
218                     .build();
219             final TransformContext context = new TransformContext(null, SystemExports.NONE, new JarPluginArtifact(file), null, PluginAccessor.Descriptor.FILENAME, osgiContainerManager);
220             context.setShouldRequireSpring(true);
221             final Attributes attrs = executeStage(context);
222             assertEquals("config/account-data-context.xml;timeout:=789;create-asynchrously:=false", attrs.getValue("Spring-Context"));
223         }
224         finally
225         {
226             System.clearProperty(PluginUtils.ATLASSIAN_PLUGINS_ENABLE_WAIT);
227         }
228     }
229 
230 
231     public void testGenerateManifestMergeHostComponentImportsWithExisting() throws Exception
232     {
233         final File plugin = new PluginJarBuilder("plugin")
234                 .addFormattedResource("META-INF/MANIFEST.MF",
235                         "Manifest-Version: 1.0",
236                         "Import-Package: javax.swing",
237                         "Bundle-SymbolicName: my.foo.symbolicName",
238                         "Bundle-Version: 1.0",
239                         "Bundle-ClassPath: .,foo")
240                 .addResource("foo/bar.txt", "Something")
241                 .addPluginInformation("innerjarcp", "Some name", "1.0")
242                 .build();
243 
244         final TransformContext context = new TransformContext(null, SystemExports.NONE, new JarPluginArtifact(plugin), null, PluginAccessor.Descriptor.FILENAME, osgiContainerManager);
245         context.getExtraImports().add(AttributeSet.class.getPackage().getName());
246         final Attributes attrs = executeStage(context);
247         assertEquals("my.foo.symbolicName", attrs.getValue(Constants.BUNDLE_SYMBOLICNAME));
248         assertEquals(".,foo", attrs.getValue(Constants.BUNDLE_CLASSPATH));
249         assertEquals("innerjarcp", attrs.getValue(OsgiPlugin.ATLASSIAN_PLUGIN_KEY));
250         final String importPackage = attrs.getValue(Constants.IMPORT_PACKAGE);
251         assertTrue(importPackage.contains(AttributeSet.class.getPackage().getName()));
252         assertTrue(importPackage.contains("javax.swing"));
253     }
254 
255     public void testGenerateManifestInvalidVersionWithExisting() throws Exception
256     {
257         final File plugin = new PluginJarBuilder("plugin")
258                 .addFormattedResource("META-INF/MANIFEST.MF",
259                         "Manifest-Version: 1.0",
260                         "Bundle-SymbolicName: my.foo.symbolicName",
261                         "Bundle-Version: beta1",
262                         "Bundle-ClassPath: .,foo\n")
263                 .addResource("foo/bar.txt", "Something")
264                 .addPluginInformation("innerjarcp", "Some name", "1.0")
265                 .build();
266 
267         final TransformContext context = new TransformContext(null, SystemExports.NONE, new JarPluginArtifact(plugin), null, PluginAccessor.Descriptor.FILENAME, osgiContainerManager);
268         try
269         {
270             executeStage(context);
271             fail("Should have complained about bad plugin version");
272         }
273         catch (PluginParseException ex)
274         {
275             ex.printStackTrace();
276             // expected
277         }
278     }
279 
280     public void testGenerateManifestInvalidVersion() throws Exception
281     {
282         final File plugin = new PluginJarBuilder("plugin")
283                 .addPluginInformation("innerjarcp", "Some name", "beta1.0")
284                 .build();
285 
286         final TransformContext context = new TransformContext(null, SystemExports.NONE, new JarPluginArtifact(plugin), null, PluginAccessor.Descriptor.FILENAME, osgiContainerManager);
287         try
288         {
289             executeStage(context);
290             fail("Should have complained about bad plugin version");
291         }
292         catch (PluginParseException ex)
293         {
294             ex.printStackTrace();
295             // expected
296         }
297 
298     }
299 
300     public void testGenerateManifestWithExistingManifestNoSpringButDescriptor() throws Exception
301     {
302         final File plugin = new PluginJarBuilder("plugin")
303                 .addFormattedResource("META-INF/MANIFEST.MF",
304                         "Manifest-Version: 1.0",
305                         "Bundle-SymbolicName: my.foo.symbolicName",
306                         "Bundle-Version: 1.0",
307                         "Bundle-ClassPath: .,foo")
308                 .addResource("foo/bar.txt", "Something")
309                 .addPluginInformation("innerjarcp", "Some name", "1.0")
310                 .build();
311 
312         final TransformContext context = new TransformContext(null, SystemExports.NONE, new JarPluginArtifact(plugin), null, PluginAccessor.Descriptor.FILENAME, osgiContainerManager);
313         final Attributes attrs = executeStage(context);
314         assertEquals("innerjarcp", attrs.getValue("Atlassian-Plugin-Key"));
315         assertNotNull(attrs.getValue("Spring-Context"));
316 
317     }
318 
319     public void testThatGeneratingManifestWithExistingManifestWithSimilarSpringAndAtlassianPluginKeyDoesNotRecreateTheManifest() throws Exception
320     {
321         final File file = new PluginJarBuilder().addPluginInformation("someKey", "someName", "1.0")
322                 .addFormattedResource("META-INF/MANIFEST.MF",
323                         "Manifest-Version: 1.0",
324                         "Spring-Context: *;timeout:=60",
325                         "Atlassian-Plugin-Key: someKey",
326                         "Bundle-Version: 4.2.0.jira40",
327                         "Bundle-SymbolicName: my.foo.symbolicName")
328                 .build();
329 
330         final TransformContext context = new TransformContext(null, SystemExports.NONE, new JarPluginArtifact(file), null, PluginAccessor.Descriptor.FILENAME, osgiContainerManager);
331         final Attributes attrs = executeStage(context);
332         assertEquals("someKey", attrs.getValue("Atlassian-Plugin-Key"));
333         assertEquals("*;timeout:=60", attrs.getValue("Spring-Context"));
334         assertNull(context.getFileOverrides().get("META-INF/MANIFEST.MF"));
335     }
336 
337     public void testThatGeneratingManifestWithExistingManifestWithDifferentSpringTimeoutRecreatesTheManifest() throws Exception
338     {
339         try
340         {
341             System.setProperty(PluginUtils.ATLASSIAN_PLUGINS_ENABLE_WAIT, "333");
342             stage = new GenerateManifestStage();
343             final File file = new PluginJarBuilder().addPluginInformation("someKey", "someName", "1.0")
344                     .addFormattedResource("META-INF/MANIFEST.MF",
345                             "Manifest-Version: 1.0",
346                             "Spring-Context: *;timeout:=60",
347                             "Atlassian-Plugin-Key: someKey",
348                             "Bundle-Version: 4.2.0.jira40",
349                             "Bundle-SymbolicName: my.foo.symbolicName")
350                     .build();
351 
352             final TransformContext context = new TransformContext(null, SystemExports.NONE, new JarPluginArtifact(file), null, PluginAccessor.Descriptor.FILENAME, osgiContainerManager);
353             final Attributes attrs = executeStage(context);
354             assertEquals("someKey", attrs.getValue("Atlassian-Plugin-Key"));
355             assertEquals("*;timeout:=333", attrs.getValue("Spring-Context"));
356             assertNotNull(context.getFileOverrides().get("META-INF/MANIFEST.MF"));
357         }
358         finally
359         {
360             System.clearProperty(PluginUtils.ATLASSIAN_PLUGINS_ENABLE_WAIT);
361         }
362     }
363 
364     public void testThatGeneratingManifestWithExistingManifestWithDifferentAtlassianPluginKeyRecreatesTheManifest() throws Exception
365     {
366         final File file = new PluginJarBuilder().addPluginInformation("someKey", "someName", "1.0")
367                 .addFormattedResource("META-INF/MANIFEST.MF",
368                         "Manifest-Version: 1.0",
369                         "Spring-Context: *;timeout:=60",
370                         "Atlassian-Plugin-Key: anotherKey",
371                         "Bundle-Version: 4.2.0.jira40",
372                         "Bundle-SymbolicName: my.foo.symbolicName")
373                 .build();
374 
375         final TransformContext context = new TransformContext(null, SystemExports.NONE, new JarPluginArtifact(file), null, PluginAccessor.Descriptor.FILENAME, osgiContainerManager);
376         final Attributes attrs = executeStage(context);
377         assertEquals("someKey", attrs.getValue("Atlassian-Plugin-Key"));
378         assertEquals("*;timeout:=60", attrs.getValue("Spring-Context"));
379         assertNotNull(context.getFileOverrides().get("META-INF/MANIFEST.MF"));
380     }
381 
382     public void testGenerateManifestWithExistingManifestWithSpringWithDescriptor() throws Exception
383     {
384         final File plugin = new PluginJarBuilder("plugin")
385                 .addFormattedResource("META-INF/MANIFEST.MF",
386                         "Manifest-Version: 1.0",
387                         "Bundle-SymbolicName: my.foo.symbolicName",
388                         "Bundle-Version: 1.0",
389                         "Spring-Context: *",
390                         "Bundle-ClassPath: .,foo")
391                 .addResource("foo/bar.txt", "Something")
392                 .addPluginInformation("innerjarcp", "Some name", "1.0")
393                 .build();
394 
395         final TransformContext context = new TransformContext(null, SystemExports.NONE, new JarPluginArtifact(plugin), null, PluginAccessor.Descriptor.FILENAME, osgiContainerManager);
396         final Attributes attrs = executeStage(context);
397         assertEquals("innerjarcp", attrs.getValue("Atlassian-Plugin-Key"));
398         assertEquals("*", attrs.getValue("Spring-Context"));
399     }
400 
401     public void testGenerateManifestNoExistingManifestButDescriptor() throws Exception
402     {
403         final File plugin = new PluginJarBuilder("plugin")
404                 .addResource("foo/bar.txt", "Something")
405                 .addPluginInformation("innerjarcp", "Some name", "1.0")
406                 .build();
407 
408         final TransformContext context = new TransformContext(null, SystemExports.NONE, new JarPluginArtifact(plugin), null, PluginAccessor.Descriptor.FILENAME, osgiContainerManager);
409         final Attributes attrs = executeStage(context);
410         assertEquals("innerjarcp", attrs.getValue("Atlassian-Plugin-Key"));
411         assertNotNull(attrs.getValue("Spring-Context"));
412 
413     }
414 
415     public void testGenerateManifestWarnNoTimeout() throws Exception
416     {
417         org.slf4j.Logger log = mock(org.slf4j.Logger.class);
418         GenerateManifestStage.log = log;
419 
420         final File plugin = new PluginJarBuilder("plugin")
421                 .addFormattedResource("META-INF/MANIFEST.MF",
422                         "Manifest-Version: 1.0",
423                         "Import-Package: javax.swing",
424                         "Bundle-SymbolicName: my.foo.symbolicName",
425                         "Bundle-Version: 1.0",
426                         "Spring-Context: *",
427                         "Bundle-ClassPath: .,foo")
428                 .addResource("foo/bar.txt", "Something")
429                 .addPluginInformation("innerjarcp", "Some name", "1.0")
430                 .build();
431 
432         final TransformContext context = new TransformContext(null, SystemExports.NONE, new JarPluginArtifact(plugin), null, PluginAccessor.Descriptor.FILENAME, osgiContainerManager);
433         context.setShouldRequireSpring(true);
434         context.getExtraImports().add(AttributeSet.class.getPackage().getName());
435         executeStage(context);
436         verify(log).warn(contains("Please add ';timeout:=60'"));
437     }
438 
439     public void testGenerateManifest_innerjarsInImports() throws Exception, PluginParseException, IOException
440     {
441         final File innerJar = new PluginJarBuilder("innerjar")
442                 .addFormattedJava("my.Foo",
443                         "package my;",
444                         "import org.apache.log4j.Logger;",
445                         "public class Foo{",
446                         "   Logger log;",
447                         "}")
448                 .build();
449         assertNotNull(innerJar);
450         final File plugin = new PluginJarBuilder("plugin")
451                 .addJava("my.Bar", "package my;import org.apache.log4j.spi.Filter; public class Bar{Filter log;}")
452                 .addFile("META-INF/lib/innerjar.jar", innerJar)
453                 .addPluginInformation("innerjarcp", "Some name", "1.0")
454                 .build();
455 
456         final TransformContext context = new TransformContext(null, SystemExports.NONE, new JarPluginArtifact(plugin), null, PluginAccessor.Descriptor.FILENAME, osgiContainerManager);
457         context.addBundleClasspathJar("META-INF/lib/innerjar.jar");
458         final Attributes attrs = executeStage(context);
459 
460         assertEquals("1.0", attrs.getValue(Constants.BUNDLE_VERSION));
461         assertEquals("innerjarcp", attrs.getValue(Constants.BUNDLE_SYMBOLICNAME));
462 
463         final Collection classpathEntries = Arrays.asList(attrs.getValue(Constants.BUNDLE_CLASSPATH).split(","));
464         assertEquals(2, classpathEntries.size());
465         assertTrue(classpathEntries.contains("."));
466         assertTrue(classpathEntries.contains("META-INF/lib/innerjar.jar"));
467 
468         final Collection imports = Arrays.asList(attrs.getValue("Import-Package").split(","));
469         assertEquals(2, imports.size());
470         assertTrue(imports.contains(org.apache.log4j.Logger.class.getPackage().getName() + ";resolution:=\"optional\""));
471         assertTrue(imports.contains(Filter.class.getPackage().getName() + ";resolution:=\"optional\""));
472     }
473 
474     public void testGenerateManifestWithBundleInstructions() throws Exception
475     {
476         final File plugin = new PluginJarBuilder("plugin")
477                 .addPluginInformation("test.plugin", "test.plugin", "1.0")
478                 .addJava("foo.MyClass", "package foo; public class MyClass{}")
479                 .addJava("foo.internal.MyPrivateClass", "package foo.internal; public class MyPrivateClass{}")
480                 .build();
481 
482         final TransformContext context = new TransformContext(null, SystemExports.NONE, new JarPluginArtifact(plugin), null, PluginAccessor.Descriptor.FILENAME, osgiContainerManager);
483         context.getBndInstructions().put("Export-Package", "!*.internal.*,*");
484         final Attributes attrs = executeStage(context);
485         assertEquals("test.plugin", attrs.getValue(Constants.BUNDLE_SYMBOLICNAME));
486         assertEquals("foo;version=\"1.0\"", attrs.getValue(Constants.EXPORT_PACKAGE));
487     }
488 
489     public void testGenerateManifestWithHostAndExternalImports() throws Exception
490     {
491         final File plugin = new PluginJarBuilder("plugin")
492                 .addPluginInformation("test.plugin", "test.plugin", "1.0")
493                 .build();
494 
495         SystemExports exports = new SystemExports("foo.bar,foo.baz;version=\"1.0\"");
496         final TransformContext context = new TransformContext(null, exports, new JarPluginArtifact(plugin), null, PluginAccessor.Descriptor.FILENAME, osgiContainerManager);
497         context.getBndInstructions().put("Import-Package", "foo.bar,foo.baz");
498         final Attributes attrs = executeStage(context);
499         assertEquals("test.plugin", attrs.getValue(Constants.BUNDLE_SYMBOLICNAME));
500 
501         String imports = attrs.getValue(Constants.IMPORT_PACKAGE);
502         assertTrue(imports.contains("foo.baz;version=\"[1.0,1.0]\""));
503         assertTrue(imports.contains("foo.bar"));
504     }
505 
506     private Attributes executeStage(final TransformContext context) throws IOException
507     {
508         stage.execute(context);
509         Manifest mf;
510         if (context.getFileOverrides().get("META-INF/MANIFEST.MF") != null)
511         {
512             mf = new Manifest(new ByteArrayInputStream(context.getFileOverrides().get("META-INF/MANIFEST.MF")));
513         }
514         else
515         {
516             mf = context.getManifest();
517         }
518         return mf.getMainAttributes();
519     }
520 }