Skip to content

Commit

Permalink
✨ feat: Updating regex to fully support "semver"
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardoapaes committed Jan 29, 2025
1 parent 20009ae commit dd669e5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Launch4jFileVersionGenerator {
private static final int REQUIRED_NESTED_VERSION_LEVELS = 4;
private static final String SIMPLE_PROJECT_VERSION_REGEX = "^((\\d(\\.)?)*\\d+)(-\\w+)?$";
private static final String SIMPLE_PROJECT_VERSION_REGEX = "^((\\d(\\.)?)*\\d+)(-\\w+)?(?:-(?<prerelease>[\\w.-]+))?(?:\\+(?<build>[\\w.-]+))?$";
private static final Pattern simpleProjectVersionPattern = Pattern.compile(
SIMPLE_PROJECT_VERSION_REGEX, Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE
);
Expand Down Expand Up @@ -40,12 +41,13 @@ public static String generate(String projectVersion) {
}

private static String removeTextFlags(String version) {
if(version.contains("-")) {
String[] parts = version.split("-");
return parts[0];
Pattern pattern = Pattern.compile("[-+]");
Matcher matcher = pattern.matcher(version);
if (matcher.find()) {
return version.substring(0, matcher.start());
} else {
return version;
}

return version;
}

private static String cutOffTooManyNestedLevels(String versionLevels) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ public void shouldFillMissingPlacesByZeros(String projectVersion, String expecte
"1.2.1-alpha, 1.2.1.0",
"1.2.3.4-beta, 1.2.3.4",
"0.0.1-snapshot, 0.0.1.0",
"1.2.3.4-alpha+001, 1.2.3.4",
"1.2.3-alpha+001, 1.2.3.0",
"1.2.3.4-alpha+001, 1.2.3.4",
"1.2.3+20130313144700, 1.2.3.0",
"1.2.3.4+20130313144700, 1.2.3.4",
"1.2.3-beta+exp.sha.5114f85, 1.2.3.0",
"1.2.3.4-beta+exp.sha.5114f85, 1.2.3.4",
})
public void shouldCutOffTextFlags(String projectVersion, String expected) {
// when
Expand Down

0 comments on commit dd669e5

Please sign in to comment.