5 |
5 |
import java.io.IOException;
|
6 |
6 |
import java.net.MalformedURLException;
|
7 |
7 |
import java.net.URL;
|
|
8 |
import java.net.URLConnection;
|
8 |
9 |
import java.util.Comparator;
|
9 |
10 |
import java.util.HashMap;
|
10 |
11 |
import java.util.HashSet;
|
... | ... | |
35 |
36 |
*
|
36 |
37 |
*/
|
37 |
38 |
public class GSERunner extends GroovyScriptEngine {
|
38 |
|
|
|
39 |
|
39 |
40 |
protected GSERunner(String[] urls) throws IOException {
|
40 |
41 |
super(urls, getTXMClassLoader());
|
41 |
42 |
}
|
42 |
|
|
|
43 |
|
43 |
44 |
protected static GSERunner defaultGSE;
|
44 |
45 |
protected static File defaultScriptRootDir;
|
45 |
46 |
|
... | ... | |
59 |
60 |
File rootDir = new File(Toolbox.getTxmHomePath(), "scripts/groovy/");
|
60 |
61 |
// check if script root dir was changed
|
61 |
62 |
if (defaultScriptRootDir != null && defaultScriptRootDir.equals(rootDir) && defaultGSE != null) {
|
62 |
|
// try {
|
63 |
|
// defaultGSE.getGroovyClassLoader().addURL(rootDir.toURI().toURL());
|
64 |
|
// } catch (MalformedURLException e) {
|
65 |
|
// // TODO Auto-generated catch block
|
66 |
|
// e.printStackTrace();
|
67 |
|
// }
|
|
63 |
// try {
|
|
64 |
// defaultGSE.getGroovyClassLoader().addURL(rootDir.toURI().toURL());
|
|
65 |
// } catch (MalformedURLException e) {
|
|
66 |
// // TODO Auto-generated catch block
|
|
67 |
// e.printStackTrace();
|
|
68 |
// }
|
68 |
69 |
return defaultGSE;
|
69 |
70 |
}
|
70 |
|
|
|
71 |
|
71 |
72 |
String[] roots = new String[] {
|
72 |
73 |
rootDir.getAbsolutePath()+"/user/", //$NON-NLS-1$
|
73 |
74 |
//rootDir.getAbsolutePath()+"/system/", //$NON-NLS-1$
|
74 |
75 |
};
|
75 |
|
|
|
76 |
|
76 |
77 |
try {
|
77 |
78 |
defaultScriptRootDir = rootDir;
|
78 |
79 |
Log.fine("GSE roots: "+Arrays.toString(roots));
|
... | ... | |
81 |
82 |
e.printStackTrace();
|
82 |
83 |
return null;
|
83 |
84 |
}
|
84 |
|
|
|
85 |
|
85 |
86 |
ImportCustomizer imports = new ImportCustomizer();
|
86 |
87 |
imports.addStarImports("org.txm.rcp.utils",
|
87 |
88 |
"org.txm.utils",
|
... | ... | |
147 |
148 |
HashSet<ClassLoader> loaders = new HashSet<ClassLoader>();
|
148 |
149 |
BundleContext bundleContext = InternalPlatform.getDefault().getBundleContext();
|
149 |
150 |
Bundle[] bundles = bundleContext.getBundles();
|
150 |
|
// java.util.Arrays.sort(bundles, new Comparator<Bundle>() {
|
151 |
|
//
|
152 |
|
// @Override
|
153 |
|
// public int compare(Bundle o1, Bundle o2) {
|
154 |
|
// if (o1.getSymbolicName().startsWith("org.txm")) return 1;
|
155 |
|
// return -1;
|
156 |
|
// }
|
157 |
|
// });
|
|
151 |
// java.util.Arrays.sort(bundles, new Comparator<Bundle>() {
|
|
152 |
//
|
|
153 |
// @Override
|
|
154 |
// public int compare(Bundle o1, Bundle o2) {
|
|
155 |
// if (o1.getSymbolicName().startsWith("org.txm")) return 1;
|
|
156 |
// return -1;
|
|
157 |
// }
|
|
158 |
// });
|
158 |
159 |
HashSet<String> defaultPlugins = new HashSet<String>();
|
159 |
160 |
//getDependancies("org.txm.rcp", defaultPlugins);
|
160 |
161 |
|
... | ... | |
175 |
176 |
//System.out.println("GSERunner.createGSERunner(): NO class loader: " + b.getSymbolicName());
|
176 |
177 |
}
|
177 |
178 |
}
|
178 |
|
|
|
179 |
|
179 |
180 |
Log.fine("Initializing TXMClassLoader with " + loaders.size() + " bundles.");
|
180 |
181 |
//for (ClassLoader l : loaders) System.out.println(l);
|
181 |
182 |
return new TXMClassLoader(loaders);
|
182 |
183 |
}
|
183 |
|
|
|
184 |
|
184 |
185 |
/**
|
185 |
186 |
*
|
186 |
187 |
* Simplify the call a Groovy script within a Groovy script and allow to send named and typed arguments
|
... | ... | |
211 |
212 |
public Object run(Class clazz, Map args) throws ResourceException, ScriptException {
|
212 |
213 |
return run(clazz.getCanonicalName().replace(".", "/")+".groovy", new Binding(args));
|
213 |
214 |
}
|
214 |
|
|
|
215 |
|
215 |
216 |
/**
|
216 |
217 |
* Convenience method exactly the same as calling
|
217 |
218 |
* run(clazz, ["args":args])
|
... | ... | |
243 |
244 |
|
244 |
245 |
return run(clazz.getCanonicalName().replace(".", "/")+".groovy", new Binding(arrangedMap));
|
245 |
246 |
}
|
246 |
|
|
|
247 |
|
247 |
248 |
/**
|
248 |
249 |
* Convenience method exactly the same as calling
|
249 |
250 |
* run(clazz, ["args":[:]])
|
... | ... | |
260 |
261 |
arrangedMap.put("args", new HashMap<String, Object>());
|
261 |
262 |
return run(clazz.getCanonicalName().replace(".", "/")+".groovy", new Binding(arrangedMap));
|
262 |
263 |
}
|
|
264 |
|
|
265 |
////TODO ScriptCacheEntry is a private class...
|
|
266 |
// public boolean needToRecompile(String scriptName) throws ResourceException, ScriptException {
|
|
267 |
//
|
|
268 |
// URLConnection conn = this.getResourceConnection(scriptName);
|
|
269 |
// String path = conn.getURL().toExternalForm();
|
|
270 |
// ScriptCacheEntry entry = null;
|
|
271 |
// Class clazz = null;
|
|
272 |
// if (entry != null) clazz = entry.scriptClass;
|
|
273 |
// try {
|
|
274 |
// return isSourceNewer(entry);
|
|
275 |
//
|
|
276 |
// }
|
|
277 |
// catch(Exception e) {
|
|
278 |
//
|
|
279 |
// }
|
|
280 |
//
|
|
281 |
// }
|
|
282 |
// }
|
263 |
283 |
}
|