Archi Forum

Archi Plug-ins => Other Plug-ins => Topic started by: Hervé on September 07, 2017, 11:53:47 AM

Title: New script plugin
Post by: Hervé on September 07, 2017, 11:53:47 AM
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:

I've chosen this second option.

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

My roadmap includes:

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é

Title: Re: New script plugin
Post by: Jean-Baptiste Sarrodie on September 07, 2017, 12:08:33 PM
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
Title: Re: New script plugin
Post by: Hervé on September 07, 2017, 12:44:13 PM
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  :
So, as you can see, I'll be quite busy with Archi the next months or so ;D
Title: Re: New script plugin
Post by: Hervé on September 07, 2017, 15:01:49 PM
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é
Title: Re: New script plugin
Post by: Jean-Baptiste Sarrodie on September 07, 2017, 16:07:38 PM
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
Title: Re: New script plugin
Post by: Hervé on September 07, 2017, 16:53:03 PM
Thanks.

I can rename it if you wish  :)
Title: Re: New script plugin
Post by: Phil Beauvoir on September 07, 2017, 20:48:09 PM
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.
Title: Re: New script plugin
Post by: Hervé on September 07, 2017, 21:09:44 PM
Thank you very much Phil  :D
Title: Re: New script plugin
Post by: Phil Beauvoir on September 07, 2017, 21:17:43 PM
I mentioned it in the roadmap https://www.archimatetool.com/dev/roadmap
Title: Re: New script plugin
Post by: Phil Beauvoir on September 08, 2017, 12:31:15 PM
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
Title: Re: New script plugin
Post by: Phil Beauvoir on September 08, 2017, 12:33:46 PM
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.