Sfoglia il codice sorgente

add support for build number to semantic version

tags/2.0.1
Jonathan Cobb 3 anni fa
parent
commit
5f82610c79
2 ha cambiato i file con 18 aggiunte e 2 eliminazioni
  1. +2
    -0
      wizard-common/src/main/java/org/cobbzilla/wizard/model/BasicConstraintConstants.java
  2. +16
    -2
      wizard-common/src/main/java/org/cobbzilla/wizard/model/SemanticVersion.java

+ 2
- 0
wizard-common/src/main/java/org/cobbzilla/wizard/model/BasicConstraintConstants.java Vedi File

@@ -26,6 +26,8 @@ public class BasicConstraintConstants {
public static final String SV_MINOR_TOO_SMALL = "{err.semanticVersion.minor.tooSmall}";
public static final String SV_PATCH_TOO_LARGE = "{err.semanticVersion.patch.tooBig}";
public static final String SV_PATCH_TOO_SMALL = "{err.semanticVersion.patch.tooSmall}";
public static final String SV_BUILD_TOO_LARGE = "{err.semanticVersion.build.tooBig}";
public static final String SV_BUILD_TOO_SMALL = "{err.semanticVersion.build.tooSmall}";
public static final int SV_VERSION_MAXLEN = 30;

public static final int SV_VERSION_MAX = 999999999;


+ 16
- 2
wizard-common/src/main/java/org/cobbzilla/wizard/model/SemanticVersion.java Vedi File

@@ -20,7 +20,7 @@ import static org.cobbzilla.wizard.model.BasicConstraintConstants.*;
@NoArgsConstructor @AllArgsConstructor @Slf4j
public class SemanticVersion implements Comparable<SemanticVersion>, Serializable {

public static final String SEMANTIC_VERSION_RE = "(\\d+)\\.(\\d+)\\.(\\d+)";
public static final String SEMANTIC_VERSION_RE = "(\\d+)\\.(\\d+)\\.(\\d+)(\\.(\\d+))?";
public static final String VERSION_REGEXP = "^" + SEMANTIC_VERSION_RE + "$";
public static final Pattern VERSION_PATTERN = Pattern.compile(VERSION_REGEXP);

@@ -28,6 +28,8 @@ public class SemanticVersion implements Comparable<SemanticVersion>, Serializabl

public static final Comparator<SemanticVersion> COMPARE_LATEST_FIRST = Comparator.reverseOrder();

public SemanticVersion(int major, int minor, int patch) { this(major, minor, patch, null); }

/**
* Is v2 newer than v1?
* @param v1 first version
@@ -53,6 +55,9 @@ public class SemanticVersion implements Comparable<SemanticVersion>, Serializabl
setMajor(Integer.parseInt(matcher.group(1)));
setMinor(Integer.parseInt(matcher.group(2)));
setPatch(Integer.parseInt(matcher.group(3)));
if (matcher.groupCount() > 4) {
setBuild(Integer.valueOf(matcher.group(5)));
}
}

@Max(value=SV_VERSION_MAX, message=SV_MAJOR_TOO_LARGE)
@@ -77,9 +82,14 @@ public class SemanticVersion implements Comparable<SemanticVersion>, Serializabl
return new SemanticVersion(other.getMajor(), other.getMinor(), other.getPatch()+1);
}

@Max(value=SV_VERSION_MAX, message=SV_BUILD_TOO_LARGE)
@Min(value=SV_VERSION_MIN, message=SV_BUILD_TOO_SMALL)
@Column(name="build_version", length=SV_VERSION_MAXLEN)
@Getter @Setter private Integer build = null;

public static boolean isValid (String version) { return VERSION_PATTERN.matcher(version).find(); }

@Override public String toString () { return major + "." + minor + "." + patch; }
@Override public String toString () { return major + "." + minor + "." + patch + (build == null ? "" : "."+build); }

@Override public int compareTo(SemanticVersion other) {
if (other == null) throw new IllegalArgumentException("compareTo: argument was null");
@@ -87,6 +97,10 @@ public class SemanticVersion implements Comparable<SemanticVersion>, Serializabl
diff = major - other.major; if (diff != 0) return diff;
diff = minor - other.minor; if (diff != 0) return diff;
diff = patch - other.patch; if (diff != 0) return diff;
if (build != null && other.build != null) {
diff = build - other.build;
if (diff != 0) return diff;
}
return 0;
}



Caricamento…
Annulla
Salva