39
39
import org .codehaus .plexus .util .FileUtils ;
40
40
import org .eclipse .aether .DefaultRepositorySystemSession ;
41
41
import org .eclipse .aether .artifact .DefaultArtifact ;
42
+ import org .eclipse .aether .internal .impl .DefaultLocalPathComposer ;
43
+ import org .eclipse .aether .internal .impl .DefaultLocalPathPrefixComposerFactory ;
44
+ import org .eclipse .aether .internal .impl .DefaultTrackingFileManager ;
42
45
import org .eclipse .aether .internal .impl .EnhancedLocalRepositoryManagerFactory ;
43
46
import org .eclipse .aether .repository .LocalRepository ;
44
47
import org .eclipse .aether .repository .NoLocalRepositoryManagerException ;
@@ -84,10 +87,11 @@ public void testBasicInstall() throws Exception {
84
87
MavenProject project = (MavenProject ) getVariableValueFromObject (mojo , "project" );
85
88
updateMavenProject (project );
86
89
90
+ MavenSession session = createMavenSession ();
91
+ session .setProjects (Collections .singletonList (project ));
92
+ setVariableValueToObject (mojo , "session" , session );
87
93
setVariableValueToObject (mojo , "pluginContext" , new ConcurrentHashMap <>());
88
94
setVariableValueToObject (mojo , "pluginDescriptor" , new PluginDescriptor ());
89
- setVariableValueToObject (mojo , "reactorProjects" , Collections .singletonList (project ));
90
- setVariableValueToObject (mojo , "session" , createMavenSession ());
91
95
92
96
artifact = (InstallArtifactStub ) project .getArtifact ();
93
97
@@ -120,10 +124,11 @@ public void testBasicInstallWithAttachedArtifacts() throws Exception {
120
124
MavenProject project = (MavenProject ) getVariableValueFromObject (mojo , "project" );
121
125
updateMavenProject (project );
122
126
127
+ MavenSession session = createMavenSession ();
128
+ session .setProjects (Collections .singletonList (project ));
129
+ setVariableValueToObject (mojo , "session" , session );
123
130
setVariableValueToObject (mojo , "pluginContext" , new ConcurrentHashMap <>());
124
131
setVariableValueToObject (mojo , "pluginDescriptor" , new PluginDescriptor ());
125
- setVariableValueToObject (mojo , "reactorProjects" , Collections .singletonList (project ));
126
- setVariableValueToObject (mojo , "session" , createMavenSession ());
127
132
128
133
List <Artifact > attachedArtifacts = project .getAttachedArtifacts ();
129
134
@@ -164,10 +169,11 @@ public void testUpdateReleaseParamSetToTrue() throws Exception {
164
169
MavenProject project = (MavenProject ) getVariableValueFromObject (mojo , "project" );
165
170
updateMavenProject (project );
166
171
172
+ MavenSession session = createMavenSession ();
173
+ session .setProjects (Collections .singletonList (project ));
174
+ setVariableValueToObject (mojo , "session" , session );
167
175
setVariableValueToObject (mojo , "pluginContext" , new ConcurrentHashMap <>());
168
176
setVariableValueToObject (mojo , "pluginDescriptor" , new PluginDescriptor ());
169
- setVariableValueToObject (mojo , "reactorProjects" , Collections .singletonList (project ));
170
- setVariableValueToObject (mojo , "session" , createMavenSession ());
171
177
172
178
artifact = (InstallArtifactStub ) project .getArtifact ();
173
179
@@ -190,10 +196,11 @@ public void testInstallIfArtifactFileIsNull() throws Exception {
190
196
MavenProject project = (MavenProject ) getVariableValueFromObject (mojo , "project" );
191
197
updateMavenProject (project );
192
198
199
+ MavenSession session = createMavenSession ();
200
+ session .setProjects (Collections .singletonList (project ));
201
+ setVariableValueToObject (mojo , "session" , session );
193
202
setVariableValueToObject (mojo , "pluginContext" , new ConcurrentHashMap <>());
194
203
setVariableValueToObject (mojo , "pluginDescriptor" , new PluginDescriptor ());
195
- setVariableValueToObject (mojo , "reactorProjects" , Collections .singletonList (project ));
196
- setVariableValueToObject (mojo , "session" , createMavenSession ());
197
204
198
205
artifact = (InstallArtifactStub ) project .getArtifact ();
199
206
@@ -223,10 +230,11 @@ public void testInstallIfPackagingIsPom() throws Exception {
223
230
MavenProject project = (MavenProject ) getVariableValueFromObject (mojo , "project" );
224
231
updateMavenProject (project );
225
232
233
+ MavenSession session = createMavenSession ();
234
+ session .setProjects (Collections .singletonList (project ));
235
+ setVariableValueToObject (mojo , "session" , session );
226
236
setVariableValueToObject (mojo , "pluginContext" , new ConcurrentHashMap <>());
227
237
setVariableValueToObject (mojo , "pluginDescriptor" , new PluginDescriptor ());
228
- setVariableValueToObject (mojo , "reactorProjects" , Collections .singletonList (project ));
229
- setVariableValueToObject (mojo , "session" , createMavenSession ());
230
238
231
239
String packaging = project .getPackaging ();
232
240
@@ -248,6 +256,43 @@ public void testInstallIfPackagingIsPom() throws Exception {
248
256
assertEquals (4 , FileUtils .getFiles (new File (LOCAL_REPO ), null , null ).size ());
249
257
}
250
258
259
+ public void testInstallIfPackagingIsBom () throws Exception {
260
+ File testPom = new File (
261
+ getBasedir (), "target/test-classes/unit/basic-install-test-packaging-bom/" + "plugin-config.xml" );
262
+
263
+ AbstractMojo mojo = (AbstractMojo ) lookupMojo ("install" , testPom );
264
+
265
+ assertNotNull (mojo );
266
+
267
+ MavenProject project = (MavenProject ) getVariableValueFromObject (mojo , "project" );
268
+ updateMavenProject (project );
269
+
270
+ MavenSession session = createMavenSession ();
271
+ session .setProjects (Collections .singletonList (project ));
272
+ setVariableValueToObject (mojo , "session" , session );
273
+ setVariableValueToObject (mojo , "pluginContext" , new ConcurrentHashMap <>());
274
+ setVariableValueToObject (mojo , "pluginDescriptor" , new PluginDescriptor ());
275
+
276
+ String packaging = project .getPackaging ();
277
+
278
+ assertEquals ("bom" , packaging );
279
+
280
+ artifact = (InstallArtifactStub ) project .getArtifact ();
281
+
282
+ mojo .execute ();
283
+
284
+ String groupId = dotToSlashReplacer (artifact .getGroupId ());
285
+
286
+ File installedArtifact = new File (
287
+ getBasedir (),
288
+ LOCAL_REPO + groupId + "/" + artifact .getArtifactId () + "/" + artifact .getVersion () + "/"
289
+ + artifact .getArtifactId () + "-" + artifact .getVersion () + "." + "pom" );
290
+
291
+ assertTrue (installedArtifact .exists ());
292
+
293
+ assertEquals (4 , FileUtils .getFiles (new File (LOCAL_REPO ), null , null ).size ());
294
+ }
295
+
251
296
public void testBasicInstallAndCreate () throws Exception {
252
297
File testPom = new File (getBasedir (), "target/test-classes/unit/basic-install-checksum/plugin-config.xml" );
253
298
@@ -261,10 +306,11 @@ public void testBasicInstallAndCreate() throws Exception {
261
306
MavenSession mavenSession = createMavenSession ();
262
307
updateMavenProject (project );
263
308
309
+ MavenSession session = createMavenSession ();
310
+ session .setProjects (Collections .singletonList (project ));
311
+ setVariableValueToObject (mojo , "session" , session );
264
312
setVariableValueToObject (mojo , "pluginContext" , new ConcurrentHashMap <>());
265
313
setVariableValueToObject (mojo , "pluginDescriptor" , new PluginDescriptor ());
266
- setVariableValueToObject (mojo , "reactorProjects" , Collections .singletonList (project ));
267
- setVariableValueToObject (mojo , "session" , mavenSession );
268
314
269
315
artifact = (InstallArtifactStub ) project .getArtifact ();
270
316
@@ -308,10 +354,11 @@ public void testSkip() throws Exception {
308
354
MavenProject project = (MavenProject ) getVariableValueFromObject (mojo , "project" );
309
355
updateMavenProject (project );
310
356
357
+ MavenSession session = createMavenSession ();
358
+ session .setProjects (Collections .singletonList (project ));
359
+ setVariableValueToObject (mojo , "session" , session );
311
360
setVariableValueToObject (mojo , "pluginContext" , new ConcurrentHashMap <>());
312
361
setVariableValueToObject (mojo , "pluginDescriptor" , new PluginDescriptor ());
313
- setVariableValueToObject (mojo , "reactorProjects" , Collections .singletonList (project ));
314
- setVariableValueToObject (mojo , "session" , createMavenSession ());
315
362
setVariableValueToObject (mojo , "skip" , Boolean .TRUE );
316
363
317
364
artifact = (InstallArtifactStub ) project .getArtifact ();
@@ -341,7 +388,10 @@ private String dotToSlashReplacer(String parameter) {
341
388
private MavenSession createMavenSession () throws NoLocalRepositoryManagerException {
342
389
MavenSession session = mock (MavenSession .class );
343
390
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession ();
344
- repositorySession .setLocalRepositoryManager (new EnhancedLocalRepositoryManagerFactory ()
391
+ repositorySession .setLocalRepositoryManager (new EnhancedLocalRepositoryManagerFactory (
392
+ new DefaultLocalPathComposer (),
393
+ new DefaultTrackingFileManager (),
394
+ new DefaultLocalPathPrefixComposerFactory ())
345
395
.newInstance (repositorySession , new LocalRepository (LOCAL_REPO )));
346
396
ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest ();
347
397
buildingRequest .setRepositorySession (repositorySession );
0 commit comments