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.component.annotations.Requirement;
34 import org.codehaus.plexus.component.repository.ComponentDescriptor;
35
36 public class PluginManagerTest
37 extends AbstractCoreMavenComponentTestCase
38 {
39 @Requirement
40 private DefaultBuildPluginManager pluginManager;
41
42 protected void setUp()
43 throws Exception
44 {
45 super.setUp();
46 pluginManager = (DefaultBuildPluginManager) lookup( BuildPluginManager.class );
47 }
48
49 @Override
50 protected void tearDown()
51 throws Exception
52 {
53 pluginManager = null;
54 super.tearDown();
55 }
56
57 protected String getProjectsDirectory()
58 {
59 return "src/test/projects/plugin-manager";
60 }
61
62 public void testPluginLoading()
63 throws Exception
64 {
65 MavenSession session = createMavenSession( null );
66 Plugin plugin = new Plugin();
67 plugin.setGroupId( "org.apache.maven.its.plugins" );
68 plugin.setArtifactId( "maven-it-plugin" );
69 plugin.setVersion( "0.1" );
70 PluginDescriptor pluginDescriptor =
71 pluginManager.loadPlugin( plugin, session.getCurrentProject().getRemotePluginRepositories(),
72 session.getRepositorySession() );
73 assertNotNull( pluginDescriptor );
74 }
75
76 public void testMojoDescriptorRetrieval()
77 throws Exception
78 {
79 MavenSession session = createMavenSession( null );
80 String goal = "it";
81 Plugin plugin = new Plugin();
82 plugin.setGroupId( "org.apache.maven.its.plugins" );
83 plugin.setArtifactId( "maven-it-plugin" );
84 plugin.setVersion( "0.1" );
85
86 MojoDescriptor mojoDescriptor =
87 pluginManager.getMojoDescriptor( plugin, goal, session.getCurrentProject().getRemotePluginRepositories(),
88 session.getRepositorySession() );
89 assertNotNull( mojoDescriptor );
90 assertEquals( goal, mojoDescriptor.getGoal() );
91
92
93
94 PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
95 assertNotNull( pluginDescriptor );
96 assertEquals( "org.apache.maven.its.plugins", pluginDescriptor.getGroupId() );
97 assertEquals( "maven-it-plugin", pluginDescriptor.getArtifactId() );
98 assertEquals( "0.1", pluginDescriptor.getVersion() );
99 }
100
101
102
103
104
105
106
107
108
109
110
111
112 public void testRemoteResourcesPlugin()
113 throws Exception
114 {
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 public void testSurefirePlugin()
142 throws Exception
143 {
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163 }
164
165 public void testMojoConfigurationIsMergedCorrectly()
166 throws Exception
167 {
168 }
169
170
171
172
173
174
175 public void testMojoWhereInternallyStatedDependencyIsOverriddenByProject()
176 throws Exception
177 {
178 }
179
180
181
182
183
184 public void testMojoThatIsPresentInTheCurrentBuild()
185 throws Exception
186 {
187 }
188
189
190
191
192
193 public void testAggregatorMojo()
194 throws Exception
195 {
196 }
197
198
199
200
201
202 public void testMojoThatRequiresExecutionToAGivenPhaseBeforeExecutingItself()
203 throws Exception
204 {
205 }
206
207
208
209
210
211
212
213 public void testThatPluginDependencyThatHasSystemScopeIsResolved()
214 throws Exception
215 {
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238 MavenSession session = createMavenSession( getProject( "project-contributing-system-scope-plugin-dep" ) );
239 MavenProject project = session.getCurrentProject();
240 Plugin plugin = project.getPlugin( "org.apache.maven.its.plugins:maven-it-plugin" );
241
242 RepositoryRequest repositoryRequest = new DefaultRepositoryRequest();
243 repositoryRequest.setLocalRepository( getLocalRepository() );
244 repositoryRequest.setRemoteRepositories( getPluginArtifactRepositories() );
245
246 PluginDescriptor pluginDescriptor =
247 pluginManager.loadPlugin( plugin, session.getCurrentProject().getRemotePluginRepositories(),
248 session.getRepositorySession() );
249 pluginManager.getPluginRealm( session, pluginDescriptor );
250 List<Artifact> artifacts = pluginDescriptor.getArtifacts();
251
252 for ( Artifact a : artifacts )
253 {
254 if ( a.getGroupId().equals( "org.apache.maven.its.mng3586" ) && a.getArtifactId().equals( "tools" ) )
255 {
256
257 return;
258 }
259 }
260
261 fail( "Can't find the system scoped dependency in the plugin artifacts." );
262 }
263
264
265
266
267
268 protected void assertPluginDescriptor( MojoDescriptor mojoDescriptor, String groupId, String artifactId, String version )
269 {
270 assertNotNull( mojoDescriptor );
271 PluginDescriptor pd = mojoDescriptor.getPluginDescriptor();
272 assertNotNull( pd );
273 assertEquals( groupId, pd.getGroupId() );
274 assertEquals( artifactId, pd.getArtifactId() );
275 assertEquals( version, pd.getVersion() );
276 }
277
278 public void testPluginRealmCache()
279 throws Exception
280 {
281 RepositoryRequest repositoryRequest = new DefaultRepositoryRequest();
282 repositoryRequest.setLocalRepository( getLocalRepository() );
283 repositoryRequest.setRemoteRepositories( getPluginArtifactRepositories() );
284
285
286 MavenSession session = createMavenSession( getProject( "project-contributing-system-scope-plugin-dep" ) );
287 MavenProject project = session.getCurrentProject();
288 Plugin plugin = project.getPlugin( "org.apache.maven.its.plugins:maven-it-plugin" );
289
290 PluginDescriptor pluginDescriptor =
291 pluginManager.loadPlugin( plugin, session.getCurrentProject().getRemotePluginRepositories(),
292 session.getRepositorySession() );
293 pluginManager.getPluginRealm( session, pluginDescriptor );
294
295 for ( ComponentDescriptor<?> descriptor : pluginDescriptor.getComponents() )
296 {
297 assertNotNull( descriptor.getRealm() );
298 assertNotNull( descriptor.getImplementationClass() );
299 }
300
301
302 session = createMavenSession( getProject( "project-contributing-system-scope-plugin-dep" ) );
303 project = session.getCurrentProject();
304 plugin = project.getPlugin( "org.apache.maven.its.plugins:maven-it-plugin" );
305
306 pluginDescriptor =
307 pluginManager.loadPlugin( plugin, session.getCurrentProject().getRemotePluginRepositories(),
308 session.getRepositorySession() );
309 pluginManager.getPluginRealm( session, pluginDescriptor );
310
311 for ( ComponentDescriptor<?> descriptor : pluginDescriptor.getComponents() )
312 {
313 assertNotNull( descriptor.getRealm() );
314 assertNotNull( descriptor.getImplementationClass() );
315 }
316 }
317 }