Skip to content

Commit

Permalink
Add UI notification to alert user of deprecated manifest version (#312)
Browse files Browse the repository at this point in the history
  • Loading branch information
nborges-aws authored and taldekar committed Feb 6, 2025
1 parent 5c35c46 commit 78e776d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
import java.util.HashSet;
import java.util.Optional;

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 software.aws.toolkits.eclipse.amazonq.exception.AmazonQPluginException;
import software.aws.toolkits.eclipse.amazonq.lsp.manager.fetcher.ArtifactUtils;
import software.aws.toolkits.eclipse.amazonq.lsp.manager.fetcher.LspFetcher;
Expand Down Expand Up @@ -83,6 +89,14 @@ private LspInstallResult fetchLspInstallation() {
}
Manifest manifest = fetchManifest();

if (manifest.isManifestDeprecated() && manifest.manifestSchemaVersion() != null) {
try {
showDeprecatedManifestNotification(manifest.manifestSchemaVersion());
} catch (Exception e) {
Activator.getLogger().error("Failed to show deprecated manifest notification", e);
}
}

var platform = platformOverride != null ? platformOverride : PluginUtils.getPlatform();
var architecture = architectureOverride != null ? architectureOverride : PluginUtils.getArchitecture();

Expand Down Expand Up @@ -239,6 +253,33 @@ private static void makeExecutable(final Path filePath) throws IOException {
Files.setPosixFilePermissions(filePath, permissions);
}

private static void showDeprecatedManifestNotification(final String 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(() -> {
AbstractNotificationPopup notification = new PersistentToolkitNotification(Display.getCurrent(),
Constants.MANIFEST_DEPRECATED_NOTIFICATION_TITLE,
Constants.MANIFEST_DEPRECATED_NOTIFICATION_BODY,
(selected) -> {
if (selected) {
Activator.getPluginStore().put(Constants.MANIFEST_DEPRECATED_NOTIFICATION_KEY, schemaVersion.toString());
} else {
Activator.getPluginStore().remove(Constants.MANIFEST_DEPRECATED_NOTIFICATION_KEY);
}
});
notification.open();
});
}
}

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

public static class Builder {
private String manifestUrl;
private Path workingDirectory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ private Constants() {
public static final String DO_NOT_SHOW_UPDATE_KEY = "doNotShowUpdate";
public static final String PLUGIN_UPDATE_NOTIFICATION_TITLE = "Amazon Q Update Available";
public static final String PLUGIN_UPDATE_NOTIFICATION_BODY = "Amazon Q plugin version %s is available."
+ "Please update to receive the latest features and bug fixes.";
+ " Please update to receive the latest features and bug fixes.";
public static final String LSP_CW_OPT_OUT_KEY = "shareCodeWhispererContentWithAWS";
public static final String LSP_CODE_REFERENCES_OPT_OUT_KEY = "includeSuggestionsWithCodeReferences";
public static final String IDE_CUSTOMIZATION_NOTIFICATION_TITLE = "Amazon Q Customization";
public static final String IDE_CUSTOMIZATION_NOTIFICATION_BODY_TEMPLATE = "Amazon Q inline suggestions are now coming from the %s";
public static final String MANIFEST_DEPRECATED_NOTIFICATION_KEY = "doNotShowDeprecatedManifest";
public static final String MANIFEST_DEPRECATED_NOTIFICATION_TITLE = "Update Amazon Q Extension";
public static final String MANIFEST_DEPRECATED_NOTIFICATION_BODY = "This version of the plugin"
+ " will no longer receive updates to Amazon Q Language authoring features";
public static final String DEFAULT_Q_FOUNDATION_DISPLAY_NAME = "Amazon Q foundation (Default)";
public static final String LOGIN_TYPE_KEY = "LOGIN_TYPE";
public static final String LOGIN_IDC_PARAMS_KEY = "IDC_PARAMS";
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 78e776d

Please sign in to comment.