1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.felix.bundleplugin;
20
21
22 import java.io.File;
23 import java.util.ArrayList;
24 import java.util.Arrays;
25 import java.util.HashMap;
26 import java.util.List;
27 import java.util.Map;
28 import java.util.Properties;
29 import java.util.jar.Manifest;
30
31 import junit.framework.TestCase;
32
33 import org.apache.maven.model.Resource;
34 import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
35 import org.osgi.framework.Constants;
36
37 import aQute.lib.osgi.Builder;
38
39
40 public class BlueprintComponentTest extends TestCase
41 {
42
43 public void testBlueprint() throws Exception
44 {
45 MavenProjectStub project = new MavenProjectStub()
46 {
47 private final List resources = new ArrayList();
48
49
50 @Override
51 public void addResource( Resource resource )
52 {
53 resources.add( resource );
54 }
55
56
57 @Override
58 public List getResources()
59 {
60 return resources;
61 }
62
63
64 @Override
65 public File getBasedir()
66 {
67 return new File( "target/tmp/basedir" );
68 }
69 };
70 project.setGroupId( "group" );
71 project.setArtifactId( "artifact" );
72 project.setVersion( "1.1.0.0" );
73 Resource r = new Resource();
74 r.setDirectory( new File( "src/test/resources" ).getAbsoluteFile().getCanonicalPath() );
75 r.setIncludes( Arrays.asList( "**/*.*" ) );
76 project.addResource( r );
77 project.addCompileSourceRoot( new File( "src/test/resources" ).getAbsoluteFile().getCanonicalPath() );
78
79 ManifestPlugin plugin = new ManifestPlugin();
80 plugin.setBuildDirectory( "target/tmp/basedir/target" );
81 plugin.setOutputDirectory( new File( "target/tmp/basedir/target/classes" ) );
82
83 Map instructions = new HashMap();
84 instructions.put( "Test", "Foo" );
85
86 instructions.put( "nsh_interface", "foo.bar.Namespace" );
87 instructions.put( "nsh_namespace", "ns" );
88
89 instructions.put( "Export-Service", "p7.Foo;mk=mv" );
90 instructions.put( "Import-Service", "org.osgi.service.cm.ConfigurationAdmin;availability:=optional" );
91
92 Properties props = new Properties();
93 Builder builder = plugin.buildOSGiBundle( project, instructions, props, plugin.getClasspath( project ) );
94
95 Manifest manifest = builder.getJar().getManifest();
96 String expSvc = manifest.getMainAttributes().getValue( Constants.EXPORT_SERVICE );
97 String impSvc = manifest.getMainAttributes().getValue( Constants.IMPORT_SERVICE );
98 assertNotNull( expSvc );
99 assertNotNull( impSvc );
100
101 String impPkg = manifest.getMainAttributes().getValue( Constants.IMPORT_PACKAGE );
102 List<String> pkgs = Arrays.asList( impPkg.split( "," ) );
103 for ( int i = 1; i <= 13; i++ )
104 {
105 assertTrue( pkgs.contains( "p" + i ) );
106 }
107 }
108
109 }