@Override public boolean equals(Object obj) { boolean result; if (!(obj instanceof GatewayVersion)) { result = false; } else if (obj == this) { result = true; } else { result = this.compareTo((GatewayVersion) obj) == 0; } return result; }
@Override public String getAvailableUpdateVersion() { return (this.latestVersion != null) ? this.latestVersion.toString() : ""; }
JSONObject root = new JSONObject(tokener); String version = root.getString("version"); latestVersion = parseGatewayVersion(version);
/** * Parses a GatewayVersion from a String * @param version * @return * @throws Exception */ public static GatewayVersion parseGatewayVersion(String version) throws Exception { if ("develop-SNAPSHOT".equals(version)) { return new GatewayVersion(0, 0, 0); } else { String regex = "(?<major>[0-9]+)\\.(?<minor>[0-9]+)\\.(?<patch>[0-9]+)-?(?<rc>[RC0-9{3}]*)"; Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(version); if (matcher.matches()) { int major = Integer.parseInt(matcher.group("major")); int minor = Integer.parseInt(matcher.group("minor")); int patch = Integer.parseInt(matcher.group("patch")); String rc = matcher.group("rc"); return new GatewayVersion(major, minor, patch, rc); } else { throw new IllegalArgumentException(String.format("version String is not of form %s", regex)); } } }
public UpdateCheckService() { ProductInfo productInfo = getProductInfoInstance(); productName = productInfo.getTitle().replaceAll("\\s+", ""); try { String version = productInfo.getMajor() +"."+ productInfo.getMinor() +"."+ productInfo.getPatch(); currentVersion = parseGatewayVersion(version); } catch (Exception e) { throw new RuntimeException("Could not locate a product version associated with the jars on the classpath", e); } final String productEdition = productInfo.getEdition().replaceAll("\\s+", ""); versionServiceUrl = (productEdition.toLowerCase().contains("enterprise")) ? "https://version.kaazing.com" : "https://version.kaazing.org"; }
@Override public void newVersionAvailable(GatewayVersion currentVersion, GatewayVersion latestGatewayVersion) { if (latestVersion == null || latestVersion.compareTo(latestGatewayVersion) < 0) { this.latestVersion = latestGatewayVersion; } }
protected void setLatestGatewayVersion(GatewayVersion newlatestVersion) { if (this.latestVersion == null || this.latestVersion.compareTo(newlatestVersion) < 0) { synchronized (this) { this.latestVersion = newlatestVersion; } if (newlatestVersion.compareTo(currentVersion) > 0) { notifyListeners(); } } }
/** * Adds a @UpdateCheckListener who will be notified when the version changes, * @param newListener */ public void addListener(UpdateCheckListener newListener) { GatewayVersion latestGatewayVersion = this.getLatestGatewayVersion(); if (latestGatewayVersion != null && latestGatewayVersion.compareTo(currentVersion) > 0) { newListener.newVersionAvailable(currentVersion, latestGatewayVersion); } newListener.setUpdateCheckService(this); listeners.add(newListener); } }