Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Advanced Scripting Environment (EASE) » Jython not used
Jython not used [message #1851654] Tue, 12 April 2022 00:23 Go to next message
Henning Riedel is currently offline Henning RiedelFriend
Messages: 310
Registered: July 2009
Senior Member
I wanted to try out EASE in the latest Artop-4.15.1 environment to script some things. There are several problems I encounter:

First of all, I'm just using 0.8.0 and also only PyDev 8.2.0, since these are the last versions as it seems, that still support Java-8. Artop is not yet ready to run on Java-11.

Even though Javascript seems to work (execution), when I try to compare a getSelection(), if it is an instance of the interface ISignalTriggering, it does not work, since it seems, Javascript does not understand Java Interfaces.

Now I tried Python, but here there seems to be even more problems:

It always starts with Py4J, except when explicitly started with RunAs Jython.
When I use the script integration, where in the script I say to add it to the popupmenu of the ProjectExplorer, it always starts with Py4J, but never with Jython. I tried now almost anywhere to get rid of Py4J / Python, and set everthing to Jython, but nothing seems to work. I added a print("sysver, sys.version) and it always shows version 3.9 python.

I tried also the script-engine : Jython or Jython !Py4J or just !Py4J or !Python
but it always starts with Python 3.9 over Py4J.

Also, I still haven't figured out, how to actually access Java packages like the autosar40 metamodel Java package in python script. In Javascript it seems to work, but not in Python.

Maybe some up-to-date documentation would also help, since most of the documentation and tutorials are from 2014 to 2017 and only seem to use Javascript.

The Javascript version, where at least it does not bail out with "don't know Packages"
/*
  name : artoolsJS
  toolbar : Projecct Explorer 
  popup : Project Explorer
  description : test

*/

loadModule('/System/Platform');
loadModule('/System/Resources');
loadModule('/System/UI');

var project = getProject('test_ar');
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;

print('Project   ' + project.name);
print('arrelease ' + autosarRelease);

var sel = getSelection();
//var ccf = Packages.autosar40.system.fibex.fibexcore.corecommunication.CoreCommunicationFactory;
//var xx = ccf.createISignalTriggering();
if (sel instanceof Packages.autosar40.system.fibex.fibexcore.corecommunication.impl.ISignalTriggeringImpl) {
	print("sel ISignalTriggering " + sel.shortName)
} else {
	print("sel 'dont know'" + sel)
}

--> always returns with "sel don't know"


The Python Script looks like:
#! /usr/bin/env python
# name : artools
# toolbar : Projecct Explorer 
# popup : Project Explorer
# script-engine : Jython        <-- no matter what I write here
# description : test

 
loadModule('/System/Platform');
loadModule('/System/Resources');
loadModule('/System/UI');

#import autosar40.system.fibex.fibexcore.corecommunication.ISignalTriggering   <-- if enabled, exception package not found
print("sysver ", sys.version)       # <-- I always get Python 3.9 printed here
project = getProject('test_ar')
autosarRelease = org.artop.aal.workspace.preferences.IAutosarWorkspacePreferences.AUTOSAR_RELEASE.get(project)
editingDomain = org.eclipse.sphinx.emf.util.WorkspaceEditingDomainUtil.getEditingDomain(project, autosarRelease)
contentTypeID = Packages.autosar40.util.Autosar40ReleaseDescriptor.ARXML_CONTENT_TYPE_ID   # <-- exception "Name "Packages" is not defined

print('Project   ' + project.name)
print('arrelease ' + autosarRelease)

sel = getSelection()
if isinstance(sel, Packages.autosar40.system.fibex.fibexcore.corecommunication.ISignalTriggering): 
    print("sel ISignalTriggering " + sel.shortName)
else :
    print("sel 'dont know'" + sel)
  

[Updated on: Tue, 12 April 2022 00:26]

Report message to a moderator

Re: Jython not used [message #1852030 is a reply to message #1851654] Tue, 26 April 2022 13:01 Go to previous message
Christian Pontesegger is currently offline Christian PonteseggerFriend
Messages: 232
Registered: July 2009
Location: Graz, Austria
Senior Member
Hi,

as I do not have your installation; I just can give you some pointers in the right direction:

JavaScript perfectly works with interfaces, eg:
loadModule("/System/Resources", false);
   org.eclipse.ease.modules.platform.resources.ResourcesModule@692d0a28
getWorkspace() instanceof org.eclipse.core.internal.resources.WorkspaceRoot
   true


getSelection() returns an org.eclipse.jface.viewers.ISelection, you need to unpack it first to check its contents.

For scripts, to pick a dedicated engine you need to supply the engine-id to the script-engine keyword, see [1]. That would result in
script-engine: org.eclipse.ease.python.jython


The 'Packages' keyword you used in your python scripts will not work there, as this is a Rhino specific keyword [2]. In jython you use full qualified names or use imports [3]. Basically each language has its specific ways to connect to java. There is no universal approach that works for all of them.

HTH
Christian

[1] https://wiki.eclipse.org/EASE/Scripts
[2] https://devopspoints.com/javascript-scripting-java-with-rhino.html
[3] https://www.tutorialspoint.com/jython/jython_importing_java_libraries.htm
Previous Topic:Eclipse CDT project configuration
Next Topic:Keyboard shortcut- EASE (Context: Python4Capella)
Goto Forum:
  


Current Time: Fri Aug 19 18:09:09 GMT 2022

Powered by FUDForum. Page generated in 0.02268 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top