From 182669918a1b252c168cf53f3ce5826de2f3aada Mon Sep 17 00:00:00 2001 From: Nicolas Borges Date: Mon, 13 Jan 2025 13:17:43 -0500 Subject: [PATCH] change version fetch to use http factory and version lock xz dependency --- plugin/META-INF/MANIFEST.MF | 2 +- plugin/pom.xml | 5 --- .../eclipse/amazonq/util/UpdateUtils.java | 37 ++++++++++--------- 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/plugin/META-INF/MANIFEST.MF b/plugin/META-INF/MANIFEST.MF index 7a2a56cb5..6509ef8c9 100644 --- a/plugin/META-INF/MANIFEST.MF +++ b/plugin/META-INF/MANIFEST.MF @@ -9,7 +9,7 @@ Automatic-Module-Name: amazon.q.eclipse Bundle-ActivationPolicy: lazy Bundle-Activator: software.aws.toolkits.eclipse.amazonq.plugin.Activator Require-Bundle: org.eclipse.core.runtime;bundle-version="3.31.0", - org.tukaani.xz, + org.tukaani.xz;bundle-version="1.9.0", org.eclipse.ui;bundle-version="3.205.100", org.eclipse.core.resources;bundle-version="3.20.100", org.eclipse.jface.text;bundle-version="3.25.100", diff --git a/plugin/pom.xml b/plugin/pom.xml index 428b7920b..16f296c72 100644 --- a/plugin/pom.xml +++ b/plugin/pom.xml @@ -47,11 +47,6 @@ jakarta.inject-api 2.0.1 - - org.tukaani - xz - 1.9 - com.fasterxml.jackson.core jackson-databind diff --git a/plugin/src/software/aws/toolkits/eclipse/amazonq/util/UpdateUtils.java b/plugin/src/software/aws/toolkits/eclipse/amazonq/util/UpdateUtils.java index a4cba356a..e8cba5003 100644 --- a/plugin/src/software/aws/toolkits/eclipse/amazonq/util/UpdateUtils.java +++ b/plugin/src/software/aws/toolkits/eclipse/amazonq/util/UpdateUtils.java @@ -7,7 +7,11 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; -import java.net.URL; +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.time.Duration; import org.eclipse.mylyn.commons.ui.dialogs.AbstractNotificationPopup; import org.eclipse.swt.widgets.Display; @@ -21,8 +25,7 @@ import software.aws.toolkits.eclipse.amazonq.telemetry.metadata.PluginClientMetadata; public final class UpdateUtils { - //env for this link? - private static final String REQUESTURL = "https://amazonq.eclipsetoolkit.amazonwebservices.com/artifacts.xml.xz"; + private static final String REQUEST_URL = "https://amazonq.eclipsetoolkit.amazonwebservices.com/artifacts.xml.xz"; private static Version mostRecentNotificationVersion; private static Version remoteVersion; private static Version localVersion; @@ -40,7 +43,7 @@ private UpdateUtils() { private boolean newUpdateAvailable() { //fetch artifact file containing version info from repo - remoteVersion = fetchRemoteArtifactVersion(REQUESTURL); + remoteVersion = fetchRemoteArtifactVersion(REQUEST_URL); //return early if either version is unavailable if (remoteVersion == null || localVersion == null) { @@ -60,22 +63,24 @@ public void checkForUpdate() { } private Version fetchRemoteArtifactVersion(final String repositoryUrl) { - HttpURLConnection connection = null; + HttpClient connection = HttpClientFactory.getInstance(); try { - URL url = new URL(repositoryUrl); - connection = (HttpURLConnection) url.openConnection(); - connection.setRequestMethod("GET"); - connection.setConnectTimeout(5000); - connection.setReadTimeout(5000); + HttpRequest request = HttpRequest.newBuilder() + .uri(URI.create(repositoryUrl)) + .timeout(Duration.ofSeconds(5)) + .GET() + .build(); + + HttpResponse response = connection.send(request, + HttpResponse.BodyHandlers.ofInputStream()); // handle response codes - int responseCode = connection.getResponseCode(); - if (responseCode != HttpURLConnection.HTTP_OK) { - throw new AmazonQPluginException("HTTP request failed with response code: " + responseCode); + if (response.statusCode() != HttpURLConnection.HTTP_OK) { + throw new AmazonQPluginException("HTTP request failed with response code: " + response.statusCode()); } // process XZ content from input stream - try (InputStream inputStream = connection.getInputStream(); + try (InputStream inputStream = response.body(); XZInputStream xzis = new XZInputStream(inputStream); BufferedReader reader = new BufferedReader(new InputStreamReader(xzis))) { @@ -92,10 +97,6 @@ private Version fetchRemoteArtifactVersion(final String repositoryUrl) { } catch (Exception e) { e.printStackTrace(); - } finally { - if (connection != null) { - connection.disconnect(); - } } return null; }