public Optional fetch()

in plugin/src/software/aws/toolkits/eclipse/amazonq/lsp/manager/fetcher/VersionManifestFetcher.java [63:114]


    public Optional<Manifest> fetch() {
        var cachedManifest = getResourceFromCache();
        // if a remote location does not exist, default to content in the download cache
        if (manifestUrl == null) {
            return cachedManifest;
        }
        var cachedEtag = Activator.getPluginStore().get(manifestUrl);
        // only use cached content if it is valid and a cached etag exists
        var etagToRequest = cachedManifest.isPresent() && cachedEtag != null ? cachedEtag : null;

        // fetch contents from remote if new version exists
        // if that fails, use cache as fallback
        try {
            var latestResponse = getResourceFromRemote(etagToRequest);
            // If not modified is returned cached content is latest
            if (latestResponse.statusCode() == HttpURLConnection.HTTP_NOT_MODIFIED) {
                Activator.getLogger().info("Version manifest contains latest content");
                emitGetManifest(cachedManifest.orElse(null), ManifestLocation.CACHE, null);
                return cachedManifest;
            }
            // validate latest manifest fetched from remote location and cache it
            var latestManifest = validateAndCacheLatest(latestResponse);
            emitGetManifest(latestManifest.orElse(null), ManifestLocation.REMOTE, null);
            return latestManifest;
        } catch (Exception e) {
            if (e.getCause() instanceof SSLHandshakeException) {
                ThreadingUtils.executeAsyncTask(() -> {
                    Display display = null;
                    while (display == null) {
                        display = Display.getDefault();
                        if (display == null) {
                            try {
                                Thread.sleep(100);
                            } catch (InterruptedException interrupted) {
                                Thread.currentThread().interrupt();
                                return;
                            }
                        }
                    }
                    display.asyncExec(() -> {
                        AbstractNotificationPopup notification = new ToolkitNotification(Display.getCurrent(),
                                Constants.IDE_SSL_HANDSHAKE_TITLE,
                                Constants.IDE_SSL_HANDSHAKE_BODY);
                        notification.open();
                    });
                });
            }
            Activator.getLogger().error("Error fetching manifest from remote location", e);
            emitGetManifest(null, ManifestLocation.UNKNOWN, ExceptionMetadata.scrubException(LspError.MANIFEST_FETCH_ERROR.toString(), e));
            return cachedManifest;
        }
    }