1 package org.apache.maven.plugin;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.List;
23
24 import org.apache.maven.AbstractCoreMavenComponentTestCase;
25 import org.apache.maven.artifact.Artifact;
26 import org.apache.maven.artifact.repository.DefaultRepositoryRequest;
27 import org.apache.maven.artifact.repository.RepositoryRequest;
28 import org.apache.maven.execution.MavenSession;
29 import org.apache.maven.model.Plugin;
30 import org.apache.maven.plugin.descriptor.MojoDescriptor;
31 import org.apache.maven.plugin.descriptor.PluginDescriptor;
32 import org.apache.maven.project.MavenProject;
33 import org.codehaus.plexus.classworlds.realm.ClassRealm;
34 import org.codehaus.plexus.component.annotations.Requirement;
35 import org.codehaus.plexus.component.repository.ComponentDescriptor;
36
37 public class PluginManagerTest
38 extends AbstractCoreMavenComponentTestCase
39 {
40 @Requirement
41 private DefaultBuildPluginManager pluginManager;
42
43 protected void setUp()
44 throws Exception
45 {
46 super.setUp();
47 pluginManager = (DefaultBuildPluginManager) lookup( BuildPluginManager.class );
48 }
49
50 @Override
51 protected void tearDown()
52 throws Exception
53 {
54 pluginManager = null;
55 super.tearDown();
56 }
57
58 protected String getProjectsDirectory()
59 {
60 return "src/test/projects/plugin-manager";
61 }
62
63 public void testPluginLoading()
64 throws Exception
65 {
66 MavenSession session = createMavenSession( null );
67 Plugin plugin = new Plugin();
68 plugin.setGroupId( "org.apache.maven.its.plugins" );
69 plugin.setArtifactId( "maven-it-plugin" );
70 plugin.setVersion( "0.1" );
71 PluginDescriptor pluginDescriptor =
72 pluginManager.loadPlugin( plugin, session.getCurrentProject().getRemotePluginRepositories(),
73 session.getRepositorySession() );
74 assertNotNull( pluginDescriptor );
75 }
76
77 public void testMojoDescriptorRetrieval()
78 throws Exception
79 {
80 MavenSession session = createMavenSession( null );
81 String goal = "it";
82 Plugin plugin = new Plugin();
83 plugin.setGroupId( "org.apache.maven.its.plugins" );
84 plugin.setArtifactId( "maven-it-plugin" );
85 plugin.setVersion( "0.1" );
86
87 MojoDescriptor mojoDescriptor =
88 pluginManager.getMojoDescriptor( plugin, goal, session.getCurrentProject().getRemotePluginRepositories(),
89 session.getRepositorySession() );
90 assertNotNull( mojoDescriptor );
91 assertEquals( goal, mojoDescriptor.getGoal() );
92
93
94
95 PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
96 assertNotNull( pluginDescriptor );
97 assertEquals( "org.apache.maven.its.plugins", pluginDescriptor.getGroupId() );
98 assertEquals( "maven-it-plugin", pluginDescriptor.getArtifactId() );
99 assertEquals( "0.1", pluginDescriptor.getVersion() );
100 }
101
102
103
104
105
106
107
108
109
110
111
112
113 public void testRemoteResourcesPlugin()
114 throws Exception
115 {
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139 }
140
141
142 public void testSurefirePlugin()
143 throws Exception
144 {
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164 }
165
166 public void testMojoConfigurationIsMergedCorrectly()
167 throws Exception
168 {
169 }
170
171
172
173
174
175
176 public void testMojoWhereInternallyStatedDependencyIsOverriddenByProject()
177 throws Exception
178 {
179 }
180
181
182
183
184
185 public void testMojoThatIsPresentInTheCurrentBuild()
186 throws Exception
187 {
188 }
189
190
191
192
193
194 public void testAggregatorMojo()
195 throws Exception
196 {
197 }
198
199
200
201
202
203 public void testMojoThatRequiresExecutionToAGivenPhaseBeforeExecutingItself()
204 throws Exception
205 {
206 }
207
208
209
210
211
212
213
214 public void testThatPluginDependencyThatHasSystemScopeIsResolved()
215 throws Exception
216 {
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239 MavenSession session = createMavenSession( getProject( "project-contributing-system-scope-plugin-dep" ) );
240 MavenProject project = session.getCurrentProject();
241 Plugin plugin = project.getPlugin( "org.apache.maven.its.plugins:maven-it-plugin" );
242
243 RepositoryRequest repositoryRequest = new DefaultRepositoryRequest();
244 repositoryRequest.setLocalRepository( getLocalRepository() );
245 repositoryRequest.setRemoteRepositories( getPluginArtifactRepositories() );
246
247 PluginDescriptor pluginDescriptor =
248 pluginManager.loadPlugin( plugin, session.getCurrentProject().getRemotePluginRepositories(),
249 session.getRepositorySession() );
250 pluginManager.getPluginRealm( session, pluginDescriptor );
251 List<Artifact> artifacts = pluginDescriptor.getArtifacts();
252
253 for ( Artifact a : artifacts )
254 {
255 if ( a.getGroupId().equals( "org.apache.maven.its.mng3586" ) && a.getArtifactId().equals( "tools" ) )
256 {
257
258 return;
259 }
260 }
261
262 fail( "Can't find the system scoped dependency in the plugin artifacts." );
263 }
264
265
266
267
268
269 protected void assertPluginDescriptor( MojoDescriptor mojoDescriptor, String groupId, String artifactId, String version )
270 {
271 assertNotNull( mojoDescriptor );
272 PluginDescriptor pd = mojoDescriptor.getPluginDescriptor();
273 assertNotNull( pd );
274 assertEquals( groupId, pd.getGroupId() );
275 assertEquals( artifactId, pd.getArtifactId() );
276 assertEquals( version, pd.getVersion() );
277 }
278
279 public void testPluginRealmCache()
280 throws Exception
281 {
282 RepositoryRequest repositoryRequest = new DefaultRepositoryRequest();
283 repositoryRequest.setLocalRepository( getLocalRepository() );
284 repositoryRequest.setRemoteRepositories( getPluginArtifactRepositories() );
285
286
287 MavenSession session = createMavenSession( getProject( "project-contributing-system-scope-plugin-dep" ) );
288 MavenProject project = session.getCurrentProject();
289 Plugin plugin = project.getPlugin( "org.apache.maven.its.plugins:maven-it-plugin" );
290
291 PluginDescriptor pluginDescriptor =
292 pluginManager.loadPlugin( plugin, session.getCurrentProject().getRemotePluginRepositories(),
293 session.getRepositorySession() );
294 pluginManager.getPluginRealm( session, pluginDescriptor );
295
296 assertEquals( 1, pluginDescriptor.getDependencies().size() );
297
298 for ( ComponentDescriptor<?> descriptor : pluginDescriptor.getComponents() )
299 {
300 assertNotNull( descriptor.getRealm() );
301 assertNotNull( descriptor.getImplementationClass() );
302 }
303
304
305 session = createMavenSession( getProject( "project-contributing-system-scope-plugin-dep" ) );
306 project = session.getCurrentProject();
307 plugin = project.getPlugin( "org.apache.maven.its.plugins:maven-it-plugin" );
308
309 pluginDescriptor =
310 pluginManager.loadPlugin( plugin, session.getCurrentProject().getRemotePluginRepositories(),
311 session.getRepositorySession() );
312 pluginManager.getPluginRealm( session, pluginDescriptor );
313
314 assertEquals( 1, pluginDescriptor.getDependencies().size() );
315
316 for ( ComponentDescriptor<?> descriptor : pluginDescriptor.getComponents() )
317 {
318 assertNotNull( descriptor.getRealm() );
319 assertNotNull( descriptor.getImplementationClass() );
320 }
321 }
322
323 public void testBuildExtensionsPluginLoading()
324 throws Exception
325 {
326 RepositoryRequest repositoryRequest = new DefaultRepositoryRequest();
327 repositoryRequest.setLocalRepository( getLocalRepository() );
328 repositoryRequest.setRemoteRepositories( getPluginArtifactRepositories() );
329
330
331 MavenSession session = createMavenSession( getProject( "project-with-build-extensions-plugin" ) );
332 MavenProject project = session.getCurrentProject();
333 Plugin plugin = project.getPlugin( "org.apache.maven.its.plugins:maven-it-plugin" );
334
335 PluginDescriptor pluginDescriptor =
336 pluginManager.loadPlugin( plugin, session.getCurrentProject().getRemotePluginRepositories(),
337 session.getRepositorySession() );
338 ClassRealm pluginRealm = pluginManager.getPluginRealm( session, pluginDescriptor );
339
340 assertEquals(pluginRealm, pluginDescriptor.getComponents().get(0).getRealm());
341 }
342 }