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.artifact.Artifact;
28 import org.apache.maven.artifact.DefaultArtifact;
29 import org.apache.maven.artifact.handler.ArtifactHandler;
30 import org.apache.maven.artifact.handler.DefaultArtifactHandler;
31 import org.apache.maven.artifact.versioning.VersionRange;
32 import org.apache.maven.plugin.testing.stubs.ArtifactStub;
33 import org.apache.maven.project.MavenProject;
34 import org.apache.maven.shared.dependency.graph.DependencyGraphBuilder;
35
36
37
38
39
40
41
42 public class BundleAllPluginTest extends AbstractBundlePluginTest
43 {
44
45 private BundleAllPlugin plugin;
46
47
48 @Override
49 protected void setUp() throws Exception
50 {
51 super.setUp();
52 init();
53 }
54
55
56 private void init() throws Exception
57 {
58 plugin = new BundleAllPlugin();
59 File baseDirectory = new File( getBasedir() );
60 File buildDirectory = new File( baseDirectory, "target" );
61 plugin.setBuildDirectory( buildDirectory.getPath() );
62 File outputDirectory = new File( buildDirectory, "test-classes" );
63 plugin.setOutputDirectory( outputDirectory );
64 setVariableValueToObject(plugin, "m_dependencyGraphBuilder", lookup(DependencyGraphBuilder.class.getName(), "default"));
65 }
66
67
68 public void testSnapshotMatch()
69 {
70 ArtifactStub artifact = getArtifactStub();
71 String bundleName;
72
73 artifact.setVersion( "2.1-SNAPSHOT" );
74 bundleName = "group.artifact_2.1.0.20070207_193904_2.jar";
75
76 assertTrue( plugin.snapshotMatch( artifact, bundleName ) );
77
78 artifact.setVersion( "2-SNAPSHOT" );
79 assertFalse( plugin.snapshotMatch( artifact, bundleName ) );
80
81 artifact.setArtifactId( "artifactx" );
82 artifact.setVersion( "2.1-SNAPSHOT" );
83 assertFalse( plugin.snapshotMatch( artifact, bundleName ) );
84 }
85
86
87 public void testNoReBundling() throws Exception
88 {
89 File testFile = getTestFile( "target/test-classes/org.apache.maven.maven-model_1.0.0.0.jar" );
90 if ( testFile.exists() )
91 {
92 testFile.delete();
93 }
94
95 VersionRange versionRange = VersionRange.createFromVersion("1.0.0.0");
96 ArtifactHandler artifactHandler = new DefaultArtifactHandler( "jar" );
97 Artifact artifact = new DefaultArtifact("group","artifact",versionRange, null, "jar", null, artifactHandler);
98
99 MavenProject project = getMavenProjectStub();
100 project.setGroupId( artifact.getGroupId() );
101 project.setArtifactId( artifact.getArtifactId() );
102 project.setVersion( artifact.getVersion() );
103 project.setArtifact( artifact );
104 project.setArtifacts( Collections.EMPTY_SET );
105 project.setDependencyArtifacts( Collections.EMPTY_SET );
106 File bundleFile = getTestFile( "src/test/resources/org.apache.maven.maven-model_2.1.0.SNAPSHOT.jar" );
107 artifact.setFile( bundleFile );
108
109 BundleInfo bundleInfo = plugin.bundle( project );
110
111 Map exports = bundleInfo.getExportedPackages();
112 String[] packages = new String[]
113 { "org.apache.maven.model.io.jdom", "org.apache.maven.model" };
114
115 for ( int i = 0; i < packages.length; i++ )
116 {
117 assertTrue( "Bundle info does not contain a package that it is exported in the manifest: " + packages[i],
118 exports.containsKey( packages[i] ) );
119 }
120
121 assertFalse( "Bundle info contains a package that it is not exported in the manifest",
122 exports.containsKey( "org.apache.maven.model.io.xpp3" ) );
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
148
149
150
151 }