13
13
import java .nio .channels .ReadableByteChannel ;
14
14
import java .nio .file .Files ;
15
15
import java .nio .file .Paths ;
16
- import java .util .Arrays ;
17
16
import java .util .HashMap ;
18
- import java .util .List ;
19
17
import java .util .Map ;
20
18
import java .util .concurrent .CompletableFuture ;
21
19
@@ -28,44 +26,57 @@ public class DependenciesDownloader {
28
26
public static final String TOOL_SHELL = "shell" ;
29
27
public static final String TOOL_IMPORT_EXPORT = "import_export" ;
30
28
29
+ public static final String ALL_TOOLS = "all_tools" ;
30
+
31
31
32
32
private String getToolInstallPath (String toolKey ) {
33
33
34
34
if (TOOL_SHELL .equals (toolKey )) {
35
35
return "cbshell" ;
36
36
} else if (TOOL_IMPORT_EXPORT .equals (toolKey )) {
37
37
return "cbimport_export" ;
38
+ } else if (ALL_TOOLS .equals (toolKey )) {
39
+ return "cbtools" ;
38
40
} else {
39
41
throw new IllegalStateException ("Not Implemented yet" );
40
42
}
41
43
}
42
44
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
+
44
49
boolean unixBased = MACOS_64 .equals (os )
45
50
|| MACOS_ARM .equals (os )
46
51
|| LINUX_64 .equals (os )
47
52
|| LINUX_ARM .equals (os );
48
53
54
+ if (!unixBased ) {
55
+ suffix = ".exe" ;
56
+ }
57
+
58
+ Map <CBTools .Type , String > map = new HashMap <>();
59
+
49
60
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
+
55
63
} 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
+
62
71
} else {
63
72
throw new IllegalStateException ("Not implemented yet" );
64
73
}
74
+
75
+ return map ;
65
76
}
66
77
67
78
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 ));
69
80
}
70
81
71
82
public Map <String , ToolSpec > getDownloadList (String os ) {
@@ -74,22 +85,27 @@ public Map<String, ToolSpec> getDownloadList(String os) {
74
85
if (MACOS_64 .equals (os )) {
75
86
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 ));
76
87
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 ));
77
89
78
90
} else if (MACOS_ARM .equals (os )) {
79
91
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 ));
80
92
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 ));
81
94
82
95
} else if (WINDOWS_64 .equals (os )) {
83
96
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 ));
84
97
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 ));
85
99
86
100
} else if (WINDOWS_ARM .equals (os )) {
87
101
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 ));
88
102
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 ));
89
104
90
105
} else if (LINUX_64 .equals (os )) {
91
106
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 ));
92
107
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 ));
93
109
94
110
} else if (LINUX_ARM .equals (os )) {
95
111
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 {
111
127
112
128
ToolSpec shell = downloads .get (TOOL_SHELL );
113
129
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 )) {
116
132
//avoiding 2 threads to install the same thing at the same time
117
133
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 );
120
136
} 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 );
123
139
}
124
140
125
141
ToolSpec cbImport = downloads .get (TOOL_IMPORT_EXPORT );
126
142
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 )) {
129
145
//avoiding 2 threads to install the same thing at the same time
130
146
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 );
134
150
} 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 );
137
153
}
138
- }
139
154
140
155
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 );
160
165
} else {
161
- throw new IllegalStateException ("Not Implemented Yet" );
166
+ Log .debug ("CB Tools are already installed" );
167
+ setToolActive (ToolStatus .AVAILABLE , toolsDir , cbTools );
168
+ }
169
+
170
+ }
171
+
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 );
162
178
}
163
179
}
164
180
165
- public void downloadAndUnzip (String toolKey , String targetDir , ToolSpec spec ) {
181
+ public void downloadAndUnzip (String targetDir , ToolSpec spec ) {
166
182
CompletableFuture .runAsync (() -> {
167
183
try {
168
184
createFolder (targetDir );
@@ -176,19 +192,19 @@ public void downloadAndUnzip(String toolKey, String targetDir, ToolSpec spec) {
176
192
177
193
unzipFile (localFilePath , targetDir );
178
194
makeFilesExecutable (new File (targetDir ));
179
- setToolActive (toolKey , ToolStatus .AVAILABLE , targetDir , spec );
195
+ setToolActive (ToolStatus .AVAILABLE , targetDir , spec );
180
196
} catch (Exception e ) {
181
- setToolActive (toolKey , ToolStatus .NOT_AVAILABLE , null , null );
197
+ setToolActive (ToolStatus .NOT_AVAILABLE , null , null );
182
198
Log .error (e );
183
199
e .printStackTrace ();
184
200
}
185
201
});
186
202
}
187
203
188
- public boolean isInstalled (String pluginPath , ToolSpec spec ) {
204
+ public boolean isInstalled (String pluginPath , ToolSpec spec , CBTools . Type type ) {
189
205
return Files .exists (Paths .get (pluginPath + File .separator
190
206
+ spec .getInstallationPath ()
191
207
+ File .separator
192
- + spec .getToolsList ().get (0 )));
208
+ + spec .getToolsMap ().get (type )));
193
209
}
194
210
}
0 commit comments