1 package org.apache.felix.bundleplugin;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 import java.io.File;
24 import java.util.Collections;
25 import java.util.Map;
26
27 import org.apache.maven.plugin.testing.stubs.ArtifactStub;
28 import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
29 import org.apache.maven.project.MavenProject;
30 import org.apache.maven.shared.osgi.DefaultMaven2OsgiConverter;
31
32
33
34
35
36
37
38 public class BundleAllPluginTest extends AbstractBundlePluginTest
39 {
40
41 private BundleAllPlugin plugin;
42
43
44 protected void setUp() throws Exception
45 {
46 super.setUp();
47 init();
48 }
49
50
51 private void init()
52 {
53 plugin = new BundleAllPlugin();
54 File baseDirectory = new File( getBasedir() );
55 File buildDirectory = new File( baseDirectory, "target" );
56 plugin.setBuildDirectory( buildDirectory.getPath() );
57 File outputDirectory = new File( buildDirectory, "test-classes" );
58 plugin.setOutputDirectory( outputDirectory );
59 plugin.setMaven2OsgiConverter( new DefaultMaven2OsgiConverter() );
60 }
61
62
63 public void testSnapshotMatch()
64 {
65 ArtifactStub artifact = getArtifactStub();
66 String bundleName;
67
68 artifact.setVersion( "2.1-SNAPSHOT" );
69 bundleName = "group.artifact_2.1.0.20070207_193904_2.jar";
70
71 assertTrue( plugin.snapshotMatch( artifact, bundleName ) );
72
73 artifact.setVersion( "2-SNAPSHOT" );
74 assertFalse( plugin.snapshotMatch( artifact, bundleName ) );
75
76 artifact.setArtifactId( "artifactx" );
77 artifact.setVersion( "2.1-SNAPSHOT" );
78 assertFalse( plugin.snapshotMatch( artifact, bundleName ) );
79 }
80
81
82 public void testNoReBundling() throws Exception
83 {
84 File testFile = getTestFile( "target/test-classes/org.apache.maven.maven-model_1.0.0.0.jar" );
85 if ( testFile.exists() )
86 {
87 testFile.delete();
88 }
89
90 ArtifactStub artifact = new ArtifactStub();
91 artifact.setGroupId( "group" );
92 artifact.setArtifactId( "artifact" );
93 artifact.setVersion( "1.0.0.0" );
94
95 MavenProject project = new MavenProjectStub();
96 project.setGroupId( artifact.getGroupId() );
97 project.setArtifactId( artifact.getArtifactId() );
98 project.setVersion( artifact.getVersion() );
99 project.setArtifact( artifact );
100 project.setArtifacts( Collections.EMPTY_SET );
101 project.setDependencyArtifacts( Collections.EMPTY_SET );
102 File bundleFile = getTestFile( "src/test/resources/org.apache.maven.maven-model_2.1.0.SNAPSHOT.jar" );
103 artifact.setFile( bundleFile );
104
105 BundleInfo bundleInfo = plugin.bundle( project );
106
107 Map exports = bundleInfo.getExportedPackages();
108 String[] packages = new String[]
109 { "org.apache.maven.model.io.jdom", "org.apache.maven.model" };
110
111 for ( int i = 0; i < packages.length; i++ )
112 {
113 assertTrue( "Bundle info does not contain a package that it is exported in the manifest: " + packages[i],
114 exports.containsKey( packages[i] ) );
115 }
116
117 assertFalse( "Bundle info contains a package that it is not exported in the manifest",
118 exports.containsKey( "org.apache.maven.model.io.xpp3" ) );
119 }
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147 }