Mercurial > octave
annotate scripts/java/javarmpath.m @ 28168:b3bd3385d07a stable
* javaaddpath.m, javarmpath.m: Skip BISTs if Java is unavailable on run-time.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Sun, 22 Mar 2020 17:57:50 +0100 |
parents | 367ab44d18c8 |
children | dc80e087df4b |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 ######################################################################## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 ## |
27919
1891570abac8
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27918
diff
changeset
|
3 ## Copyright (C) 2007-2020 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27877
diff
changeset
|
4 ## |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 ## See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 ## distribution or <https://octave.org/copyright/>. |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
7 ## |
15746
da26f72408a7
update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
8 ## This file is part of Octave. |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
9 ## |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
15746
da26f72408a7
update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
11 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
12 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
13 ## (at your option) any later version. |
15746
da26f72408a7
update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
14 ## |
da26f72408a7
update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
15 ## Octave is distributed in the hope that it will be useful, but |
da26f72408a7
update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
18 ## GNU General Public License for more details. |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
19 ## |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
20 ## You should have received a copy of the GNU General Public License |
15746
da26f72408a7
update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents:
15625
diff
changeset
|
21 ## along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
22 ## <https://www.gnu.org/licenses/>. |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 ## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 ######################################################################## |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
25 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
26 ## -*- texinfo -*- |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
27 ## @deftypefn {} {} javarmpath (@var{clspath}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
28 ## @deftypefnx {} {} javarmpath (@var{clspath1}, @dots{}) |
27877
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
29 ## @deftypefnx {} {} javarmpath (@{@var{clspath1}, @dots{}@}) |
15772
0f1a143e5002
Overhaul scripts/java directory to conform to Octave core.
Rik <rik@octave.org>
parents:
15748
diff
changeset
|
30 ## Remove @var{clspath} from the dynamic class path of the Java virtual |
20160
03b9d17a2d95
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
31 ## machine. |
03b9d17a2d95
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
32 ## |
03b9d17a2d95
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
33 ## @var{clspath} may either be a directory where @file{.class} files are found, |
03b9d17a2d95
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
34 ## or a @file{.jar} file containing Java classes. Multiple paths may be |
27877
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
35 ## removed at once by specifying additional arguments, or by using a cell array |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
36 ## of strings. |
15748
54e8c2527a9e
style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents:
15746
diff
changeset
|
37 ## @seealso{javaaddpath, javaclasspath} |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
38 ## @end deftypefn |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
39 |
15772
0f1a143e5002
Overhaul scripts/java directory to conform to Octave core.
Rik <rik@octave.org>
parents:
15748
diff
changeset
|
40 function javarmpath (varargin) |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
41 |
15772
0f1a143e5002
Overhaul scripts/java directory to conform to Octave core.
Rik <rik@octave.org>
parents:
15748
diff
changeset
|
42 if (nargin < 1) |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
43 print_usage (); |
15772
0f1a143e5002
Overhaul scripts/java directory to conform to Octave core.
Rik <rik@octave.org>
parents:
15748
diff
changeset
|
44 endif |
0f1a143e5002
Overhaul scripts/java directory to conform to Octave core.
Rik <rik@octave.org>
parents:
15748
diff
changeset
|
45 |
27877
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
46 if (! all (cellfun (@(c) ischar (c) || iscellstr (c), varargin))) |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
47 error ("javarmpath: arguments must be strings or cell array of strings"); |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
48 endif |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
49 |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
50 for arg = varargin |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
51 if (iscellstr (arg{1})) |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
52 arg = arg{1}(:).'; # Guarantee cellstr array is a row vector |
15772
0f1a143e5002
Overhaul scripts/java directory to conform to Octave core.
Rik <rik@octave.org>
parents:
15748
diff
changeset
|
53 endif |
0f1a143e5002
Overhaul scripts/java directory to conform to Octave core.
Rik <rik@octave.org>
parents:
15748
diff
changeset
|
54 |
27877
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
55 for clspath = arg |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
56 clspath = clspath{1}; |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
57 |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
58 old_path = canonicalize_file_name (tilde_expand (clspath)); |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
59 if (isfolder (old_path)) |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
60 if (old_path(end) != filesep ()) |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
61 old_path = [old_path, filesep()]; |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
62 endif |
15748
54e8c2527a9e
style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents:
15746
diff
changeset
|
63 endif |
54e8c2527a9e
style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents:
15746
diff
changeset
|
64 |
27877
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
65 success = javaMethod ("removeClassPath", "org.octave.ClassHelper", |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
66 old_path); |
15748
54e8c2527a9e
style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents:
15746
diff
changeset
|
67 |
27877
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
68 if (! success) |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
69 warning ("javarmpath: %s: not found in Java classpath", old_path); |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
70 endif |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
71 endfor |
15772
0f1a143e5002
Overhaul scripts/java directory to conform to Octave core.
Rik <rik@octave.org>
parents:
15748
diff
changeset
|
72 endfor |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
73 |
15748
54e8c2527a9e
style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents:
15746
diff
changeset
|
74 endfunction |
27877
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
75 |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
76 |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
77 ## FIXME: These tests may fail if either TEMPDIR or HOME have already |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
78 ## been added to the Java class path. |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
79 |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
80 ## Basic test with single string |
28168
b3bd3385d07a
* javaaddpath.m, javarmpath.m: Skip BISTs if Java is unavailable on run-time.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28033
diff
changeset
|
81 %!testif HAVE_JAVA; usejava ("jvm") |
27877
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
82 %! pth = tempdir (); |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
83 %! unwind_protect |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
84 %! javaaddpath (pth); |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
85 %! clspth1 = javaclasspath ("-dynamic"); |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
86 %! javarmpath (pth); |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
87 %! clspth2 = javaclasspath ("-dynamic"); |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
88 %! assert (numel (clspth2), numel (clspth1) - 1); |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
89 %! assert (clspth2(1:end), clspth1(2:end)); |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
90 %! unwind_protect_cleanup |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
91 %! javarmpath (pth); |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
92 %! end_unwind_protect |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
93 |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
94 ## Remove two strings |
28168
b3bd3385d07a
* javaaddpath.m, javarmpath.m: Skip BISTs if Java is unavailable on run-time.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28033
diff
changeset
|
95 %!testif HAVE_JAVA; usejava ("jvm") |
27877
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
96 %! pth1 = tempdir (); |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
97 %! pth2 = tilde_expand ("~"); |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
98 %! unwind_protect |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
99 %! javaaddpath (pth1, pth2); |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
100 %! clspth1 = javaclasspath ("-dynamic"); |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
101 %! javarmpath (pth1, pth2); |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
102 %! clspth2 = javaclasspath ("-dynamic"); |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
103 %! assert (numel (clspth2), numel (clspth1) - 2); |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
104 %! assert (clspth2(1:end), clspth1(3:end)); |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
105 %! unwind_protect_cleanup |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
106 %! javarmpath (pth1, pth2); |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
107 %! end_unwind_protect |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
108 |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
109 ## Remove cell array of two strings |
28168
b3bd3385d07a
* javaaddpath.m, javarmpath.m: Skip BISTs if Java is unavailable on run-time.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28033
diff
changeset
|
110 %!testif HAVE_JAVA; usejava ("jvm") |
27877
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
111 %! pth1 = tempdir (); |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
112 %! pth2 = tilde_expand ("~"); |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
113 %! unwind_protect |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
114 %! javaaddpath (pth1, pth2); |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
115 %! clspth1 = javaclasspath ("-dynamic"); |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
116 %! javarmpath ({pth1, pth2}); |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
117 %! clspth2 = javaclasspath ("-dynamic"); |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
118 %! assert (numel (clspth2), numel (clspth1) - 2); |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
119 %! assert (clspth2(1:end), clspth1(3:end)); |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
120 %! unwind_protect_cleanup |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
121 %! javarmpath (pth1, pth2); |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
122 %! end_unwind_protect |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
123 |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
124 ## Test input validation |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
125 %!error <Invalid call> javarmpath () |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
126 %!error <arguments must be strings> javarmpath (5) |
0850f7c37970
javarmpath.m: Allow cell array of string inputs.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
127 %!error <arguments must be .* cell array of strings> javarmpath ({5}) |