add plantuml_cmd config for custom command

This commit is contained in:
Le Tan 2018-05-07 08:51:24 +08:00
parent 966d9fb7d7
commit 39a8bae529
5 changed files with 42 additions and 8 deletions

View File

@ -285,6 +285,13 @@ plantuml_jar=
; Double quotes to enclose arguments with spaces ; Double quotes to enclose arguments with spaces
plantuml_args= plantuml_args=
; Custom PlantUML command to execute to convert a PlantUML diagram in local PlantUML
; Read data definition from stdin and output diagram result to stdout
; When set, other local PlantUML related settings are ignored
; %0 will be replaced with the format string like svg or png
; plantuml_cmd=/bin/sh -c \"cat | java -jar /opt/plantuml/plantuml.jar -charset UTF-8 -nbthread 4 -pipe -t%0\"
plantuml_cmd=
; Graphviz Dot location ; Graphviz Dot location
graphviz_dot= graphviz_dot=

View File

@ -292,6 +292,8 @@ void VConfigManager::initialize()
QString plantUMLArgs = getConfigFromSettings("web", "plantuml_args").toString(); QString plantUMLArgs = getConfigFromSettings("web", "plantuml_args").toString();
m_plantUMLArgs = VUtils::parseCombinedArgString(plantUMLArgs); m_plantUMLArgs = VUtils::parseCombinedArgString(plantUMLArgs);
m_plantUMLCmd = getConfigFromSettings("web", "plantuml_cmd").toString();
m_enableGraphviz = getConfigFromSettings("global", "enable_graphviz").toBool(); m_enableGraphviz = getConfigFromSettings("global", "enable_graphviz").toBool();
m_graphvizDot = getConfigFromSettings("web", "graphviz_dot").toString(); m_graphvizDot = getConfigFromSettings("web", "graphviz_dot").toString();
} }

View File

@ -479,6 +479,7 @@ public:
void setPlantUMLJar(const QString &p_jarPath); void setPlantUMLJar(const QString &p_jarPath);
const QStringList &getPlantUMLArgs() const; const QStringList &getPlantUMLArgs() const;
const QString &getPlantUMLCmd() const;
const QString &getGraphvizDot() const; const QString &getGraphvizDot() const;
void setGraphvizDot(const QString &p_dotPath); void setGraphvizDot(const QString &p_dotPath);
@ -892,6 +893,8 @@ private:
QStringList m_plantUMLArgs; QStringList m_plantUMLArgs;
QString m_plantUMLCmd;
// The name of the config file in each directory, obsolete. // The name of the config file in each directory, obsolete.
// Use c_dirConfigFile instead. // Use c_dirConfigFile instead.
static const QString c_obsoleteDirConfigFile; static const QString c_obsoleteDirConfigFile;
@ -2288,6 +2291,11 @@ inline const QStringList &VConfigManager::getPlantUMLArgs() const
return m_plantUMLArgs; return m_plantUMLArgs;
} }
inline const QString &VConfigManager::getPlantUMLCmd() const
{
return m_plantUMLCmd;
}
inline const QString &VConfigManager::getGraphvizDot() const inline const QString &VConfigManager::getGraphvizDot() const
{ {
return m_graphvizDot; return m_graphvizDot;

View File

@ -14,7 +14,7 @@ extern VConfigManager *g_config;
VPlantUMLHelper::VPlantUMLHelper(QObject *p_parent) VPlantUMLHelper::VPlantUMLHelper(QObject *p_parent)
: QObject(p_parent) : QObject(p_parent)
{ {
prepareCommand(m_program, m_args); prepareCommand(m_customCmd, m_program, m_args);
} }
void VPlantUMLHelper::processAsync(int p_id, void VPlantUMLHelper::processAsync(int p_id,
@ -29,12 +29,18 @@ void VPlantUMLHelper::processAsync(int p_id,
connect(process, SIGNAL(finished(int, QProcess::ExitStatus)), connect(process, SIGNAL(finished(int, QProcess::ExitStatus)),
this, SLOT(handleProcessFinished(int, QProcess::ExitStatus))); this, SLOT(handleProcessFinished(int, QProcess::ExitStatus)));
if (m_customCmd.isEmpty()) {
QStringList args(m_args); QStringList args(m_args);
args << ("-t" + p_format); args << ("-t" + p_format);
qDebug() << m_program << args; qDebug() << m_program << args;
process->start(m_program, args); process->start(m_program, args);
} else {
QString cmd(m_customCmd);
cmd.replace("%0", p_format);
qDebug() << cmd;
process->start(cmd);
}
if (process->write(p_text.toUtf8()) == -1) { if (process->write(p_text.toUtf8()) == -1) {
qWarning() << "fail to write to QProcess:" << process->errorString(); qWarning() << "fail to write to QProcess:" << process->errorString();
} }
@ -42,8 +48,15 @@ void VPlantUMLHelper::processAsync(int p_id,
process->closeWriteChannel(); process->closeWriteChannel();
} }
void VPlantUMLHelper::prepareCommand(QString &p_program, QStringList &p_args) const void VPlantUMLHelper::prepareCommand(QString &p_customCmd,
QString &p_program,
QStringList &p_args) const
{ {
p_customCmd = g_config->getPlantUMLCmd();
if (!p_customCmd.isEmpty()) {
return;
}
p_program = "java"; p_program = "java";
p_args << "-jar" << g_config->getPlantUMLJar(); p_args << "-jar" << g_config->getPlantUMLJar();

View File

@ -19,7 +19,7 @@ public:
const QString &p_format, const QString &p_format,
const QString &p_text); const QString &p_text);
void prepareCommand(QString &p_cmd, QStringList &p_args) const; void prepareCommand(QString &p_customCmd, QString &p_cmd, QStringList &p_args) const;
signals: signals:
void resultReady(int p_id, TimeStamp p_timeStamp, const QString &p_format, const QString &p_result); void resultReady(int p_id, TimeStamp p_timeStamp, const QString &p_format, const QString &p_result);
@ -29,7 +29,11 @@ private slots:
private: private:
QString m_program; QString m_program;
QStringList m_args; QStringList m_args;
// When not empty, @m_program and @m_args will be ignored.
QString m_customCmd;
}; };
#endif // VPLANTUMLHELPER_H #endif // VPLANTUMLHELPER_H