|
23 | 23 | import java.text.DateFormat;
|
24 | 24 | import java.text.SimpleDateFormat;
|
25 | 25 | import java.util.ArrayList;
|
26 |
| -import java.util.Arrays; |
27 | 26 | import java.util.Date;
|
28 | 27 | import java.util.LinkedHashSet;
|
29 |
| -import java.util.LinkedList; |
30 | 28 | import java.util.List;
|
31 | 29 | import java.util.Map;
|
32 | 30 | import java.util.Objects;
|
|
35 | 33 | import java.util.TimeZone;
|
36 | 34 | import java.util.TreeMap;
|
37 | 35 | import java.util.regex.Pattern;
|
| 36 | +import java.util.stream.Collectors; |
| 37 | +import java.util.stream.IntStream; |
38 | 38 |
|
39 | 39 | import org.apache.commons.lang3.StringUtils;
|
40 | 40 | import org.apache.maven.artifact.ArtifactUtils;
|
@@ -201,9 +201,11 @@ public class SetMojo extends AbstractVersionsUpdaterMojo {
|
201 | 201 | /**
|
202 | 202 | * <p>Specifies the version index to increment when using <code>nextSnapshot</code>.
|
203 | 203 | * Will increment the (1-based, counting from the left, or the most major component) index
|
204 |
| - * of the snapshot version, e.g. for <code>-DnextSnapshotIndexToIncrement=1</code> |
205 |
| - * and the version being <code>1.2.3-SNAPSHOT</code>, the new version will become <code>2.2.3-SNAPSHOT.</code></p> |
206 |
| - * <p>Only valid with <code>nextSnapshot</code>.</p> |
| 204 | + * of the snapshot version, e.g. for @{code -DnextSnapshotIndexToIncrement=1} whilst |
| 205 | + * all lesser components will become 0's.</p> |
| 206 | + * <p>For example, the version being @{code 1.2.3-SNAPSHOT}, the new version will |
| 207 | + * become {@code 2.0.0-SNAPSHOT}.</p> |
| 208 | + * <p>Only valid with {@code nextSnapshot}.</p> |
207 | 209 | *
|
208 | 210 | * @since 2.12
|
209 | 211 | */
|
@@ -434,20 +436,29 @@ protected String getIncrementedVersion(String version, Integer nextSnapshotIndex
|
434 | 436 | throws MojoExecutionException {
|
435 | 437 | String versionWithoutSnapshot =
|
436 | 438 | version.endsWith(SNAPSHOT) ? version.substring(0, version.indexOf(SNAPSHOT)) : version;
|
437 |
| - List<String> numbers = new LinkedList<>(Arrays.asList(versionWithoutSnapshot.split("\\."))); |
| 439 | + String[] versionComponents = versionWithoutSnapshot.split("\\."); |
438 | 440 |
|
439 | 441 | if (nextSnapshotIndexToIncrement == null) {
|
440 |
| - nextSnapshotIndexToIncrement = numbers.size(); |
| 442 | + nextSnapshotIndexToIncrement = versionComponents.length; |
441 | 443 | } else if (nextSnapshotIndexToIncrement < 1) {
|
442 | 444 | throw new MojoExecutionException("nextSnapshotIndexToIncrement cannot be less than 1");
|
443 |
| - } else if (nextSnapshotIndexToIncrement > numbers.size()) { |
| 445 | + } else if (nextSnapshotIndexToIncrement > versionComponents.length) { |
444 | 446 | throw new MojoExecutionException(
|
445 | 447 | "nextSnapshotIndexToIncrement cannot be greater than the last version index");
|
446 | 448 | }
|
447 |
| - int snapshotVersionToIncrement = Integer.parseInt(numbers.remove(nextSnapshotIndexToIncrement - 1)); |
448 |
| - numbers.add(nextSnapshotIndexToIncrement - 1, String.valueOf(snapshotVersionToIncrement + 1)); |
449 | 449 |
|
450 |
| - return StringUtils.join(numbers.toArray(new String[0]), ".") + "-SNAPSHOT"; |
| 450 | + int finalNextSnapshotIndexToIncrement = nextSnapshotIndexToIncrement; |
| 451 | + return IntStream.range(0, versionComponents.length) |
| 452 | + .mapToObj(i -> { |
| 453 | + if (i + 1 < finalNextSnapshotIndexToIncrement) { |
| 454 | + return versionComponents[i]; |
| 455 | + } else if (i + 1 == finalNextSnapshotIndexToIncrement) { |
| 456 | + return String.valueOf(Integer.parseInt(versionComponents[i]) + 1); |
| 457 | + } |
| 458 | + return "0"; |
| 459 | + }) |
| 460 | + .collect(Collectors.joining(".")) |
| 461 | + + "-SNAPSHOT"; |
451 | 462 | }
|
452 | 463 |
|
453 | 464 | private void applyChange(
|
|
0 commit comments