Skip to content

Commit 5e39d4c

Browse files
committed
add checkout_license()
1 parent de43389 commit 5e39d4c

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

+stdlib/checkout_license.m

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
%% CHECKOUT_LICENSE checkout Matlab license
2+
% NOTE: checking out a license holds that license as long as Matlab is
3+
% running. This could impact other users at an institution with a limited
4+
% number of networked licenses. Only use this function at point-of-use,
5+
% that is, when it's certain the function next called requires this license
6+
% to be checked out.
7+
%
8+
% This function provides a more accurate indicator that a function can
9+
% be used rather than just checking if the relevant toolbox is installed.
10+
11+
function [ok, featureName] = checkout_license(packageName)
12+
arguments
13+
packageName {mustBeTextScalar}
14+
end
15+
16+
ok = false;
17+
18+
addons = matlab.addons.installedAddons;
19+
installedPackages = addons.Name;
20+
name = addons.Name(strcmpi(installedPackages, packageName));
21+
22+
if isempty(name)
23+
warning('stdlib:checkout_license:ValueError', 'Did not find an installed package %s.\nInstalled packages:\n%s', packageName, join(installedPackages, newline))
24+
return
25+
end
26+
27+
if ~usejava('jvm')
28+
error('Java must be enabled for this function to work.')
29+
end
30+
31+
% https://www.mathworks.com/help/matlab/matlab_env/index-of-code-analyzer-checks.html
32+
featureName = string(com.mathworks.product.util.ProductIdentifier.get(name).getFlexName()); %#ok<JAPIMATHWORKS>
33+
34+
ok = license('checkout', featureName);
35+
36+
end

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ CodeIssues.sarif
33
*.xml
44
*.html
55

6+
mpm
7+
mpm.exe
8+
69
release/
710
resources/
811
.buildtool/

0 commit comments

Comments
 (0)