]> Creatis software - CreaPhase.git/blob - octave_packages/java-1.2.8/javaclasspath.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / java-1.2.8 / javaclasspath.m
1 ## Copyright (C) 2007 Michael Goffioul, 2010 Martin Hepperle
2 ##
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.
7 ##
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.
12 ##
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/>.
15
16 ## -*- texinfo -*-
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})
21 ##
22 ## Returns the class path of the Java virtual machine in
23 ## the form of a cell array of strings. 
24 ##
25 ## If called without input parameter:@*
26 ## @itemize
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.
34 ## @end itemize
35 ## 
36 ## If called with a single input parameter @var{WHAT}:@*
37 ## @itemize
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
42 ## @end itemize
43 ## @end deftypefn
44 ## @seealso{javaaddpath,javarmpath}
45
46 function varargout = javaclasspath (which)
47
48   % dynamic classpath
49   dynamic_path = java_invoke ("org.octave.ClassHelper", "getClassPath");
50   dynamic_path_list = strsplit (dynamic_path, pathsep ());
51
52   % static classpath
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));
58   else
59     static_path_list = {};
60   end
61
62   switch nargin
63     case 0
64       switch nargout
65         case 0
66           disp_path_list ( 'STATIC', static_path_list )
67           disp('');
68           disp_path_list ( 'DYNAMIC', dynamic_path_list )
69         case 1
70           varargout{1} = cellstr (dynamic_path_list);
71         case 2
72           varargout{1} = cellstr (dynamic_path_list);
73           varargout{2} = cellstr (static_path_list);
74       endswitch
75         
76     case 1
77       switch nargout
78         case 0
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 )
83           end
84         case 1
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]);
91           end
92       endswitch
93   endswitch
94   
95 end
96 #
97 # Display cell array of paths
98 #
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{:});
103   else
104     printf ('      - empty -\n');
105   endif
106 end