asciidoctor / asciidoctor-diagram

:left_right_arrow: Asciidoctor diagram extension, with support for AsciiToSVG, BlockDiag (BlockDiag, SeqDiag, ActDiag, NwDiag), Ditaa, Erd, GraphViz, Mermaid, Msc, PlantUML, Shaape, SvgBob, Syntrax, UMLet, Vega, Vega-Lite and WaveDrom.
http://asciidoctor.org
MIT License
431 stars 106 forks source link

Structurizr DSL include file is not working #449

Closed cachescrubber closed 5 months ago

cachescrubber commented 6 months ago

Structurizr DSL include file is not working

Using the !include feature of the Structurizr DSL does not work as expected:

Failed to generate image: PlantUML preprocessing failed: [From <input> (line 2) ]

@startuml
Failed to generate image: Structurizr code generation failed: com.structurizr.dsl.StructurizrDslParserException: /Users/ ...
^^^^^
 Syntax Error?

Failed to generate image: Structurizr code generation failed: com.structurizr.dsl.StructurizrDslParserException: /Users/lars/Scratch/catalog.dsl could not be found at line 1 of /Users/lars/Scratch/asciidoctor-diagram-structurizr-include/.: workspace extends ../catalog.dsl {
workspace extends ../catalog.dsl {

Steps to reproduce

I prepared an example project demonstrating the issue.

https://github.com/cachescrubber/asciidoctor-diagram-structurizr-include

Open the file src/main/asciidoc/system-catalog/dsl/preview.adoc.

Using the strucurizr-cli is working as expected:

# structurizr-cli validate -w src/main/asciidoc/system-catalog/dsl/system-landscape/workspace.dsl

Environment

Plugin Version: 0.41.4

IntelliJ Details: IntelliJ IDEA 2023.3.1 (Ultimate Edition) Build #IU-233.11799.300, built on December 12, 2023 Runtime version: 17.0.9+7-b1087.7 aarch64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. macOS 14.2 org.asciidoctor.intellij.asciidoc (0.41.4)

cachescrubber commented 6 months ago

I had a closer look and most likely the issue is in between the asciidoctor-diagram / asciidoctor-diagram-java repos. Is it possible to transfer the issue? Just let me know, I'll close and re-open otherwise.

ahus1 commented 6 months ago

If the person has write (admin?) permissions in both projects, this is possible. As I don't have those permissions in the target project, please re-open an issue in the target repository.

mojavelinux commented 6 months ago

I can take care of it.

cachescrubber commented 6 months ago

Further analysis after reading asciidoctor-diagram, asciidoctor-diagram-java and structurizr-dsl source:

The contents of a workspace dsl fragment embedded in an asciidoc is passed as a String:

org.asciidoctor.diagram.structurizr.Structurizr#parseWorkspace is using com.structurizr.dsl.StructurizrDslParser#parse(java.lang.String).

structurizr-dsl is referencing include files relative to the filename of a workspace.dsl file, which does not exists in this case. There is code prepared in asciidoctor-diagram-java to support an X-Structurizr-IncludeDir but structurizr-dsl lacks a public method to pass in a include-directory. So a solution here would involve support from structurizr-dsl as well.

However in case of a Diagram Block Macro, it is possible to pass the filename the macro points to directly to structurizr-dsl using com.structurizr.dsl.StructurizrDslParser#parse(java.io.File).

cachescrubber commented 6 months ago

Hi @pepijnve , i have just noticed your activity on this issue (could it be that an issue transfer silences notifications?) Thanks a lot!

FYI I raised an issue in structurizr/java to support a public parse method which allows a proper includeDirectory.

cachescrubber commented 6 months ago

The next structurizr-java release will support a public void parse(String, File) method: https://github.com/structurizr/java/commit/4f5aa81a5cfb743cd85312dbfc4221b975c0b86d

pepijnve commented 5 months ago

This should be fixed in 2.2.16

cachescrubber commented 5 months ago

Many Thanks -- I could verify the include file processing using the example mentioned above.