From 2ab508e1cd5e61b152ce518d79b95ac3a98bbeaf Mon Sep 17 00:00:00 2001 From: Alexander Artemenko Date: Sun, 5 Jan 2025 08:58:54 +0000 Subject: [PATCH 1/2] Use a PlantUML installed by package manager, if it is available. --- docs/changelog.lisp | 5 ++- src/core.lisp | 90 +++++++++++++++++++++++++++------------------ 2 files changed, 58 insertions(+), 37 deletions(-) diff --git a/docs/changelog.lisp b/docs/changelog.lisp index be15664..d11a1be 100644 --- a/docs/changelog.lisp +++ b/docs/changelog.lisp @@ -8,6 +8,9 @@ (defchangelog (:ignore-words ("SLY" "ASDF" "REPL" + "PlantUML" "HTTP")) - (0.1.0 2023-02-05 + (0.2.0 2025-01-05 + "* Use a `PlantUML` installed by package manager, if it is available.") + (0.1.0 2025-01-04 "* Initial version.")) diff --git a/src/core.lisp b/src/core.lisp index 939f9ed..9c177f9 100644 --- a/src/core.lisp +++ b/src/core.lisp @@ -44,40 +44,58 @@ (defun render (diagram-code output-filename) - (unless *path-to-jar* - (error "Please, set 40ants-plantuml:*path-to-jar* variable.")) - - (unless (probe-file *path-to-jar*) - (error "Variable 40ants-plantuml:*path-to-jar* points to ~S which can't be found." - *path-to-jar*)) - - (when (and *path-to-graphviz* - (not (probe-file *path-to-graphviz*))) - (error "Variable 40ants-plantuml:*path-to-graphviz* points to ~S which can't be found." - *path-to-graphviz*)) + (let ((path-to-jar + (cond + ((null *path-to-jar*) + (let ((system-jar + (probe-file "/usr/share/plantuml/plantuml.jar"))) + (cond + (system-jar + system-jar) + (t + (error "Please, set 40ants-plantuml:*path-to-jar* variable or do \"apt install plantuml\"."))))) + ((probe-file *path-to-jar*) + (probe-file *path-to-jar*)) + (t + (error "Variable 40ants-plantuml:*path-to-jar* points to ~S which can't be found." + *path-to-jar*)))) + (path-to-graphviz + (when *path-to-graphviz* + (cond + ((probe-file *path-to-graphviz*) + ;; We should not use result of PROBE-FILE + ;; here because it can resolve /usr/bin/dot + ;; to /usr/sbin/libgvc6-config-update and + ;; graphviz will work incorrectly when used like this. + *path-to-graphviz*) + (t + (error "Variable 40ants-plantuml:*path-to-graphviz* points to ~S which can't be found." + *path-to-graphviz*)))))) - (with-input-from-string (input-stream diagram-code) - (uiop:with-output-file (output-stream output-filename - :if-exists :supersede - :element-type '(unsigned-byte 8)) - (let ((error-stream (make-string-output-stream))) - (handler-bind ((uiop:subprocess-error - (lambda (err) - (error 'plantuml-error - :exit-code (uiop:subprocess-error-code err) - :error-message (string-right-trim '(#\Space #\Newline) - (get-output-stream-string error-stream)))))) - (uiop:run-program (append - (list "java" - "-jar" - (namestring - (probe-file *path-to-jar*)) - "-pipe") - (when *path-to-graphviz* - (list "-graphvizdot" - *path-to-graphviz*))) - :input input-stream - :output output-stream - :error-output error-stream))) - ;; (values) - ))) + (with-input-from-string (input-stream diagram-code) + (uiop:with-output-file (output-stream output-filename + :if-exists :supersede + :element-type '(unsigned-byte 8)) + (let ((error-stream (make-string-output-stream))) + (handler-bind ((uiop:subprocess-error + (lambda (err) + (error 'plantuml-error + :exit-code (uiop:subprocess-error-code err) + :error-message (string-right-trim '(#\Space #\Newline) + (get-output-stream-string error-stream)))))) + (let ((command-line + (append + (list "java" + "-jar" + (namestring + (probe-file path-to-jar)) + "-pipe") + (when path-to-graphviz + (list "-graphvizdot" + (namestring + path-to-graphviz)))))) + (uiop:run-program command-line + :input input-stream + :output output-stream + :error-output error-stream)))) + (values))))) From a5d2b8e76fc9c0c2ea610101d64a0661f2c78e0c Mon Sep 17 00:00:00 2001 From: Alexander Artemenko Date: Sun, 5 Jan 2025 09:03:26 +0000 Subject: [PATCH 2/2] A note on path-to-jar. --- src/core.lisp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/core.lisp b/src/core.lisp index 9c177f9..61cf78c 100644 --- a/src/core.lisp +++ b/src/core.lisp @@ -16,7 +16,11 @@ (defvar *path-to-jar* nil - "Set this variable to a path to the plantuml.jar. Note, there are different builds of plantuml with different licensing.") + "Set this variable to a path to the plantuml.jar. Note, there are different builds of plantuml with different licensing. + + If this variable is NIL, then /usr/share/plantuml/plantuml.jar will be used if it is exists. On Ubuntu this file + is created when use do `apt install plantuml`. Note, the version of the `PlantUML` in the Ubuntu package could be outdated + and missing some important features.") (defvar *path-to-graphviz*