You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by kr...@apache.org on 2022/10/15 20:55:59 UTC

[solr] branch main updated: SOLR-15854: Upgrade semver library to fix versioning constraint bugs in the PackageManager. (#515)

This is an automated email from the ASF dual-hosted git repository.

krisden pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/main by this push:
     new 7515cd544eb SOLR-15854: Upgrade semver library to fix versioning constraint bugs in the PackageManager. (#515)
7515cd544eb is described below

commit 7515cd544eb020b9e2446611c918c581236e1dc9
Author: Houston Putman <ho...@apache.org>
AuthorDate: Sat Oct 15 16:55:53 2022 -0400

    SOLR-15854: Upgrade semver library to fix versioning constraint bugs in the PackageManager. (#515)
    
    Co-authored-by: Kevin Risden <kr...@apache.org>
---
 gradle/validation/jar-checks.gradle                |  2 +-
 solr/CHANGES.txt                                   |  2 +
 solr/core/build.gradle                             |  2 +-
 .../apache/solr/packagemanager/PackageUtils.java   |  4 +-
 .../src/java/org/apache/solr/util/SolrVersion.java | 60 ++++++++--------------
 .../test/org/apache/solr/util/TestSolrVersion.java | 13 ++---
 solr/licenses/java-semver-0.9.0.jar.sha1           |  1 -
 solr/licenses/semver4j-2.1.1.jar.sha1              |  1 +
 ...er-LICENSE-MIT.txt => semver4j-LICENSE-MIT.txt} |  0
 versions.lock                                      |  2 +-
 versions.props                                     |  2 +-
 11 files changed, 34 insertions(+), 55 deletions(-)

diff --git a/gradle/validation/jar-checks.gradle b/gradle/validation/jar-checks.gradle
index 55b8089aea4..6f502ff407d 100644
--- a/gradle/validation/jar-checks.gradle
+++ b/gradle/validation/jar-checks.gradle
@@ -180,7 +180,7 @@ subprojects {
       }
 
       if (errors) {
-        def msg = "Dependency checksum validation failed:\n  - " + errors.join("\n  - ")
+        def msg = "Dependency checksum validation failed:\n  - " + errors.join("\n  - ") + "\n\nThese missing checksums can be generated using:\n  ./gradlew updateLicenses"
         if (failOnError) {
           throw new GradleException(msg)
         } else {
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 49b894739ac..138d10b72cc 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -60,6 +60,8 @@ Bug Fixes
 * SOLR-16436: Fix "false positive" suggestions from DirectSolrSpellChecker when using maxQueryFrequency > 1 in
   multi-shard collections (hossman)
 
+* SOLR-15854: Upgrade semver library to fix versioning constraint bugs in the PackageManager. (Houston Putman, Kevin Risden)
+
 Build
 ---------------------
 * Upgrade forbiddenapis to 3.4 (Uwe Schindler)
diff --git a/solr/core/build.gradle b/solr/core/build.gradle
index fed83bdff2d..2d31beea7b3 100644
--- a/solr/core/build.gradle
+++ b/solr/core/build.gradle
@@ -165,7 +165,7 @@ dependencies {
   runtimeOnly ('org.xerial.snappy:snappy-java')
 
   // For Package Manager
-  implementation 'com.github.zafarkhaja:java-semver'
+  implementation 'org.semver4j:semver4j'
 
   implementation('com.jayway.jsonpath:json-path', {
     exclude group: "net.minidev", module: "json-smart"
diff --git a/solr/core/src/java/org/apache/solr/packagemanager/PackageUtils.java b/solr/core/src/java/org/apache/solr/packagemanager/PackageUtils.java
index 0c62ec057ec..f212493da86 100644
--- a/solr/core/src/java/org/apache/solr/packagemanager/PackageUtils.java
+++ b/solr/core/src/java/org/apache/solr/packagemanager/PackageUtils.java
@@ -17,7 +17,6 @@
 package org.apache.solr.packagemanager;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
-import com.github.zafarkhaja.semver.Version;
 import com.jayway.jsonpath.Configuration;
 import com.jayway.jsonpath.spi.json.JacksonJsonProvider;
 import com.jayway.jsonpath.spi.json.JsonProvider;
@@ -52,6 +51,7 @@ import org.apache.solr.filestore.DistribPackageStore;
 import org.apache.solr.filestore.PackageStoreAPI;
 import org.apache.solr.packagemanager.SolrPackage.Manifest;
 import org.apache.solr.util.SolrJacksonAnnotationInspector;
+import org.semver4j.Semver;
 
 public class PackageUtils {
 
@@ -216,7 +216,7 @@ public class PackageUtils {
    * isGreaterThan v2 and 0 if equal.
    */
   public static int compareVersions(String v1, String v2) {
-    return Version.valueOf(v1).compareTo(Version.valueOf(v2));
+    return new Semver(v1).compareTo(new Semver(v2));
   }
 
   public static String BLACK = "\u001B[30m";
diff --git a/solr/core/src/java/org/apache/solr/util/SolrVersion.java b/solr/core/src/java/org/apache/solr/util/SolrVersion.java
index 1b6d8c258ec..6661e9e891c 100644
--- a/solr/core/src/java/org/apache/solr/util/SolrVersion.java
+++ b/solr/core/src/java/org/apache/solr/util/SolrVersion.java
@@ -16,11 +16,9 @@
  */
 package org.apache.solr.util;
 
-import com.github.zafarkhaja.semver.ParseException;
-import com.github.zafarkhaja.semver.Version;
-import com.github.zafarkhaja.semver.expr.ExpressionParser;
 import java.util.Locale;
 import org.apache.solr.common.SolrException;
+import org.semver4j.Semver;
 
 /**
  * Simple Solr version representation backed by a <a href="https://devhints.io/semver">Semantic
@@ -29,7 +27,7 @@ import org.apache.solr.common.SolrException;
  */
 public final class SolrVersion implements Comparable<SolrVersion> {
   // Backing SemVer version
-  private final Version version;
+  private final Semver version;
 
   // This static variable should be bumped for each release
   public static final String LATEST_STRING = "10.0.0";
@@ -39,50 +37,34 @@ public final class SolrVersion implements Comparable<SolrVersion> {
 
   /** Create a SolrVersion instance from string value. The string must comply to the SemVer spec */
   public static SolrVersion valueOf(String version) {
-    return new SolrVersion(Version.valueOf(version));
+    return new SolrVersion(new Semver(version));
   }
 
   /** Create a SolrVersion instance from set of integer values. Must comply to the SemVer spec */
   public static SolrVersion forIntegers(int major, int minor, int patch) {
-    return new SolrVersion(Version.forIntegers(major, minor, patch));
+    return new SolrVersion(new Semver(String.format(Locale.ROOT, "%d.%d.%d", major, minor, patch)));
   }
 
   /** Return version as plain SemVer string, e.g. "9.0.1" */
   @Override
   public String toString() {
-    // Workaround for bug https://github.com/zafarkhaja/jsemver/issues/32
-    // TODO: Needs to find a newer SemVer lib
-    StringBuilder sb =
-        new StringBuilder(
-            String.format(
-                Locale.ROOT,
-                "%d.%d.%d",
-                version.getMajorVersion(),
-                version.getMinorVersion(),
-                version.getPatchVersion()));
-    if (!version.getPreReleaseVersion().isEmpty()) {
-      sb.append("-").append(version.getPreReleaseVersion());
-    }
-    if (!version.getBuildMetadata().isEmpty()) {
-      sb.append("+").append(version.getBuildMetadata());
-    }
-    return sb.toString();
+    return version.toString();
   }
 
   public boolean greaterThan(SolrVersion other) {
-    return version.greaterThan(other.version);
+    return version.isGreaterThan(other.version);
   }
 
   public boolean greaterThanOrEqualTo(SolrVersion other) {
-    return version.greaterThanOrEqualTo(other.version);
+    return version.isGreaterThanOrEqualTo(other.version);
   }
 
   public boolean lessThan(SolrVersion other) {
-    return version.lessThan(other.version);
+    return version.isLowerThan(other.version);
   }
 
   public boolean lessThanOrEqualTo(SolrVersion other) {
-    return version.lessThanOrEqualTo(other.version);
+    return version.isLowerThanOrEqualTo(other.version);
   }
 
   /**
@@ -90,34 +72,29 @@ public final class SolrVersion implements Comparable<SolrVersion> {
    * Expression</a>
    *
    * @param semVerExpression the expression to test
-   * @throws InvalidSemVerExpressionException if the SemVer expression is invalid
    */
   public boolean satisfies(String semVerExpression) {
-    try {
-      return ExpressionParser.newInstance().parse(semVerExpression).interpret(version);
-    } catch (ParseException parseException) {
-      throw new InvalidSemVerExpressionException();
-    }
+    return version.satisfies(semVerExpression);
   }
 
   public int getMajorVersion() {
-    return version.getMajorVersion();
+    return version.getMajor();
   }
 
   public int getMinorVersion() {
-    return version.getMinorVersion();
+    return version.getMinor();
   }
 
   public int getPatchVersion() {
-    return version.getPatchVersion();
+    return version.getPatch();
   }
 
   public String getPrereleaseVersion() {
-    return version.getPreReleaseVersion();
+    return String.join(".", version.getPreRelease());
   }
 
   // Private constructor. Should be instantiated from static factory methods
-  private SolrVersion(Version version) {
+  private SolrVersion(Semver version) {
     this.version = version;
   }
 
@@ -143,8 +120,11 @@ public final class SolrVersion implements Comparable<SolrVersion> {
   }
 
   public static class InvalidSemVerExpressionException extends SolrException {
-    public InvalidSemVerExpressionException() {
-      super(ErrorCode.BAD_REQUEST, "Invalid SemVer expression");
+    public InvalidSemVerExpressionException(Exception exception, String expression) {
+      super(
+          ErrorCode.BAD_REQUEST,
+          String.format(Locale.ROOT, "Invalid SemVer expression: %s", expression),
+          exception);
     }
   }
 }
diff --git a/solr/core/src/test/org/apache/solr/util/TestSolrVersion.java b/solr/core/src/test/org/apache/solr/util/TestSolrVersion.java
index 6ea34613066..1a43e7cab71 100644
--- a/solr/core/src/test/org/apache/solr/util/TestSolrVersion.java
+++ b/solr/core/src/test/org/apache/solr/util/TestSolrVersion.java
@@ -16,8 +16,8 @@
  */
 package org.apache.solr.util;
 
-import com.github.zafarkhaja.semver.ParseException;
 import org.apache.solr.SolrTestCase;
+import org.semver4j.SemverException;
 
 public class TestSolrVersion extends SolrTestCase {
   private static final SolrVersion SOLR_9_0_1 = SolrVersion.valueOf("9.0.1");
@@ -45,20 +45,17 @@ public class TestSolrVersion extends SolrTestCase {
   }
 
   public void testParseExceptions() {
-    expectThrows(ParseException.class, () -> SolrVersion.valueOf("SOLR_7_0_0"));
+    expectThrows(SemverException.class, () -> SolrVersion.valueOf("SOLR_7_0_0"));
   }
 
   public void testSatisfies() {
     assertTrue(SOLR_9_0_1.satisfies("~9.0"));
     assertTrue(SOLR_9_0_1.satisfies("9.x"));
     assertTrue(SOLR_9_0_1.satisfies("9"));
+    assertTrue(SOLR_9_0_1.satisfies("<=9"));
     assertTrue(SOLR_9_0_1.satisfies("<9.1"));
-    assertTrue(SOLR_9_0_1.satisfies(">9.0"));
+    assertFalse(SOLR_9_0_1.satisfies(">9.0"));
     assertFalse(SOLR_9_0_1.satisfies("8.x"));
-  }
-
-  public void testSatisfiesParseFailure() {
-    assertThrows(
-        SolrVersion.InvalidSemVerExpressionException.class, () -> SOLR_9_0_1.satisfies(":"));
+    assertTrue(SOLR_9_0_1.satisfies("8 - 9"));
   }
 }
diff --git a/solr/licenses/java-semver-0.9.0.jar.sha1 b/solr/licenses/java-semver-0.9.0.jar.sha1
deleted file mode 100644
index e59c2edfaee..00000000000
--- a/solr/licenses/java-semver-0.9.0.jar.sha1
+++ /dev/null
@@ -1 +0,0 @@
-59a83ca73c72a5e25b3f0b1bb305230a11000329
diff --git a/solr/licenses/semver4j-2.1.1.jar.sha1 b/solr/licenses/semver4j-2.1.1.jar.sha1
new file mode 100644
index 00000000000..470d47111b4
--- /dev/null
+++ b/solr/licenses/semver4j-2.1.1.jar.sha1
@@ -0,0 +1 @@
+6ebbbbd834460ab2e7b66b119cb21f616f8d2ccc
diff --git a/solr/licenses/java-semver-LICENSE-MIT.txt b/solr/licenses/semver4j-LICENSE-MIT.txt
similarity index 100%
rename from solr/licenses/java-semver-LICENSE-MIT.txt
rename to solr/licenses/semver4j-LICENSE-MIT.txt
diff --git a/versions.lock b/versions.lock
index 459cc7c5726..4605289a4fe 100644
--- a/versions.lock
+++ b/versions.lock
@@ -18,7 +18,6 @@ com.github.junrar:junrar:7.5.2 (1 constraints: 650c1002)
 com.github.openjson:openjson:1.0.12 (1 constraints: 8b0c6d0e)
 com.github.spotbugs:spotbugs-annotations:4.7.2 (1 constraints: 0f051636)
 com.github.virtuald:curvesapi:1.07 (1 constraints: 9e0ac7c0)
-com.github.zafarkhaja:java-semver:0.9.0 (1 constraints: 0b050636)
 com.google.api:api-common:2.2.1 (5 constraints: 8543fda1)
 com.google.api:gax:2.18.7 (5 constraints: 874a5ca6)
 com.google.api:gax-httpjson:0.103.7 (2 constraints: 3e21a5bc)
@@ -292,6 +291,7 @@ org.ow2.asm:asm-commons:7.2 (1 constraints: 6b0f7267)
 org.ow2.asm:asm-tree:7.2 (2 constraints: 2f14468c)
 org.quicktheories:quicktheories:0.26 (1 constraints: dc04f530)
 org.reactivestreams:reactive-streams:1.0.3 (3 constraints: 3c2b02fd)
+org.semver4j:semver4j:2.1.1 (1 constraints: 0605f935)
 org.slf4j:jcl-over-slf4j:1.7.36 (3 constraints: 05188eb8)
 org.slf4j:jul-to-slf4j:1.7.36 (3 constraints: 5928c263)
 org.slf4j:slf4j-api:1.7.36 (40 constraints: 08f98db1)
diff --git a/versions.props b/versions.props
index c0fad8f5496..14a702f8572 100644
--- a/versions.props
+++ b/versions.props
@@ -6,7 +6,6 @@ com.fasterxml.jackson:jackson-bom=2.13.3
 com.fasterxml.woodstox:woodstox-core=6.2.8
 com.github.ben-manes.caffeine:caffeine=3.1.1
 com.github.spotbugs:*=4.7.2
-com.github.zafarkhaja:java-semver=0.9.0
 com.google.cloud:google-cloud-bom=0.178.0
 com.google.errorprone:*=2.15.0
 com.google.guava:guava=31.1-jre
@@ -67,6 +66,7 @@ org.jctools:jctools-core=3.3.0
 org.mockito:mockito-core=3.8.0
 org.openjdk.jmh:*=1.32
 org.quicktheories:quicktheories=0.26
+org.semver4j:semver4j=2.1.1
 org.slf4j:*=1.7.36
 org.xerial.snappy:snappy-java=1.1.7.6
 software.amazon.awssdk:*=2.17.63