Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a PlantUML installed by package manager, if it is available. #1

Merged
merged 2 commits into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docs/changelog.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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."))
96 changes: 59 additions & 37 deletions src/core.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down Expand Up @@ -44,40 +48,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)))))
Loading