plantuml.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * Copyright (C) 1997-2015 by Dimitri van Heesch.
4  *
5  * Permission to use, copy, modify, and distribute this software and its
6  * documentation under the terms of the GNU General Public License is hereby
7  * granted. No representations are made about the suitability of this software
8  * for any purpose. It is provided "as is" without express or implied warranty.
9  * See the GNU General Public License for more details.
10  *
11  * Documents produced by Doxygen are derivative works derived from the
12  * input used in their production; they are not affected by this license.
13  *
14  */
15 
16 #include "plantuml.h"
17 #include "portable.h"
18 #include "config.h"
19 #include "message.h"
20 
21 #include <qdir.h>
22 
23 static const int maxCmdLine = 40960;
24 
25 QCString writePlantUMLSource(const QCString &outDir,const QCString &fileName,const QCString &content)
26 {
27  QCString baseName(4096);
28  static int umlindex=1;
29 
30  if (fileName.isEmpty()) // generate name
31  {
32  baseName = outDir+"/inline_umlgraph_"+QCString().setNum(umlindex++);
33  }
34  else // user specified name
35  {
36  baseName = fileName;
37  int i=baseName.findRev('.');
38  if (i!=-1) baseName = baseName.left(i);
39  baseName.prepend(outDir+"/");
40  }
41  QFile file(baseName+".pu");
42  if (!file.open(IO_WriteOnly))
43  {
44  err("Could not open file %s for writing\n",baseName.data());
45  }
46  QCString text = "@startuml";
47  text+=content;
48  text+="@enduml\n";
49  file.writeBlock( text, text.length() );
50  file.close();
51  return baseName;
52 }
53 
54 void generatePlantUMLOutput(const char *baseName,const char *outDir,PlantUMLOutputFormat format)
55 {
56  static QCString plantumlJarPath = Config_getString("PLANTUML_JAR_PATH");
57 
58  QCString pumlExe = "java";
59  QCString pumlArgs = "";
60 
61  QStrList &pumlIncludePathList = Config_getList("PLANTUML_INCLUDE_PATH");
62  char *s=pumlIncludePathList.first();
63  if (s)
64  {
65  pumlArgs += "-Dplantuml.include.path=\"";
66  pumlArgs += s;
67  s = pumlIncludePathList.next();
68  }
69  while (s)
70  {
71  pumlArgs += portable_pathListSeparator();
72  pumlArgs += s;
73  s = pumlIncludePathList.next();
74  }
75  if (pumlIncludePathList.first()) pumlArgs += "\" ";
76  pumlArgs += "-Djava.awt.headless=true -jar \""+plantumlJarPath+"plantuml.jar\" ";
77  pumlArgs+="-o \"";
78  pumlArgs+=outDir;
79  pumlArgs+="\" ";
80  QCString extension;
81  switch (format)
82  {
83  case PUML_BITMAP:
84  pumlArgs+="-tpng";
85  extension=".png";
86  break;
87  case PUML_EPS:
88  pumlArgs+="-teps";
89  extension=".eps";
90  break;
91  case PUML_SVG:
92  pumlArgs+="-tsvg";
93  extension=".svg";
94  break;
95  }
96  pumlArgs+=" \"";
97  pumlArgs+=baseName;
98  pumlArgs+=".pu\" ";
99  pumlArgs+="-charset UTF-8 ";
100  int exitCode;
101  //printf("*** running: %s %s outDir:%s %s\n",pumlExe.data(),pumlArgs.data(),outDir,outFile);
102  msg("Running PlantUML on generated file %s.pu\n",baseName);
104  if ((exitCode=portable_system(pumlExe,pumlArgs,TRUE))!=0)
105  {
106  err("Problems running PlantUML. Verify that the command 'java -jar \"%splantuml.jar\" -h' works from the command line. Exit code: %d\n",
107  plantumlJarPath.data(),exitCode);
108  }
109  else if (Config_getBool("DOT_CLEANUP"))
110  {
111  QFile(QCString(baseName)+".pu").remove();
112  }
114  if ( (format==PUML_EPS) && (Config_getBool("USE_PDFLATEX")) )
115  {
116  QCString epstopdfArgs(maxCmdLine);
117  epstopdfArgs.sprintf("\"%s.eps\" --outfile=\"%s.pdf\"",baseName,baseName);
119  if ((exitCode=portable_system("epstopdf",epstopdfArgs))!=0)
120  {
121  err("Problems running epstopdf. Check your TeX installation! Exit code: %d\n",exitCode);
122  }
124  }
125 }
126 
PlantUMLOutputFormat
Definition: plantuml.h:22
void portable_sysTimerStop()
Definition: portable.cpp:415
static const int maxCmdLine
Definition: plantuml.cpp:23
bool isEmpty() const
Definition: qcstring.h:189
void msg(const char *fmt,...)
Definition: message.cpp:107
#define IO_WriteOnly
Definition: qiodevice.h:62
type * first()
Definition: qinternallist.h:87
static bool format(QChar::Decomposition tag, QString &str, int index, int len)
Definition: qstring.cpp:11496
QCString()
Definition: qcstring.h:135
QCString writePlantUMLSource(const QCString &outDir, const QCString &fileName, const QCString &content)
Definition: plantuml.cpp:25
#define Config_getList(val)
Definition: config.cpp:662
QCString left(uint len) const
Definition: qcstring.cpp:213
int findRev(char c, int index=-1, bool cs=TRUE) const
Definition: qcstring.cpp:95
void portable_sysTimerStart()
Definition: portable.cpp:410
int writeBlock(const char *data, uint len)
Definition: qfile_unix.cpp:537
fileName
Definition: dumpTree.py:9
bool open(int)
Definition: qfile_unix.cpp:134
QCString & prepend(const char *s)
Definition: qcstring.cpp:387
const char * data() const
Definition: qcstring.h:207
char portable_pathListSeparator()
Definition: portable.cpp:364
#define Config_getString(val)
Definition: config.cpp:660
#define Config_getBool(val)
Definition: config.cpp:664
void generatePlantUMLOutput(const char *baseName, const char *outDir, PlantUMLOutputFormat format)
Definition: plantuml.cpp:54
type * next()
Definition: qinternallist.h:89
void err(const char *fmt,...)
Definition: message.cpp:226
The QFile class is an I/O device that operates on files.
Definition: qfile.h:50
QCString & sprintf(const char *format,...)
Definition: qcstring.cpp:27
bool remove()
Definition: qfile.cpp:205
static QCString baseName
Definition: scanner.cpp:10890
void close()
Definition: qfile_unix.cpp:614
static QCString * s
Definition: config.cpp:1042
const bool TRUE
Definition: qglobal.h:371
Portable versions of functions that are platform dependent.
int portable_system(const char *command, const char *args, bool commandHasConsole)
Definition: portable.cpp:33