Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion code/+matbox/+setup/+internal/installFexPackage.m
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,17 @@
end

elseif endsWith(addonUrl, '/mltbx')
[tempFilepath, C] = matbox.setup.internal.utility.tempsave(addonUrl, [toolboxIdentifier, '_temp.mltbx']);
isLicenseOptionSupported = isMATLABReleaseOlderThan("R2026b");
if isLicenseOptionSupported && ~isLicenseAgreed && ~canShowLicenseDialog()
fprintf(newline)
error("MatBox:Setup:LicenseDialogUnavailable", ...
['Installing "%s" shows its license agreement in a dialog, and ', ...
'this MATLAB session cannot display one. Pass AgreeToLicense=true ', ...
'(AgreeToLicenses=true in installRequirements) to accept the ', ...
'license without the dialog.'], toolboxName)
end

[tempFilepath, C] = matbox.setup.internal.utility.tempsave(addonUrl, [toolboxIdentifier, '_temp.mltbx']);
if isLicenseOptionSupported
installedAddon = matlab.addons.install(tempFilepath, isLicenseAgreed);
else
Expand Down Expand Up @@ -142,6 +151,17 @@
end
end

function tf = canShowLicenseDialog()
% canShowLicenseDialog - Whether this session can display the add-on license dialog
%
% Before R2026b, matlab.addons.install shows the license agreement of an
% .mltbx add-on in a Java Swing dialog unless agreeToLicense is true.
% Java is headless when there is no display, as on a CI runner, and
% creating the dialog then throws java.awt.HeadlessException.

tf = usejava("jvm") && ~java.awt.GraphicsEnvironment.isHeadless();
end

function toolboxName = retrieveToolboxName(toolboxIdentifier)
fex = matlab.addons.repositories.FileExchangeRepository();

Expand Down
21 changes: 19 additions & 2 deletions tools/tests/+matboxtools/+unittest/SetupTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ function testOmittedAgreeToLicenseDoesNotWarn(testCase)
[~, lastWarningId] = lastwarn();
testCase.verifyNotEqual(lastWarningId, 'MatBox:Setup:AgreeToLicenseIgnored')
end

function testOmittedAgreeToLicenseWithoutDisplayErrors(testCase)
testCase.assumeTrue(isMATLABReleaseOlderThan("R2026b"), ...
"From R2026b MATLAB installs an add-on without a license dialog.")
testCase.assumeTrue(usejava("jvm") && java.awt.GraphicsEnvironment.isHeadless(), ...
"This session can display the license dialog.")
testCase.uninstallFexAddon(testCase.FexMltbxUri)

testCase.verifyError( ...
@() matbox.setup.installFromSourceUri(testCase.FexMltbxUri, "InstallationLocation", pwd), ...
"MatBox:Setup:LicenseDialogUnavailable")
end
end

methods
Expand All @@ -88,11 +100,16 @@ function installRequirements(testCase, options)
pathStr = matboxtools.projectdir();
requirementsPath = fullfile(pathStr, "tools", "tests", "test_resources");

% The requirements include an .mltbx add-on. Before R2026b,
% installing one without accepting its license shows a dialog,
% which a session without a display, such as CI, cannot show.
try
if options.Update
matbox.installRequirements(requirementsPath, "u", "InstallationLocation", pwd)
matbox.installRequirements(requirementsPath, "u", ...
"InstallationLocation", pwd, "AgreeToLicenses", true)
else
matbox.installRequirements(requirementsPath, "InstallationLocation", pwd)
matbox.installRequirements(requirementsPath, ...
"InstallationLocation", pwd, "AgreeToLicenses", true)
end
catch ME
testCase.verifyFail(ME.message)
Expand Down
Loading