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