@@ -76,6 +76,7 @@ public static void setUpStatic() {
76
76
put ("dummy-parent2" , new String [] {"1.0" , "2.0" , "3.0" , "3.0-alpha-1" , "3.0-beta-1" });
77
77
put ("test-incremental" , new String [] {"1.0.0" , "1.1.0" , "1.1.1" , "2.0.0" });
78
78
put ("unknown-artifact" , new String [0 ]);
79
+ put ("mojo-parent" , new String [] {"70" , "78" , "86" });
79
80
}
80
81
});
81
82
}
@@ -186,10 +187,10 @@ public void testParentDowngradeAllowedWithRange()
186
187
{
187
188
setGroupId ("default-group" );
188
189
setArtifactId ("parent-artifact" );
190
+ setVersion ("[1.0.1-SNAPSHOT,)" );
189
191
}
190
192
});
191
-
192
- ArtifactVersion newVersion = mojo .resolveTargetVersion ("[1.0.1-SNAPSHOT,)" );
193
+ ArtifactVersion newVersion = mojo .resolveTargetVersion ();
193
194
assertThat (newVersion , notNullValue ());
194
195
assertThat (newVersion .toString (), is ("1.0.0" ));
195
196
}
@@ -199,7 +200,8 @@ public void testParentDowngradeForbiddenWithRange()
199
200
throws MojoExecutionException , VersionRetrievalException , InvalidVersionSpecificationException ,
200
201
InvalidSegmentException {
201
202
mojo .allowDowngrade = false ;
202
- ArtifactVersion newVersion = mojo .resolveTargetVersion ("[1.0.1-SNAPSHOT,)" );
203
+ mojo .parentVersion = "[1.0.1-SNAPSHOT,)" ;
204
+ ArtifactVersion newVersion = mojo .resolveTargetVersion ();
203
205
assertThat (newVersion , nullValue ());
204
206
}
205
207
@@ -212,10 +214,11 @@ public void testAllowSnapshots()
212
214
{
213
215
setGroupId ("default-group" );
214
216
setArtifactId ("issue-670-artifact" );
217
+ setVersion ("0.0.1-1" );
215
218
}
216
219
});
217
220
218
- ArtifactVersion newVersion = mojo .resolveTargetVersion ("0.0.1-1" );
221
+ ArtifactVersion newVersion = mojo .resolveTargetVersion ();
219
222
assertThat (newVersion , notNullValue ());
220
223
assertThat (newVersion .toString (), is ("0.0.1-1-impl-SNAPSHOT" ));
221
224
}
@@ -253,10 +256,11 @@ public void testIgnoredVersions()
253
256
{
254
257
setGroupId ("default-group" );
255
258
setArtifactId ("parent-artifact" );
259
+ setVersion ("0.9.0" );
256
260
}
257
261
});
258
262
setVariableValueToObject (mojo , "ignoredVersions" , singleton ("1.0.0" ));
259
- assertThat (mojo .resolveTargetVersion ("0.9.0" ), nullValue ());
263
+ assertThat (mojo .resolveTargetVersion (), nullValue ());
260
264
}
261
265
262
266
@ Test
@@ -337,8 +341,8 @@ public void testAllowMinorUpdates()
337
341
mojo .allowMajorUpdates = false ;
338
342
mojo .allowMinorUpdates = true ;
339
343
mojo .allowIncrementalUpdates = true ;
340
-
341
- ArtifactVersion newVersion = mojo .resolveTargetVersion ("0.8.0" );
344
+ mojo . parentVersion = "0.8.0" ;
345
+ ArtifactVersion newVersion = mojo .resolveTargetVersion ();
342
346
343
347
assertThat (newVersion , notNullValue ());
344
348
assertThat (newVersion .toString (), is ("0.9.0" ));
@@ -352,13 +356,13 @@ public void testAllowIncrementalUpdates()
352
356
{
353
357
setGroupId ("default-group" );
354
358
setArtifactId ("test-incremental" );
359
+ setVersion ("1.1.0" );
355
360
}
356
361
});
357
362
mojo .allowMajorUpdates = false ;
358
363
mojo .allowMinorUpdates = false ;
359
364
mojo .allowIncrementalUpdates = true ;
360
-
361
- ArtifactVersion newVersion = mojo .resolveTargetVersion ("1.1.0" );
365
+ ArtifactVersion newVersion = mojo .resolveTargetVersion ();
362
366
363
367
assertThat (newVersion , notNullValue ());
364
368
assertThat (newVersion .toString (), is ("1.1.1" ));
@@ -407,4 +411,52 @@ public void testParentVersionRange2()
407
411
}
408
412
assertThat (changeRecorder .getChanges (), empty ());
409
413
}
414
+
415
+ /*
416
+ * Reproduces issue 1060
417
+ */
418
+ @ Test
419
+ public void testIssue1060VersionRangeAllowDowngradeFalse ()
420
+ throws MojoExecutionException , XMLStreamException , MojoFailureException , VersionRetrievalException {
421
+ mojo .getProject ().setParent (new MavenProject () {
422
+ {
423
+ setGroupId ("default-group" );
424
+ setArtifactId ("dummy-parent2" );
425
+ setVersion ("2.0" );
426
+ }
427
+ });
428
+ mojo .parentVersion = "[,2.9-!)" ;
429
+ mojo .allowDowngrade = false ;
430
+ try (MockedStatic <PomHelper > pomHelper = mockStatic (PomHelper .class )) {
431
+ pomHelper
432
+ .when (() -> PomHelper .setProjectParentVersion (any (), any ()))
433
+ .thenReturn (true );
434
+ mojo .update (null );
435
+ }
436
+ assertThat (changeRecorder .getChanges (), empty ());
437
+ }
438
+
439
+ /*
440
+ * Reproduces issue 1060
441
+ */
442
+ @ Test
443
+ public void testIssue1060VersionRangeAllowDowngradeTrue ()
444
+ throws MojoExecutionException , XMLStreamException , MojoFailureException , VersionRetrievalException {
445
+ mojo .getProject ().setParent (new MavenProject () {
446
+ {
447
+ setGroupId ("default-group" );
448
+ setArtifactId ("mojo-parent" );
449
+ setVersion ("78" );
450
+ }
451
+ });
452
+ mojo .parentVersion = "[,79-!)" ;
453
+ mojo .allowDowngrade = true ;
454
+ try (MockedStatic <PomHelper > pomHelper = mockStatic (PomHelper .class )) {
455
+ pomHelper
456
+ .when (() -> PomHelper .setProjectParentVersion (any (), any ()))
457
+ .thenReturn (true );
458
+ mojo .update (null );
459
+ }
460
+ assertThat (changeRecorder .getChanges (), empty ());
461
+ }
410
462
}
0 commit comments