Skip to content
This repository has been archived by the owner on Jun 23, 2023. It is now read-only.

Commit

Permalink
3.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
rk0cc committed Jan 22, 2022
1 parent 04f2eed commit a623530
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 27 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 3.1.1

* Fix `SemVer.parse(String)` throw `IllegalStateException` when importing this dependency.

## 3.1.0

* Assign `provide` scope to dependencies which doesn't need outside this package
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

<groupId>xyz.rk0cc.josev</groupId>
<artifactId>josev-core</artifactId>
<version>3.1.0</version>
<version>3.1.1</version>

<licenses>
<license>
Expand Down
51 changes: 25 additions & 26 deletions src/main/java/xyz/rk0cc/josev/SemVer.java
Original file line number Diff line number Diff line change
Expand Up @@ -428,37 +428,36 @@ public String toString() {
*
* @see #tryParse(String)
*/
@SuppressWarnings("AssertWithSideEffects")
@Nonnull
public static SemVer parse(@Nonnull String version) throws NonStandardSemVerException {
final String v = version.charAt(0) == 'v' ? version.substring(1) : version;
try {
final Matcher vm = compiledSemverRegex().matcher(v);
assert vm.matches();

// Extract string from group
ArrayList<String> matchedGroup = new ArrayList<>();
int g = 1; // Must be started from 1, 0 is entire version string
while (true) {
try {
matchedGroup.add(vm.group(g++));
} catch (IndexOutOfBoundsException ioobe) {
// Stop append if reached maximum
break;
}
}
final Matcher vm = compiledSemverRegex().matcher(v);
if (!vm.matches()) throw new NonStandardSemVerException(version, new AssertionError());

// 3 mandatory part
final long major, minor, patch;
// Extract string from group
ArrayList<String> matchedGroup = new ArrayList<>();
int g = 1; // Must be started from 1, 0 is entire version string
while (true) {
try {
// It should be decimal, otherwise it has been thrown already.
major = Long.parseLong(matchedGroup.get(0), 10);
minor = Long.parseLong(matchedGroup.get(1), 10);
patch = Long.parseLong(matchedGroup.get(2), 10);
} catch (IndexOutOfBoundsException isvd) {
throw new AssertionError(isvd);
matchedGroup.add(vm.group(g++));
} catch (IndexOutOfBoundsException ioobe) {
// Stop append if reached maximum
break;
}
}

// 3 mandatory part
final long major, minor, patch;
try {
// It should be decimal, otherwise it has been thrown already.
major = Long.parseLong(matchedGroup.get(0), 10);
minor = Long.parseLong(matchedGroup.get(1), 10);
patch = Long.parseLong(matchedGroup.get(2), 10);
} catch (IndexOutOfBoundsException | NumberFormatException e) {
throw new NonStandardSemVerException(version, e);
}

try {
switch (matchedGroup.size()) {
case 3:
return new SemVer(major, minor, patch);
Expand All @@ -472,8 +471,8 @@ public static SemVer parse(@Nonnull String version) throws NonStandardSemVerExce
default:
throw new AssertionError("Unexpected number of semver pattern group found");
}
} catch (Throwable t) {
throw (t instanceof NonStandardSemVerException nt) ? nt : new NonStandardSemVerException(version, t);
} catch (AssertionError e) {
throw new NonStandardSemVerException(version, e);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/test/resources/xyz/rk0cc/josev/semver_sample.csv
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ semver,valid
1.1.2+meta-valid,true
1.0.0-alpha,true
1.0.0-beta,true
1.0.0-pre-1,true
1.0.0-alpha.beta,true
1.0.0-alpha.beta.1,true
1.0.0-alpha.1,true
Expand Down

0 comments on commit a623530

Please sign in to comment.