ArchiMate diagram generation with jArchi and PlantUML

Started by lemoux, January 21, 2021, 13:07:27 PM

Previous topic - Next topic

lemoux

Hi,

Just a post to share a nice feature. I wanted to generate from scratch an AchiMate diagram based on the result of a query executed by jArchi.
Such results can - of course - be displayed in a simple table. But sometimes, it is nice to also have a more graphical view of these results...

PlantUML can be used to generate UML diagrams (along with the resulting image in PNG format) from a model description in a text file based on a simple grammar.
I casually found out that PlantUML also supports ArchiMate diagram description and generation.

Here's a summary of the steps to set up this feature :
1.   Download plantuml.jar in /path/to/Archi4/scripts (where jArchi scripts are stored by default)
2.   Download the ArchiMate "extension" of PlantUML from the dedicated project in Github (https://github.com/plantuml-stdlib/Archimate-PlantUML). The Archimate.puml file must be stored in the same location
3.   Add "-Dnashorn.args=-cp /path/to/Archi4/scripts/plantuml.jar" to the Archi.ini configuration file to add plantuml.jar to jArchi classpath

One can then write scripts to generate a diagram from the result of a model query like the basic attached example that displays the clients invoking (triggering) operations implemented (realized) by a service.

Have fun !

Phil Beauvoir

Thanks for sharing.

I was not aware of the Nashorn args "-Dnashorn.args=-cp path_to_jar", is that documented?

Also, I wonder if there is a similar argument for GraalVM?
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

lemoux

Actually, I googled during a while before I figured out how to use the .jar from a script...

Apparently it's not as well documented as the jvm args :
https://stackoverflow.com/a/30251930/1700467

Concerning GraalVM, no idea...

Jean-Baptiste Sarrodie

Hi,

Only one word (actually two): THANK YOU !

I had this idea too some time ago but had no way at that time to include plantuml inside Archi (this simple plantuml.jar didn't exist).

For other projects I also wanted to add jar to the classpath, but again found no way.

You've just solved both.

Regards,

JB
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

Phil Beauvoir

#4
This is the frustrating thing about many of these frameworks (Eclipse included) - the lack of comprehensive documentation. I must have spent several weeks randomly Googling for things either to find nothing or some obscure reference on Stack Overflow. Meanwhile, there's someone out there who could answer the question in two minutes.

As a matter of fact, it was by chance that I discovered how to ship GraalVM as a set of jar files with jArchi. And even then several hours of trial and error to figire out the additional dependencies.

It would be good if there was an equivalent to this classpath argument for GraalVM. (Anyone got a spare few days to randomly Google this?)
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

lemoux

You're welcome.
About PlantUml integration, you're fully right. Since version 1.2020.21, the .jar file is shipped with a reduced version of GraphViz, the component in charge of diagrams auto-layout and rendering like the Zest framework used by Archi :

https://plantuml.com/fr/graphviz-dot

Which makes it even more simple to use...

Phil Beauvoir

#6
Quote from: Phil Beauvoir on January 21, 2021, 13:53:44 PM
It would be good if there was an equivalent to this classpath argument for GraalVM. (Anyone got a spare few days to randomly Google this?)

I found this:

https://www.graalvm.org/reference-manual/js/JavaInteroperability/

So you can add this line in a JS script:

Java.addToClasspath("path_to_jar")

But it doesn't work with the plantuml.jar as various Exceptions are thrown.

However, this works:


Java.addToClasspath("path_to/plantuml.jar");
var plantUMLText = "@startuml\nBob->Alice: Hello\n@enduml";
var fileOutputStream = new Packages.java.io.FileOutputStream("path_to/PlantUMLDemo.png");
var reader = new Packages.net.sourceforge.plantuml.SourceStringReader(plantUMLText);
console.log(reader.outputImage(fileOutputStream).getDescription());
fileOutputStream.close();


Edit - I think PlantUML tries to load a sprite PNG image which is contained inside the plantuml.jar in the "sprites" directory. The class net.sourceforge.plantuml.sprite.SpriteImage uses a local class-loader (SpriteImage.class.getResourceAsStream(path)) and fails. This is probably a defect in GraalVM.

I opened this issue: https://github.com/oracle/graaljs/issues/413
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

Phil Beauvoir

#7
After much experimenting with getting this to work on GraalVM I discovered that GraalVM has a problem accessing resources inside of a jar file. These are the image files that PlantUML uses.

However, if the contents of the plantuml.jar file are extracted into a directory it works.

1. Extract the contents of plantuml.jar into a directory named "plantuml" (a jar file is basically a zip file)
2. Add this to the start of the Script:
Java.addToClasspath("path_to/plantuml");

And it all works on GraalVM without having to edit the classpath in the Archi.ini file.

I've reported the problem of loading resources in jar files here - https://github.com/oracle/graaljs/issues/413

If a Java jar only contains class files it's OK, but if the jar contains other resources that are loaded internally that's a problem.

Edit - it might be a problem with this particular jar file, or how the code accesses resources in the jar. I made a test jar file with an image file inside of it and some simple accessor code to extract the image using Class.getResourceAsStream(path) and it worked fine.

Edit 2 - it seems that it's a bug in GraalVM - https://github.com/oracle/graaljs/issues/413#issuecomment-767150552
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.