Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cbshell #220

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
33 changes: 33 additions & 0 deletions .github/workflows/plugin-verifier.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Plugin compatibility
on:
- push
- workflow_dispatch
jobs:
run:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Setup Java
uses: actions/setup-java@v1
with:
java-version: 21.x.x
- name: Build the plugin using Gradle
run: ./gradlew buildPlugin
- name: Verify Plugin on IntelliJ Platforms
id: verify
uses: ChrisCarini/intellij-platform-plugin-verifier-action@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
ide-versions: |
ideaIC:LATEST-EAP-SNAPSHOT
failure-levels: |
COMPATIBILITY_PROBLEMS
INVALID_PLUGIN
NOT_DYNAMIC
DEPRECATED_API_USAGES
INTERNAL_API_USAGES
OVERRIDE_ONLY_API_USAGES
NON_EXTENDABLE_API_USAGES
MISSING_DEPENDENCIES
INVALID_PLUGIN
3 changes: 1 addition & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
java-version: '21'
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@ccb4328a959376b642e027874838f60f8e596de3
- name: Run the Gradle package task
Expand Down
17 changes: 9 additions & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = "com.couchbase"
version = "1.1.4"
version = "1.1.5"
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
Expand Down Expand Up @@ -57,33 +57,34 @@ dependencies {
implementation("com.theokanning.openai-gpt3-java:service:0.14.0")
implementation("com.vladsch.flexmark:flexmark:0.64.8")
implementation("com.vladsch.flexmark:flexmark-ext-tables:0.64.8")

implementation("com.vladsch.flexmark:flexmark-html2md-converter:0.64.8")

testImplementation("org.testcontainers:couchbase:1.19.7")
testImplementation("org.testcontainers:junit-jupiter:1.19.7")



}

// Configure Gradle IntelliJ Plugin
// Read more: https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html
intellij {
version.set("2024.1")
version.set("2024.2")
type.set("IC") // Target IDE Platform

plugins.set(listOf("com.intellij.java"))
plugins.set(listOf("com.intellij.java", "org.jetbrains.plugins.terminal"))
}

tasks {
// Set the JVM compatibility versions
withType<JavaCompile> {
sourceCompatibility = "17"
targetCompatibility = "17"
sourceCompatibility = "21"
targetCompatibility = "21"
}

patchPluginXml {
sinceBuild.set("241.14494.240")
untilBuild.set("246.*")
sinceBuild.set("242.22855.74")
untilBuild.set("242.*")
}

signPlugin {
Expand Down
35 changes: 28 additions & 7 deletions src/main/java/com/couchbase/intellij/database/ActiveCluster.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.couchbase.intellij.tree.overview.apis.CouchbaseRestAPI;
import com.couchbase.intellij.tree.overview.apis.ServerOverview;
import com.couchbase.intellij.utils.Subscribable;
import com.couchbase.intellij.workbench.CbShellEmulator;
import com.couchbase.intellij.workbench.Log;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.progress.ProgressIndicator;
Expand Down Expand Up @@ -67,6 +68,8 @@ public class ActiveCluster implements CouchbaseClusterEntity {
*/
private static final List<Consumer<ActiveCluster>> clusterListeners = new ArrayList<>();

private final List<Runnable> disconnectListeners = new ArrayList<>();

private Integer queryLimit = 200;

protected ActiveCluster() {
Expand Down Expand Up @@ -109,6 +112,10 @@ public void deregisterNewConnectionListener(Runnable runnable) {
this.newConnectionListener.remove(runnable);
}

public void onDisconnect(Runnable runnable) {
disconnectListeners.add(runnable);
}

public Cluster get() {
return cluster;
}
Expand Down Expand Up @@ -265,6 +272,13 @@ public void disconnect() {
} catch (Exception e) {
Log.error(e);
}
disconnectListeners.forEach(r -> {
try {
r.run();
} catch (Exception e) {
Log.error(e);
}
});
}
this.savedCluster = null;
this.cluster = null;
Expand Down Expand Up @@ -378,32 +392,39 @@ public Set<CouchbaseBucket> getChildren() {
return buckets;
}

private List<Consumer<Exception>> schemaListeners = Collections.synchronizedList(new ArrayList<>());

private void scheduleSchemaUpdate(Consumer<Exception> onComplete) {

if (!hasQueryService()) {
return;
}
if (!schemaUpdating.get() && System.currentTimeMillis() - lastSchemaUpdate > 60000) {
if (schemaUpdating.get()) {
schemaListeners.add(onComplete);
} else if (System.currentTimeMillis() - lastSchemaUpdate > 60000) {
schemaListeners.add(onComplete);
schemaUpdating.set(true);

ProgressManager.getInstance().run(new Task.Backgroundable(null, "Reading Couchbase cluster schema", true) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
try {
doUpdateSchema();
if (onComplete != null) {
onComplete.accept(null);
}
schemaListeners.forEach(l -> l.accept(null));
schemaListeners.clear();
} catch (Exception e) {
e.printStackTrace();
if (onComplete != null) {
onComplete.accept(e);
}
schemaListeners.forEach(l -> l.accept(e));
schemaListeners.clear();
ApplicationManager.getApplication().invokeLater(() -> Messages.showErrorDialog("Could not read cluster schema.", "Couchbase Connection Error"));
disconnect();
}
}
});
} else {
if (onComplete != null) {
onComplete.accept(null);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,38 +84,38 @@ public Map<String, ToolSpec> getDownloadList(String os) {
Map<String, ToolSpec> map = new HashMap<>();

if (MACOS_64.equals(os)) {
map.put(TOOL_SHELL, getToolSpec("https://github.com/couchbaselabs/couchbase-shell/releases/download/v0.75.1/cbsh-x86_64-apple-darwin.zip", TOOL_SHELL, MACOS_64));
map.put(TOOL_SHELL, getToolSpec("https://github.com/couchbaselabs/couchbase-shell/releases/download/v1.0.0/cbsh-x86_64-apple-darwin.zip", TOOL_SHELL, MACOS_64));
map.put(TOOL_IMPORT_EXPORT, getToolSpec("https://packages.couchbase.com/releases/7.6.0/couchbase-server-tools_7.6.0-macos_x86_64.zip", TOOL_IMPORT_EXPORT, MACOS_64));
map.put(ALL_TOOLS, getToolSpec("https://intellij-plugin-dependencies.s3.us-east-2.amazonaws.com/7.2.0-macos_64.zip", ALL_TOOLS, MACOS_64));
map.put(CB_MIGRATE, getToolSpec("https://intellij-plugin-dependencies.s3.us-east-2.amazonaws.com/cbmigrate/cbmigrate_0.1.0_darwin_amd64.zip", CB_MIGRATE, MACOS_64));

} else if (MACOS_ARM.equals(os)) {
map.put(TOOL_SHELL, getToolSpec("https://github.com/couchbaselabs/couchbase-shell/releases/download/v0.75.1/cbsh-aarch64-apple-darwin.zip", TOOL_SHELL, MACOS_ARM));
map.put(TOOL_SHELL, getToolSpec("https://github.com/couchbaselabs/couchbase-shell/releases/download/v1.0.0/cbsh-aarch64-apple-darwin.zip", TOOL_SHELL, MACOS_ARM));
map.put(TOOL_IMPORT_EXPORT, getToolSpec("https://packages.couchbase.com/releases/7.6.0/couchbase-server-tools_7.6.0-macos_arm64.zip", TOOL_IMPORT_EXPORT, MACOS_ARM));
map.put(ALL_TOOLS, getToolSpec("https://intellij-plugin-dependencies.s3.us-east-2.amazonaws.com/7.2.0-macos_arm.zip", ALL_TOOLS, MACOS_ARM));
map.put(CB_MIGRATE, getToolSpec("https://intellij-plugin-dependencies.s3.us-east-2.amazonaws.com/cbmigrate/cbmigrate_0.1.0_darwin_arm64.zip", CB_MIGRATE, MACOS_ARM));


} else if (WINDOWS_64.equals(os)) {
map.put(TOOL_SHELL, getToolSpec("https://github.com/couchbaselabs/couchbase-shell/releases/download/v0.75.1/cbsh-x86_64-pc-windows-msvc.zip", TOOL_SHELL, WINDOWS_64));
map.put(TOOL_SHELL, getToolSpec("https://github.com/couchbaselabs/couchbase-shell/releases/download/v1.0.0/cbsh-x86_64-pc-windows-msvc.zip", TOOL_SHELL, WINDOWS_64));
map.put(TOOL_IMPORT_EXPORT, getToolSpec("https://packages.couchbase.com/releases/7.6.0/couchbase-server-tools_7.6.0-windows_amd64.zip", TOOL_IMPORT_EXPORT, WINDOWS_64));
map.put(ALL_TOOLS, getToolSpec("https://intellij-plugin-dependencies.s3.us-east-2.amazonaws.com/7.2.0-windows_64.zip", ALL_TOOLS, WINDOWS_64));
map.put(CB_MIGRATE, getToolSpec("https://intellij-plugin-dependencies.s3.us-east-2.amazonaws.com/cbmigrate/cbmigrate_0.1.0_windows_amd64.zip", CB_MIGRATE, WINDOWS_64));

} else if (WINDOWS_ARM.equals(os)) {
map.put(TOOL_SHELL, getToolSpec("https://github.com/couchbaselabs/couchbase-shell/releases/download/v0.75.1/cbsh-x86_64-pc-windows-msvc.zip", TOOL_SHELL, WINDOWS_ARM));
map.put(TOOL_SHELL, getToolSpec("https://github.com/couchbaselabs/couchbase-shell/releases/download/v1.0.0/cbsh-x86_64-pc-windows-msvc.zip", TOOL_SHELL, WINDOWS_ARM));
map.put(TOOL_IMPORT_EXPORT, getToolSpec("https://packages.couchbase.com/releases/7.6.0/couchbase-server-tools_7.6.0-windows_amd64.zip", TOOL_IMPORT_EXPORT, WINDOWS_ARM));
map.put(ALL_TOOLS, getToolSpec("https://intellij-plugin-dependencies.s3.us-east-2.amazonaws.com/7.2.0-windows_64.zip", ALL_TOOLS, WINDOWS_ARM));
map.put(CB_MIGRATE, getToolSpec("https://intellij-plugin-dependencies.s3.us-east-2.amazonaws.com/cbmigrate/cbmigrate_0.1.0_windows_amd64.zip", CB_MIGRATE, WINDOWS_ARM));

} else if (LINUX_64.equals(os)) {
map.put(TOOL_SHELL, getToolSpec("https://github.com/couchbaselabs/couchbase-shell/releases/download/v0.75.1/cbsh-x86_64-unknown-linux-gnu.tar.gz", TOOL_SHELL, LINUX_64));
map.put(TOOL_SHELL, getToolSpec("https://github.com/couchbaselabs/couchbase-shell/releases/download/v1.0.0/cbsh-x86_64-unknown-linux-gnu.tar.gz", TOOL_SHELL, LINUX_64));
map.put(TOOL_IMPORT_EXPORT, getToolSpec("https://packages.couchbase.com/releases/7.6.0/couchbase-server-tools_7.6.0-linux_x86_64.tar.gz", TOOL_IMPORT_EXPORT, LINUX_64));
map.put(ALL_TOOLS, getToolSpec("https://intellij-plugin-dependencies.s3.us-east-2.amazonaws.com/7.2.0-linux_64.zip", ALL_TOOLS, LINUX_64));
map.put(CB_MIGRATE, getToolSpec("https://intellij-plugin-dependencies.s3.us-east-2.amazonaws.com/cbmigrate/cbmigrate_0.1.0_linux_amd64.zip", CB_MIGRATE, LINUX_64));

} else if (LINUX_ARM.equals(os)) {
map.put(TOOL_SHELL, getToolSpec("https://github.com/couchbaselabs/couchbase-shell/releases/download/v0.75.1/cbsh-aarch64-unknown-linux-gnu.tar.gz", TOOL_SHELL, LINUX_ARM));
map.put(TOOL_SHELL, getToolSpec("https://github.com/couchbaselabs/couchbase-shell/releases/download/v1.0.0/cbsh-aarch64-unknown-linux-gnu.tar.gz", TOOL_SHELL, LINUX_ARM));
map.put(TOOL_IMPORT_EXPORT, getToolSpec("https://packages.couchbase.com/releases/7.6.0/couchbase-server-tools_7.6.0-linux_aarch64.tar.gz", TOOL_IMPORT_EXPORT, LINUX_ARM));
map.put(CB_MIGRATE, getToolSpec("https://intellij-plugin-dependencies.s3.us-east-2.amazonaws.com/cbmigrate/cbmigrate_0.1.0_linux_arm64.zip", CB_MIGRATE, LINUX_ARM));

Expand Down
26 changes: 13 additions & 13 deletions src/main/java/com/couchbase/intellij/listener/DependenciesUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class DependenciesUtil {
public static final String TOOLS_VERSION = "7.2";

public static final String CBMIGRATE_VERSION = "5";
public static final String SHELL_VERSION = "1";
public static final String SHELL_VERSION = "4";
public static final String CBIMPORT_EXPORT_VERSION = "7.6";
public static final String EXPLAIN_VERSION = "1";

Expand Down Expand Up @@ -97,21 +97,21 @@ public static void deleteFolder(String folderPath) {

try {
Files.walkFileTree(path, EnumSet.noneOf(FileVisitOption.class), Integer.MAX_VALUE,
new SimpleFileVisitor<Path>() {
new SimpleFileVisitor<Path>() {

@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Files.delete(file);
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Files.delete(file);
return FileVisitResult.CONTINUE;
}

@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
Files.delete(dir);
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
Files.delete(dir);
return FileVisitResult.CONTINUE;
}

});
});

} catch (IOException e) {
Log.error("An error occurred while deleting a folder: ", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,17 @@ public static void start(String toolsPath) throws Exception {
String configPath = toolsPath + File.separator + "config";
createFolder(configPath);

//initCBShell(configPath);
initExplain(toolsPath, configPath);
initJSDependencies(toolsPath, configPath);
}

//NOTE: LEAVE THIS CODE COMMENTED FOR NOW
// public static void initCBShell(String configPath) throws Exception {
// String path = configPath + File.separator + "cbshell";
// Path dest = Paths.get(path);
//
// if (!Files.exists(dest)) {
// Log.debug("Copying CBShell autopass.sh script");
// createFolder(path);
// copyFile("/tools/cbshell.zip", Paths.get(configPath + File.separator + "cbshell.zip"));
// unzipFile(configPath + File.separator + "cbshell.zip", configPath);
// makeFilesExecutable(new File(path));
// } else {
// Log.debug("The script for cbshell is already copied to the config");
// }
//
// CBFolders.getInstance().setCbShellPath(path);
// }

public static void initExplain(String toolsPath, String configPath) throws Exception {

String path = configPath + File.separator + "explain";

if (!EXPLAIN_VERSION.equals(getPropertyValue(toolsPath, EXPLAIN_KEY))) {
Log.info("A new version of Couchbase Explain is available. Removing local version and downloading the new one");
Log.info(
"A new version of Couchbase Explain is available. Removing local version and downloading the new one");
DependenciesUtil.deleteFolder(path);
}

Expand Down Expand Up @@ -84,7 +66,8 @@ public static void initJSDependencies(String toolsPath, String configPath) throw
String path = configPath + File.separator + "js_dependencies";

if (!JS_DEPENDENCIES_VERSION.equals(getPropertyValue(toolsPath, JS_DEPENDENCIES_KEY))) {
Log.info("A new version of Couchbase JS Dependencies is available. Removing local version and downloading the new one");
Log.info(
"A new version of Couchbase JS Dependencies is available. Removing local version and downloading the new one");
DependenciesUtil.deleteFolder(path);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void actionPerformed(@NotNull AnActionEvent e) {
}
};

executeAction.registerCustomShortcutSet(CommonShortcuts.CTRL_ENTER, queryEditor.getComponent());
executeAction.registerCustomShortcutSet(CommonShortcuts.getCtrlEnter(), queryEditor.getComponent());
executeGroup.replaceAction(this, cancelAction);
isExecutingQuery = true;

Expand Down
Loading
Loading