Blame src/plantuml.cpp

Packit Service 50c9f2
/******************************************************************************
Packit Service 50c9f2
 *
Packit Service 50c9f2
 * Copyright (C) 1997-2015 by Dimitri van Heesch.
Packit Service 50c9f2
 *
Packit Service 50c9f2
 * Permission to use, copy, modify, and distribute this software and its
Packit Service 50c9f2
 * documentation under the terms of the GNU General Public License is hereby
Packit Service 50c9f2
 * granted. No representations are made about the suitability of this software
Packit Service 50c9f2
 * for any purpose. It is provided "as is" without express or implied warranty.
Packit Service 50c9f2
 * See the GNU General Public License for more details.
Packit Service 50c9f2
 *
Packit Service 50c9f2
 * Documents produced by Doxygen are derivative works derived from the
Packit Service 50c9f2
 * input used in their production; they are not affected by this license.
Packit Service 50c9f2
 *
Packit Service 50c9f2
 */
Packit Service 50c9f2
Packit Service 50c9f2
#include "plantuml.h"
Packit Service 50c9f2
#include "portable.h"
Packit Service 50c9f2
#include "config.h"
Packit Service 50c9f2
#include "doxygen.h"
Packit Service 50c9f2
#include "index.h"
Packit Service 50c9f2
#include "message.h"
Packit Service 50c9f2
Packit Service 50c9f2
#include <qdir.h>
Packit Service 50c9f2
Packit Service 50c9f2
static const int maxCmdLine = 40960;
Packit Service 50c9f2
Packit Service 50c9f2
QCString writePlantUMLSource(const QCString &outDir,const QCString &fileName,const QCString &content)
Packit Service 50c9f2
{
Packit Service 50c9f2
  QCString baseName(4096);
Packit Service 50c9f2
  static int umlindex=1;
Packit Service 50c9f2
Packit Service 50c9f2
  if (fileName.isEmpty()) // generate name
Packit Service 50c9f2
  {
Packit Service 50c9f2
    baseName = outDir+"/inline_umlgraph_"+QCString().setNum(umlindex++);
Packit Service 50c9f2
  }
Packit Service 50c9f2
  else // user specified name
Packit Service 50c9f2
  {
Packit Service 50c9f2
    baseName = fileName;
Packit Service 50c9f2
    int i=baseName.findRev('.');
Packit Service 50c9f2
    if (i!=-1) baseName = baseName.left(i);
Packit Service 50c9f2
    baseName.prepend(outDir+"/");
Packit Service 50c9f2
  }
Packit Service 50c9f2
  QFile file(baseName+".pu");
Packit Service 50c9f2
  if (!file.open(IO_WriteOnly))
Packit Service 50c9f2
  {
Packit Service 50c9f2
    err("Could not open file %s for writing\n",baseName.data());
Packit Service 50c9f2
  }
Packit Service 50c9f2
  QCString text = "@startuml\n";
Packit Service 50c9f2
  text+=content;
Packit Service 50c9f2
  text+="@enduml\n";
Packit Service 50c9f2
  file.writeBlock( text, text.length() );
Packit Service 50c9f2
  file.close();
Packit Service 50c9f2
  return baseName;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
void generatePlantUMLOutput(const char *baseName,const char *outDir,PlantUMLOutputFormat format)
Packit Service 50c9f2
{
Packit Service 50c9f2
  static QCString plantumlJarPath = Config_getString(PLANTUML_JAR_PATH);
Packit Service 50c9f2
  static QCString plantumlConfigFile = Config_getString(PLANTUML_CFG_FILE);
Packit Service 50c9f2
  static QCString dotPath = Config_getString(DOT_PATH);
Packit Service 50c9f2
Packit Service 50c9f2
  QCString pumlExe = "java";
Packit Service 50c9f2
  QCString pumlArgs = "";
Packit Service 50c9f2
Packit Service 50c9f2
  QStrList &pumlIncludePathList = Config_getList(PLANTUML_INCLUDE_PATH);
Packit Service 50c9f2
  char *s=pumlIncludePathList.first();
Packit Service 50c9f2
  if (s)
Packit Service 50c9f2
  {
Packit Service 50c9f2
    pumlArgs += "-Dplantuml.include.path=\"";
Packit Service 50c9f2
    pumlArgs += s;
Packit Service 50c9f2
    s = pumlIncludePathList.next(); 
Packit Service 50c9f2
  }
Packit Service 50c9f2
  while (s)
Packit Service 50c9f2
  {
Packit Service 50c9f2
    pumlArgs += portable_pathListSeparator();
Packit Service 50c9f2
    pumlArgs += s;
Packit Service 50c9f2
    s = pumlIncludePathList.next(); 
Packit Service 50c9f2
  }
Packit Service 50c9f2
  if (pumlIncludePathList.first()) pumlArgs += "\" ";
Packit Service 50c9f2
  pumlArgs += "-Djava.awt.headless=true -jar \""+plantumlJarPath+"plantuml.jar\" ";
Packit Service 50c9f2
  if (!plantumlConfigFile.isEmpty())
Packit Service 50c9f2
  {
Packit Service 50c9f2
    pumlArgs += "-config \"";
Packit Service 50c9f2
    pumlArgs += plantumlConfigFile;
Packit Service 50c9f2
    pumlArgs += "\" ";
Packit Service 50c9f2
  }
Packit Service 50c9f2
  if (Config_getBool(HAVE_DOT) && !dotPath.isEmpty())
Packit Service 50c9f2
  {
Packit Service 50c9f2
    pumlArgs += "-graphvizdot \"";
Packit Service 50c9f2
    pumlArgs += dotPath;
Packit Service 50c9f2
    pumlArgs += "dot\" ";
Packit Service 50c9f2
  }
Packit Service 50c9f2
  pumlArgs+="-o \"";
Packit Service 50c9f2
  pumlArgs+=outDir;
Packit Service 50c9f2
  pumlArgs+="\" ";
Packit Service 50c9f2
  QCString imgName = baseName;
Packit Service 50c9f2
  // The basename contains path, we need to strip the path from the filename in order
Packit Service 50c9f2
  // to create the image file name which should be included in the index.qhp (Qt help index file).
Packit Service 50c9f2
  int i;
Packit Service 50c9f2
  if ((i=imgName.findRev('/'))!=-1) // strip path
Packit Service 50c9f2
  {
Packit Service 50c9f2
    imgName=imgName.right(imgName.length()-i-1);
Packit Service 50c9f2
  }
Packit Service 50c9f2
  switch (format)
Packit Service 50c9f2
  {
Packit Service 50c9f2
    case PUML_BITMAP:
Packit Service 50c9f2
      pumlArgs+="-tpng";
Packit Service 50c9f2
      imgName+=".png";
Packit Service 50c9f2
      break;
Packit Service 50c9f2
    case PUML_EPS:
Packit Service 50c9f2
      pumlArgs+="-teps";
Packit Service 50c9f2
      imgName+=".eps";
Packit Service 50c9f2
      break;
Packit Service 50c9f2
    case PUML_SVG:
Packit Service 50c9f2
      pumlArgs+="-tsvg";
Packit Service 50c9f2
      imgName+=".svg";
Packit Service 50c9f2
      break;
Packit Service 50c9f2
  }
Packit Service 50c9f2
  pumlArgs+=" \"";
Packit Service 50c9f2
  pumlArgs+=baseName;
Packit Service 50c9f2
  pumlArgs+=".pu\" ";
Packit Service 50c9f2
  pumlArgs+="-charset UTF-8 ";
Packit Service 50c9f2
  int exitCode;
Packit Service 50c9f2
  //printf("*** running: %s %s outDir:%s %s\n",pumlExe.data(),pumlArgs.data(),outDir,baseName);
Packit Service 50c9f2
  msg("Running PlantUML on generated file %s.pu\n",baseName);
Packit Service 50c9f2
  portable_sysTimerStart();
Packit Service 50c9f2
  if ((exitCode=portable_system(pumlExe,pumlArgs,TRUE))!=0)
Packit Service 50c9f2
  {
Packit Service 50c9f2
    err("Problems running PlantUML. Verify that the command 'java -jar \"%splantuml.jar\" -h' works from the command line. Exit code: %d\n",
Packit Service 50c9f2
        plantumlJarPath.data(),exitCode);
Packit Service 50c9f2
  }
Packit Service 50c9f2
  else if (Config_getBool(DOT_CLEANUP))
Packit Service 50c9f2
  {
Packit Service 50c9f2
    QFile(QCString(baseName)+".pu").remove();
Packit Service 50c9f2
  }
Packit Service 50c9f2
  portable_sysTimerStop();
Packit Service 50c9f2
  if ( (format==PUML_EPS) && (Config_getBool(USE_PDFLATEX)) )
Packit Service 50c9f2
  {
Packit Service 50c9f2
    QCString epstopdfArgs(maxCmdLine);
Packit Service 50c9f2
    epstopdfArgs.sprintf("\"%s.eps\" --outfile=\"%s.pdf\"",baseName,baseName);
Packit Service 50c9f2
    portable_sysTimerStart();
Packit Service 50c9f2
    if ((exitCode=portable_system("epstopdf",epstopdfArgs))!=0)
Packit Service 50c9f2
    {
Packit Service 50c9f2
      err("Problems running epstopdf. Check your TeX installation! Exit code: %d\n",exitCode);
Packit Service 50c9f2
    }
Packit Service 50c9f2
    portable_sysTimerStop();
Packit Service 50c9f2
  }
Packit Service 50c9f2
  Doxygen::indexList->addImageFile(imgName);
Packit Service 50c9f2
}
Packit Service 50c9f2