Programmatically making M2Doc generated docs

Trying to make multiple docs and replacing a single variable in each, the goal is to do so without going through the template and renaming the element being used can creating a new doc to save. Was planning on doing so via python scripts but is there a way to do so via the command line? (open to other suggestions)

Thank you :slight_smile:

There is a Capella command line tool to launch the generation of a .genconf file in the M2Doc Capella extensions. It works like the Python4Capella one if you have a Team for Capella environment.

You can launch it with the following command:

capella.exe -nosplash -consolelog -application org.polarsys.capella.core.commandline.core -appid org.obeonetwork.capella.m2doc.commandline -filepath project/myGeneration.genconf -data ./workspace -outputfolder /project/generated -forceoutputfoldercreation

If you want to generate documents programmatically you can also have a look at the documentation.

Thank you for the command. I was looking at the documentation for generating automatically but I was confused on how to use it through java as it is in the documentation. I was trying to figure out how to develop in java, is there an easier way to learn to programmatically create the generation code, because I’m not sure how to use the java code given in the documentation. May be a simple answer but it has me quite confused.

Also, when I run that command, the Capella terminal window pops-up but shuts-down after a second after it tries generating. Is there somewhere I can see the error log to see what is causing it to close/crash?

If you want to launch your generation form a .genconf file you might also use this method as a starting point.

The log should be in the console when you use -consolelog… but you should also find a file in the workspace workspace/.metadata/.log.

Not sure what to make of this error message, here is the command and log info (I also chan):

Command:
capella.exe -nosplash -consolelog -application org.polarsys.capella.core.commandline.core -appid org.obeonetwork.capella.m2doc.commandline -filepath ./workspace/In-Flight Entertainment System With M2Doc/Template LA Complete.genconf -data ./workspace -outputfolder ./workspace/In-Flight Entertainment System With M2Doc/generated -forceoutputfoldercreation

(also tried changing names to avoid spaces in path names):
capella.exe -nosplash -consolelog -application org.polarsys.capella.core.commandline.core -appid org.obeonetwork.capella.m2doc.commandline -filepath C:/Apps/capella/workspace/FES-M2Doc/TemplateLA.getconf -data C:/Apps/capella/workspace/FES-M2Doc -outputfolder C:/Apps/capella/workspace/FES-M2Doc/generated -forceoutputfoldercreation

Error:
java.lang.NullPointerException: Cannot invoke “org.obeonetwork.capella.m2doc.commandline.M2DocCommandLinePlugin$Implementation.log(Object)” because the return value of “org.obeonetwork.capella.m2doc.commandline.M2DocCommandLinePlugin.getPlugin()” is null

Do you have the complete stack trace ? There is an exception because we try to log something…

The complete stack trace for the above error:

at org.obeonetwork.capella.m2doc.commandline.M2DocCommandLine.execute(M2DocCommandLine.java:119)
at org.polarsys.capella.core.commandline.core.CommandLineApp.launchApp(CommandLineApp.java:138)
at org.polarsys.capella.core.commandline.core.CommandLineApp.start(CommandLineApp.java:72)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:203)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:401)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:255)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:654)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:591)
at org.eclipse.equinox.launcher.Main.run(Main.java:1462)

The .genconf file can’t be loaded. Maybe try an URI in the form file:///C:/... or file:///home/... also if you have spaces in the path try to surround the URI with double quote. You can also try to replace spaces with %20 (URI escape).

It’s not possible to use absolute file path to genconf (file:///) .
Only workspace path is possible with current realization of M2DocCommandLine

platform type is added to the genconf file provided
genconfs[0] = “platform:/resource/” + CommandLineArgumentHelper.getInstance().getFilePath();

I thought is was strange to compute the URI this way, but I think for the Capella session to open the URI needs to be a platform URI. And the aird URI is computed with the genconf URI…

After some time I’ve returned to the thought of using docker to build documentation using m2doc. Before I had docker image already that was created manually by installing different packages. Now I’ve created dockerfile that can be used to create docker image for m2doc using docker build. It works. I will share it soon. But it needs capella workspace with imported projects to build documentation. And it’s not good. It would be great to have possibility to clone repo from git and start build documentation without the need to create Capella workspace (in Jenkins, for example)

made test modification to M2DocCommandLine and was able to publish doc without prepared
capella workspace

In details:

  1. for test changed in M2DocCommandLine to
    genconfs[0] = CommandLineArgumentHelper.getInstance().getFilePath();
    i.e. removed “platform:/resource/” +
    and rebuild CapellaExtensions repository

  2. in command line arguments used -data pointing to non existing folder for capella workspace

  3. in command line arguments used -filepath with absolute path to genconf
    file:///publish/genconfs/relative.genconf

  4. in genconf used relative paths to capella and aird file

You are inserting diagrams from Capella in your M2Doc template ?

Yes. And diagram were successfully published in this test.

Can you open a PR so I can merge this change please ?

Ok, I will create PR.

1 Like

Created PR

1 Like