Skip to content

Commit

Permalink
refactor to use artifactVersioning and use strings for persistent sto…
Browse files Browse the repository at this point in the history
…rage
  • Loading branch information
Nicolas Borges authored and nborges-aws committed Jan 28, 2025
1 parent d2cf074 commit eaca34b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import org.eclipse.swt.widgets.Display;
import software.aws.toolkits.eclipse.amazonq.util.Constants;
import software.aws.toolkits.eclipse.amazonq.util.PersistentToolkitNotification;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.eclipse.mylyn.commons.ui.dialogs.AbstractNotificationPopup;
import org.osgi.framework.Version;

import software.aws.toolkits.eclipse.amazonq.exception.AmazonQPluginException;
import software.aws.toolkits.eclipse.amazonq.lsp.manager.fetcher.ArtifactUtils;
Expand Down Expand Up @@ -254,8 +254,10 @@ private static void makeExecutable(final Path filePath) throws IOException {
}

private static void showDeprecatedManifestNotification(final String version) {
Version storedValue = Activator.getPluginStore().getObject(Constants.MANIFEST_DEPRECATED_NOTIFICATION_KEY, Version.class);
Version schemaVersion = ArtifactUtils.parseVersion(version);
ArtifactVersion schemaVersion = ArtifactUtils.parseVersion(version);
ArtifactVersion storedValue = Optional.ofNullable(Activator.getPluginStore().get(Constants.MANIFEST_DEPRECATED_NOTIFICATION_KEY))
.map(ArtifactUtils::parseVersion)
.orElse(null);

if (storedValue == null || remoteVersionIsGreater(schemaVersion, storedValue)) {
Display.getDefault().asyncExec(() -> {
Expand All @@ -264,7 +266,7 @@ private static void showDeprecatedManifestNotification(final String version) {
Constants.MANIFEST_DEPRECATED_NOTIFICATION_BODY,
(selected) -> {
if (selected) {
Activator.getPluginStore().putObject(Constants.MANIFEST_DEPRECATED_NOTIFICATION_KEY, schemaVersion);
Activator.getPluginStore().put(Constants.MANIFEST_DEPRECATED_NOTIFICATION_KEY, schemaVersion.toString());
} else {
Activator.getPluginStore().remove(Constants.MANIFEST_DEPRECATED_NOTIFICATION_KEY);
}
Expand All @@ -274,7 +276,7 @@ private static void showDeprecatedManifestNotification(final String version) {
}
}

private static boolean remoteVersionIsGreater(final Version remote, final Version storedValue) {
private static boolean remoteVersionIsGreater(final ArtifactVersion remote, final ArtifactVersion storedValue) {
return remote.compareTo(storedValue) > 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;
import java.util.Optional;

import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.eclipse.mylyn.commons.ui.dialogs.AbstractNotificationPopup;
Expand All @@ -36,7 +37,9 @@ public static UpdateUtils getInstance() {
}

private UpdateUtils() {
mostRecentNotificationVersion = Activator.getPluginStore().getObject(Constants.DO_NOT_SHOW_UPDATE_KEY, ArtifactVersion.class);
mostRecentNotificationVersion = Optional.ofNullable(Activator.getPluginStore().get(Constants.DO_NOT_SHOW_UPDATE_KEY))
.map(ArtifactUtils::parseVersion)
.orElse(null);
String localString = PluginClientMetadata.getInstance().getPluginVersion();
localVersion = ArtifactUtils.parseVersion(localString.substring(0, localString.lastIndexOf(".")));
}
Expand Down Expand Up @@ -108,7 +111,7 @@ private void showNotification() {
String.format(Constants.PLUGIN_UPDATE_NOTIFICATION_BODY, remoteVersion.toString()),
(selected) -> {
if (selected) {
Activator.getPluginStore().putObject(Constants.DO_NOT_SHOW_UPDATE_KEY, remoteVersion);
Activator.getPluginStore().put(Constants.DO_NOT_SHOW_UPDATE_KEY, remoteVersion.toString());
} else {
Activator.getPluginStore().remove(Constants.DO_NOT_SHOW_UPDATE_KEY);
}
Expand Down

0 comments on commit eaca34b

Please sign in to comment.