Skip to content

Commit

Permalink
Merge pull request #215 from nocalhost/dev-tian-add-233-support
Browse files Browse the repository at this point in the history
feat: add 2023.3 support
  • Loading branch information
tianyu-sz authored Jan 4, 2024
2 parents 85473b4 + 492b9cd commit 0dbb13b
Show file tree
Hide file tree
Showing 11 changed files with 331 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
platform-version: [ 203, 211, 212, 213, 221, 222, 223, 231, 232 ]
platform-version: [ 203, 211, 212, 213, 221, 222, 223, 231, 232, 233 ]
env:
ORG_GRADLE_PROJECT_platformVersion: ${{ matrix.platform-version }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
needs: create-release
strategy:
matrix:
platform-version: [ 203, 211, 212, 213, 221, 222, 223, 231, 232 ]
platform-version: [ 203, 211, 212, 213, 221, 222, 223, 231, 232, 233 ]
env:
ORG_GRADLE_PROJECT_platformVersion: ${{ matrix.platform-version }}

Expand Down
2 changes: 1 addition & 1 deletion .run/nocalhost-intellij-plugin [buildPlugin].run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<ExternalSystemSettings>
<option name="env">
<map>
<entry key="ORG_GRADLE_PROJECT_platformVersion" value="232" />
<entry key="ORG_GRADLE_PROJECT_platformVersion" value="233" />
</map>
</option>
<option name="executionName" />
Expand Down
2 changes: 1 addition & 1 deletion .run/nocalhost-intellij-plugin [runIde].run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<ExternalSystemSettings>
<option name="env">
<map>
<entry key="ORG_GRADLE_PROJECT_platformVersion" value="232" />
<entry key="ORG_GRADLE_PROJECT_platformVersion" value="233" />
</map>
</option>
<option name="executionName" />
Expand Down
17 changes: 17 additions & 0 deletions gradle-233.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Existent IDE versions can be found in the following repos:
# https://www.jetbrains.com/intellij-repository/releases/
# https://www.jetbrains.com/intellij-repository/snapshots/
ideaVersion=IU-2023.3

# see org.gradle.api.JavaVersion
javaCompatibility=VERSION_17

# Get the number from the IDE's download page
# For more info, see https://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html for description
sinceBuild=233.11799.241
untilBuild=233.*

# plugin versions from intellij marketplace https://plugins.jetbrains.com
goPluginVersion=233.11799.196
phpPluginVersion=233.11799.300
pythonPluginVersion=233.11799.300
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
propertiesPluginEnvironmentNameProperty=platformVersion
# Supported platforms: 203, 211, 212, 213, 223, 231
platformVersion=232
# Supported platforms: 203, 211, 212, 213, 223, 231, ...
platformVersion=233

kotlin.code.style=official
version=0.6.30
version=0.6.31
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
package dev.nocalhost.plugin.intellij.exception;

import com.intellij.ide.BrowserUtil;
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationDisplayType;
import com.intellij.notification.NotificationGroup;
import com.intellij.notification.NotificationListener;
import com.intellij.notification.NotificationType;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.extensions.PluginId;
import com.intellij.openapi.options.ShowSettingsUtil;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.NlsContexts;
import com.intellij.openapi.wm.ToolWindowManager;

import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.event.HyperlinkEvent;

import dev.nocalhost.plugin.intellij.topic.NocalhostExceptionPrintNotifier;
import icons.NocalhostIcons;

public class NocalhostNotifier {

public static final String NOCALHOST_NOTIFICATION_ID = "Nocalhost.Notification";
public static final String NOCALHOST_ERROR_NOTIFICATION_ID = "Nocalhost.Notification.Error";

public static final NotificationGroup NOCALHOST_NOTIFICATION =
NotificationGroup.create(
"Nocalhost.Notification", NotificationDisplayType.BALLOON, false, "Nocalhost",
"Nocalhost", PluginId.getId("dev.nocalhost.nocalhost-intellij-plugin"));
public static final NotificationGroup NOCALHOST_ERROR_NOTIFICATION =
NotificationGroup.create(
"Nocalhost.Notification.Error", NotificationDisplayType.STICKY_BALLOON, true, "Nocalhost",
"Nocalhost", PluginId.getId("dev.nocalhost.nocalhost-intellij-plugin"));

private final Project project;

public NocalhostNotifier(Project project) {
this.project = project;
}

public static NocalhostNotifier getInstance(Project project) {
return project.getService(NocalhostNotifier.class);
}

@NotNull
public Notification notify(@NotNull Notification notification) {
notification.notify(project);
return notification;
}

@NotNull
public Notification notifyError(@NlsContexts.NotificationTitle @NotNull String title,
@NlsContexts.NotificationContent @NotNull String message) {
return notify(NOCALHOST_ERROR_NOTIFICATION, NOCALHOST_ERROR_NOTIFICATION_ID, title, message, NotificationType.ERROR, null);
}

@NotNull
public Notification notifyError(@NlsContexts.NotificationTitle @NotNull String title,
@NlsContexts.NotificationContent @NotNull String message,
@NotNull String eMessage) {
String content = String.format("<html>%s <a href=\"nocalhost.show\">Show More</a></html>", message);
return notify(NOCALHOST_ERROR_NOTIFICATION, NOCALHOST_ERROR_NOTIFICATION_ID, title, content, NotificationType.ERROR, new NotificationListener.Adapter() {
@Override
protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent e) {
ToolWindowManager.getInstance(project).getToolWindow("Nocalhost Console").activate(() -> {
project.getMessageBus().syncPublisher(NocalhostExceptionPrintNotifier.NOCALHOST_EXCEPTION_PRINT_NOTIFIER_TOPIC)
.action(title, message, eMessage);
});
}
});
}

public void notifyBinaryNotFound(String binary) {
String content = String.format("<html>%s binary not found. <a href=\"nocalhost.setting\">Setting</a></html>", binary);
notify(NOCALHOST_ERROR_NOTIFICATION, NOCALHOST_ERROR_NOTIFICATION_ID, "Nocalhost", content, NotificationType.ERROR, new NotificationListener.Adapter() {
@Override
protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent e) {
ShowSettingsUtil showSettingsUtil = ApplicationManager.getApplication().getService(ShowSettingsUtil.class);
showSettingsUtil.showSettingsDialog(project, "Nocalhost");
}
});
}

public void notifyVersionTips() {
String content = "<html>nocalhost plugin need upgrade. <a href=\"nocalhost.setting\">upgrade plugin</a></html>";
notify(NOCALHOST_ERROR_NOTIFICATION, NOCALHOST_ERROR_NOTIFICATION_ID, "Nocalhost", content, NotificationType.ERROR, new NotificationListener.Adapter() {
@Override
protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent e) {
BrowserUtil.browse("https://plugins.jetbrains.com/plugin/16058-nocalhost/versions");
}
});
}


@NotNull
public Notification notifyError(@NlsContexts.NotificationTitle @NotNull String title,
@NlsContexts.NotificationContent @NotNull String message,
@Nullable NotificationListener listener) {
return notify(NOCALHOST_ERROR_NOTIFICATION, NOCALHOST_ERROR_NOTIFICATION_ID, title, message, NotificationType.ERROR, listener);
}

@NotNull
public Notification notifySuccess(@NlsContexts.NotificationTitle @NotNull String title,
@NlsContexts.NotificationContent @NotNull String message) {
return notify(NOCALHOST_NOTIFICATION, NOCALHOST_NOTIFICATION_ID, title, message, NotificationType.INFORMATION, null);
}

@NotNull
public Notification notifySuccess(@NlsContexts.NotificationTitle @NotNull String title,
@NlsContexts.NotificationContent @NotNull String message,
@Nullable NotificationListener listener) {
return notify(NOCALHOST_NOTIFICATION, NOCALHOST_NOTIFICATION_ID, title, message, NotificationType.INFORMATION, listener);
}

@NotNull
private Notification notify(@NotNull NotificationGroup notificationGroup,
@NonNls @Nullable String displayId,
@NlsContexts.NotificationTitle @NotNull String title,
@NlsContexts.NotificationContent @NotNull String message,
@NotNull NotificationType type,
@Nullable NotificationListener listener) {
Notification notification = createNotification(notificationGroup, displayId, title, message, type, listener);
return notify(notification);
}

private static Notification createNotification(@NotNull NotificationGroup notificationGroup,
@NonNls @Nullable String displayId,
@NlsContexts.NotificationTitle @NotNull String title,
@NlsContexts.NotificationContent @NotNull String message,
@NotNull NotificationType type,
@Nullable NotificationListener listener) {

if (StringUtils.isBlank(message)) {
message = title;
title = "";
}
Notification notification = notificationGroup.createNotification(title, message, type);
if (listener != null) {
notification.setListener(listener);
}
notification.setDisplayId(StringUtils.trimToEmpty(displayId));
return notification;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package dev.nocalhost.plugin.intellij.ui.action.workload;

import com.intellij.ide.RecentProjectsManagerBase;
import com.intellij.ide.impl.OpenProjectTask;
import com.intellij.openapi.application.ApplicationManager;

import java.nio.file.Paths;

public class OpenProjectExecutor {

public static void open(String projectPath) {
var task = OpenProjectTask.build();
ApplicationManager.getApplication().executeOnPooledThread(() -> {
RecentProjectsManagerBase.getInstanceEx().openProjectSync(Paths.get(projectPath), task);
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package dev.nocalhost.plugin.intellij.ui.sync;

import com.intellij.dvcs.ui.BranchActionGroupPopup;
import com.intellij.ide.DataManager;
import com.intellij.openapi.actionSystem.ActionGroup;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.WindowManager;
import com.intellij.ui.popup.PopupFactoryImpl;

import org.jetbrains.annotations.NotNull;

import java.util.List;

import dev.nocalhost.plugin.intellij.commands.data.NhctlDevAssociateQueryResult;
import dev.nocalhost.plugin.intellij.topic.NocalhostSyncUpdateNotifier;

public class NocalhostSyncPopup {
private final Project project;
private final ActionGroup actions;
private NocalhostSyncPopup(@NotNull Project project, @NotNull ActionGroup actions) {
this.project = project;
this.actions = actions;
}

public static NocalhostSyncPopup getInstance(@NotNull Project project, @NotNull ActionGroup actions) {
return new NocalhostSyncPopup(project, actions);
}

public BranchActionGroupPopup asListPopup() {
var statusBar = WindowManager.getInstance().getStatusBar(project);
var popup = new BranchActionGroupPopup("Nocalhost Sync Manage", project, (action) -> false, actions, "Nocalhost.Sync.Manage", DataManager.getInstance().getDataContext(statusBar.getComponent()));
project.getMessageBus().connect(popup).subscribe(
NocalhostSyncUpdateNotifier.NOCALHOST_SYNC_UPDATE_NOTIFIER_TOPIC,
(NocalhostSyncUpdateNotifier) results -> update(popup, results)
);
return popup;
}

private void update(@NotNull BranchActionGroupPopup popup, @NotNull List<NhctlDevAssociateQueryResult> results) {
List<Object> items = popup.getListStep().getValues();
items.forEach(x -> {
var item = (PopupFactoryImpl.ActionItem) x;
if (item.getAction() instanceof ServiceActionGroup) {
var group = (ServiceActionGroup) item.getAction();
results.forEach(it -> {
if (group.compare(it)) {
group.setResult(it);
}
});
}
});
popup.update();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package dev.nocalhost.plugin.intellij.utils;

import com.intellij.openapi.fileChooser.FileChooser;
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;

import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

public final class FileChooseUtil {
public static FileChooserDescriptor singleFileChooserDescriptor() {
FileChooserDescriptor fileChooserDescriptor = new FileChooserDescriptor(true, false, false, false, false, false);
return fileChooserDescriptor;
}

public static FileChooserDescriptor singleDirectoryChooserDescriptor() {
FileChooserDescriptor fileChooserDescriptor = new FileChooserDescriptor(false, true, false, false, false, false);
return fileChooserDescriptor;
}

public static Path chooseSingleFile(Project project) {
FileChooserDescriptor fileChooserDescriptor = new FileChooserDescriptor(true, false, false, false, false, false)
.withFileFilter(f -> !f.isDirectory());
VirtualFile virtualFile = FileChooser.chooseFile(fileChooserDescriptor, project, null);
if (virtualFile == null) {
return null;
}
return virtualFile.toNioPath().toAbsolutePath();
}

public static Path chooseSingleFile(Project project, String title, Path root, Set<String> filenames) {
FileChooserDescriptor fileChooserDescriptor = new FileChooserDescriptor(true, false, false, false, false, false)
.withTitle(title)
.withRoots(LocalFileSystem.getInstance().findFileByNioFile(root))
.withFileFilter(f -> !f.isDirectory() && filenames.contains(f.getName()));
VirtualFile virtualFile = FileChooser.chooseFile(fileChooserDescriptor, project, null);
if (virtualFile == null) {
return null;
}
return virtualFile.toNioPath().toAbsolutePath();
}

public static Path chooseSingleDirectory(Project project) {
FileChooserDescriptor fileChooserDescriptor = new FileChooserDescriptor(false, true, false, false, false, false)
.withFileFilter(VirtualFile::isDirectory);
VirtualFile virtualFile = FileChooser.chooseFile(fileChooserDescriptor, project, null);
if (virtualFile == null) {
return null;
}
return virtualFile.toNioPath().toAbsolutePath();
}

public static Path chooseSingleDirectory(Project project, String title, String message) {
FileChooserDescriptor fileChooserDescriptor = new FileChooserDescriptor(false, true, false, false, false, false)
.withTitle(title)
.withDescription(message)
.withFileFilter(VirtualFile::isDirectory);
VirtualFile virtualFile = FileChooser.chooseFile(fileChooserDescriptor, project, null);
if (virtualFile == null) {
return null;
}
return virtualFile.toNioPath().toAbsolutePath();
}

public static Path chooseSingleFileOrDirectory(Project project) {
FileChooserDescriptor fileChooserDescriptor = new FileChooserDescriptor(true, true, false, false, false, false);
VirtualFile virtualFile = FileChooser.chooseFile(fileChooserDescriptor, project, null);
if (virtualFile == null) {
return null;
}
return virtualFile.toNioPath().toAbsolutePath();
}

public static List<Path> chooseFilesAndDirectories(Project project) {
FileChooserDescriptor fileChooserDescriptor = new FileChooserDescriptor(true, true, false, false, false, true);
VirtualFile[] virtualFiles = FileChooser.chooseFiles(fileChooserDescriptor, project, null);
return Arrays.stream(virtualFiles).map(e -> e.toNioPath()).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
import dev.nocalhost.plugin.intellij.settings.data.NocalhostAccount;
import dev.nocalhost.plugin.intellij.utils.TokenUtil;

// Todo fix this deprecated interface according to
// https://youtrack.jetbrains.com/issue/GO-16024/com.intellij.diagnostic.PluginException-Override-execute
// https://github.com/JetBrains/intellij-platform-plugin-template/blob/main/src/main/kotlin/org/jetbrains/plugins/template/listeners/MyApplicationActivationListener.kt
public class NocalhostTokenRefreshListener implements ApplicationInitializedListener {
private static final Logger LOG = Logger.getInstance(NocalhostTokenRefreshListener.class);

Expand Down

0 comments on commit 0dbb13b

Please sign in to comment.