Skip to content

Commit e01bf00

Browse files
committed
Merge branch 'main' into DA-311-deploy-as-a-function
2 parents bc23cfb + 45f94ac commit e01bf00

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1090
-890
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,6 @@ bin/
3939
.vscode/
4040

4141
### Mac OS ###
42-
.DS_Store
42+
.DS_Store
43+
### Couchbase Plugin ###
44+
.cbcache/

build.gradle.kts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
plugins {
22
id("java")
3-
id("org.jetbrains.intellij") version "1.8.0"
3+
id("org.jetbrains.intellij") version "1.13.3"
44
}
55

66
group = "com.couchbase"
7-
version = "1.0-SNAPSHOT"
7+
version = "1.0.1"
88

99

1010
sourceSets["main"].java.srcDirs("src/main/gen")
@@ -19,6 +19,7 @@ dependencies {
1919
implementation("org.eclipse.jgit:org.eclipse.jgit:6.5.0.202303070854-r")
2020
}
2121

22+
2223
// Configure Gradle IntelliJ Plugin
2324
// Read more: https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html
2425
intellij {
@@ -37,7 +38,7 @@ tasks {
3738

3839
patchPluginXml {
3940
sinceBuild.set("213")
40-
untilBuild.set("223.*")
41+
untilBuild.set("243.*")
4142
}
4243

4344
signPlugin {

settings.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
rootProject.name = "couchbase-intellij-plugin"
1+
rootProject.name = "couchbase-intellij-plugin"

src/main/java/com/couchbase/intellij/listener/DependenciesDownloader.java

+70-88
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
import java.nio.channels.ReadableByteChannel;
1414
import java.nio.file.Files;
1515
import java.nio.file.Paths;
16-
import java.util.Arrays;
1716
import java.util.HashMap;
18-
import java.util.List;
1917
import java.util.Map;
2018
import java.util.concurrent.CompletableFuture;
2119

@@ -28,44 +26,57 @@ public class DependenciesDownloader {
2826
public static final String TOOL_SHELL = "shell";
2927
public static final String TOOL_IMPORT_EXPORT = "import_export";
3028

29+
public static final String ALL_TOOLS = "all_tools";
30+
3131

3232
private String getToolInstallPath(String toolKey) {
3333

3434
if (TOOL_SHELL.equals(toolKey)) {
3535
return "cbshell";
3636
} else if (TOOL_IMPORT_EXPORT.equals(toolKey)) {
3737
return "cbimport_export";
38+
} else if (ALL_TOOLS.equals(toolKey)) {
39+
return "cbtools";
3840
} else {
3941
throw new IllegalStateException("Not Implemented yet");
4042
}
4143
}
4244

43-
private List<String> getToolsList(String toolKey, String os) {
45+
private Map<CBTools.Type, String> getToolsMap(String toolKey, String os) {
46+
String suffix = "";
47+
String path = "bin" + File.separator;
48+
4449
boolean unixBased = MACOS_64.equals(os)
4550
|| MACOS_ARM.equals(os)
4651
|| LINUX_64.equals(os)
4752
|| LINUX_ARM.equals(os);
4853

54+
if (!unixBased) {
55+
suffix = ".exe";
56+
}
57+
58+
Map<CBTools.Type, String> map = new HashMap<>();
59+
4960
if (TOOL_SHELL.equals(toolKey)) {
50-
if (unixBased) {
51-
return List.of("cbsh");
52-
} else {
53-
return List.of("cbsh.exe");
54-
}
61+
map.put(CBTools.Type.SHELL, "cbsh" + suffix);
62+
5563
} else if (TOOL_IMPORT_EXPORT.equals(toolKey)) {
56-
String path = "bin" + File.separator;
57-
if (unixBased) {
58-
return Arrays.asList(path + "cbimport", path + "cbexport");
59-
} else {
60-
return Arrays.asList(path + "cbimport.exe", path + "cbexport.exe");
61-
}
64+
map.put(CBTools.Type.CB_IMPORT, path + "cbimport" + suffix);
65+
map.put(CBTools.Type.CB_EXPORT, path + "cbexport" + suffix);
66+
67+
} else if (ALL_TOOLS.equals(toolKey)) {
68+
map.put(CBTools.Type.CBC_PILLOW_FIGHT, path + "cbc-pillowfight" + suffix);
69+
map.put(CBTools.Type.MCTIMINGS, path + "mctimings" + suffix);
70+
6271
} else {
6372
throw new IllegalStateException("Not implemented yet");
6473
}
74+
75+
return map;
6576
}
6677

6778
private ToolSpec getToolSpec(String url, String toolKey, String os) {
68-
return new ToolSpec(url, getToolInstallPath(toolKey), getToolsList(toolKey, os));
79+
return new ToolSpec(url, getToolInstallPath(toolKey), getToolsMap(toolKey, os));
6980
}
7081

7182
public Map<String, ToolSpec> getDownloadList(String os) {
@@ -74,22 +85,27 @@ public Map<String, ToolSpec> getDownloadList(String os) {
7485
if (MACOS_64.equals(os)) {
7586
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));
7687
map.put(TOOL_IMPORT_EXPORT, getToolSpec("https://packages.couchbase.com/releases/7.2.0/couchbase-server-tools_7.2.0-macos_x86_64.zip", TOOL_IMPORT_EXPORT, MACOS_64));
88+
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));
7789

7890
} else if (MACOS_ARM.equals(os)) {
7991
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));
8092
map.put(TOOL_IMPORT_EXPORT, getToolSpec("https://packages.couchbase.com/releases/7.2.0/couchbase-server-tools_7.2.0-macos_arm64.zip", TOOL_IMPORT_EXPORT, MACOS_ARM));
93+
map.put(ALL_TOOLS, getToolSpec("https://intellij-plugin-dependencies.s3.us-east-2.amazonaws.com/7.2.0-macos_arm.zip", ALL_TOOLS, MACOS_64));
8194

8295
} else if (WINDOWS_64.equals(os)) {
8396
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));
8497
map.put(TOOL_IMPORT_EXPORT, getToolSpec("https://packages.couchbase.com/releases/7.2.0/couchbase-server-tools_7.2.0-windows_amd64.zip", TOOL_IMPORT_EXPORT, WINDOWS_64));
98+
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));
8599

86100
} else if (WINDOWS_ARM.equals(os)) {
87101
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));
88102
map.put(TOOL_IMPORT_EXPORT, getToolSpec("https://packages.couchbase.com/releases/7.2.0/couchbase-server-tools_7.2.0-windows_amd64.zip", TOOL_IMPORT_EXPORT, WINDOWS_ARM));
103+
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));
89104

90105
} else if (LINUX_64.equals(os)) {
91106
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));
92107
map.put(TOOL_IMPORT_EXPORT, getToolSpec("https://packages.couchbase.com/releases/7.2.0/couchbase-server-tools_7.2.0-linux_x86_64.tar.gz", TOOL_IMPORT_EXPORT, LINUX_64));
108+
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));
93109

94110
} else if (LINUX_ARM.equals(os)) {
95111
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));
@@ -111,58 +127,58 @@ public void downloadDependencies() throws Exception {
111127

112128
ToolSpec shell = downloads.get(TOOL_SHELL);
113129
String shellPath = toolsPath + File.separator + shell.getInstallationPath();
114-
if (CBTools.getShell().getStatus() == ToolStatus.NOT_AVAILABLE
115-
&& !isInstalled(toolsPath, downloads.get(TOOL_SHELL))) {
130+
if (CBTools.getTool(CBTools.Type.SHELL).getStatus() == ToolStatus.NOT_AVAILABLE
131+
&& !isInstalled(toolsPath, downloads.get(TOOL_SHELL), CBTools.Type.SHELL)) {
116132
//avoiding 2 threads to install the same thing at the same time
117133
Log.debug("Downloading CB Shell");
118-
CBTools.getShell().setStatus(ToolStatus.DOWNLOADING);
119-
downloadAndUnzip(TOOL_SHELL, shellPath, shell);
134+
CBTools.getTool(CBTools.Type.SHELL).setStatus(ToolStatus.DOWNLOADING);
135+
downloadAndUnzip(shellPath, shell);
120136
} else {
121-
Log.debug("CBShell is already downloaded");
122-
setToolActive(TOOL_SHELL, ToolStatus.AVAILABLE, shellPath, shell);
137+
Log.debug("CBShell is already installed");
138+
setToolActive(ToolStatus.AVAILABLE, shellPath, shell);
123139
}
124140

125141
ToolSpec cbImport = downloads.get(TOOL_IMPORT_EXPORT);
126142
String cbImportDir = toolsPath + File.separator + cbImport.getInstallationPath();
127-
if (CBTools.getCbImport().getStatus() == ToolStatus.NOT_AVAILABLE
128-
&& !isInstalled(toolsPath, downloads.get(TOOL_IMPORT_EXPORT))) {
143+
if (CBTools.getTool(CBTools.Type.CB_IMPORT).getStatus() == ToolStatus.NOT_AVAILABLE
144+
&& !isInstalled(toolsPath, downloads.get(TOOL_IMPORT_EXPORT), CBTools.Type.CB_EXPORT)) {
129145
//avoiding 2 threads to install the same thing at the same time
130146
Log.debug("Downloading CB Import/Export");
131-
CBTools.getCbExport().setStatus(ToolStatus.DOWNLOADING);
132-
CBTools.getCbImport().setStatus(ToolStatus.DOWNLOADING);
133-
downloadAndUnzip(TOOL_IMPORT_EXPORT, cbImportDir, cbImport);
147+
CBTools.getTool(CBTools.Type.CB_EXPORT).setStatus(ToolStatus.DOWNLOADING);
148+
CBTools.getTool(CBTools.Type.CB_IMPORT).setStatus(ToolStatus.DOWNLOADING);
149+
downloadAndUnzip(cbImportDir, cbImport);
134150
} else {
135-
Log.debug("CB Import/Export is already downloaded");
136-
setToolActive(TOOL_IMPORT_EXPORT, ToolStatus.AVAILABLE, cbImportDir, cbImport);
151+
Log.debug("CB Import/Export is already installed");
152+
setToolActive(ToolStatus.AVAILABLE, cbImportDir, cbImport);
137153
}
138-
}
139154

140155

141-
private void setToolActive(String toolKey, ToolStatus status, String path, ToolSpec spec) {
142-
if (TOOL_SHELL.equals(toolKey)) {
143-
CBTools.getShell().setStatus(status);
144-
if (status == ToolStatus.AVAILABLE) {
145-
CBTools.getShell().setPath(path + File.separator + spec.getToolsList().get(0));
146-
}
147-
} else if (TOOL_IMPORT_EXPORT.equals(toolKey)) {
148-
CBTools.getCbImport().setStatus(status);
149-
CBTools.getCbExport().setStatus(status);
150-
151-
if (status == ToolStatus.AVAILABLE) {
152-
for (String tool : spec.getToolsList()) {
153-
if (tool.contains("cbimport")) {
154-
CBTools.getCbImport().setPath(path + File.separator + tool);
155-
} else if (tool.contains("cbexport")) {
156-
CBTools.getCbExport().setPath(path + File.separator + tool);
157-
}
158-
}
159-
}
156+
ToolSpec cbTools = downloads.get(ALL_TOOLS);
157+
String toolsDir = toolsPath + File.separator + cbTools.getInstallationPath();
158+
if (CBTools.getTool(CBTools.Type.CBC_PILLOW_FIGHT).getStatus() == ToolStatus.NOT_AVAILABLE
159+
&& !isInstalled(toolsPath, downloads.get(ALL_TOOLS), CBTools.Type.CBC_PILLOW_FIGHT)) {
160+
161+
Log.debug("Downloading CB tools");
162+
CBTools.getTool(CBTools.Type.CBC_PILLOW_FIGHT).setStatus(ToolStatus.DOWNLOADING);
163+
CBTools.getTool(CBTools.Type.MCTIMINGS).setStatus(ToolStatus.DOWNLOADING);
164+
downloadAndUnzip(toolsDir, cbTools);
160165
} else {
161-
throw new IllegalStateException("Not Implemented Yet");
166+
Log.debug("CB Tools are already installed");
167+
setToolActive(ToolStatus.AVAILABLE, toolsDir, cbTools);
162168
}
169+
163170
}
164171

165-
public void downloadAndUnzip(String toolKey, String targetDir, ToolSpec spec) {
172+
173+
private void setToolActive(ToolStatus status, String path, ToolSpec spec) {
174+
175+
for (Map.Entry<CBTools.Type, String> entry : spec.getToolsMap().entrySet()) {
176+
CBTools.getTool(entry.getKey()).setPath(path + File.separator + entry.getValue());
177+
CBTools.getTool(entry.getKey()).setStatus(status);
178+
}
179+
}
180+
181+
public void downloadAndUnzip(String targetDir, ToolSpec spec) {
166182
CompletableFuture.runAsync(() -> {
167183
try {
168184
createFolder(targetDir);
@@ -176,53 +192,19 @@ public void downloadAndUnzip(String toolKey, String targetDir, ToolSpec spec) {
176192

177193
unzipFile(localFilePath, targetDir);
178194
makeFilesExecutable(new File(targetDir));
179-
setToolActive(toolKey, ToolStatus.AVAILABLE, targetDir, spec);
195+
setToolActive(ToolStatus.AVAILABLE, targetDir, spec);
180196
} catch (Exception e) {
181-
setToolActive(toolKey, ToolStatus.NOT_AVAILABLE, null, null);
197+
setToolActive(ToolStatus.NOT_AVAILABLE, null, null);
182198
Log.error(e);
183199
e.printStackTrace();
184200
}
185201
});
186202
}
187203

188-
189-
//TODO: Keep this code until we have tested everything on windows
190-
// private void unzipFile(String zipFilePath, String destDir) throws IOException {
191-
// File dir = new File(destDir);
192-
// if (!dir.exists()) dir.mkdirs();
193-
// File zipFile = new File(zipFilePath);
194-
// try (ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile))) {
195-
// ZipEntry entry = zis.getNextEntry();
196-
// while (entry != null) {
197-
// String filePath = destDir + File.separator + entry.getName();
198-
// if (!entry.isDirectory()) {
199-
// extractFile(zis, filePath);
200-
// } else {
201-
// File dir1 = new File(filePath);
202-
// dir1.mkdir();
203-
// }
204-
// zis.closeEntry();
205-
// entry = zis.getNextEntry();
206-
// }
207-
// }
208-
// Files.delete(zipFile.toPath());
209-
// }
210-
//
211-
// private void extractFile(ZipInputStream zis, String filePath) throws IOException {
212-
// try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath))) {
213-
// byte[] bytesIn = new byte[4096];
214-
// int read;
215-
// while ((read = zis.read(bytesIn)) != -1) {
216-
// bos.write(bytesIn, 0, read);
217-
// }
218-
// }
219-
// }
220-
221-
222-
public boolean isInstalled(String pluginPath, ToolSpec spec) {
204+
public boolean isInstalled(String pluginPath, ToolSpec spec, CBTools.Type type) {
223205
return Files.exists(Paths.get(pluginPath + File.separator
224206
+ spec.getInstallationPath()
225207
+ File.separator
226-
+ spec.getToolsList().get(0)));
208+
+ spec.getToolsMap().get(type)));
227209
}
228210
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.couchbase.intellij.listener;
2+
3+
import com.couchbase.intellij.workbench.Log;
4+
import com.intellij.openapi.application.ApplicationManager;
5+
import com.intellij.openapi.project.Project;
6+
import com.intellij.openapi.project.ProjectUtil;
7+
import com.intellij.openapi.vfs.VfsUtil;
8+
import com.intellij.openapi.vfs.VirtualFile;
9+
import utils.OSUtil;
10+
11+
import java.io.IOException;
12+
import java.io.OutputStream;
13+
14+
public class GitIgnore {
15+
16+
private static final String GIT_IGNORE_FILE = ".gitignore";
17+
18+
public static void updateGitIgnore(Project project) {
19+
20+
ApplicationManager.getApplication().invokeLater(() -> {
21+
ApplicationManager.getApplication().runWriteAction(() -> {
22+
23+
24+
String GIT_IGNORE_CONTENT = OSUtil.isWindows() ? "cbcache/" : ".cbcache/";
25+
26+
VirtualFile baseDir = ProjectUtil.guessProjectDir(project);
27+
VirtualFile gitignoreFile = baseDir.findChild(GIT_IGNORE_FILE);
28+
29+
if (gitignoreFile == null) { // If .gitignore file doesn't exist
30+
try {
31+
gitignoreFile = baseDir.createChildData(null, GIT_IGNORE_FILE);
32+
} catch (IOException e) {
33+
e.printStackTrace();
34+
return;
35+
}
36+
}
37+
38+
try {
39+
String gitignoreContent = VfsUtil.loadText(gitignoreFile);
40+
if (!gitignoreContent.contains(GIT_IGNORE_CONTENT)) {
41+
OutputStream os = gitignoreFile.getOutputStream(null);
42+
os.write((gitignoreContent + "\n### Couchbase Plugin ###\n" + GIT_IGNORE_CONTENT + "\n").getBytes());
43+
os.close();
44+
}
45+
} catch (IOException e) {
46+
Log.error(e);
47+
e.printStackTrace();
48+
}
49+
});
50+
});
51+
}
52+
}

src/main/java/com/couchbase/intellij/tools/CBExport.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void run(@NotNull ProgressIndicator indicator) {
5050
// The progress indicator shows a moving bar by default. If you want to show progress, use:
5151
indicator.setIndeterminate(true);
5252
try {
53-
ProcessBuilder processBuilder = new ProcessBuilder(CBTools.getCbExport().getPath(),
53+
ProcessBuilder processBuilder = new ProcessBuilder(CBTools.getTool(CBTools.Type.CB_EXPORT).getPath(),
5454
"json", "--no-ssl-verify", "-c", ActiveCluster.getInstance().getClusterURL(),
5555
"-u", ActiveCluster.getInstance().getUsername(), "-p", ActiveCluster.getInstance().getPassword(),
5656
"-b", bucket,
@@ -111,7 +111,7 @@ public void run(@NotNull ProgressIndicator indicator) {
111111
// The progress indicator shows a moving bar by default. If you want to show progress, use:
112112
indicator.setIndeterminate(true);
113113
try {
114-
ProcessBuilder processBuilder = new ProcessBuilder(CBTools.getCbExport().getPath(),
114+
ProcessBuilder processBuilder = new ProcessBuilder(CBTools.getTool(CBTools.Type.CB_EXPORT).getPath(),
115115
"json", "--no-ssl-verify", "-c", ActiveCluster.getInstance().getClusterURL(),
116116
"-u", ActiveCluster.getInstance().getUsername(), "-p", ActiveCluster.getInstance().getPassword(),
117117
"-b", bucket,

0 commit comments

Comments
 (0)