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 }
65
66
67 public void testSnapshotMatch()
68 {
69 ArtifactStub artifact = getArtifactStub();
70 String bundleName;
71
72 artifact.setVersion( "2.1-SNAPSHOT" );
73 bundleName = "group.artifact_2.1.0.20070207_193904_2.jar";
74
75 assertTrue( plugin.snapshotMatch( artifact, bundleName ) );
76
77 artifact.setVersion( "2-SNAPSHOT" );
78 assertFalse( plugin.snapshotMatch( artifact, bundleName ) );
79
80 artifact.setArtifactId( "artifactx" );
81 artifact.setVersion( "2.1-SNAPSHOT" );
82 assertFalse( plugin.snapshotMatch( artifact, bundleName ) );
83 }
84
85
86 public void testNoReBundling() throws Exception
87 {
88 File testFile = getTestFile( "target/test-classes/org.apache.maven.maven-model_1.0.0.0.jar" );
89 if ( testFile.exists() )
90 {
91 testFile.delete();
92 }
93
94 VersionRange versionRange = VersionRange.createFromVersion("1.0.0.0");
95 ArtifactHandler artifactHandler = new DefaultArtifactHandler( "jar" );
96 Artifact artifact = new DefaultArtifact("group","artifact",versionRange, null, "jar", null, artifactHandler);
97
98 MavenProject project = getMavenProjectStub();
99 project.setGroupId( artifact.getGroupId() );
100 project.setArtifactId( artifact.getArtifactId() );
101 project.setVersion( artifact.getVersion() );
102 project.setArtifact( artifact );
103 project.setArtifacts( Collections.EMPTY_SET );
104 project.setDependencyArtifacts( Collections.EMPTY_SET );
105 File bundleFile = getTestFile( "src/test/resources/org.apache.maven.maven-model_2.1.0.SNAPSHOT.jar" );
106 artifact.setFile( bundleFile );
107
108 BundleInfo bundleInfo = plugin.bundle( project );
109
110 Map exports = bundleInfo.getExportedPackages();
111 String[] packages = new String[]
112 { "org.apache.maven.model.io.jdom", "org.apache.maven.model" };
113
114 for ( int i = 0; i < packages.length; i++ )
115 {
116 assertTrue( "Bundle info does not contain a package that it is exported in the manifest: " + packages[i],
117 exports.containsKey( packages[i] ) );
118 }
119
120 assertFalse( "Bundle info contains a package that it is not exported in the manifest",
121 exports.containsKey( "org.apache.maven.model.io.xpp3" ) );
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
148
149
150 }