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

Go to the source code of this file.

Functions

static DString javaExecutable ()
 Returns the java executable used to run the PlantUML jar file.
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 DString &outDir, const DString &puContent, const DString &srcFile, int srcLine)

Variables

static std::mutex g_PlantUmlMutex

Function Documentation

◆ addPlantumlContent()

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

Definition at line 478 of file plantuml.cpp.

481{
482 auto kv = plantumlContent.find(key);
483 if (kv==plantumlContent.end())
484 {
485 kv = plantumlContent.emplace(key,PlantumlContent("",outDir,srcFile,srcLine)).first;
486 }
487 kv->second.content+=puContent;
488}

Referenced by PlantumlManager::insert().

◆ addPlantumlFiles()

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

Definition at line 467 of file plantuml.cpp.

469{
470 auto kv = plantumlFiles.find(key);
471 if (kv==plantumlFiles.end())
472 {
473 kv = plantumlFiles.emplace(key,StringVector()).first;
474 }
475 kv->second.push_back(value);
476}
std::vector< std::string > StringVector
Definition containers.h:33

Referenced by PlantumlManager::insert().

◆ javaExecutable()

DString javaExecutable ( )
static

Returns the java executable used to run the PlantUML jar file.

Definition at line 253 of file plantuml.cpp.

254{
255 DString javaPath = Config_getString(PLANTUML_JAVA_PATH);
256 if (!javaPath.empty()) return javaPath;
257 DString javaHome = Portable::getenv("JAVA_HOME");
258 if (!javaHome.empty())
259 {
260 DString javaHomeExe = javaHome+"/bin/java"+Portable::commandExtension();
261 FileInfo fi(javaHomeExe.str());
262 if (fi.exists() && fi.isFile()) return javaHomeExe;
263 }
264 return "java";
265}
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition dstring.h:84
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:148
const std::string & str() const
Definition dstring.h:645
Minimal replacement for QFileInfo.
Definition fileinfo.h:26
#define Config_getString(name)
Definition config.h:32
DString getenv(const DString &variable)
Definition portable.cpp:337
const char * commandExtension()
Definition portable.cpp:477

References Portable::commandExtension(), Config_getString, DString::empty(), FileInfo::exists(), Portable::getenv(), FileInfo::isFile(), and DString::str().

Referenced by runPlantumlContent().

◆ print() [1/2]

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

Definition at line 455 of file plantuml.cpp.

456{
458 {
459 for (const auto &[key,content] : plantumlContent)
460 {
461 Debug::print(Debug::Plantuml,0,"*** PlantumlManager::print Content PlantumlContent key: {}\n",key);
462 Debug::print(Debug::Plantuml,0,"*** PlantumlManager::print Content:\n{}\n",content.content);
463 }
464 }
465}
@ Plantuml
Definition debug.h:40
static bool isFlagSet(const DebugMask mask)
Definition debug.cpp:132
static void print(DebugMask mask, int prio, fmt::format_string< Args... > fmt, Args &&... args)
Definition debug.h:78

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

◆ print() [2/2]

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

Definition at line 440 of file plantuml.cpp.

441{
443 {
444 for (const auto &[key,list] : plantumlFiles)
445 {
446 Debug::print(Debug::Plantuml,0,"*** PlantumlManager::print Files PlantumlFiles key:{} size:{}\n",key,list.size());
447 for (const auto &s : list)
448 {
449 Debug::print(Debug::Plantuml,0,"*** PlantumlManager::print list:{}\n",s);
450 }
451 }
452 }
453}

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 267 of file plantuml.cpp.

270{
271 /* example : running: java -Djava.awt.headless=true
272 -jar "/usr/local/bin/plantuml.jar"
273 -o "test_doxygen/DOXYGEN_OUTPUT/html"
274 -tpng
275 "test_doxygen/DOXYGEN_OUTPUT/html/A.pu"
276 -charset UTF-8
277 outDir:test_doxygen/DOXYGEN_OUTPUT/html
278 test_doxygen/DOXYGEN_OUTPUT/html/A
279 */
280 int exitCode = 0;
281 DString plantumlJarPath = Config_getString(PLANTUML_JAR_PATH);
282 DString plantumlConfigFile = Config_getString(PLANTUML_CFG_FILE);
283 DString plantumlTool = Config_getString(PLANTUML_TOOL);
284 bool useJar = plantumlTool.empty(); // no PlantUML executable given, so run the jar file via java
285
286 DString pumlExe = useJar ? javaExecutable() : plantumlTool;
287 DString pumlArgs = "";
288 DString pumlType = "";
289 DString pumlOutDir = "";
290
291 StringVector pumlIncludePathList = Config_getList(PLANTUML_INCLUDE_PATH);
292 if (useJar)
293 {
294 auto it = pumlIncludePathList.begin();
295 if (it!=pumlIncludePathList.end())
296 {
297 pumlArgs += "-Dplantuml.include.path=\"";
298 pumlArgs += it->c_str();
299 ++it;
300 }
301 while (it!=pumlIncludePathList.end())
302 {
303 pumlArgs += Portable::pathListSeparator();
304 pumlArgs += it->c_str();
305 ++it;
306 }
307 if (!pumlIncludePathList.empty()) pumlArgs += "\" ";
308 pumlArgs += "-Djava.awt.headless=true -jar \""+plantumlJarPath+"\" ";
309 }
310 else if (!pumlIncludePathList.empty())
311 {
312 // a PlantUML executable does not take java system properties, but PlantUML also
313 // accepts the include path via the environment.
314 DString includePath;
315 bool first = true;
316 for (const auto &path : pumlIncludePathList)
317 {
318 if (!first) includePath += Portable::pathListSeparator();
319 includePath += path.c_str();
320 first = false;
321 }
322 Portable::setenv("PLANTUML_INCLUDE_PATH",includePath);
323 }
324 if (!plantumlConfigFile.empty())
325 {
326 pumlArgs += "-config \"";
327 pumlArgs += plantumlConfigFile;
328 pumlArgs += "\" ";
329 }
330 // the -graphvizdot option expects a relative or absolute path to the dot executable, so
331 // we need to use the unverified DOT_PATH option and check if it points to an existing file.
332 DString dotPath = Config_getString(DOT_PATH);
333 FileInfo dp(dotPath.str());
334 if (Config_getBool(HAVE_DOT) && dp.exists() && dp.isFile())
335 {
336 pumlArgs += "-graphvizdot \"";
337 pumlArgs += dotPath;
338 pumlArgs += "\" ";
339 }
340 switch (format)
341 {
343 pumlType="png";
344 break;
346 pumlType="eps";
347 break;
349 pumlType="svg";
350 break;
351 }
352
353 {
354 for (const auto &[name,nb] : plantumlContent)
355 {
356 if (nb.content.empty()) continue;
357
358 DString pumlArguments = pumlArgs;
359 msg("Generating PlantUML {} Files in {}\n",pumlType,name);
360 pumlArguments+="-o \"";
361 pumlArguments+=nb.outDir;
362 pumlArguments+="\" ";
363 pumlArguments+="-charset UTF-8 -t";
364 pumlArguments+=pumlType;
365 pumlArguments+=" ";
366
367 DString puFileName("");
368 puFileName+=nb.outDir;
369 puFileName+="/";
370 pumlOutDir=puFileName;
371 puFileName+="inline_umlgraph_";
372 puFileName+=pumlType;
373 puFileName+=name.c_str();
374 puFileName+=".pu";
375
376 pumlArguments+="\"";
377 pumlArguments+=puFileName;
378 pumlArguments+="\" ";
379
380
381 DString cachedContent;
382 FileInfo fi(puFileName.str());
383 if (fi.exists())
384 {
385 cachedContent = fileToString(puFileName);
386 }
387
388 std::ofstream file = Portable::openOutputStream(puFileName);
389 if (!file.is_open())
390 {
391 err_full(nb.srcFile,nb.srcLine,"Could not open file {} for writing",puFileName);
392 }
393 file.write( nb.content.data(), nb.content.length() );
394 file.close();
395 Debug::print(Debug::Plantuml,0,"*** PlantumlManager::runPlantumlContent Running Plantuml arguments:{}\n",pumlArguments);
396
397 if (cachedContent == nb.content) continue;
398
399 if ((exitCode=Portable::system(pumlExe.data(),pumlArguments.data(),true))!=0)
400 {
401 err_full(nb.srcFile,nb.srcLine,"Problems running PlantUML. Verify that the command '{} -h' works from the command line. Exit code: {}.",
402 useJar ? pumlExe+" -jar \""+plantumlJarPath+"\"" : pumlExe,exitCode);
403 }
404
405 if ( (format==PlantumlManager::PUML_EPS) && (Config_getBool(USE_PDFLATEX)) )
406 {
407 Debug::print(Debug::Plantuml,0,"*** PlantumlManager::runPlantumlContent Running epstopdf\n");
408 auto files_kv = plantumlFiles.find(name);
409 if (files_kv!=plantumlFiles.end())
410 {
411 for (const auto &str : files_kv->second)
412 {
413 const int maxCmdLine = 40960;
415 epstopdfArgs.sprintf("\"%s%s.eps\" --outfile=\"%s%s.pdf\"",
416 pumlOutDir.data(),str.c_str(), pumlOutDir.data(),str.c_str());
417 if ((exitCode=Portable::system("epstopdf",epstopdfArgs.data()))!=0)
418 {
419 err_full(nb.srcFile,nb.srcLine,"Problems running epstopdf. Check your TeX installation! Exit code: {}.",exitCode);
420 }
421 else
422 {
423 Dir().remove(pumlOutDir.str()+str+".eps");
424 }
425 }
426 }
427 }
428 }
429 }
430}
const char * c_str() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
Definition dstring.h:160
@ ExplicitSize
Definition dstring.h:131
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
Definition dstring.h:157
Class representing a directory in the file system.
Definition dir.h:73
bool remove(const std::string &path, bool acceptsAbsPath=true) const
Definition dir.cpp:320
#define Config_getList(name)
Definition config.h:38
#define Config_getBool(name)
Definition config.h:33
static const int maxCmdLine
Definition dia.cpp:27
#define msg(fmt,...)
Definition message.h:94
#define err_full(file, line, fmt,...)
Definition message.h:132
void setenv(const DString &variable, const DString &value)
Definition portable.cpp:302
int system(const DString &command, const DString &args, bool commandHasConsole=true)
Definition portable.cpp:121
DString pathListSeparator()
Definition portable.cpp:399
std::ofstream openOutputStream(const DString &name, bool append=false)
Definition portable.cpp:681
static DString javaExecutable()
Returns the java executable used to run the PlantUML jar file.
Definition plantuml.cpp:253
DString fileToString(const DString &name, bool filter, bool isSourceCode)
Definition util.cpp:1053

References DString::c_str(), Config_getBool, Config_getList, Config_getString, DString::data(), DString::empty(), err_full, FileInfo::exists(), DString::ExplicitSize, fileToString(), FileInfo::isFile(), javaExecutable(), msg, Portable::openOutputStream(), Portable::pathListSeparator(), Debug::Plantuml, Debug::print(), PlantumlManager::PUML_BITMAP, PlantumlManager::PUML_EPS, PlantumlManager::PUML_SVG, Dir::remove(), Portable::setenv(), DString::sprintf(), DString::str(), and Portable::system().

Referenced by PlantumlManager::run().

Variable Documentation

◆ g_PlantUmlMutex

std::mutex g_PlantUmlMutex
static

Definition at line 35 of file plantuml.cpp.

Referenced by PlantumlManager::generatePlantUmlFileNames().