java.lang.Object
org.klomp.snark.web.BridgeVersion

public final class BridgeVersionextends Object
Version helpers for the I2PSnark Bridge extension: reads the version from the manifest.json inside the bundled XPI, and compares dotted extension versions numerically so the router can tell whether the installed extension is current.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The HTTP header the extension adds to router requests to self-report.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Utility class, not intended for instantiation.
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    Compares two dotted version strings numerically by segment; missing or non-numeric segments count as 0.
    (package private) static String
    Extracts the "version" string from extension manifest JSON without a JSON parser, by locating the version key and reading the quoted value after it.
    static boolean
    isUpdateAvailable(String installed, String bundled)
    Whether an update to the bundled version is available for the installed one.
    static String
    Reads the "version" field from the manifest.json inside a zipped XPI.
    private static int
    segment(String[] parts, int i)
    The leading digits of one part, 0 if there are none.
    private static String[]
    Splits a version string on dots, empty if it is null.

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • BridgeVersion

      private BridgeVersion()
      Utility class, not intended for instantiation.
  • Method Details

    • readXpiVersion

      public static String readXpiVersion(InputStream xpi)
      Reads the "version" field from the manifest.json inside a zipped XPI.
      Parameters:
      xpi - the open XPI stream; closed by this method. May be null.
      Returns:
      the version string, or null if it cannot be determined
    • extractVersion

      static String extractVersion(String json)
      Extracts the "version" string from extension manifest JSON without a JSON parser, by locating the version key and reading the quoted value after it.
      Parameters:
      json - the manifest content
      Returns:
      the version, or null if not found
    • compare

      public static int compare(String a, String b)
      Compares two dotted version strings numerically by segment; missing or non-numeric segments count as 0. "0.1.1" > "0.1.0", "0.1.10" > "0.1.9", "1.0" > "0.9.99".
      Parameters:
      a - first version, may be null
      b - second version, may be null
      Returns:
      negative if a is older, zero if equal, positive if a is newer
    • isUpdateAvailable

      public static boolean isUpdateAvailable(String installed, String bundled)
      Whether an update to the bundled version is available for the installed one.
      Parameters:
      installed - the version reported by the extension, may be null
      bundled - the version bundled in this war, may be null
      Returns:
      true if installed is older than bundled
    • split

      private static String[] split(String v)
      Splits a version string on dots, empty if it is null.
      Parameters:
      v - the version string
      Returns:
      the parts between the dots
    • segment

      private static int segment(String[] parts, int i)
      The leading digits of one part, 0 if there are none.
      Parameters:
      parts - the version parts
      i - which part to read
      Returns:
      the value of those digits