Skip to content

Commit

Permalink
v3.1.1-SNAPSHOT - Add pre-release checking
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuasing committed May 18, 2021
1 parent 213ff4c commit ad70be1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -22,7 +22,7 @@

<groupId>dev.hypera</groupId>
<artifactId>UpdateLib</artifactId>
<version>3.1.0-SNAPSHOT</version>
<version>3.1.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>UpdateLib</name>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/hypera/updatelib/UpdateLib.java
Expand Up @@ -27,7 +27,7 @@

public class UpdateLib {

private final static String VERSION = "3.1.0-SNAPSHOT"; // Current UpdateLib version.
private final static String VERSION = "3.1.1-SNAPSHOT"; // Current UpdateLib version.

private final long resourceId;
private final String currentVersion;
Expand Down
Expand Up @@ -20,7 +20,9 @@

public enum VersionScheme {

BASIC("MAJOR.MINOR", "^(v?)(?<major>0|[1-9]\\d*)\\.(?<minor>0|[1-9]\\d*)(?:-(?<prerelease>(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?$"), SEMANTIC("MAJOR.MINOR.PATCH - https://semver.org/", "^(v?)(?<major>0|[1-9]\\d*)\\.(?<minor>0|[1-9]\\d*)\\.(?<patch>0|[1-9]\\d*)(?:-(?<prerelease>(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+(?<buildmetadata>[0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$"), CALENDAR("YYYY-MM-DD - https://calver.org", "^(v?)(?<year>\\d{4})-(?<month>\\d{2})-(?<day>\\d{2})$");
BASIC("MAJOR.MINOR", "^(v?)(?<major>0|[1-9]\\d*)\\.(?<minor>0|[1-9]\\d*)(?:-(?<prerelease>(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?$"),
SEMANTIC("MAJOR.MINOR.PATCH - https://semver.org/", "^(v?)(?<major>0|[1-9]\\d*)\\.(?<minor>0|[1-9]\\d*)\\.(?<patch>0|[1-9]\\d*)(?:-(?<prerelease>(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+(?<buildmetadata>[0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$"),
CALENDAR("YYYY-MM-DD - https://calver.org", "^(v?)(?<year>\\d{4})-(?<month>\\d{2})-(?<day>\\d{2})$");

private final String description;
private final Pattern pattern;
Expand Down
15 changes: 12 additions & 3 deletions src/main/java/dev/hypera/updatelib/utils/VersionUtils.java
Expand Up @@ -54,8 +54,8 @@ public static VersionChange compare(VersionScheme versionScheme, String newVersi
Check.notNull("new version", newVersion);
Check.notNull("current version", currentVersion);

if(newVersion.equals(currentVersion))
return VersionChange.NONE;
// if(newVersion.equals(currentVersion))
// return VersionChange.NONE;

Matcher matcher = versionScheme.getPattern().matcher(newVersion);
Matcher currentMatcher = versionScheme.getPattern().matcher(currentVersion);
Expand Down Expand Up @@ -111,9 +111,12 @@ public static VersionChange compare(VersionScheme versionScheme, String newVersi
* @since 3.0.0-SNAPSHOT
*/
private static boolean safeCheck(String currentGroup, String newGroup) {
if(null == currentGroup || currentGroup.equals("") || null == newGroup || newGroup.equals(""))
if(isEmpty(currentGroup) && isEmpty(newGroup))
return false;

if(isEmpty(currentGroup) || isEmpty(newGroup))
return true;

int currentInt;
int newInt;

Expand All @@ -127,6 +130,12 @@ private static boolean safeCheck(String currentGroup, String newGroup) {
return newInt > currentInt;
}

private static boolean isEmpty(String one) {
if(null == one) return true;
if(one.equals("")) return true;
return false;
}

@Internal
public enum VersionChange {
NONE, MAJOR, MINOR, PATCH, PRE_RELEASE, METADATA, YEAR, MONTH, DAY
Expand Down

0 comments on commit ad70be1

Please sign in to comment.