diff options
Diffstat (limited to 'src/plantuml.cpp')
-rw-r--r-- | src/plantuml.cpp | 241 |
1 files changed, 222 insertions, 19 deletions
diff --git a/src/plantuml.cpp b/src/plantuml.cpp index 3930e60..d3d139e 100644 --- a/src/plantuml.cpp +++ b/src/plantuml.cpp @@ -27,16 +27,19 @@ static const int maxCmdLine = 40960; -QCString writePlantUMLSource(const QCString &outDir,const QCString &fileName,const QCString &content) +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",__PRETTY_FUNCTION__,qPrint(fileName)); - Debug::print(Debug::Plantuml,0,"*** %s outDir: %s\n",__PRETTY_FUNCTION__,qPrint(outDir)); + 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 @@ -44,20 +47,50 @@ QCString writePlantUMLSource(const QCString &outDir,const QCString &fileName,con baseName = fileName; int i=baseName.findRev('.'); if (i!=-1) baseName = baseName.left(i); + puName = baseName; baseName.prepend(outDir+"/"); } - Debug::print(Debug::Plantuml,0,"*** %s baseName: %s\n",__PRETTY_FUNCTION__,qPrint(baseName)); + 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\n"; + 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; } @@ -137,12 +170,12 @@ void generatePlantUMLOutput(const char *baseName,const char *outDir,PlantUMLOutp QCString qcOutDir(outDir); uint pos = qcOutDir.findRev("/"); QCString generateType(qcOutDir.right(qcOutDir.length() - (pos + 1)) ); - Debug::print(Debug::Plantuml,0,"*** %s generateType: %s\n",__PRETTY_FUNCTION__,qPrint(generateType)); + 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",__PRETTY_FUNCTION__,qPrint(baseFileName)); - PlantumlManager::instance()->insert(generateType,baseFileName,format); + 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) @@ -197,6 +230,27 @@ PlantumlManager::~PlantumlManager() (*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(); } } @@ -255,7 +309,7 @@ void PlantumlManager::runPlantumlFiles(QDict< QList <QCString> > &PlantumlFiles, pumlArguments+="/"; pumlArguments+=it.currentKey(); pumlArguments+="\" "; - pumlArguments+="-charset UTF-8 "; + pumlArguments+="-charset UTF-8 -t"; pumlArguments+=type; pumlArguments+=" "; QListIterator<QCString> li(*list); @@ -271,7 +325,7 @@ void PlantumlManager::runPlantumlFiles(QDict< QList <QCString> > &PlantumlFiles, pumlArguments+=".pu"; pumlArguments+="\" "; } - Debug::print(Debug::Plantuml,0,"*** %s Running Plantuml arguments:%s\n",__PRETTY_FUNCTION__,qPrint(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", @@ -292,15 +346,135 @@ void PlantumlManager::runPlantumlFiles(QDict< QList <QCString> > &PlantumlFiles, } } } +} +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",__PRETTY_FUNCTION__); - runPlantumlFiles(m_pngPlantumlFiles, "-tpng"); - runPlantumlFiles(m_svgPlantumlFiles, "-tsvg"); - runPlantumlFiles(m_epsPlantumlFiles, "-teps"); + 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) @@ -310,17 +484,30 @@ void PlantumlManager::print(QDict< QList <QCString> > &PlantumlFiles) QList<QCString> *list; for (it.toFirst();(list=it.current());++it) { - Debug::print(Debug::Plantuml,0,"*** %s PlantumlFiles key:%s\n",__PRETTY_FUNCTION__,qPrint(it.currentKey())); + 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",__PRETTY_FUNCTION__,qPrint(*nb)); + 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); @@ -330,25 +517,41 @@ void PlantumlManager::addPlantumlFiles(QDict< QList <QCString> > &PlantumlFiles, PlantumlFiles.insert(key,list); } list->append(new QCString(value)); - Debug::print(Debug::Plantuml,0,"*** %s append : png key:%s ,value:%s\n",__PRETTY_FUNCTION__,qPrint(key),qPrint(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) +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",__PRETTY_FUNCTION__,qPrint(key),qPrint(value)); + 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; } } |