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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
|
/******************************************************************************
*
* Copyright (C) 1997-2015 by Dimitri van Heesch.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation under the terms of the GNU General Public License is hereby
* granted. No representations are made about the suitability of this software
* for any purpose. It is provided "as is" without express or implied warranty.
* See the GNU General Public License for more details.
*
* Documents produced by Doxygen are derivative works derived from the
* input used in their production; they are not affected by this license.
*
*/
#include "plantuml.h"
#include "portable.h"
#include "config.h"
#include "doxygen.h"
#include "index.h"
#include "message.h"
#include "debug.h"
#include <qdir.h>
#include <qdict.h>
#include <qlist.h>
static const int maxCmdLine = 40960;
QCString writePlantUMLSource(const QCString &outDir,const QCString &fileName,const QCString &content,PlantUMLOutputFormat format)
{
QCString baseName(4096);
QCString puName(4096);
QCString imgName(4096);
static int umlindex=1;
Debug::print(Debug::Plantuml,0,"*** %s fileName: %s\n","writePlantUMLSource",qPrint(fileName));
Debug::print(Debug::Plantuml,0,"*** %s outDir: %s\n","writePlantUMLSource",qPrint(outDir));
if (fileName.isEmpty()) // generate name
{
puName = "inline_umlgraph_"+QCString().setNum(umlindex);
baseName = outDir+"/inline_umlgraph_"+QCString().setNum(umlindex++);
}
else // user specified name
{
baseName = fileName;
int i=baseName.findRev('.');
if (i!=-1) baseName = baseName.left(i);
puName = baseName;
baseName.prepend(outDir+"/");
}
switch (format)
{
case PUML_BITMAP:
imgName =puName+".png";
break;
case PUML_EPS:
imgName =puName+".eps";
break;
case PUML_SVG:
imgName =puName+".svg";
break;
}
Debug::print(Debug::Plantuml,0,"*** %s baseName: %s\n","writePlantUMLSource",qPrint(baseName));
Debug::print(Debug::Plantuml,0,"*** %s puName: %s\n","writePlantUMLSource",qPrint(puName));
Debug::print(Debug::Plantuml,0,"*** %s imgName: %s\n","writePlantUMLSource",qPrint(imgName));
QFile file(baseName+".pu");
if (!file.open(IO_WriteOnly))
{
err("Could not open file %s for writing\n",baseName.data());
}
QCString text = "@startuml "+imgName+"\n";
text+=content;
text+="\n@enduml\n";
file.writeBlock( text, text.length() );
file.close();
//Debug::print(Debug::Plantuml,0,"*** %s baseFileName text: %s\n","writePlantUMLSource",qPrint(text));
if(Config_getBool(PLANTUML_RUN_JAVA_ONCE)){
QCString qcOutDir(outDir);
uint pos = qcOutDir.findRev("/");
QCString generateType(qcOutDir.right(qcOutDir.length() - (pos + 1)) );
Debug::print(Debug::Plantuml,0,"*** %s generateType: %s\n","writePlantUMLSource",qPrint(generateType));
//QCString qcBaseName(baseName);
//pos = qcBaseName.findRev("/");
//QCString baseFileName(qcBaseName.right(qcBaseName.length() - (pos + 1)) );
//Debug::print(Debug::Plantuml,0,"*** %s baseFileName: %s\n","writePlantUMLSource",qPrint(baseFileName));
PlantumlManager::instance()->insert(generateType,puName,format,text);
}
return baseName;
}
void generatePlantUMLOutput(const char *baseName,const char *outDir,PlantUMLOutputFormat format)
{
QCString plantumlJarPath = Config_getString(PLANTUML_JAR_PATH);
QCString plantumlConfigFile = Config_getString(PLANTUML_CFG_FILE);
QCString dotPath = Config_getString(DOT_PATH);
QCString pumlExe = "java";
QCString pumlArgs = "";
QStrList &pumlIncludePathList = Config_getList(PLANTUML_INCLUDE_PATH);
char *s=pumlIncludePathList.first();
if (s)
{
pumlArgs += "-Dplantuml.include.path=\"";
pumlArgs += s;
s = pumlIncludePathList.next();
}
while (s)
{
pumlArgs += portable_pathListSeparator();
pumlArgs += s;
s = pumlIncludePathList.next();
}
if (pumlIncludePathList.first()) pumlArgs += "\" ";
pumlArgs += "-Djava.awt.headless=true -jar \""+plantumlJarPath+"plantuml.jar\" ";
if (!plantumlConfigFile.isEmpty())
{
pumlArgs += "-config \"";
pumlArgs += plantumlConfigFile;
pumlArgs += "\" ";
}
if (Config_getBool(HAVE_DOT) && !dotPath.isEmpty())
{
pumlArgs += "-graphvizdot \"";
pumlArgs += dotPath;
pumlArgs += "dot";
pumlArgs += portable_commandExtension();
pumlArgs += "\" ";
}
pumlArgs+="-o \"";
pumlArgs+=outDir;
pumlArgs+="\" ";
QCString imgName = baseName;
// The basename contains path, we need to strip the path from the filename in order
// to create the image file name which should be included in the index.qhp (Qt help index file).
int i;
if ((i=imgName.findRev('/'))!=-1) // strip path
{
imgName=imgName.right(imgName.length()-i-1);
}
switch (format)
{
case PUML_BITMAP:
pumlArgs+="-tpng";
imgName+=".png";
break;
case PUML_EPS:
pumlArgs+="-teps";
imgName+=".eps";
break;
case PUML_SVG:
pumlArgs+="-tsvg";
imgName+=".svg";
break;
}
pumlArgs+=" \"";
pumlArgs+=baseName;
pumlArgs+=".pu\" ";
pumlArgs+="-charset UTF-8 ";
int exitCode;
msg("Running PlantUML on generated file %s.pu\n",baseName);
portable_sysTimerStart();
if(Config_getBool(PLANTUML_RUN_JAVA_ONCE)){
QCString qcOutDir(outDir);
uint pos = qcOutDir.findRev("/");
QCString generateType(qcOutDir.right(qcOutDir.length() - (pos + 1)) );
Debug::print(Debug::Plantuml,0,"*** %s generateType: %s\n","generatePlantUMLOutput",qPrint(generateType));
QCString qcBaseName(baseName);
pos = qcBaseName.findRev("/");
QCString baseFileName(qcBaseName.right(qcBaseName.length() - (pos + 1)) );
Debug::print(Debug::Plantuml,0,"*** %s baseFileName: %s\n","generatePlantUMLOutput",qPrint(baseFileName));
//PlantumlManager::instance()->insert(generateType,baseFileName,format);
} else { // ! Config_getBool(PLANTUML_RUN_JAVA_ONCE)
Debug::print(Debug::Plantuml,0,"*** running: %s %s outDir:%s %s\n",qPrint(pumlExe),qPrint(pumlArgs),outDir,baseName);
if ((exitCode=portable_system(pumlExe,pumlArgs,TRUE))!=0)
{
err("Problems running PlantUML. Verify that the command 'java -jar \"%splantuml.jar\" -h' works from the command line. Exit code: %d\n",
plantumlJarPath.data(),exitCode);
}
else if (Config_getBool(DOT_CLEANUP))
{
QFile(QCString(baseName)+".pu").remove();
}
}
portable_sysTimerStop();
if ( (format==PUML_EPS) && (Config_getBool(USE_PDFLATEX)) )
{
QCString epstopdfArgs(maxCmdLine);
epstopdfArgs.sprintf("\"%s.eps\" --outfile=\"%s.pdf\"",baseName,baseName);
portable_sysTimerStart();
if ((exitCode=portable_system("epstopdf",epstopdfArgs))!=0)
{
err("Problems running epstopdf. Check your TeX installation! Exit code: %d\n",exitCode);
}
portable_sysTimerStop();
}
Doxygen::indexList->addImageFile(imgName);
}
//--------------------------------------------------------------------
PlantumlManager *PlantumlManager::m_theInstance = 0;
PlantumlManager *PlantumlManager::instance()
{
if (!m_theInstance)
{
m_theInstance = new PlantumlManager;
}
return m_theInstance;
}
PlantumlManager::PlantumlManager()
{
}
PlantumlManager::~PlantumlManager()
{
{
QDictIterator< QList<QCString> > it( m_pngPlantumlFiles); // See QDictIterator
QList<QCString> *list;
for (it.toFirst();(list=it.current());++it)
{
(*list).clear();
}
m_pngPlantumlFiles.clear();
m_pngPlantumlContent.clear();
}
{
QDictIterator< QList<QCString> > it( m_epsPlantumlFiles); // See QDictIterator
QList<QCString> *list;
for (it.toFirst();(list=it.current());++it)
{
(*list).clear();
}
m_epsPlantumlFiles.clear();
m_epsPlantumlContent.clear();
}
{
QDictIterator< QList<QCString> > it( m_svgPlantumlFiles); // See QDictIterator
QList<QCString> *list;
for (it.toFirst();(list=it.current());++it)
{
(*list).clear();
}
m_svgPlantumlFiles.clear();
m_svgPlantumlContent.clear();
}
}
void PlantumlManager::runPlantumlFiles(QDict< QList <QCString> > &PlantumlFiles,const char *type)
{
/* example : running: java -Djava.awt.headless=true -jar "/Users/cheoljoo/code/common_telltale/GP/Apps/Src/MgrTelltale/tools/plantuml.jar" -o "/Users/cheoljoo/Code/LG/test_doxygen/DOXYGEN_OUTPUT/html" -tpng "/Users/cheoljoo/Code/LG/test_doxygen/DOXYGEN_OUTPUT/html/A.pu" -charset UTF-8 outDir:/Users/cheoljoo/Code/LG/test_doxygen/DOXYGEN_OUTPUT/html /Users/cheoljoo/Code/LG/test_doxygen/DOXYGEN_OUTPUT/html/A
*/
int exitCode;
QCString plantumlJarPath = Config_getString(PLANTUML_JAR_PATH);
QCString plantumlConfigFile = Config_getString(PLANTUML_CFG_FILE);
QCString dotPath = Config_getString(DOT_PATH);
QCString pumlExe = "java";
QCString pumlArgs = "";
QStrList &pumlIncludePathList = Config_getList(PLANTUML_INCLUDE_PATH);
char *s=pumlIncludePathList.first();
if (s)
{
pumlArgs += "-Dplantuml.include.path=\"";
pumlArgs += s;
s = pumlIncludePathList.next();
}
while (s)
{
pumlArgs += portable_pathListSeparator();
pumlArgs += s;
s = pumlIncludePathList.next();
}
if (pumlIncludePathList.first()) pumlArgs += "\" ";
pumlArgs += "-Djava.awt.headless=true -jar \""+plantumlJarPath+"plantuml.jar\" ";
if (!plantumlConfigFile.isEmpty())
{
pumlArgs += "-config \"";
pumlArgs += plantumlConfigFile;
pumlArgs += "\" ";
}
if (Config_getBool(HAVE_DOT) && !dotPath.isEmpty())
{
pumlArgs += "-graphvizdot \"";
pumlArgs += dotPath;
pumlArgs += "dot";
pumlArgs += portable_commandExtension();
pumlArgs += "\" ";
}
QDictIterator< QList<QCString> > it( PlantumlFiles); // See QDictIterator
QList<QCString> *list;
for (it.toFirst();(list=it.current());++it)
{
QCString pumlArguments(pumlArgs);
msg("Running PlantUML on png PlantumlFiles in %s\n",qPrint(it.currentKey()));
pumlArguments+="-o \"";
pumlArguments+=Config_getString(OUTPUT_DIRECTORY);
pumlArguments+="/";
pumlArguments+=it.currentKey();
pumlArguments+="\" ";
pumlArguments+="-charset UTF-8 -t";
pumlArguments+=type;
pumlArguments+=" ";
QListIterator<QCString> li(*list);
QCString *nb;
for (li.toFirst();(nb=li.current());++li)
{
pumlArguments+="\"";
pumlArguments+=Config_getString(OUTPUT_DIRECTORY);
pumlArguments+="/";
pumlArguments+=it.currentKey();
pumlArguments+="/";
pumlArguments+=*nb;
pumlArguments+=".pu";
pumlArguments+="\" ";
}
Debug::print(Debug::Plantuml,0,"*** %s Running Plantuml arguments:%s\n","PlantumlManager::runPlantumlFiles",qPrint(pumlArguments));
if ((exitCode=portable_system(pumlExe,pumlArguments,TRUE))!=0)
{
err("Problems running PlantUML. Verify that the command 'java -jar \"%splantuml.jar\" -h' works from the command line. Exit code: %d\n",
plantumlJarPath.data(),exitCode);
}
else if (Config_getBool(DOT_CLEANUP))
{
for (li.toFirst();(nb=li.current());++li)
{
QCString pumlName = "";
pumlName+=Config_getString(OUTPUT_DIRECTORY);
pumlName+="/";
pumlName+=it.currentKey();
pumlName+="/";
pumlName+=*nb;
pumlName+=".pu";
QFile(pumlName).remove();
}
}
}
}
void PlantumlManager::runPlantumlContent(QDict< QList <QCString> > &PlantumlFiles,QDict< QCString > &PlantumlContent, const char *type)
{
/* example : running: java -Djava.awt.headless=true -jar "/Users/cheoljoo/code/common_telltale/GP/Apps/Src/MgrTelltale/tools/plantuml.jar" -o "/Users/cheoljoo/Code/LG/test_doxygen/DOXYGEN_OUTPUT/html" -tpng "/Users/cheoljoo/Code/LG/test_doxygen/DOXYGEN_OUTPUT/html/A.pu" -charset UTF-8 outDir:/Users/cheoljoo/Code/LG/test_doxygen/DOXYGEN_OUTPUT/html /Users/cheoljoo/Code/LG/test_doxygen/DOXYGEN_OUTPUT/html/A
*/
int exitCode;
QCString plantumlJarPath = Config_getString(PLANTUML_JAR_PATH);
QCString plantumlConfigFile = Config_getString(PLANTUML_CFG_FILE);
QCString dotPath = Config_getString(DOT_PATH);
QCString pumlExe = "java";
QCString pumlArgs = "";
QStrList &pumlIncludePathList = Config_getList(PLANTUML_INCLUDE_PATH);
char *s=pumlIncludePathList.first();
if (s)
{
pumlArgs += "-Dplantuml.include.path=\"";
pumlArgs += s;
s = pumlIncludePathList.next();
}
while (s)
{
pumlArgs += portable_pathListSeparator();
pumlArgs += s;
s = pumlIncludePathList.next();
}
if (pumlIncludePathList.first()) pumlArgs += "\" ";
pumlArgs += "-Djava.awt.headless=true -jar \""+plantumlJarPath+"plantuml.jar\" ";
if (!plantumlConfigFile.isEmpty())
{
pumlArgs += "-config \"";
pumlArgs += plantumlConfigFile;
pumlArgs += "\" ";
}
if (Config_getBool(HAVE_DOT) && !dotPath.isEmpty())
{
pumlArgs += "-graphvizdot \"";
pumlArgs += dotPath;
pumlArgs += "dot";
pumlArgs += portable_commandExtension();
pumlArgs += "\" ";
}
{
QDictIterator< QCString > it( PlantumlContent); // See QDictIterator
QCString *nb;
for (it.toFirst();(nb=it.current());++it)
{
QCString pumlArguments(pumlArgs);
msg("Running PlantUML on png PlantumlFiles in %s\n",qPrint(it.currentKey()));
pumlArguments+="-o \"";
pumlArguments+=Config_getString(OUTPUT_DIRECTORY);
pumlArguments+="/";
pumlArguments+=it.currentKey();
pumlArguments+="\" ";
pumlArguments+="-charset UTF-8 -t";
pumlArguments+=type;
pumlArguments+=" ";
QCString puFileName("");
puFileName+=Config_getString(OUTPUT_DIRECTORY);
puFileName+="/";
puFileName+=it.currentKey();
puFileName+="/";
puFileName+="inline_umlgraph_";
puFileName+=type;
puFileName+=it.currentKey();
puFileName+=".pu";
pumlArguments+="\"";
pumlArguments+=puFileName;
pumlArguments+="\" ";
QFile file(puFileName);
if (!file.open(IO_WriteOnly))
{
err("Could not open file %s for writing\n",puFileName.data());
}
file.writeBlock( *nb, nb->length() );
file.close();
Debug::print(Debug::Plantuml,0,"*** %s Running Plantuml arguments:%s\n","PlantumlManager::runPlantumlContent",qPrint(pumlArguments));
if ((exitCode=portable_system(pumlExe,pumlArguments,TRUE))!=0)
{
err("Problems running PlantUML. Verify that the command 'java -jar \"%splantuml.jar\" -h' works from the command line. Exit code: %d\n",
plantumlJarPath.data(),exitCode);
}
else if (Config_getBool(DOT_CLEANUP))
{
file.remove();
}
}
}
{
QDictIterator< QList<QCString> > it( PlantumlFiles); // See QDictIterator
QList<QCString> *list;
for (it.toFirst();(list=it.current());++it)
{
QListIterator<QCString> li(*list);
QCString *nb;
if (Config_getBool(DOT_CLEANUP))
{
for (li.toFirst();(nb=li.current());++li)
{
QCString pumlName = "";
pumlName+=Config_getString(OUTPUT_DIRECTORY);
pumlName+="/";
pumlName+=it.currentKey();
pumlName+="/";
pumlName+=*nb;
pumlName+=".pu";
QFile(pumlName).remove();
}
}
}
}
}
void PlantumlManager::run()
{
Debug::print(Debug::Plantuml,0,"*** %s\n","PlantumlManager::run");
//runPlantumlFiles(m_pngPlantumlFiles, "png");
//runPlantumlFiles(m_svgPlantumlFiles, "svg");
//runPlantumlFiles(m_epsPlantumlFiles, "eps");
runPlantumlContent(m_pngPlantumlFiles, m_pngPlantumlContent, "png");
runPlantumlContent(m_svgPlantumlFiles, m_svgPlantumlContent, "svg");
runPlantumlContent(m_epsPlantumlFiles, m_epsPlantumlContent, "eps");
}
void PlantumlManager::print(QDict< QList <QCString> > &PlantumlFiles)
{
if (Debug::isFlagSet(Debug::Plantuml)){
QDictIterator< QList<QCString> > it( PlantumlFiles); // See QDictIterator
QList<QCString> *list;
for (it.toFirst();(list=it.current());++it)
{
Debug::print(Debug::Plantuml,0,"*** %s PlantumlFiles key:%s\n","PlantumlManager::print",qPrint(it.currentKey()));
QListIterator<QCString> li(*list);
QCString *nb;
for (li.toFirst();(nb=li.current());++li)
{
Debug::print(Debug::Plantuml,0,"*** %s PlantumlFiles list:%s\n","PlantumlManager::print",qPrint(*nb));
}
}
}
}
void PlantumlManager::print(QDict<QCString> &PlantumlContent)
{
if (Debug::isFlagSet(Debug::Plantuml)){
QDictIterator< QCString > it( PlantumlContent); // See QDictIterator
QCString *nb;
for (it.toFirst();(nb=it.current());++it)
{
Debug::print(Debug::Plantuml,0,"*** %s PlantumlContent key:%s\n","PlantumlManager::print",qPrint(it.currentKey()));
Debug::print(Debug::Plantuml,0,"*** Content :%s\n\n\n",qPrint(*nb));
}
}
}
void PlantumlManager::addPlantumlFiles(QDict< QList <QCString> > &PlantumlFiles,const QCString key , const QCString value)
{
QList<QCString> *list = PlantumlFiles.find(key);
if (list==0)
{
list = new QList<QCString>;
PlantumlFiles.insert(key,list);
}
list->append(new QCString(value));
Debug::print(Debug::Plantuml,0,"*** %s append : png key:%s ,value:%s\n","PlantumlManager::addPlantumlFiles",qPrint(key),qPrint(value));
}
void PlantumlManager::addPlantumlContent(QDict< QCString > &PlantumlContent,const QCString key , const QCString &puContent)
{
QCString* content = PlantumlContent.find(key);
if(content == 0){
content = new QCString("");
m_pngPlantumlContent.insert(key,content);
}
(*content)+=puContent;
}
void PlantumlManager::insert(const QCString key , const QCString value, PlantUMLOutputFormat format,const QCString &puContent)
{
Debug::print(Debug::Plantuml,0,"*** %s key:%s ,value:%s\n","PlantumlManager::insert",qPrint(key),qPrint(value));
switch (format)
{
case PUML_BITMAP:
addPlantumlFiles(m_pngPlantumlFiles,key,value);
print(m_pngPlantumlFiles);
addPlantumlContent(m_pngPlantumlContent,key,puContent);
print(m_pngPlantumlContent);
break;
case PUML_EPS:
addPlantumlFiles(m_epsPlantumlFiles,key,value);
print(m_epsPlantumlFiles);
addPlantumlContent(m_epsPlantumlContent,key,puContent);
print(m_epsPlantumlContent);
break;
case PUML_SVG:
addPlantumlFiles(m_svgPlantumlFiles,key,value);
print(m_svgPlantumlFiles);
addPlantumlContent(m_svgPlantumlContent,key,puContent);
print(m_svgPlantumlContent);
break;
}
}
//--------------------------------------------------------------------
|