My Project
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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\n";
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