Archi Forum

Archi Plug-ins => jArchi => Topic started by: Manj75 on June 23, 2021, 12:31:48 PM

Title: Is it possible to get the preferences settings from jArchi
Post by: Manj75 on June 23, 2021, 12:31:48 PM
If the collaboration plugin is installed and setup I want to script the ability to fetch the Tools -> Preferences -> Collaboration -> Name text field value.

The script would throw an exception of the coArchi was not installed or if that field does not exist.

I'm want to create a script where you can append to the documentation that stamps the date and Name of the text appended.  This would also work on appending to multiple elements in one operation.
Title: Re: Is it possible to get the preferences settings from jArchi
Post by: Phil Beauvoir on June 23, 2021, 13:38:59 PM
jArchi does not have an API for Archi's preferences.

If you are trying to access the user name that is used for coArchi (i.e. git) commits, this can be found in the ~/.gitconfig file which could be loaded in JS and parsed.

Or for other preferences, load and read Archi's preference files directly - %Home%\AppData\Roaming\Archi4\.metadata\.plugins\org.eclipse.core.runtime\.settings
Title: Re: Is it possible to get the preferences settings from jArchi
Post by: Manj75 on June 23, 2021, 17:36:48 PM
Phil - your suggestion of using the plugin preferences config file would've been perfect, however I don't see all the settings from the preferences Collaboration tab, only the following is there in the file:

eclipse.preferences.version=1
sshIdentityFile=
sshIdentityRequiresPassword=false


I'm I missing anything - could it be that the Name and Email values are only stored in the encrypted file?
Title: Re: Is it possible to get the preferences settings from jArchi
Post by: Phil Beauvoir on June 23, 2021, 17:39:58 PM
I did say "Or for other preferences"  ;)

The name and email used by git (and coArchi) are stored in the <user.home>/.gitconfig file not the preferences file (I think it does say that on the Preferences dialog)
Title: Re: Is it possible to get the preferences settings from jArchi
Post by: Manj75 on June 25, 2021, 12:17:38 PM
Looking at the .gitconfig file it has exactly what I need and as it's basically an ini file I need to load and parse it, however I see no examples from community of file IO in jArchi/JS.  I've tried the FileReader but this doesn't seem to be supported - can you or anyone please point me to an example that'll work in jArchi to load a local file that I can parse or even if there is already an available JS library script that readily does this.  Thanks.
Title: Re: Is it possible to get the preferences settings from jArchi
Post by: projetnumero9 on June 25, 2021, 12:35:00 PM
This gist (https://gist.github.com/search?q=%23jarchi+extension%3Aajs+readfully&ref=searchresults (https://gist.github.com/search?q=%23jarchi+extension%3Aajs+readfully&ref=searchresults)) served me right on the spot (see the polyfill readFully)! (so happy you could publish it, JB!)

Another/similar example would be:
- https://gist.github.com/smileham/1e57a5946235e780dee5a824f664aa3d (https://gist.github.com/smileham/1e57a5946235e780dee5a824f664aa3d)

Regards,
PN9
Title: Re: Is it possible to get the preferences settings from jArchi
Post by: Jean-Baptiste Sarrodie on June 25, 2021, 13:27:36 PM
Hi,

Quote from: projetnumero9 on June 25, 2021, 12:35:00 PM
so happy you could publish it, JB!

What do you mean by "publish it" ?

JB
Title: Re: Is it possible to get the preferences settings from jArchi
Post by: Jean-Baptiste Sarrodie on June 25, 2021, 13:29:14 PM
BTW, I mentioned a bunch of useful blog posts and polyfills here: https://forum.archimatetool.com/index.php?topic=625.msg3506#msg3506

JB
Title: Re: Is it possible to get the preferences settings from jArchi
Post by: projetnumero9 on June 25, 2021, 13:50:56 PM
Quote from: Jean-Baptiste Sarrodie on June 25, 2021, 13:27:36 PM
Hi,

Quote from: projetnumero9 on June 25, 2021, 12:35:00 PM
so happy you could publish it, JB!

What do you mean by "publish it" ?

JB

Making it publicly available,

PN9
Title: Re: Is it possible to get the preferences settings from jArchi
Post by: Jean-Baptiste Sarrodie on June 25, 2021, 14:18:22 PM
Quote from: projetnumero9 on June 25, 2021, 13:50:56 PM
Making it publicly available,

PN9

You mean, in a dedicated gist, a real git repo, somewhere else ? (BTW, this is not my work but someone else's work I used).

Maybe have a set of wiki page on jArchi repo with a list of really useful snippets ?

Don't know what's the best.

JB
Title: Re: Is it possible to get the preferences settings from jArchi
Post by: Manj75 on June 25, 2021, 14:24:56 PM
I've used the second example mentioned by PN9 in combination with a parse_ini_string function I found on https://gist.github.com/anonymous/dad852cde5df545ed81f1bc334ea6f72

Now, I just need to be able to get the user homedirectory, i.e. %userprofile% for win32 and $home for mac.

I was pointed to the $.process but not sure if it supports .env for environment variable.  I want to do something like:

process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'];

but, I get undefined for $.process.env, so not if this is supported.