Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

✨ feat: Updating regex to fully support "semver" #424

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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