

def use_plugin(pluginName):
  from org.gvsig.andami import PluginsLocator

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

def use_jar(fname, root=__file__):
  from java.io import File
  import sys
  import os

  if isinstance(fname,File):
    f = fname
    fname = f.getPath()
  else:
    f = File(fname)
  if not f.isAbsolute() :
    rf = File(root)
    if rf.isFile() :
      rf = rf.getParentFile()
    f = File( rf,fname)

  fname = f.getCanonicalPath()
  if not fname in sys.path:
    sys.path.append(fname)

def use_libs(folder):
  import sys
  if not folder in sys.path:
    sys.path.append(folder)

def use_jars(base,folder):
  import os, os.path

  if os.path.isfile(base):
    base = os.path.dirname(base)
  folder = os.path.join(base,folder)
  for f in os.listdir(folder):
    if f.endswith(".jar"):
      pathname = os.path.join(folder,f)
      use_jar(pathname)
