3 JAVA_CLASS_PATH_TXT=
'javaclasspath.txt' 5 properties (Access=
protected)
9 %returns a list of jar files to be put on a static java path
10 fileNameList=getJarFileNameList(self)
12 methods (Abstract,Access=protected)
13 pathClassCMat=getRelativePathListToJars(~)
17 self.classPathFileName=classPathFileName;
19 function setUp(self,isUserDirStartUpDir)
23 isUserDirStartUpDir=true;
25 pathClassCMat=self.getRelativePathListToJars();
27 if ~isempty(pathClassCMat)
28 nPaths=size(pathClassCMat,1);
30 defClassName=pathClassCMat{iPath,2};
31 classLocDir=fileparts(which(defClassName));
32 if isempty(classLocDir)
34 'cannot find class %s on Matlab path',...
37 indLoc=regexp(classLocDir,
'((\\|\/)(\@|\+))',
'once');
38 classLocDir=classLocDir(1:indLoc);
39 indSepVec=find(classLocDir==
filesep);
40 indSep=indSepVec(end-pathClassCMat{iPath,3});
41 classLocDir=classLocDir(1:indSep-1);
42 relPath=pathClassCMat{iPath,1};
44 relPath=strrep(relPath,
'/',
filesep);
45 relPath=strrep(relPath,
'\',
filesep);
47 pathList=[classLocDir,
filesep,relPath];
52 jarFileNameList=
self.getJarFileNameList();
53 toAddPathList=cellfun(@which,jarFileNameList,...
54 'UniformOutput',
false);
56 isEmptyVec=cellfun(
'isempty',toAddPathList);
58 if isUserDirStartUpDir
63 fThrow(
'noJarFilesOnMatlabPath',...
64 'Files %s cannot be found on Matlab path',...
65 list2str(jarFileNameList(isEmptyVec)));
67 toAddPathList=toAddPathList(~isEmptyVec);
69 if verLessThan(
'matlab',
'8.2')
71 'Matlab version 8.2/2013b or higher is expected');
72 javaaddpath(toAddPathList);
74 if ~self.isUserDirClassPathSet()
75 missingPathList=toAddPathList;
76 isnThereVec=true(size(toAddPathList));
79 existingUserPathList=
self.readUserDirClassPath();
80 isnThereVec=~
ismember(toAddPathList,existingUserPathList);
81 missingPathList=toAddPathList(isnThereVec);
82 delPathList=setdiff(existingUserPathList,toAddPathList);
85 fullStaticPathList=javaclasspath(
'-static');
86 isnFullThereVec=~
ismember(toAddPathList,fullStaticPathList);
87 if ~any(isnFullThereVec)
89 sprintf([
'files %s are already on ',...
90 'static java classpath'],...
91 list2str(toAddPathList)));
94 if isUserDirStartUpDir&&...
95 ~all(isnThereVec==isnFullThereVec)
96 isInFullStaticVec=~isnFullThereVec&isnThereVec;
97 isInUserStaticVec=isnFullThereVec&~isnThereVec;
98 globalClassPathFile=
self.getPrefDirClassPathFileName();
100 [
'files %s are in current static path but not\n',...
101 'in %s while files %s are in %s but not in\n',...
102 'current static path.\n',...
103 'It can be that %s file contains the same ',...
104 'entries as %s.\n',...
105 'If that is the case please remove those ',...
106 'entries and restart Matlab!'],...
107 list2str(toAddPathList(isInFullStaticVec)),...
108 self.classPathFileName,...
109 list2str(toAddPathList(isInUserStaticVec)),...
110 self.classPathFileName,globalClassPathFile,...
111 self.classPathFileName);
114 self.setUserDirClassPath(toAddPathList);
116 if any(isnFullThereVec)
118 [
'files %s have been added ',...
119 'to Java static class path,\n ',...
120 'files %s have been deleted from Java ',...
121 'static class path, \n',...
122 '<<-------------------->> \n',...
123 'adding these files to Dynamic Java Path \n',...
124 'as a temporary measure \n',...
125 '<<-------------------->> \n',...
127 '<<<<------ PLEASE RESTART MATLAB ------->>>>'],...
128 list2str(missingPathList),list2str(delPathList));
130 javaaddpath(toAddPathList(isnFullThereVec));
136 function pathList=getUserPathList(~)
137 staticPathList=javaclasspath('-static');
138 isUserPath=cellfun('isempty',regexp(javaclasspath('-static'),...
139 ['^',regexptranslate('escape',matlabroot)]));
140 pathList=staticPathList(isUserPath);
143 methods (Access=protected)
144 function pathList=readClassPathFile(~,fileName)
145 [fid,errMsg]=fopen(fileName,'r');
151 resCell=textscan(fid,'%s','Delimiter','\n');
159 function pathList=parseClassPathStr(~,classPathStr)
160 resCell=textscan(classPathStr,
'%s',
'Delimiter',
'\n');
163 function globalClassPathFile=getPrefDirClassPathFileName(
self)
164 globalClassPathFile=[prefdir,
filesep,self.JAVA_CLASS_PATH_TXT];
167 methods (Access=private)
168 function isPos=isUserDirClassPathSet(self)
170 self.classPathFileName,false);
173 function pathList=readUserDirClassPath(self)
174 pathList=self.readClassPathFile(self.classPathFileName);
177 function setUserDirClassPath(self,pathList)
179 [fid,errMsg]=fopen(self.classPathFileName,'w');
184 if ~isempty(pathList)
185 msgStr=sprintf('adding %s to %s',...
186 list2str(pathList),self.classPathFileName);
189 self.dispMsg([msgStr,' :done'])
191 self.dispMsg(sprintf('Nothing to add to %s',...
192 self.classPathFileName));
200 function dispMsg(self,msgStr)
203 prefixStr=class(self);
204 remSep=
repmat(SEP_SYMB,1,max(SEP_LENGTH-numel(prefixStr),0));
206 nMid=fix(numel(remSep)*0.5);
207 fprintf([remSep(1:nMid),prefixStr,remSep((nMid+1):end),'\n']);
209 fprintf(['\n',
repmat(SEP_SYMB,1,SEP_LENGTH),'\n']);
215 function outStr=list2str(inpList)
216 outStr=sprintf('\n[%s]\n',
mxberry.core.
string.
catwithsep(inpList,sprintf(',\n')));
function throwerror(in msgTag, in varargin)
THROWERROR works similarly to built-in ERROR function in case when there is no output arguments but s...
function repmat(in inpArray, in varargin)
function throwwarn(in msgTag, in varargin)
THROWWARN works similarly to built-in WARNING function in case when there is no output arguments but ...
function isfile(in fileName, in isJavaBased)
ISFILE returns true if a specified name corresponds to an existing file.
function ismember(in leftVec, in rightVec, in varargin)
ISMEMBER - ismember implementation for arrays of any type.
function catwithsep(in inpStrList, in sepStr)
CATWITHSEP concatenates input cell array of strings inserting a specified separator between the strin...