Hello Felix,
as you suggested (
https://forum.mbse-capella.org/t/384/) I start a new topic here for Groovy4Capella…
I managed to get Groovy4Capella working - thank you!
… with some small difficulties:
- installing eclipse-plugins, especially behind a firewall (for future releases: dropins are the “easiest” way to install add-ons)
- the example script won’t run without an “Argument” definition in the Run-Configuration for the script
So some first questions:
- List ExchangeItems per architecture level (System, Logical, Physical)
In your example the Functions of the Logical-Architecture and Physical-Architecture are found by LogicalFunction.each PhysicalFunction.each.
If I look for ExchangeItem.each all EIs are found - from every level. How can I select only one specified level e.g. LogicalArchitecture?
- Add/Write a new ExchangeItem to the model
How can I add a new EI to the model at a defined location e.g.
LogicalArchitecture -> Interfaces -> NewInterfacePgk -> NewExchangeItem
- Groovy & Excel
Is Groovy able to directly read from / write to Excel files?
kind regards
Hi,
You can write/read from Excel using for example
https://poi.apache.org/
It’s powerful lib and you can use it for other type of MST documents (Word, PPT, …)
Regards
Richard, great you got it installed
I am not a big fan of dropins. A firewall does not mean you cannot install from a p2 update site. You just need a .zip that contains that update site, and then you can install it from your local file system.
- there are tons of ways to do this
. You could try to find the LA, PA, SA elements first, and then maybe use the method EcoreUtil.isAncestor(EObject ancestorEObject,
EObject eObject) to see if a given element is a child of any of these architectures… Maybe I can add a helper when I have time. Could be useful.
- First you need to have the element to which you want to add the new EI. You can then create the EI with the factory method: InformationFactory.eInstance().createExchangeItem(). Then need to add the exchange item to the interface.
- See EL Arbi’s anwswer, maybe we can add an example for this too.
Really, the main problem is time… I would be happy to have people write more examples so we can add them to the repo…
Hello all together,
I have downloaded the poi-lib - how do I have to “install” it so I can use it with capella-groovy?
Hello Felix (or anyone who can help with this)
some more questions…
concerning 2) “add a new EI to the model at a defined location e.g. PhysicalArchitecture”
You mentioned to use
InformationFactory.eInstance().createExchangeItem()
How have I to use it? Can you give an example? (Im sorry, I am not a Java or groovy-coder…)
4) To go further - what are the methods to
- generate (System/Locical/Physical)Functions
- generate Function Input/Output Ports in a Function
- generate a FunctionalExchange between two Ports
- assigning an ExchangeItem to a FunctionalExchange
- …
In general where can I find information about how to do these things?
Kind regards
Hello Felix,
have you continued your work on Groovy4Capella? Can you provide an updatesite-snapshot compatible with Capella-1.3.0?
Kind regards
Hello Felix,
thank you for your help.
I have the problem that I am behind a firewall - I can not directly access a maven repository on the Internet with eclipse/capella.
Is there any other way to use the local jar-libs?
greetings
Ok I see. Well, I looked at the capella groovy code, and it seems I added support for local libraries at some point. I didn’t remember. So I tested, and I can run a poi example script just fine. What I did was:
- Create a new ‘capella.groovy.example’ project.
- Inside the project, select new->folder, and under ‘advanced’, select “link to external” and pick the folder containing the poi libs (I downloaded this here:
https://www.apache.org/dyn/closer.lua/poi/release/bin/poi-bi n-4.0.1-20181203.zip)
- I then open the projects META-INF/MANIFEST.MF file, and on the “Runtime” tab, select Add… on the part with the “Classpath” header. I add all the .jar files in the poi folder (and also the lib subfolder and the ooxml-lib subfolder). I save that. I now see all these jar files under the “Referenced Libraries” pseudofolder in the project.
- I can now run a script that has:
@BaseScript(org.polarsys.capella.groovy.CapellaScriptBase)
package capella.groovy.example
import org.polarsys.capella.core.data.ctx.*
import org.polarsys.capella.core.data.fa.*
import org.polarsys.capella.core.data.la.*
import org.polarsys.capella.core.data.pa.*
import groovy.transform.BaseScript
import org.apache.poi.ss.usermodel.*
Workbook wb = WorkbookFactory.create(new FileInputStream(“C:\Users\felix\Documents\Book1.xlsx”))
info wb.getSheetAt(0).getSheetName()
Maybe you forgot to add the other libraries, or the import org.apache…?
Hello Felix
this way it is working - thank you very much!
(I also had to add the commons-compress lib in the same way.)
I tried to add the libs in the projects “Properties” (mouse right klick on the Project) - this was not working.
The solution was to add the libs to the ClassPath in the MANFEST.MF
When I am outside the firewall the other solution with @Grab also is working - even better as the class-documentation ist available when hoovering with the mouse over a classname.
- To my former question - is Groovy already working with Capella 1.3? (the example is Capella-1.2.1)
- A more Capella-specific question:
I can create a new Function and “place” it beyond (inside) a FunctionPackage with
LogicalFunction NewLF = LaFactory.eINSTANCE.createLogicalFunction(“MyNewLF”)
MyLogicalFP.getOwnedLogicalFunctions().add(NewLF)
But how can I “place” a Function directly beyond another Function as a Sub-Function without a FunctionPackage? I haven’t found an “.add()” command, that is working on a Function.
(I think this is the more usual way when working in Capella and creating new SubFunctions inside a Function.)
Kind regards
Hello Felix,
thanks again!
- I will try…
- That was my mistake - I was assumed that a “LocicalFunction” owns a “LogicalFunction” not just a “Function”.
Because the “LocicalFunction” owns for e.g. a “LogicalFunctionPkgs” not a “FunctionPkgs”…
It is a very good hint to look at the xml-tags in the melodymodeller file!
Richard C. wrote on Wed, 27 February 2019 07:34
I was assumed that a “LocicalFunction” owns a “LogicalFunction” not just a “Function”.
Because the “LocicalFunction” owns for e.g. a “LogicalFunctionPkgs” not a “FunctionPkgs”…
Yes, there are inconsistencies, or at least ‘quirks’ in the Capella metamodel, so it’s better to look closely.
about 1)
again problems - I can’t get the groovy things from the org.polarsys.capella.tools-updatesite installed - error message:
Cannot complete the install because one or more required items could not be found.
Software being installed: Groovy for Capella Developer Resources 1.3.0.201812100951 (org.polarsys.capella.groovy.feature.source.feature.group 1.3.0.201812100951)
Missing requirement: Groovy for Capella 1.3.0.201812100951 (org.polarsys.capella.groovy.feature.feature.group 1.3.0.201812100951) requires ‘org.codehaus.groovy.eclipse.feature.feature.group 0.0.0’ but it could not be found
Cannot satisfy dependency:
From: Groovy for Capella Developer Resources 1.3.0.201812100951 (org.polarsys.capella.groovy.feature.source.feature.group 1.3.0.201812100951)
To: org.polarsys.capella.groovy.feature.feature.group [1.3.0.201812100951]
Do you have an idea how I can fix this?
Hi, I tested to install and it works. My guess: Capella Groovy depends on Groovy Eclipse Development Tools, but does not explicitly include it in the update site. It rather references their own update site. If you’re behind a firewall, this won’t work. Try and download
https://build.spring.io/browse/GRECLIPSE-E47M-536/artifact/J OB1/Zipped-Update-Site/org.codehaus.groovy-3.3.0.xx-20190301 0013-e47-updatesite.zip. Install the Groovy Eclipse Development Tools from that update site, and then retry with Groovy Capella.
Yes, that is working! Thanks!
The last (new) command of the example.groovy has a problem:
la.descendants().grep(ExchangeItem).each {
info it }
==>>
An internal error occurred during: “Capella Groovy Script Execution”.
No such property: ExchangeItem for class: capella.groovy.example.Example
==<<
Any Idea?
Oh, thanks, there’s a missing import in the example. Add
import org.polarsys.capella.core.data.information.* to the top (where the other import statements are) and then it works. I’ll fix the example.
Hello Felix,
I have another classpath(?) problem (or is it somewhere else?)…
When I generate a new class inside of the Example.groovy script there is no Problem to use this class inside of the script.
But when I transfer this class into an extra file I get an “unable to resolve class MyTestClass…” error.
The file is in the same directory and contains in the head the package definition…
file MyTestClass.groovy:
in Example.groovy
The code-completion is also working for this new class as expected and .class-files are generated for all classes in the ./bin/capella/groovy/example/ directory.
But I’m not able to run the script anymore.
So what am I missing here?
No I don’t thing it’s on your end. I think I have not done anything to make this case work. I will need to check.
Hello Felix,
did you have a look at it? I guess it is a “small” issue with groovy wrapping something around the classes as the classes result in both cases in class-files in the bin-directory.