-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpackage.m
77 lines (64 loc) · 2.94 KB
/
package.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
function package(skipTests)
if nargin < 1
skipTests = false;
end
if ~skipTests
test();
end
rootPath = fileparts(mfilename('fullpath'));
targetPath = fullfile(rootPath, 'target');
[~, ~] = mkdir(targetPath);
addpath(genpath(fullfile(rootPath, 'lib')));
addpath(genpath(fullfile(rootPath, 'src')));
projectFile = fullfile(rootPath, 'Symphony.prj');
dom = xmlread(projectFile);
root = dom.getDocumentElement();
config = root.getElementsByTagName('configuration').item(0);
% Update version number.
version = config.getElementsByTagName('param.version').item(0);
version.setTextContent(symphonyui.app.App.version);
% Set icon.
icon = config.getElementsByTagName('param.icon').item(0);
icon.setTextContent(fullfile('${PROJECT_ROOT}', 'src', 'main', 'resources', 'icons', 'app_24.png'));
icons = config.getElementsByTagName('param.icons').item(0);
files = icons.getElementsByTagName('file');
while files.getLength() > 0
icons.removeChild(files.item(0));
end
icon16 = icons.getOwnerDocument().createElement('file');
icon24 = icons.getOwnerDocument().createElement('file');
icon48 = icons.getOwnerDocument().createElement('file');
icon16.setTextContent(fullfile('${PROJECT_ROOT}', 'src', 'main', 'resources', 'icons', 'app_16.png'));
icon24.setTextContent(fullfile('${PROJECT_ROOT}', 'src', 'main', 'resources', 'icons', 'app_24.png'));
icon48.setTextContent(fullfile('${PROJECT_ROOT}', 'src', 'main', 'resources', 'icons', 'app_48.png'));
icons.appendChild(icon16);
icons.appendChild(icon24);
icons.appendChild(icon48);
% Remove unsetting the param.icon.
unsets = config.getElementsByTagName('unset').item(0);
param = unsets.getElementsByTagName('param.icon');
if param.getLength() > 0
unsets.removeChild(param.item(0));
end
% Replace fullpaths with ${PROJECT_ROOT}.
config.setAttribute('file', fullfile('${PROJECT_ROOT}', 'Symphony.prj'));
config.setAttribute('location', '${PROJECT_ROOT}');
output = config.getElementsByTagName('param.output').item(0);
output.setTextContent(fullfile('${PROJECT_ROOT}', 'target'));
deliverable = config.getElementsByTagName('build-deliverables').item(0).getElementsByTagName('file').item(0);
deliverable.setAttribute('location', '${PROJECT_ROOT}');
deliverable.setTextContent(fullfile('${PROJECT_ROOT}', 'target'));
% Remove unsetting the param.output.
unsets = config.getElementsByTagName('unset').item(0);
param = unsets.getElementsByTagName('param.output');
if param.getLength() > 0
unsets.removeChild(param.item(0));
end
% This adds a new line after each line in the XML
%xmlwrite(projectFile, dom);
domString = strrep(char(dom.saveXML(root)), 'encoding="UTF-16"', 'encoding="UTF-8"');
fid = fopen(projectFile, 'w');
fwrite(fid, domString);
fclose(fid);
matlab.apputil.package(projectFile);
end