1 ## Copyright (C) 2007 Michael Goffioul, 2010 Martin Hepperle
3 ## This program is free software; you can redistribute it and/or modify
4 ## it under the terms of the GNU General Public License as published by
5 ## the Free Software Foundation; either version 2 of the License, or
6 ## (at your option) any later version.
8 ## This program is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 ## GNU General Public License for more details.
13 ## You should have received a copy of the GNU General Public License
14 ## along with this program; If not, see <http://www.gnu.org/licenses/>.
17 ## @deftypefn {Function file} {} javaclasspath
18 ## @deftypefnx {Function file} {@var{STATIC} =} javaclasspath
19 ## @deftypefnx {Function file} {[@var{STATIC}, @var{DYNAMIC}] =} javaclasspath
20 ## @deftypefnx {Function file} {@var{PATH} =} javaclasspath (@var{WHAT})
22 ## Returns the class path of the Java virtual machine in
23 ## the form of a cell array of strings.
25 ## If called without input parameter:@*
27 ## @item If no output variable is given, the result is simply printed
28 ## on the standard output.
29 ## @item If one output variable @var{STATIC} is given, the result is
30 ## the static classpath.
31 ## @item If two output variables @var{STATIC} and @var{DYNAMIC} are
32 ## given, the first variable will contain the static classpath,
33 ## the second will be filled with the dynamic claspath.
36 ## If called with a single input parameter @var{WHAT}:@*
38 ## @item If @var{WHAT} is '-static' the static classpath is returned.
39 ## @item If @var{WHAT} is '-dynamic' the dynamic classpath is returned.
40 ## @item If @var{WHAT} is '-all' the static and the dynamic classpath
41 ## are returned in a single cell array
44 ## @seealso{javaaddpath,javarmpath}
46 function varargout = javaclasspath (which)
49 dynamic_path = java_invoke ("org.octave.ClassHelper", "getClassPath");
50 dynamic_path_list = strsplit (dynamic_path, pathsep ());
53 static_path = java_invoke ('java.lang.System', 'getProperty', 'java.class.path');
54 static_path_list = strsplit (static_path, pathsep ());
55 if (length (static_path_list) > 1)
56 % remove first element (which is .../octave.jar)
57 static_path_list = static_path_list(2:length (static_path_list));
59 static_path_list = {};
66 disp_path_list ( 'STATIC', static_path_list )
68 disp_path_list ( 'DYNAMIC', dynamic_path_list )
70 varargout{1} = cellstr (dynamic_path_list);
72 varargout{1} = cellstr (dynamic_path_list);
73 varargout{2} = cellstr (static_path_list);
79 if (strcmp (which, '-static') == 1)
80 disp_path_list ( 'STATIC', static_path_list )
81 elseif (strcmp (which, '-dynamic') == 1)
82 disp_path_list ( 'DYNAMIC', dynamic_path_list )
85 if (strcmp (which, '-static') == 1)
86 varargout{1} = cellstr (static_path_list);
87 elseif (strcmp (which, '-dynamic') == 1)
88 varargout{1} = cellstr (dynamic_path_list);
89 elseif (strcmp (which, '-all') == 1)
90 varargout{1} = cellstr ([static_path_list, dynamic_path_list]);
97 # Display cell array of paths
99 function disp_path_list ( which, path_list )
100 printf (' %s JAVA PATH\n\n', which);
101 if (length (path_list) > 0)
102 printf (' %s\n', path_list{:});
104 printf (' - empty -\n');