New script plugin

Started by Hervé, September 07, 2017, 11:53:47 AM

Previous topic - Next topic

Hervé

Hi JB,

I've started the dev of a new script plugin for Archi.

All started with the need to automate every night the creation of HTML reports for some of my models. I had two options:

  • Directly generate the web site from my SQL repository but it would restrict its usage to people who are using the database plugin
  • Implement a new plugin that allows to automate actions into Archi

I've chosen this second option.

My plugin is in alpha stage and is already able to:

  • open a model from an Archimate file
  • import a model from the database plugin
  • close a model
  • create an HTML report from a model
  • exit Archi when the script has finished

My roadmap includes:

  • export a model to a CSV file
  • create a Jasper report from a model
  • change elements or relationships properties
  • add, remove and update elements or relationships into a model
  • save a model to an archimate file
  • export a model to a database through the database plugin
  • etc...

Running such a script is quite easy as one may add the following parameters when running Archi:
QuoteD:\archi> archi.exe -?
usage: archi
-?,--help                       Shows this help message
-d,--debug                    Prints debug information
-l,--logfile <log file>      Specifies the log filename
-s,--script <script file>  Script filename
-v,--verbose                  Prints verbose information

For instance:
QuoteD:\archi> archi.exe -v -s "d:\archi\fichier.script" -l "d:\archi\fichier.log"

Could you please create a org.archicontribs.script project on GitHub ?

Thanks and regards
Hervé


Jean-Baptiste Sarrodie

Hi,

It seems you are redoing what Phil is already working on. FYI there's a (more advanced) scripting plugin and a plugin to use Archi through command line to generate (HTML and Jasper) reports.

I guess we have to discuss a bit to limit duplication of efforts here. And maybe also define some kind of API to allow such headless/command line use to access features exposed by third parties plugins.

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.

Hervé

Hi JB,

I do not remember any post talking about Phil's plugin this year.

I'm available to discuss about the plugins I'm developping or planning and having some API would be very helpful to me as learning the Eclipse Framework (or sometimes cheating to bybass it) is very time consuming.

Nevertheless, my plugin already works and some people I'm in touch with are waiting for it to automate their HTML report too.

Automating the web site creation from Archi is one of the yearly objective that my company gave me. Theend of the year will come very quick now and that's why I accelerate on this.

May be you could create the GitHub project that I deploy it and we'll discuss afterwards if I spend more time on it or if we switch to Phil's plugin when it is ready ?  :)

Thanks and regards
Hervé

ps: stopping to work on this script plugin is really an option to me because I've got plenty of things to do on my others plugins  :

  • finish the graphical editor on my form plugin,
  • rewrite my database plugin algorithm to make it more "collaborative",
  • update my ServiceNow plugin to allow to synchronize a elements and relationships of a single model from/to our CMDB,
  • create a new plugin to automate the creation/update of the documentation in a wiki (using the semantic extension),
  • ... and much more ...
So, as you can see, I'll be quite busy with Archi the next months or so ;D

Hervé

Just to give you a idea of the very simple syntax of a script, here an example:
Quote
# lines beginning with a hash key are comments
# empty lines are ignored
# keywords are case insensitive

# We set the option to automatically exit Archi when the script ends
#    the scripts end when the last line is reached or when an error is raised
OPTION ExitArchi on

# We select the "model 1" model
#    and generates an error if the model is not yet loaded in memory
SELECT "model 1"

# We close the model 1
CLOSE

# We select the "model 2" model
#    and imports it from the archimate file it is not yet loaded in memory
#    an error is generated if the archimate file cannot be loaded
SELECT "model 2" FROM FILE "path to archimate file"

# We close the model 2
CLOSE

# We select the "model 3" model
#    and import it from the "postgresql" database (which must be defined in the database plugin preferences
#    an error is generated if the model cannot be loaded from the database
SELECT "model 3" FROM DATABASE postgresql

# we generate the HTML report from the selected model
#    if the specified folder does not exits, it is created
#    if the report can't be created, then an error is raised
REPORT HTML TO "D:\archi\web"

# We close the "model 3"
CLOSE

# This is the end of the script.
# Now Archi will be automatically closed (see ExitArchi option at the beginning of the script)

I use this kind of script in my enterprise scheduler, on a daily basis, to generate my web site.

Hope this helps.

Best regards
Hervé

Jean-Baptiste Sarrodie

Hi,

I've just created a new script-plugin repo with you as admin.

Just one remark for future plugins: as the Java code (packages) is structured unders org.archi-contribs, I'd prefer we discuss the naming before you (or any other people) start coding. This is to avoid collision or bad naming, knowing that it is always better to start with the good name than to rename all classes after.

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.

Hervé

Thanks.

I can rename it if you wish  :)

Phil Beauvoir

I have a very simple command line API and plugin that can run Archi headless with command line options and do things like generate reports or clone from a repo (for the collaboration plugin). It's an extension point so folks can create their own command line plugins. It's quite generic. Herve's looks geared toward his DB plugin  I'll publish this over the coming days.
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

Hervé


Phil Beauvoir

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

I've added two new plug-ins to the main Archi codebase in GitHub:

com.archimatetool.commandline
com.archimatetool.reports.commandline

After some testing and feedback these will be distributed in the Archi 4.1.0 release.

The first plug-in, declares an extension point, "com.archimatetool.commandline.commandlineProvider" which has one method:

void run(String[] args) throws Exception;

The com.archimatetool.commandline plug-in has an application that runs Archi in headless mode. This means you don't see the UI. It then passes on command-line arguments to registered providers. A provider can then look for the command line arguments that it is interested in. This means that you can have many command-line providers invoked from one command line.

If you take a look at the "com.archimatetool.reports.commandline" plugin you can see how it's used. Also, there's a provider in the model collaboration project (https://github.com/archi-contribs/archi-modelrepository-plugin)

Phil
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

Oh, and there's also a CommandLineUtils class which has one useful utility method - loadModel(File). More methods will be added as required. This saves providers from re-inventing the wheel.
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.