Imported Upstream version 1.8.8
[platform/upstream/doxygen.git] / src / plantuml.cpp
1 /******************************************************************************
2  *
3  * Copyright (C) 1997-2014 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 = "-Djava.awt.headless=true -jar \""+plantumlJarPath+"plantuml.jar\" ";
60   pumlArgs+="-o \"";
61   pumlArgs+=outDir;
62   pumlArgs+="\" ";
63   QCString extension;
64   switch (format)
65   {
66     case PUML_BITMAP:
67       pumlArgs+="-tpng";
68       extension=".png";
69       break;
70     case PUML_EPS:
71       pumlArgs+="-teps";
72       extension=".eps";
73       break;
74     case PUML_SVG:
75       pumlArgs+="-tsvg";
76       extension=".svg";
77       break;
78   }
79   pumlArgs+=" \"";
80   pumlArgs+=baseName;
81   pumlArgs+=".pu\" ";
82   int exitCode;
83   //printf("*** running: %s %s outDir:%s %s\n",pumlExe.data(),pumlArgs.data(),outDir,outFile);
84   msg("Running PlantUML on generated file %s.pu\n",baseName);
85   portable_sysTimerStart();
86   if ((exitCode=portable_system(pumlExe,pumlArgs,FALSE))!=0)
87   {
88     err("Problems running PlantUML. Verify that the command 'java -jar \"%splantuml.jar\" -h' works from the command line\n",
89         plantumlJarPath.data());
90   }
91   else if (Config_getBool("DOT_CLEANUP"))
92   {
93     QFile(QCString(baseName)+".pu").remove();
94   }
95   portable_sysTimerStop();
96 }
97