Execute script programmatically and synchronous [message #1780088] |
Wed, 17 January 2018 09:52 |
Edgar Keller Messages: 3 Registered: January 2018 |
Junior Member |
|
|
Hi,
I'm facing a problem with my usage of EASE.
What I'm trying to do is running a script programmatically from a custom plugin, actually I already achieved that. The problem is that the script execution is called from a Job (custom build system, I'm also passing some context to the executed script with engine.setVariable() ) and when I e.g. try to create a Resource from the script it will run into a dead lock.
I'm not too familiar with Eclipse development, I just wanted to have a proof of concept. I assume the Job from where I start script execution holds some kind of Lock which my script is trying to get when creating a Resource and therefore runs into this dead lock.
So what I would like to achieve is script execution within the callers thread, assuming that would circumvent the dead lock.
Is there any possibility to do so?
Some more background:
I'm using the Rhino Engine with EASE 0.4.0.
Initially I was using engine.executeSync(), but that is actually executeAsync() + wait, so does not help.
I also tried using engine.inject() directly, but that gives me always
SyntaxError: missing ; before statement (unnamed script#1)
org.eclipse.ease.ui.scripts.repository.impl.ScriptImpl@2196ba3c
Although the script works fine when executed with .executeSync(). I get the same exception even when I only use print("test"); as the script content.
I thought using .inject() on a newly created engine might fail because some initialization is missing, so I also tried:
engine.setTerminateOnIdle(false);
engine.executeSync("null;");
ScriptResult result = (ScriptResult) engine.inject(script);
but this gives the same exception as above.
Probably I could use the Rhino Engine directly, but I would loose EASE modules, which I'm currently relying on. Furthermore I'm writing the scripts in such a way that they can be executed as usual (popup) and programmatically. So good for script development/debugging.
I don't have any ideas anymore, would be really nice to get some help/hints.
Thanks in advance.
Regards,
Edgar
|
|
|
|
Re: Execute script programmatically and synchronous [message #1780646 is a reply to message #1780128] |
Thu, 25 January 2018 09:13 |
Edgar Keller Messages: 3 Registered: January 2018 |
Junior Member |
|
|
Hi Christian,
I'm also wondering why the script runs into a deadlock, because when I use similar java code (see below) to save a resource immediately before or after script execution from my plugin it just works as it should, it only fails if executed from the script.
Here is the snippet I use to save a resource, which works totally fine when I run the script via popup. I'm using ARTOP (www.artop.org) in an AUTOSAR context.
var autosarRelease = org.artop.aal.workspace.preferences.IAutosarWorkspacePreferences.AUTOSAR_RELEASE.
get(project);
var editingDomain = org.eclipse.sphinx.emf.util.WorkspaceEditingDomainUtil.
getEditingDomain(project, autosarRelease);
var contentTypeID = Packages.autosar40.util.Autosar40ReleaseDescriptor.ARXML_CONTENT_TYPE_ID;
org.eclipse.sphinx.emf.util.EcorePlatformUtil.saveNewModelResource(
editingDomain,
file.getFullPath(),
contentTypeID,
eObj,
null, // options
false, // async
new org.eclipse.core.runtime.NullProgressMonitor());
I just read chapter "Job Scheduling Rules" (after I wrote the above part) of https://www.eclipse.org/articles/Article-Concurrency/jobs-api.html . Meanwhile I assume that the job from where I try to execute the script is using a SchedulingRule to lock all the project resources (it's a build system, so probably it wants to ensure that nothing is changed while the build is running).
Maybe I could use the JobManger to temporarily release the rule of the outer job, but that would most likely lead to unwanted side effects. E.g. A pending file save operation while the build is running might get executed and lead to unexpected output.
Do you know if there is a way to atomically pass a SchedulingRule from one job to another and back again after the nested Job is done?
Regards,
Edgar
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.08321 seconds