-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetupMongoDriver.m
executable file
·72 lines (56 loc) · 1.81 KB
/
setupMongoDriver.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
function setupMongoDriver()
%SETUPMONGODRIVER adds Mongo Java Driver downloaded by support software
%installer on java class path (JAVACLASSPATH.TXT present in MATLAB's
%preferences directory).
%
% Copyright 2017 The Mathworks, Inc.
% Updated to v3.12.0 (2019/12/24 by horsche)
%
installPath = fullfile(matlab.internal.get3pInstallLocation('mongodb.instrset'),'MongoDriver','mongo-java-driver-3.12.0.jar');
% Check if Mongo Java Driver is downloaded correctly by the Support
% Software Installer
if exist(installPath,'file') ~= 2
error(message('mongodb:mongodb:locateDriverFailed'));
end
pathToJavaClassPath = fullfile(prefdir,'javaclasspath.txt');
% If path to 3p JAR file already exists in JAVACLASSPATH.TXT, no action is
% taken and return.
if installPathExists(pathToJavaClassPath,installPath)
return;
end
% Create or append installation path to JAVACLASSPATH.TXT present in user's
% MATLAB preferences.
try
fid = fopen(pathToJavaClassPath,'a+');
fprintf(fid,"\n%s\n",installPath);
fclose(fid);
catch
error(message('mongodb:mongodb:configurationError'));
end
msgbox(message('mongodb:mongodb:restartMATLAB').getString,...
message('mongodb:mongodb:restartRequired').getString, 'modal');
end
% helper function to check is installation path exists on JAVACLASSPATH.TXT
function exists = installPathExists(pathToJavaClassPath,installPath)
fileexists = exist(pathToJavaClassPath,'file');
exists = false;
if fileexists ~= 2
exists = false;
return;
end
fid = fopen(pathToJavaClassPath,'r');
while true
str = string(fgetl(fid));
if str.strlength == 0
continue;
end
if str == "-1"
break;
end
if str == installPath
exists = true;
break;
end
end
fclose(fid);
end