make plugin visible in scripting

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

make plugin visible in scripting

Andrea Antonello
Hi developers,
I am trying to access classes of my custom plugin inside a groovy
script (but the same happens for python scripts).

I thought that the plugins added and active in the gvSIG installation
would be accessible inside the scripts, but if I try to run something
like:

import org.jgrasstools.modules.*
import org.jgrasstools.gvsig.base.*

def main() {

  def lastFile = JGTUtilities.getLastFile();
  println lastFile

  def help = ModelsSupporter.generateHelp(new Pitfiller());
  println(help)
}

I tried two different imports because:

the first is a package contained in a jar that is contained in a custom plugin
the second is a class directly contained inside a plugin

Both (run singularly) complain about the missing jgrasstools modules.

Is there something I need to do to make the plugins accessible? I know
Oscar has been able to make this work in the past.

Thanks,
Andrea

_______________________________________________
gvSIG-desktop-devel mailing list
http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
Reply | Threaded
Open this post in threaded view
|

Re: make plugin visible in scripting

Óscar Martínez
Hi Andrea,

For Jython: You have to use.. use_plugin(PluginName). The folder name of
the extension in gvSIG/extensiones/  It should be like this:

# encoding: utf-8

import gvsig
from gvsig.uselib import use_plugin
use_plugin("org.gvsig.gdal.app.mainplugin")

#now your imports

def main(*args):
     pass

I remember when I showed it to you, we had some problems when we imported the jgrasstools module.

For Groovy, i never try it.. The use_plugin function in groovy format
would be something like this:

import org.gvsig.andami.PluginsLocator
use_plugin("org.gvsig.gdal.app.mainplugin")

def use_plugin(pluginName) {
   pluginsManager = PluginsLocator.getManager()
   other = pluginsManager.getPlugin(pluginName)
   scripting =
pluginsManager.getPlugin("org.gvsig.scripting.app.mainplugin")
   scripting.addDependencyWithPlugin(other)
}

Best regards,
Óscar

El 29/09/2017 a las 10:57, andrea antonello escribió:

> Hi developers,
> I am trying to access classes of my custom plugin inside a groovy
> script (but the same happens for python scripts).
>
> I thought that the plugins added and active in the gvSIG installation
> would be accessible inside the scripts, but if I try to run something
> like:
>
> import org.jgrasstools.modules.*
> import org.jgrasstools.gvsig.base.*
>
> def main() {
>
>    def lastFile = JGTUtilities.getLastFile();
>    println lastFile
>
>    def help = ModelsSupporter.generateHelp(new Pitfiller());
>    println(help)
> }
>
> I tried two different imports because:
>
> the first is a package contained in a jar that is contained in a custom plugin
> the second is a class directly contained inside a plugin
>
> Both (run singularly) complain about the missing jgrasstools modules.
>
> Is there something I need to do to make the plugins accessible? I know
> Oscar has been able to make this work in the past.
>
> Thanks,
> Andrea
>
> _______________________________________________
> gvSIG-desktop-devel mailing list
> http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel


_______________________________________________
gvSIG-desktop-devel mailing list
http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
Reply | Threaded
Open this post in threaded view
|

Re: make plugin visible in scripting

Andrea Antonello
Hi Oscar,

> For Jython: You have to use.. use_plugin(PluginName). The folder name of the
> extension in gvSIG/extensiones/  It should be like this:
>
> # encoding: utf-8
>
> import gvsig
> from gvsig.uselib import use_plugin
> use_plugin("org.gvsig.gdal.app.mainplugin")
>
> #now your imports
>
> def main(*args):
>     pass


I tried to go step by step and therefore first with jython:

from gvsig.uselib import use_plugin
use_plugin("org.jgrasstools.gvsig.base")
import org.jgrasstools.gvsig.base

But I get:
Error ImportError: No module named jgrasstools in <script> at line number 7
where line 7 is the one with the import statement.

> I remember when I showed it to you, we had some problems when we imported
> the jgrasstools module.

Yes, but that was due to the SPI nature of the vector/geotools based
modules. Here I am just trying to access plugin-internal code. This
should be no problem at all.

Thanks,
Andrea

_______________________________________________
gvSIG-desktop-devel mailing list
http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
Reply | Threaded
Open this post in threaded view
|

Re: make plugin visible in scripting

Andrea Antonello
Ok, just to complete the thread, from an offline discussion with Oscar:

1) iin python the import needs to be done like this to work:

from org.jgrasstools.gvsig.base import JGTUtilities

2) in groovy as Oscar already stated, it has to look like this:

import org.gvsig.andami.PluginsLocator
usePlugin("org.jgrasstools.gvsig.base")
import org.jgrasstools.gvsig.base.*

def usePlugin(pluginName) {
  pluginsManager = PluginsLocator.getManager()
  other = pluginsManager.getPlugin(pluginName)
  scripting = pluginsManager.getPlugin("org.gvsig.scripting.app.mainplugin")
  scripting.addDependencyWithPlugin(other)
}

def main() {
  def lastFile = JGTUtilities.getLastFile();
  println lastFile
}


the above is obviously only an example based on the jgrasstools
plugins, but it gives the idea.

Also, for the groovy scripting part, there is a small bug that doesn't
redirect the script output properly in the editor console. So the
println statements will not be seen in the console.
An issue has already been opened here:
https://redmine.gvsig.net/redmine/issues/4693

Thanks,
Ciao
Andrea




On Fri, Sep 29, 2017 at 1:28 PM, andrea antonello
<[hidden email]> wrote:

> Hi Oscar,
>
>> For Jython: You have to use.. use_plugin(PluginName). The folder name of the
>> extension in gvSIG/extensiones/  It should be like this:
>>
>> # encoding: utf-8
>>
>> import gvsig
>> from gvsig.uselib import use_plugin
>> use_plugin("org.gvsig.gdal.app.mainplugin")
>>
>> #now your imports
>>
>> def main(*args):
>>     pass
>
>
> I tried to go step by step and therefore first with jython:
>
> from gvsig.uselib import use_plugin
> use_plugin("org.jgrasstools.gvsig.base")
> import org.jgrasstools.gvsig.base
>
> But I get:
> Error ImportError: No module named jgrasstools in <script> at line number 7
> where line 7 is the one with the import statement.
>
>> I remember when I showed it to you, we had some problems when we imported
>> the jgrasstools module.
>
> Yes, but that was due to the SPI nature of the vector/geotools based
> modules. Here I am just trying to access plugin-internal code. This
> should be no problem at all.
>
> Thanks,
> Andrea

_______________________________________________
gvSIG-desktop-devel mailing list
http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel