rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
MatlabDocMaker.m
1 classdef MatlabDocMaker
2  % MatlabDocMaker: Class for information & tasks concerning the UQ-RB-Test
3  % documentation.
4  %
5  % Prerequisites:
6  % - \c doxygen: mtoc++ is merely a filter for doxygen
7  % - \c mtocpp, \c mtocpp_post on the search/environment paths
8  % - \c m4: A macro parser [Unix only]
9  %
10  % @author Daniel Wirtz @date 2011-10-13
11  %
12  % @change{1,2,dw,2011-11-08} Improved the createUnix method by displaying the warnings and writing the output to
13  % a log file afterwards. Not using cprintf anymore as this is 3rd party software.
14  %
15  % @change{1,2,dw,2011-11-07} Fixed a recursion bug caused by copy and paste. Now the preferences
16  % are stored on an per-application basis.
17  %
18  % @change{1,2,dw,2011-11-04} Changed the name to MatlabDocMaker in
19  % order to export it into the mtoc++ distribution later.
20  %
21  % @new{1,2,dw,2011-10-13} Added this class and moved documentation related
22  % stuff here from the KerMor class.
23  %
24  % This class is part of the mtoc++ tool
25  % - \c Homepage http://www.morepas.org/software/mtocpp
26  % - \c License http://www.morepas.org/software/mtocpp/licensing.html
27 
28  methods(Static)
29  function name = getProjectName
30  % Returns the project name.
31  %
32  % @note Changing the return value of this method will require
33  % another execution of MatlabDocMaker.setup as the preferences
34  % key also depends on it.
35  %
36  % Return values:
37  % name: The project name
38  name = 'RBmatlab';
39  end
40 
41  function version = getProjectVersion
42  % Returns the current version of the project.
43  %
44  % @note The built-in @@new and @@change tags from the
45  % Doxyfile.m4 support two-level versioning a la X.X.
46  %
47  % Return values:
48  % version: The project version
49  version = '2.0';
50  end
51  end
52 
53  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54  %% End of user defined methods.
55  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56 
57  methods(Static, Sealed)
58  % The KerMor documentation directory, i.e. where createDocs places
59  % the generated documentation.
60  %
61  % Can be set during Documentation.setup
62  %
63 
64  function dir = getOutputDirectory
65  % Returns the directory where the applications source files
66  % reside
67  %
68  % Return values:
69  % dir: The output directory @type char
70  dir = getpref(MatlabDocMaker.getProjPrefTag,'outdir',[]);
71  if isempty(dir)
72  error('MatlabDocMaker preferences not set. Re-run setup method.');
73  end
74  end
75 
76  function dir = getSourceDirectory
77  % Returns the directory where the applications source files
78  % reside
79  %
80  % Return values:
81  % dir: The project source directory @type char
82  dir = getpref(MatlabDocMaker.getProjPrefTag,'srcdir',[]);
83  if isempty(dir)
84  error('MatlabDocMaker preferences not set. Re-run setup method.');
85  end
86  end
87 
88  function dir = getConfigDirectory
89  % Returns the directory where the applications documentation
90  % configuration files reside
91  %
92  % This folder must contain at least the files "mtoc.conf" and
93  % "Doxyfile.m4"
94  %
95  % Return values:
96  % dir: The documentation configuration directory @type char
97  dir = getpref(MatlabDocMaker.getProjPrefTag,'confdir',[]);
98  if isempty(dir)
99  error('MatlabDocMaker preferences not set. Re-run setup method.');
100  end
101  end
102 
103  function bin = getDoxygenBin
104  % Allows access to a custom doxygen binary.
105  %
106  % Return values:
107  % bin: The fully qualified path to a custom doxygen executable @type char
108 
109  bin = getpref(MatlabDocMaker.getProjPrefTag,'doxybin',[]);
110  % If no preference is set, expect the doxygen binary to be
111  % included in the local path.
112  if isempty(bin)
113  bin = 'LD_LIBRARY_PATH= doxygen';
114  end
115  end
116  end
117 
118  methods(Static)
119 
120  function open
121  % Opens the generated documentation.
122  web(fullfile(MatlabDocMaker.getOutputDirectory, 'index.html'));
123  end
124 
125  function create(open)
126  % Creates the Doxygen documentation
127  %
128  % Parameters:
129  % open: Set to true if the documentation should be opened after
130  % successful compilation @type bool @default false
131 
132  if nargin == 0
133  open = false;
134  end
135 
136  % Save current working dir and change into the KerMor home
137  % directory; only from there all classes and packages are
138  % detected properly.
139  curdir = pwd;
140  cd(MatlabDocMaker.getSourceDirectory);
141  %% Operation-system dependent actions
142  if isunix
143  MatlabDocMaker.createUnix;
144  elseif ispc
145  MatlabDocMaker.createWindows;
146  end
147  cd(curdir);
148 
149  %% Open index.html if wanted
150  if open
151  MatlabDocMaker.open;
152  end
153  end
154 
155  function setup
156  % Runs the setup script for MatlabDocMaker and collects all
157  % necessary paths in order for the documentation creation to
158  % work properly.
159 
160  if isempty(MatlabDocMaker.getProjectName) || isempty(MatlabDocMaker.getProjectVersion)
161  error('Please set/write the code for the getProjectName and getProjectVersion methods first!');
162  end
163 
164  fprintf('<<<< Welcome to the MatlabDocMaker setup for your project %s! >>>>\n',MatlabDocMaker.getProjectName);
165  %% Source directory
166  srcdir = getpref(MatlabDocMaker.getProjPrefTag,'srcdir',[]);
167  word = 'keep';
168  if isempty(srcdir)
169  srcdir = pwd;
170  word = 'set';
171  end
172  str = sprintf('Do you want to %s %s as your projects source directory?\n(Y)es/(N)o?: ',word,srcdir);
173  ds = lower(input(str,'s'));
174  if isequal(ds,'n')
175  d = uigetdir(srcdir,'Please select the projects source directory');
176  if d == 0
177  error('No source directory specified. Aborting setup.');
178  end
179  srcdir = d;
180  end
181  setpref(MatlabDocMaker.getProjPrefTag,'srcdir',srcdir);
182 
183  %% Config directory
184  confdir = getpref(MatlabDocMaker.getProjPrefTag,'confdir',[]);
185  word = 'keep';
186  if isempty(confdir)
187  confdir = fullfile(srcdir,'documentation');
188  word = 'set';
189  end
190  str = sprintf('Do you want to %s %s as your documentation configuration files directory?\n(Y)es/(N)o?: ',word,confdir);
191  ds = lower(input(str,'s'));
192  if isequal(ds,'n')
193  d = uigetdir(confdir,'Please select the documentation configuration directory');
194  if d == 0
195  error('No documentation configuration directory specified. Aborting setup.');
196  end
197  confdir = d;
198  end
199  setpref(MatlabDocMaker.getProjPrefTag,'confdir',confdir);
200 
201  %% Output directory
202  outdir = getpref(MatlabDocMaker.getProjPrefTag,'outdir',[]);
203  word = 'keep';
204  if isempty(outdir)
205  outdir = confdir;
206  word = 'set';
207  end
208  str = sprintf('Do you want to %s %s as your documentation output directory?\n(Y)es/(N)o?: ',word,outdir);
209  ds = lower(input(str,'s'));
210  if isequal(ds,'n')
211  d = uigetdir(outdir,'Please select the documentation output directory');
212  if d == 0
213  error('No documentation output directory specified. Aborting setup.');
214  end
215  outdir = d;
216  end
217  setpref(MatlabDocMaker.getProjPrefTag,'outdir',outdir);
218 
219  %% Doxygen binary
220  doxybin = getpref(MatlabDocMaker.getProjPrefTag,'doxybin',[]);
221  word = sprintf('Do you want to choose a different doxygen binary than %s?\n(Y)es/(N)o?: ',doxybin);
222  if isempty(doxybin)
223  [st, doxybin] = system('which doxybin');
224  if st == 0
225  word = sprintf('Doxygen found at %s. Do you want to specify a custom doxygen binary?\n(Y)es/(N)o?: ',doxybin);
226  else
227  word = sprintf('No doxygen executable found. Please type "y" to manually select a doxygen binary. ');
228  end
229  end
230  ds = lower(input(word,'s'));
231  if isequal(ds,'y')
232  d = uigetfile(pwd,'Please select a doxygen binary');
233  if d == 0
234  error('No doxygen binary specified. Aborting setup.');
235  end
236  doxybin = d;
237  end
238  setpref(MatlabDocMaker.getProjPrefTag,'doxybin',doxybin);
239 
240  fprintf('<<<< MatlabDocMaker setup successful. >>>>\nYou can now create your projects documentation by running MatlabDocMaker.create\n');
241  end
242  end
243 
244  methods(Static, Access=private)
245 
246  function value = getProjPrefTag
247  str = MatlabDocMaker.getProjectName;
248  value = ['MTOCPP_' str(regexp(str,'[a-zA-z]'))];
249  end
250 
251  function createUnix
252  % Creates the KerMor documentation on UNIX platforms.
253 
254  cdir = MatlabDocMaker.getConfigDirectory;
255  % Create "configured" binary
256  cbin = fullfile(cdir,'mtocpp_filter.sh');
257  f = fopen(cbin,'w');
258  fprintf(f,'#!/bin/bash\nmtocpp $1 %s',fullfile(cdir,'mtocpp.conf'));
259  fclose(f);
260  unix(['chmod +x ' cbin]);
261 
262  % Process macros in the Doxyfile.m4 file using m4
263  system(sprintf('m4 -D _OutputDir_="%s" -D _SourceDir_="%s" -D _ConfDir_="%s" -D _ProjectName_="%s" -D _ProjectVersion_="%s" "%s/Doxyfile.m4" > "%s/Doxyfile"',...
266 
267  tex = fullfile(cdir,'latexextras.m4');
268  if exist(tex,'file') == 2
269  % # Parse the kermorlatex include style file
270  system(sprintf('m4 -D _ConfDir_="%s" "%s" > "%s/latexextras.sty"',...
271  cdir,tex,cdir));
272  else
273  % Create empty file
274  system(sprintf('touch %s/latexextras.sty',cdir));
275  end
276 
277  %% Call doxygen
279  fprintf('Running doxygen (%s) with mtoc++ filter...\n',b);
280  [dummy,warn] = system(sprintf('%s %s/Doxyfile 1>/dev/null',b, cdir));
281 
282  %% Postprocess
283  fprintf('Running mtoc++ postprocessor...\n');
284  [dummy,dummy] = system(sprintf('mtocpp_post %s',MatlabDocMaker.getOutputDirectory));
285 
286  %% Tidy up
287  delete(cbin);
288  delete(fullfile(cdir,'latexextras.sty'));
289  delete(fullfile(cdir,'Doxyfile'));
290 
291  %% Process warnings
292  fprintf(['Warnings generated during documentation creation:\n' strrep(warn,'\','\\') '\n']);
293  % Write to log file later
294  log = fullfile(MatlabDocMaker.getOutputDirectory,'warnings.log');
295  f = fopen(log,'w'); fprintf(f,'%s',warn); fclose(f);
296  fprintf('Log file at %s.\nMatlabDocMaker finished.\n',log);
297  end
298 
299  function createWindows
300  % Creates the documentation on a windows platform.
301  %
302  % Currently not implemented.
303  error('Creating documentation on Windows is not yet implemented.');
304  end
305  end
306 
307 end
Tools for post-processing data, i.e. data extraction and visual enhancements for publication.
Definition: Assessment.m:1
static function name = getProjectName()
Returns the project name.
static function char dir = getSourceDirectory()
Returns the directory where the applications source files reside.
static function version = getProjectVersion()
Returns the current version of the project.
MatlabDocMaker: Class for information & tasks concerning the UQ-RB-Test documentation.
static function char dir = getOutputDirectory()
Returns the directory where the applications source files reside.
Test reduced basis implementation.
Definition: DetailedData.m:1
static function char bin = getDoxygenBin()
Allows access to a custom doxygen binary.
function rv = doxygen(param1, param2)
Here comes a short description text.
Definition: doxygen.m:17