Skip to content

Commit

Permalink
Corrected a problem where the version was null in the desktop version.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcpitre committed Jan 15, 2024
1 parent e0d0f1f commit 2f0c3e3
Showing 1 changed file with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.SettableFuture;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import io.github.classgraph.ClassGraph;
import io.github.classgraph.Resource;
import io.github.classgraph.ScanResult;
Expand Down Expand Up @@ -151,19 +151,23 @@ private Optional<String> resolveLatestReleaseVersion(Optional<String> currentVer
String.format(
"%s?application_type=%s&current_version=%s",
LATEST_RELEASE_VERSION_URL, applicationType, currentVersion.orElse("Ï")));
String jsonString = null;
try (BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()))) {
Gson gson = new GsonBuilder().create();
VersionResponse response = gson.fromJson(in, VersionResponse.class);
if (response != null && !Strings.isNullOrEmpty(response.version)) {
logger.atInfo().log("resolved release version=%s", response.version);
return Optional.of(response.version);

// We expect the REST call to return something like :
// {"version":"1.4.0"}
jsonString = in.readLine();
if (Strings.isNullOrEmpty(jsonString)) {
return Optional.empty();
}

JsonObject json = JsonParser.parseString(jsonString).getAsJsonObject();
String version = json.get("version").getAsString();
return Optional.of(version);
} catch (Exception e) {
logger.atInfo().log("error parsing response=%s", jsonString);
}
return Optional.empty();
}

/** Serialization object for parsing the /version API response. */
class VersionResponse {
String version;
return Optional.empty();
}
}

0 comments on commit 2f0c3e3

Please sign in to comment.