Doxygen
Loading...
Searching...
No Matches
plantuml.cpp File Reference
#include <mutex>
#include "plantuml.h"
#include "util.h"
#include "portable.h"
#include "config.h"
#include "doxygen.h"
#include "message.h"
#include "debug.h"
#include "fileinfo.h"
#include "dir.h"
#include "indexlist.h"
#include "stringutil.h"
Include dependency graph for plantuml.cpp:

Go to the source code of this file.

Functions

static void runPlantumlContent (const PlantumlManager::FilesMap &plantumlFiles, const PlantumlManager::ContentMap &plantumlContent, PlantumlManager::OutputFormat format)
static void print (const PlantumlManager::FilesMap &plantumlFiles)
static void print (const PlantumlManager::ContentMap &plantumlContent)
static void addPlantumlFiles (PlantumlManager::FilesMap &plantumlFiles, const std::string &key, const std::string &value)
static void addPlantumlContent (PlantumlManager::ContentMap &plantumlContent, const std::string &key, const QCString &outDir, const QCString &puContent, const QCString &srcFile, int srcLine)

Variables

static std::mutex g_PlantUmlMutex

Function Documentation

◆ addPlantumlContent()

void addPlantumlContent ( PlantumlManager::ContentMap & plantumlContent,
const std::string & key,
const QCString & outDir,
const QCString & puContent,
const QCString & srcFile,
int srcLine )
static

Definition at line 436 of file plantuml.cpp.

439{
440 auto kv = plantumlContent.find(key);
441 if (kv==plantumlContent.end())
442 {
443 kv = plantumlContent.emplace(key,PlantumlContent("",outDir,srcFile,srcLine)).first;
444 }
445 kv->second.content+=puContent;
446}

Referenced by PlantumlManager::insert().

◆ addPlantumlFiles()

void addPlantumlFiles ( PlantumlManager::FilesMap & plantumlFiles,
const std::string & key,
const std::string & value )
static

Definition at line 425 of file plantuml.cpp.

427{
428 auto kv = plantumlFiles.find(key);
429 if (kv==plantumlFiles.end())
430 {
431 kv = plantumlFiles.emplace(key,StringVector()).first;
432 }
433 kv->second.push_back(value);
434}
std::vector< std::string > StringVector
Definition containers.h:33

Referenced by PlantumlManager::insert().

◆ print() [1/2]

void print ( const PlantumlManager::ContentMap & plantumlContent)
static

Definition at line 413 of file plantuml.cpp.

414{
416 {
417 for (const auto &[key,content] : plantumlContent)
418 {
419 Debug::print(Debug::Plantuml,0,"*** PlantumlManager::print Content PlantumlContent key: {}\n",key);
420 Debug::print(Debug::Plantuml,0,"*** PlantumlManager::print Content:\n{}\n",content.content);
421 }
422 }
423}
@ Plantuml
Definition debug.h:39
static bool isFlagSet(const DebugMask mask)
Definition debug.cpp:133
static void print(DebugMask mask, int prio, fmt::format_string< Args... > fmt, Args &&... args)
Definition debug.h:77

References Debug::isFlagSet(), Debug::Plantuml, and Debug::print().

◆ print() [2/2]

void print ( const PlantumlManager::FilesMap & plantumlFiles)
static

Definition at line 398 of file plantuml.cpp.

399{
401 {
402 for (const auto &[key,list] : plantumlFiles)
403 {
404 Debug::print(Debug::Plantuml,0,"*** PlantumlManager::print Files PlantumlFiles key:{} size:{}\n",key,list.size());
405 for (const auto &s : list)
406 {
407 Debug::print(Debug::Plantuml,0,"*** PlantumlManager::print list:{}\n",s);
408 }
409 }
410 }
411}

References Debug::isFlagSet(), Debug::Plantuml, and Debug::print().

Referenced by PlantumlManager::insert().

◆ runPlantumlContent()

void runPlantumlContent ( const PlantumlManager::FilesMap & plantumlFiles,
const PlantumlManager::ContentMap & plantumlContent,
PlantumlManager::OutputFormat format )
static

Definition at line 242 of file plantuml.cpp.

245{
246 /* example : running: java -Djava.awt.headless=true
247 -jar "/usr/local/bin/plantuml.jar"
248 -o "test_doxygen/DOXYGEN_OUTPUT/html"
249 -tpng
250 "test_doxygen/DOXYGEN_OUTPUT/html/A.pu"
251 -charset UTF-8
252 outDir:test_doxygen/DOXYGEN_OUTPUT/html
253 test_doxygen/DOXYGEN_OUTPUT/html/A
254 */
255 int exitCode = 0;
256 QCString plantumlJarPath = Config_getString(PLANTUML_JAR_PATH);
257 QCString plantumlConfigFile = Config_getString(PLANTUML_CFG_FILE);
258
259 QCString pumlExe = "java";
260 QCString pumlArgs = "";
261 QCString pumlType = "";
262 QCString pumlOutDir = "";
263
264 const StringVector &pumlIncludePathList = Config_getList(PLANTUML_INCLUDE_PATH);
265 {
266 auto it = pumlIncludePathList.begin();
267 if (it!=pumlIncludePathList.end())
268 {
269 pumlArgs += "-Dplantuml.include.path=\"";
270 pumlArgs += it->c_str();
271 ++it;
272 }
273 while (it!=pumlIncludePathList.end())
274 {
275 pumlArgs += Portable::pathListSeparator();
276 pumlArgs += it->c_str();
277 ++it;
278 }
279 }
280 if (!pumlIncludePathList.empty()) pumlArgs += "\" ";
281 pumlArgs += "-Djava.awt.headless=true -jar \""+plantumlJarPath+"\" ";
282 if (!plantumlConfigFile.isEmpty())
283 {
284 pumlArgs += "-config \"";
285 pumlArgs += plantumlConfigFile;
286 pumlArgs += "\" ";
287 }
288 // the -graphvizdot option expects a relative or absolute path to the dot executable, so
289 // we need to use the unverified DOT_PATH option and check if it points to an existing file.
290 QCString dotPath = Config_getString(DOT_PATH);
291 FileInfo dp(dotPath.str());
292 if (Config_getBool(HAVE_DOT) && dp.exists() && dp.isFile())
293 {
294 pumlArgs += "-graphvizdot \"";
295 pumlArgs += dotPath;
296 pumlArgs += "\" ";
297 }
298 switch (format)
299 {
301 pumlType="png";
302 break;
304 pumlType="eps";
305 break;
307 pumlType="svg";
308 break;
309 }
310
311 {
312 for (const auto &[name,nb] : plantumlContent)
313 {
314 if (nb.content.isEmpty()) continue;
315
316 QCString pumlArguments = pumlArgs;
317 msg("Generating PlantUML {} Files in {}\n",pumlType,name);
318 pumlArguments+="-o \"";
319 pumlArguments+=nb.outDir;
320 pumlArguments+="\" ";
321 pumlArguments+="-charset UTF-8 -t";
322 pumlArguments+=pumlType;
323 pumlArguments+=" ";
324
325 QCString puFileName("");
326 puFileName+=nb.outDir;
327 puFileName+="/";
328 pumlOutDir=puFileName;
329 puFileName+="inline_umlgraph_";
330 puFileName+=pumlType;
331 puFileName+=name.c_str();
332 puFileName+=".pu";
333
334 pumlArguments+="\"";
335 pumlArguments+=puFileName;
336 pumlArguments+="\" ";
337
338
339 QCString cachedContent;
340 FileInfo fi(puFileName.str());
341 if (fi.exists())
342 {
343 cachedContent = fileToString(puFileName);
344 }
345
346 std::ofstream file = Portable::openOutputStream(puFileName);
347 if (!file.is_open())
348 {
349 err_full(nb.srcFile,nb.srcLine,"Could not open file {} for writing",puFileName);
350 }
351 file.write( nb.content.data(), nb.content.length() );
352 file.close();
353 Debug::print(Debug::Plantuml,0,"*** PlantumlManager::runPlantumlContent Running Plantuml arguments:{}\n",pumlArguments);
354
355 if (cachedContent == nb.content) continue;
356
357 if ((exitCode=Portable::system(pumlExe.data(),pumlArguments.data(),TRUE))!=0)
358 {
359 err_full(nb.srcFile,nb.srcLine,"Problems running PlantUML. Verify that the command 'java -jar \"{}\" -h' works from the command line. Exit code: {}.",
360 plantumlJarPath,exitCode);
361 }
362
363 if ( (format==PlantumlManager::PUML_EPS) && (Config_getBool(USE_PDFLATEX)) )
364 {
365 Debug::print(Debug::Plantuml,0,"*** PlantumlManager::runPlantumlContent Running epstopdf\n");
366 auto files_kv = plantumlFiles.find(name);
367 if (files_kv!=plantumlFiles.end())
368 {
369 for (const auto &str : files_kv->second)
370 {
371 const int maxCmdLine = 40960;
373 epstopdfArgs.sprintf("\"%s%s.eps\" --outfile=\"%s%s.pdf\"",
374 pumlOutDir.data(),str.c_str(), pumlOutDir.data(),str.c_str());
375 if ((exitCode=Portable::system("epstopdf",epstopdfArgs.data()))!=0)
376 {
377 err_full(nb.srcFile,nb.srcLine,"Problems running epstopdf. Check your TeX installation! Exit code: {}.",exitCode);
378 }
379 else
380 {
381 Dir().remove(pumlOutDir.str()+str+".eps");
382 }
383 }
384 }
385 }
386 }
387 }
388}
Class representing a directory in the file system.
Definition dir.h:75
bool remove(const std::string &path, bool acceptsAbsPath=true) const
Definition dir.cpp:314
Minimal replacement for QFileInfo.
Definition fileinfo.h:23
This is an alternative implementation of QCString.
Definition qcstring.h:101
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:163
const std::string & str() const
Definition qcstring.h:552
@ ExplicitSize
Definition qcstring.h:146
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
Definition qcstring.h:172
#define Config_getList(name)
Definition config.h:38
#define Config_getBool(name)
Definition config.h:33
#define Config_getString(name)
Definition config.h:32
static const int maxCmdLine
Definition dia.cpp:26
#define msg(fmt,...)
Definition message.h:94
#define err_full(file, line, fmt,...)
Definition message.h:132
std::ofstream openOutputStream(const QCString &name, bool append=false)
Definition portable.cpp:648
QCString pathListSeparator()
Definition portable.cpp:383
int system(const QCString &command, const QCString &args, bool commandHasConsole=true)
Definition portable.cpp:105
#define TRUE
Definition qcstring.h:37
QCString fileToString(const QCString &name, bool filter, bool isSourceCode)
Definition util.cpp:1494

References Config_getBool, Config_getList, Config_getString, QCString::data(), err_full, FileInfo::exists(), QCString::ExplicitSize, fileToString(), QCString::isEmpty(), FileInfo::isFile(), maxCmdLine, msg, Portable::openOutputStream(), Portable::pathListSeparator(), Debug::Plantuml, Debug::print(), PlantumlManager::PUML_BITMAP, PlantumlManager::PUML_EPS, PlantumlManager::PUML_SVG, Dir::remove(), QCString::sprintf(), QCString::str(), Portable::system(), and TRUE.

Referenced by PlantumlManager::run().

Variable Documentation

◆ g_PlantUmlMutex

std::mutex g_PlantUmlMutex
static

Definition at line 29 of file plantuml.cpp.

Referenced by PlantumlManager::generatePlantUmlFileNames().