@Test public void testVersionRanges() { VersionMatcher versionMatcher = new VersionMatcher(); Assert.assertFalse(versionMatcher.versionSupported("3.24.1", "3.23.13.4, 3.24")); Assert.assertFalse(versionMatcher.versionSupported("3.23.1", "3.23.13.4, 3.24")); Assert.assertTrue(versionMatcher.versionSupported("3.23.1", "3.23, 3.24")); Assert.assertTrue(versionMatcher.versionSupported("3.*", "3.23, 4.0")); Assert.assertFalse(versionMatcher.versionSupported("3.1*", "3.23, 4.0")); Assert.assertTrue(versionMatcher.versionSupported("4+", "3.23, 4.1")); String s = "SNAPSHOT"; String m2 = "M2"; String m3 = "M3"; System.out.println("===> 1<2? "+("1".compareToIgnoreCase("2"))+", M2<M3? "+m2.compareToIgnoreCase(m3)+", M3>M2? "+m3.compareToIgnoreCase(m2)+", SNAPSHOT vs M3? "+s.compareToIgnoreCase(m3)); }
public boolean versionSupported(final String requiredVersion, final String publishedVersion) { if (requiredVersion == null) { throw new IllegalArgumentException("requiredVersion is null"); } if (publishedVersion == null) { throw new IllegalArgumentException("publishedVersion is null"); } boolean supported; Version versionRequired = new Version(requiredVersion); Version versionBeingTested = new Version(publishedVersion); if (versionRequired.minorVersionSupport() || versionRequired.majorVersionSupport()) { boolean minorVersionSupport = versionRequired.minorVersionSupport(); int[] required; int[] configured; boolean isRange = versionBeingTested.isRange(); try { required = toIntArray(versionRequired.getVersion().split("\\D")); configured = toIntArray(versionBeingTested.getVersion().split("\\D")); } catch(NumberFormatException e) { return false; } if (required.length == 0) return true; if (minorVersionSupport) { supported = checkMinorVersion(required, configured); } else { supported = checkMajorVersion(required, configured); } if (!supported && isRange) { try { configured = toIntArray(versionBeingTested.getEndRange().split("\\D")); } catch(NumberFormatException e) { return false; } if (minorVersionSupport) { supported = checkMinorVersion(required, configured); } else { supported = checkMajorVersion(required, configured); } } } else { if (versionBeingTested.isRange()) { supported = withinRange(versionBeingTested, versionRequired); } else { supported = versionBeingTested.equals(versionRequired); } } return supported; }
VersionMatcher implements Serializable { public boolean versionSupported(final String requiredVersion, final String publishedVersion) { if (requiredVersion == null) { throw new IllegalArgumentException("requiredVersion is null"); } if (publishedVersion == null) { throw new IllegalArgumentException("publishedVersion is null"); } boolean supported; Version versionRequired = new Version(requiredVersion); Version versionBeingTested = new Version(publishedVersion); if (versionRequired.minorVersionSupport() || versionRequired.majorVersionSupport()) { boolean minorVersionSupport = versionRequired.minorVersionSupport(); int[] required; int[] configured; boolean isRange = versionBeingTested.isRange(); try { required = toIntArray(versionRequired.getVersion().split("\\D")); configured = toIntArray(versionBeingTested.getVersion().split("\\D")); } catch(NumberFormatException e) { return false; } if (required.length == 0) return true; if (minorVersionSupport) { supported = checkMinorVersion(required, configured); } else { supported = checkMajorVersion(required, configured); } if (!supported && isRange) { try { configured = toIntArray(versionBeingTested.getEndRange().split("\\D")); } catch(NumberFormatException e) { return false; } if (minorVersionSupport) { supported = checkMinorVersion(required, configured); } else { supported = checkMajorVersion(required, configured); } } } else { if (versionBeingTested.isRange()) { supported = withinRange(versionBeingTested, versionRequired); } else { supported = versionBeingTested.equals(versionRequired); } } return supported; } }
VersionMatcher implements Serializable { public boolean versionSupported(final String requiredVersion, final String publishedVersion) { if (requiredVersion == null) { throw new IllegalArgumentException("requiredVersion is null"); } if (publishedVersion == null) { throw new IllegalArgumentException("publishedVersion is null"); } boolean supported; Version versionRequired = new Version(requiredVersion); Version versionBeingTested = new Version(publishedVersion); if (versionRequired.minorVersionSupport() || versionRequired.majorVersionSupport()) { boolean minorVersionSupport = versionRequired.minorVersionSupport(); int[] required; int[] configured; boolean isRange = versionBeingTested.isRange(); try { required = toIntArray(versionRequired.getVersion().split("\\D")); configured = toIntArray(versionBeingTested.getVersion().split("\\D")); } catch(NumberFormatException e) { return false; } if (required.length == 0) return true; if (minorVersionSupport) { supported = checkMinorVersion(required, configured); } else { supported = checkMajorVersion(required, configured); } if (!supported && isRange) { try { configured = toIntArray(versionBeingTested.getEndRange().split("\\D")); } catch(NumberFormatException e) { return false; } if (minorVersionSupport) { supported = checkMinorVersion(required, configured); } else { supported = checkMajorVersion(required, configured); } } } else { if (versionBeingTested.isRange()) { supported = withinRange(versionBeingTested, versionRequired); } else { supported = versionBeingTested.equals(versionRequired); } } return supported; }  }
VersionMatcher implements Serializable { public boolean versionSupported(final String requiredVersion, final String publishedVersion) { if (requiredVersion == null) { throw new IllegalArgumentException("requiredVersion is null"); } if (publishedVersion == null) { throw new IllegalArgumentException("publishedVersion is null"); } boolean supported; Version versionRequired = new Version(requiredVersion); Version versionBeingTested = new Version(publishedVersion); if (versionRequired.minorVersionSupport() || versionRequired.majorVersionSupport()) { boolean minorVersionSupport = versionRequired.minorVersionSupport(); int[] required; int[] configured; boolean isRange = versionBeingTested.isRange(); try { required = toIntArray(versionRequired.getVersion().split("\\D")); configured = toIntArray(versionBeingTested.getVersion().split("\\D")); } catch(NumberFormatException e) { return false; } if (required.length == 0) return true; if (minorVersionSupport) { supported = checkMinorVersion(required, configured); } else { supported = checkMajorVersion(required, configured); } if (!supported && isRange) { try { configured = toIntArray(versionBeingTested.getEndRange().split("\\D")); } catch(NumberFormatException e) { return false; } if (minorVersionSupport) { supported = checkMinorVersion(required, configured); } else { supported = checkMajorVersion(required, configured); } } } else { if (versionBeingTested.isRange()) { supported = withinRange(versionBeingTested, versionRequired); } else { supported = versionBeingTested.equals(versionRequired); } } return supported; }  boolean versionSupported(final String requiredVersion, final String publishedVersion); }
VersionMatcher implements Serializable { public boolean versionSupported(final String requiredVersion, final String publishedVersion) { if (requiredVersion == null) { throw new IllegalArgumentException("requiredVersion is null"); } if (publishedVersion == null) { throw new IllegalArgumentException("publishedVersion is null"); } boolean supported; Version versionRequired = new Version(requiredVersion); Version versionBeingTested = new Version(publishedVersion); if (versionRequired.minorVersionSupport() || versionRequired.majorVersionSupport()) { boolean minorVersionSupport = versionRequired.minorVersionSupport(); int[] required; int[] configured; boolean isRange = versionBeingTested.isRange(); try { required = toIntArray(versionRequired.getVersion().split("\\D")); configured = toIntArray(versionBeingTested.getVersion().split("\\D")); } catch(NumberFormatException e) { return false; } if (required.length == 0) return true; if (minorVersionSupport) { supported = checkMinorVersion(required, configured); } else { supported = checkMajorVersion(required, configured); } if (!supported && isRange) { try { configured = toIntArray(versionBeingTested.getEndRange().split("\\D")); } catch(NumberFormatException e) { return false; } if (minorVersionSupport) { supported = checkMinorVersion(required, configured); } else { supported = checkMajorVersion(required, configured); } } } else { if (versionBeingTested.isRange()) { supported = withinRange(versionBeingTested, versionRequired); } else { supported = versionBeingTested.equals(versionRequired); } } return supported; }  boolean versionSupported(final String requiredVersion, final String publishedVersion);  }