Skip to content

Commit

Permalink
change version fetch to use http factory and version lock xz dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Borges committed Jan 13, 2025
1 parent 230eede commit 1826699
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 24 deletions.
2 changes: 1 addition & 1 deletion plugin/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 0 additions & 5 deletions plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@
<artifactId>jakarta.inject-api</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.tukaani</groupId>
<artifactId>xz</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -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<InputStream> 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))) {

Expand All @@ -92,10 +97,6 @@ private Version fetchRemoteArtifactVersion(final String repositoryUrl) {

} catch (Exception e) {
e.printStackTrace();
} finally {
if (connection != null) {
connection.disconnect();
}
}
return null;
}
Expand Down

0 comments on commit 1826699

Please sign in to comment.