Revision 1092
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/java/org/gvsig/scripting/app/extension/ScriptingExtension.java | ||
---|---|---|
21 | 21 |
*/ |
22 | 22 |
package org.gvsig.scripting.app.extension; |
23 | 23 |
|
24 |
import java.io.File; |
|
24 | 25 |
import java.io.InputStream; |
26 |
import java.net.MalformedURLException; |
|
27 |
import java.net.URL; |
|
25 | 28 |
import java.util.List; |
26 | 29 |
import org.apache.commons.io.IOUtils; |
27 | 30 |
import org.apache.commons.lang3.StringUtils; |
... | ... | |
31 | 34 |
import org.gvsig.andami.PluginsLocator; |
32 | 35 |
import org.gvsig.andami.PluginsManager; |
33 | 36 |
import org.gvsig.andami.plugins.Extension; |
37 |
import org.gvsig.andami.plugins.PluginClassLoader; |
|
34 | 38 |
import org.gvsig.scripting.ScriptingLocator; |
35 | 39 |
import org.gvsig.scripting.ScriptingManager; |
36 | 40 |
import org.gvsig.scripting.swing.api.ScriptingSwingLocator; |
... | ... | |
179 | 183 |
return true; |
180 | 184 |
} |
181 | 185 |
|
186 |
public static void add_classpath(URL url) { |
|
187 |
if( url==null ) { |
|
188 |
LOGGER.warn("Can't add to the plugin classloader a null URL."); |
|
189 |
return; |
|
190 |
} |
|
191 |
try { |
|
192 |
PluginsManager manager = PluginsLocator.getManager(); |
|
193 |
PluginServices thePlugin = manager.getPlugin(ScriptingExtension.class); |
|
194 |
PluginClassLoader loader = thePlugin.getClassLoader(); |
|
195 |
loader.addURL(url); |
|
196 |
} catch(Throwable th) { |
|
197 |
LOGGER.warn("Can't add the url '"+url.toString()+"' to the plugin classloader.",th); |
|
198 |
} |
|
199 |
} |
|
200 |
|
|
201 |
public static void add_classpath(File path) { |
|
202 |
if( path==null ) { |
|
203 |
LOGGER.warn("Can't create a url from a null file."); |
|
204 |
return; |
|
205 |
} |
|
206 |
try { |
|
207 |
URL url = path.toURI().toURL(); |
|
208 |
add_classpath(url); |
|
209 |
} catch (MalformedURLException ex) { |
|
210 |
LOGGER.warn("Can't create a url from the path '"+path+"'.", ex); |
|
211 |
} |
|
212 |
} |
|
213 |
|
|
214 |
public static void add_classpath(String path) { |
|
215 |
if( path==null ) { |
|
216 |
LOGGER.warn("Can't create a url from a null path."); |
|
217 |
return; |
|
218 |
} |
|
219 |
File f = new File(path); |
|
220 |
add_classpath(f); |
|
221 |
} |
|
222 |
|
|
182 | 223 |
@Override |
183 | 224 |
public PluginServices getPlugin() { |
184 | 225 |
PluginServices thePlugin = super.getPlugin(); |
... | ... | |
189 | 230 |
return thePlugin; |
190 | 231 |
} |
191 | 232 |
|
192 |
|
|
193 | 233 |
} |
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/resources-plugin/scripting/lib/gvsig/uselib.py | ||
---|---|---|
8 | 8 |
scripting = pluginsManager.getPlugin("org.gvsig.scripting.app.mainplugin") |
9 | 9 |
scripting.addDependencyWithPlugin(other) |
10 | 10 |
|
11 |
def use_jar(fname, root=__file__, isglobal=False): |
|
12 |
from org.gvsig.scripting import ScriptingLocator |
|
13 |
from java.io import File |
|
14 |
import sys |
|
15 |
import os |
|
11 |
def use_jar(fname): |
|
12 |
from org.gvsig.scripting.app.extension import ScriptingExtension |
|
16 | 13 |
|
17 |
if isinstance(fname,File): |
|
18 |
f = fname |
|
19 |
fname = f.getPath() |
|
20 |
else: |
|
21 |
f = File(fname) |
|
22 |
if not f.isAbsolute() : |
|
23 |
rf = File(root) |
|
24 |
if rf.isFile() : |
|
25 |
rf = rf.getParentFile() |
|
26 |
f = File( rf,fname) |
|
14 |
ScriptingExtension.add_classpath(fname) |
|
27 | 15 |
|
28 |
fname = f.getCanonicalPath() |
|
29 |
use_libs(fname,isglobal=isglobal) |
|
30 |
|
|
31 | 16 |
def use_libs(folder, isglobal=False): |
32 | 17 |
from org.gvsig.scripting import ScriptingLocator |
33 | 18 |
import sys |
... | ... | |
43 | 28 |
elif not folder in global_path: |
44 | 29 |
global_path.append(folder) |
45 | 30 |
|
46 |
def use_jars(base,folder, isglobal=False):
|
|
31 |
def use_jars(base): |
|
47 | 32 |
import os, os.path |
48 | 33 |
|
49 | 34 |
if os.path.isfile(base): |
50 | 35 |
base = os.path.dirname(base) |
51 |
folder = os.path.join(base,folder) |
|
52 |
for f in os.listdir(folder): |
|
36 |
for f in os.listdir(base): |
|
53 | 37 |
if f.endswith(".jar"): |
54 |
pathname = os.path.join(folder,f) |
|
55 |
use_jar(pathname,isglobal=isglobal) |
|
38 |
pathname = os.path.join(base,f) |
|
39 |
use_jar(pathname) |
Also available in: Unified diff