diff --git a/README.md b/README.md
index 767d9f7..3f4b137 100644
--- a/README.md
+++ b/README.md
@@ -47,7 +47,7 @@ Semver sem1 = new Semver("1.2.3-beta.4+sha899d8g79f87"); // Defaults to STRICT m
Semver sem2 = new Semver("1.2.3-beta.4+sha899d8g79f87", SemverType.NPM); // Specify the mode
```
-If the version is invalid, a `SemverException` will be thrown.
+If the version is invalid, a `SemverException` will be thrown.
You can access the different parts of the version using `getMajor()`, `getMinor()`, `getPatch()`, `getSuffixTokens()` or `getBuild()`.
| Type | Mandatory | Optional |
@@ -130,6 +130,7 @@ sem.diff("1.2.3-beta.4+sha32iddfu987"); // BUILD
If you want to check if a version satisfies a requirement, use the `satisfies` method.
+- A `SemverException` is thrown if the version is not fully-qualified (containing major, minor, and patch versions).
- In `STRICT` and `LOOSE` modes, the requirement can only be another version.
- In `NPM` mode, the requirement follows [NPM versioning rules](https://github.com/npm/node-semver).
@@ -180,5 +181,5 @@ You can also use built-in versioning methods such as:
## Contributing
-Any pull request or bug report is welcome!
+Any pull request or bug report is welcome!
If you have any suggestion about new features, you can open an issue.
diff --git a/pom.xml b/pom.xml
index b39fd49..bbb73b3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -2,19 +2,19 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
- com.vdurmont
+ org.thshshsemver4j
- 3.1.0
+ 3.1.1jarsemver4j
- https://github.com/vdurmont/semver4j
+ https://github.com/theshoeshiner/semver4jSemantic versioning for Java apps.
- scm:git:git@github.com:vdurmont/semver4j.git
- scm:git:git@github.com:vdurmont/semver4j.git
- git@github.com:vdurmont/semver4j.git
+ scm:git:git@github.com:theshoeshiner/semver4j.git
+ scm:git:git@github.com:theshoeshiner/semver4j.git
+ git@github.com:theshoeshiner/semver4j.git
@@ -23,6 +23,10 @@
vdurmont@gmail.comhttp://www.vdurmont.com
+
+ The Shoe Shiner
+ theshoeshiner@thshsh.org
+
@@ -129,6 +133,11 @@
sign
+
+
+ *.asc
+
+
diff --git a/src/main/java/com/vdurmont/semver4j/Requirement.java b/src/main/java/com/vdurmont/semver4j/Requirement.java
index 5a813c4..77f1dd8 100644
--- a/src/main/java/com/vdurmont/semver4j/Requirement.java
+++ b/src/main/java/com/vdurmont/semver4j/Requirement.java
@@ -322,7 +322,8 @@ private static Requirement evaluateReversePolishNotation(Iterator 0;
+ }
+
/**
* @see #isGreaterThan(Semver)
*
@@ -329,8 +339,22 @@ public boolean isEquivalentTo(String version) {
*/
public boolean isEquivalentTo(Semver version) {
// Get versions without build
- Semver sem1 = this.getBuild() == null ? this : new Semver(this.getValue().replace("+" + this.getBuild(), ""));
- Semver sem2 = version.getBuild() == null ? version : new Semver(version.getValue().replace("+" + version.getBuild(), ""));
+ Semver sem1 = this.getBuild() == null ? this : new Semver(this.getValue().replace("+" + this.getBuild(), ""), this.getType());
+ Semver sem2 = version.getBuild() == null ? version : new Semver(version.getValue().replace("+" + version.getBuild(), ""), version.getType());
+
+ // Ignore minor and/or patch when versions are not equally qualified
+ if (sem1.getType() != SemverType.STRICT) {
+ if (!sem1.areSameSuffixes(sem2.getSuffixTokens())) return false;
+
+ if (!Objects.equals(sem1.getMajor(), sem2.getMajor())) return false;
+
+ if (sem2.getMinor() == null) return true;
+ if (!Objects.equals(sem1.getMinor(), sem2.getMinor())) return false;
+
+ if (sem2.getPatch() == null) return true;
+ if (!Objects.equals(sem1.getPatch(), sem2.getPatch())) return false;
+ }
+
// Compare those new versions
return sem1.isEqualTo(sem2);
}
@@ -354,12 +378,6 @@ public boolean isEqualTo(String version) {
* @return true if the current version equals the provided version
*/
public boolean isEqualTo(Semver version) {
- if (this.type == SemverType.NPM) {
- if (this.getMajor() != version.getMajor()) return false;
- if (version.getMinor() == null) return true;
- if (version.getPatch() == null) return true;
- }
-
return this.equals(version);
}
@@ -442,6 +460,24 @@ public Semver withIncPatch() {
public Semver withIncPatch(int increment) {
return this.withInc(0, 0, increment);
}
+
+ public Semver withIncSuffix(int index) {
+ return withIncSuffix(index, 1);
+ }
+
+ public Semver withIncSuffix(int index, int increment) {
+ if(suffixTokens.length <= index) throw new SemverException("No suffix at index "+index);
+ try {
+ Integer token = Integer.valueOf(suffixTokens[index]);
+ token+=increment;
+ String[] newSuffix = Arrays.copyOf(suffixTokens,suffixTokens.length);
+ newSuffix[index] = token.toString();
+ return with(major,minor,patch,newSuffix,build);
+ }
+ catch(NumberFormatException nfe) {
+ throw new SemverException("Suffix was not integer at index "+index);
+ }
+ }
private Semver withInc(int majorInc, int minorInc, int patchInc) {
Integer minor = this.minor;
@@ -542,7 +578,7 @@ private static Semver create(SemverType type, int major, Integer minor, Integer
@Override public int compareTo(Semver version) {
if (this.isGreaterThan(version)) return 1;
- else if(this.isLowerThan(version)) return -1;
+ else if (this.isLowerThan(version)) return -1;
return 0;
}
diff --git a/src/test/java/com/vdurmont/semver4j/NpmSemverTest.java b/src/test/java/com/vdurmont/semver4j/NpmSemverTest.java
index 16ad6ad..a284eef 100644
--- a/src/test/java/com/vdurmont/semver4j/NpmSemverTest.java
+++ b/src/test/java/com/vdurmont/semver4j/NpmSemverTest.java
@@ -30,9 +30,12 @@ public static Iterable