Skip to content

Commit

Permalink
Updated constant names to uppercase with underscores
Browse files Browse the repository at this point in the history
  • Loading branch information
t-burch committed Jul 25, 2023
1 parent 8363f1c commit e208d16
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ public class ConsistentVersionNumbers {
public static final Option SNAPSHOT = Option.builder("snapshot").desc("Increase patch version and append SNAPSHOT tag").build();
public static final Option RELEASE = Option.builder("release").desc("Release version").hasArg().argName("x.y.z").build();

private static final Pattern constantsVersionPattern = Pattern.compile("(\\s*String version = \")(\\d+.\\d+)(\";.*)");
private static final Pattern rpmSpecVersionPattern = Pattern.compile("(Version:\\s+)(\\S+)(.*)");
private static final Pattern helpReferenceVersionPattern = Pattern.compile("(path.replace\\(\"%VERSION%\", \")([^\"]*)(\"\\))");
private static final Pattern CONSTANTS_VERSION_PATTERN = Pattern.compile("(\\s*String version = \")(\\d+.\\d+)(\";.*)");
private static final Pattern RPM_SPEC_VERSION_PATTERN = Pattern.compile("(Version:\\s+)(\\S+)(.*)");
private static final Pattern HELP_REFERENCE_VERSION_PATTERN = Pattern.compile("(path.replace\\(\"%VERSION%\", \")([^\"]*)(\"\\))");

@Test
public void doit() throws Exception {
Expand Down Expand Up @@ -143,17 +143,17 @@ private static void transformRecursively(File baseDirectory, VersionTransformer

private static void handleConstants(File file, VersionTransformer versionTransformer) throws Exception {
// String version = "5.1"; // fallback
handleByRegex(file, versionTransformer, constantsVersionPattern, v -> "%d.%d".formatted(v.getMajor(), v.getMinor()));
handleByRegex(file, versionTransformer, CONSTANTS_VERSION_PATTERN, v -> "%d.%d".formatted(v.getMajor(), v.getMinor()));
}

private static void handleRpmSpec(File file, VersionTransformer versionTransformer) throws Exception {
// Version: 5.1.0
handleByRegex(file, versionTransformer, rpmSpecVersionPattern, Semver::getValue);
handleByRegex(file, versionTransformer, RPM_SPEC_VERSION_PATTERN, Semver::getValue);
}

private static void handleHelpReference(File file, VersionTransformer versionTransformer) throws Exception {
// path.replace("%VERSION%", "5.0")
handleByRegex(file, versionTransformer, helpReferenceVersionPattern, v -> "%d.%d".formatted(v.getMajor(), v.getMinor()));
handleByRegex(file, versionTransformer, HELP_REFERENCE_VERSION_PATTERN, v -> "%d.%d".formatted(v.getMajor(), v.getMinor()));
}

private static void handleByRegex(File file, VersionTransformer versionTransformer, Pattern pattern, Function<Semver, String> versionFormatter) throws Exception {
Expand Down

0 comments on commit e208d16

Please sign in to comment.