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

475{
476 auto kv = plantumlContent.find(key);
477 if (kv==plantumlContent.end())
478 {
479 kv = plantumlContent.emplace(key,PlantumlContent("",outDir,srcFile,srcLine)).first;
480 }
481 kv->second.content+=puContent;
482}
PlantumlContent(const DString &content_, const DString &outDir_, const DString &srcFile_, int srcLine_)
Definition plantuml.h:30

References addPlantumlContent(), and PlantumlContent::PlantumlContent().

Referenced by addPlantumlContent(), and PlantumlManager::insert().

◆ addPlantumlFiles()

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

Definition at line 461 of file plantuml.cpp.

463{
464 auto kv = plantumlFiles.find(key);
465 if (kv==plantumlFiles.end())
466 {
467 kv = plantumlFiles.emplace(key,StringVector()).first;
468 }
469 kv->second.push_back(value);
470}
std::vector< std::string > StringVector
Definition containers.h:33

References addPlantumlFiles().

Referenced by addPlantumlFiles(), and PlantumlManager::insert().

◆ javaExecutable()

DString javaExecutable ( )
static

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

Definition at line 247 of file plantuml.cpp.

248{
249 DString javaPath = Config_getString(PLANTUML_JAVA_PATH);
250 if (!javaPath.empty()) return javaPath;
251 DString javaHome = Portable::getenv("JAVA_HOME");
252 if (!javaHome.empty())
253 {
254 DString javaHomeExe = javaHome+"/bin/java"+Portable::commandExtension();
255 FileInfo fi(javaHomeExe.str());
256 if (fi.exists() && fi.isFile()) return javaHomeExe;
257 }
258 return "java";
259}
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition dstring.h:88
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:152
const std::string & str() const
Definition dstring.h:649
Minimal replacement for QFileInfo.
Definition fileinfo.h:26
#define Config_getString(name)
Definition config.h:32
DString getenv(const DString &variable)
Definition portable.cpp:321
const char * commandExtension()
Definition portable.cpp:461

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

Referenced by javaExecutable(), and runPlantumlContent().

◆ print() [1/2]

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

Definition at line 449 of file plantuml.cpp.

450{
452 {
453 for (const auto &[key,content] : plantumlContent)
454 {
455 Debug::print(Debug::Plantuml,0,"*** PlantumlManager::print Content PlantumlContent key: {}\n",key);
456 Debug::print(Debug::Plantuml,0,"*** PlantumlManager::print Content:\n{}\n",content.content);
457 }
458 }
459}
@ Plantuml
Definition debug.h:40
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:78

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

◆ print() [2/2]

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

Definition at line 434 of file plantuml.cpp.

435{
437 {
438 for (const auto &[key,list] : plantumlFiles)
439 {
440 Debug::print(Debug::Plantuml,0,"*** PlantumlManager::print Files PlantumlFiles key:{} size:{}\n",key,list.size());
441 for (const auto &s : list)
442 {
443 Debug::print(Debug::Plantuml,0,"*** PlantumlManager::print list:{}\n",s);
444 }
445 }
446 }
447}

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

Referenced by PlantumlManager::insert(), print(), and print().

◆ runPlantumlContent()

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

Definition at line 261 of file plantuml.cpp.

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

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

Referenced by PlantumlManager::run(), and runPlantumlContent().

Variable Documentation

◆ g_PlantUmlMutex

std::mutex g_PlantUmlMutex
static

Definition at line 29 of file plantuml.cpp.

Referenced by PlantumlManager::generatePlantUmlFileNames().