Skip to Content.
Sympa Menu

grouper-users - [grouper-users] RE: example java code to run a bit of gsh script/JEXL?

Subject: Grouper Users - Open Discussion List

List archive

[grouper-users] RE: example java code to run a bit of gsh script/JEXL?


Chronological Thread 
  • From: "Hyzer, Chris" <>
  • To: "Black, Carey M." <>, "" <>
  • Subject: [grouper-users] RE: example java code to run a bit of gsh script/JEXL?
  • Date: Mon, 23 Jul 2018 16:04:08 +0000
  • Accept-language: en-US
  • Authentication-results: spf=none (sender IP is ) ;
  • Ironport-phdr: 9a23:3kQSKxIhfWogpgAWV9mcpTZWNBhigK39O0sv0rFitYgXKv77rarrMEGX3/hxlliBBdydt6oazbKO+4nbGkU4qa6bt34DdJEeHzQksu4x2zIaPcieFEfgJ+TrZSFpVO5LVVti4m3peRMNQJW2aFLduGC94iAPERvjKwV1Ov71GonPhMiryuy+4ZLebxlJiTanfb9+MAi9oBnMuMURnYZsMLs6xAHTontPdeRWxGdoKkyWkh3h+Mq+/4Nt/jpJtf45+MFOTav1f6IjTbxFFzsmKHw65NfqtRbYUwSC4GYXX3gMnRpJBwjF6wz6Xov0vyDnuOdxxDWWMMvrRr0vRz+s87lkRwPpiCcfNj427mfXitBrjKlGpB6tvgFzz5LIbI2QMvd1Y6HTcs4ARWdZXshfSTFPAp+yYYUMAeoOP+dYoJXyqVQBtha+GRCsCP/zxjNUmnP6w6s32PkhHwHc2wwgGsoDvHrWotT1NaYdT/q1wLHVxjjdb/NWwzb96JPGfhs8pvyMWK5/ccrRyEguCQzFlE6dqY3+PzyJzOgNrnCb4PRmVeKpkWIotRx+oiW2y8oql4LHhZoVx0ja+Spj3Io5ONi1RFNmbdK5FZZQuS6XO5dqTs4nQWxnpik3x7kDtJO+YiQG1IkrywbCZ/GJb4SE+BbuWPuLLTtmmX5ofKiziwuw/EWh0uH8WNe73VVWoidAl9TBtW0C1xLc58WCSfZw8Fqu1iyK2gDd9O1JLk85mK/HJJMi2LE8iJweulnZECDsgkX5lqqWe10k+ue27+TnZa3rqIeAOoFzlg3zPL0ilMK4D+k2KwQOWHOU9vqm2L3k4E35XK5FjvorkqnfrZ/WP9wbprS+Aw9JzIks9wq/Dzah0NQeh3UHK09FeA6Dj4juPFHOI+r0Auu4g1SpiDtrxvbGMaP9ApjVMHTMiqvtcat45kJB1QY/0NVS55xbB70dPP7+X038u8LXAxI9NgG5xvjrBMlg2o8GXGKAGK6ZMKfcsV+S4eIvJvGBZIoJtzb9K/kk5uDhjWUilF8cZqmmwYEbaG2gHvt4JUWZZ2DgjckcHmcXpgY+VvDliEWeUT5PYHa/R6085is8CIK7FYfMWJqtjKWc3CegAJJWfHtGB0uIEXfpbIWER+wMZDyILs9glDwESaauS5Un1R6wqA/21aBrIfTJ9S0F5trf040/zenanhJ2vRd9FcmMm0TLBSkglGcBTDxwhfokiUtm1xGO3bUux7QSGsZU+utESEInLpPG1MR7Dcz/QATMYo3PRVq7CJ3yDis2U8o82ZoTeEtnAP2jiAzOxSynH+VTmrCWUs8a6KXZijLRNtRw0TKO/6k7jkJsCp9KPm23lKNl3wnIDMjUi0ifkeCneblKj32Fz3uK0Wfb5BIQawV3S6iQGClHPhGM/93k+kPPSaOvAr07MwxHjNSPMbZOdsa30QddXPm2PtPYbirxgGq2CRuSjpK0JIvxMyR4vm3GDVQc1QUa/HKILw87UyKqo3PMASZGFEnkJV70/O947n63Uxx8wg==
  • Spamdiagnosticmetadata: NSPM
  • Spamdiagnosticoutput: 1:99


>
> -----Original Message-----
> From:
>
>
> [mailto:]
>
> On Behalf Of Black, Carey M.
> Sent: Monday, July 23, 2018 11:48 AM
> To:
>
> Subject: [grouper-users] example java code to run a bit of gsh script/JEXL?
>
> All,
>
> I have a use for having files of gsh scripts to do things like:
> Establish/maintain custom:
> Attributes Defs / AttributeName(s)
> Folder structure
> Groups
> Permissions on folders/groups
> Etc....
>
> However, I would also like to be able to embed/use those things
> inside other
> Java code. (hooks, changelog consumer, etc...)
>
> So I am looking for a Java code example for the following:
> 1) read a file from the file system (a gsh script) and "execute it".

I would recommend just writing in java and not calling GSH from java... all
GSH is just java anyways... give me a script and I will give you the java.
Here is what you are asking for though...

This is from Grouper installer:

if (runScript) {

//running with command on command line doenst work on linux since the
args with whitespace translate to
//save the commands to a file, and runt he file
StringBuilder gshCommands = new StringBuilder();

//gsh 0% GrouperSession.startRootSession()
//edu.internet2.middleware.grouper.GrouperSession:
6f94c99d5b0948a3be96f94f00ab4d87,'GrouperSystem','application'
//gsh 1% // run USDU to resolve all the subjects with type=person
//gsh 3% usdu()

gshCommands.append("grouperSession =
GrouperSession.startRootSession();\n");
gshCommands.append("usdu();\n");

File gshFile = new File(this.untarredApiDir.getAbsolutePath() +
File.separator + "gshUsdu.gsh");
GrouperInstallerUtils.saveStringIntoFile(gshFile,
gshCommands.toString());

List<String> commands = new ArrayList<String>();

addGshCommands(commands);
commands.add(gshFile.getAbsolutePath());

System.out.println("\n##################################");
System.out.println("Running USDU with command:\n " +
convertCommandsIntoCommand(commands) + "\n");

GrouperInstallerUtils.execCommand(
GrouperInstallerUtils.toArray(commands, String.class), true,
true, null,
new File(this.gshCommand()).getParentFile(), null, true);

}

> 2) use a gsh script as an "condition" ( AKA: if the script returns
> "true" then
> keep running the java code )
> Maybe this would be better done as a JEXL expression?

Not sure how to get GSH return code from java... screenscrape the output?

>
>
> I have yet to have some time to spend on this, and I suspect the code
> already exists.
> I hope someone can point me at it. :)
> I am guessing the example would be how gsh starts up and runs a file
> would be
> one place.
> And I am guessing the JEXL is "all over the place" in the code too.
>
> Any thoughts on the performance costs of "running a gsh script" vs
> evaluating JEXL
> expressions?

JEXL is fast, running an external GSH is slow. Java would be fast though as
I suggested above

>
> But maybe I am going about initialization type functions the hard way?
> Are there other facilities for this general kind of function?
>
> --
> Carey Matthew
>
>

-----Original Message-----
From:


[mailto:]
On Behalf Of Black, Carey M.
Sent: Monday, July 23, 2018 11:48 AM
To:

Subject: [grouper-users] example java code to run a bit of gsh script/JEXL?

All,

I have a use for having files of gsh scripts to do things like:
Establish/maintain custom:
Attributes Defs / AttributeName(s)
Folder structure
Groups
Permissions on folders/groups
Etc....

However, I would also like to be able to embed/use those things
inside other Java code. (hooks, changelog consumer, etc...)

So I am looking for a Java code example for the following:
1) read a file from the file system (a gsh script) and "execute it".
2) use a gsh script as an "condition" ( AKA: if the script returns
"true" then keep running the java code )
Maybe this would be better done as a JEXL expression?


I have yet to have some time to spend on this, and I suspect the code already
exists. I hope someone can point me at it. :)
I am guessing the example would be how gsh starts up and runs a file
would be one place.
And I am guessing the JEXL is "all over the place" in the code too.

Any thoughts on the performance costs of "running a gsh script" vs evaluating
JEXL expressions?

But maybe I am going about initialization type functions the hard way?
Are there other facilities for this general kind of function?

--
Carey Matthew




Archive powered by MHonArc 2.6.19.

Top of Page