4 |
4 |
import java.io.FilenameFilter;
|
5 |
5 |
import java.io.IOException;
|
6 |
6 |
import java.net.MalformedURLException;
|
7 |
|
import java.net.URL;
|
8 |
|
import java.net.URLConnection;
|
9 |
|
import java.util.Comparator;
|
10 |
7 |
import java.util.HashMap;
|
11 |
8 |
import java.util.HashSet;
|
12 |
9 |
import java.util.Map;
|
13 |
|
import java.util.jar.Attributes;
|
14 |
|
import java.util.jar.Manifest;
|
15 |
10 |
|
|
11 |
import org.apache.commons.lang.StringUtils;
|
16 |
12 |
import org.codehaus.groovy.control.CompilerConfiguration;
|
17 |
13 |
import org.codehaus.groovy.control.customizers.ImportCustomizer;
|
18 |
14 |
import org.eclipse.core.internal.runtime.InternalPlatform;
|
|
15 |
import org.eclipse.osgi.internal.loader.EquinoxClassLoader;
|
19 |
16 |
import org.osgi.framework.Bundle;
|
20 |
17 |
import org.osgi.framework.BundleContext;
|
21 |
18 |
import org.osgi.framework.wiring.BundleWiring;
|
... | ... | |
124 |
121 |
}
|
125 |
122 |
}
|
126 |
123 |
}
|
127 |
|
defaultGSE.getGroovyClassLoader().addClasspath(rootDir.getAbsolutePath()); // for the .class files if any
|
128 |
124 |
|
|
125 |
// for the .class files if any
|
|
126 |
defaultGSE.getGroovyClassLoader().addClasspath(rootDir.getAbsolutePath());
|
|
127 |
|
129 |
128 |
return defaultGSE;
|
130 |
129 |
}
|
131 |
130 |
|
... | ... | |
149 |
148 |
* @return a class loader containing all bundles activated in TXM
|
150 |
149 |
*/
|
151 |
150 |
protected static ClassLoader getTXMClassLoader() {
|
152 |
|
HashSet<ClassLoader> loaders = new HashSet<ClassLoader>();
|
|
151 |
HashSet<EquinoxClassLoader> loaders = new HashSet<>();
|
153 |
152 |
BundleContext bundleContext = InternalPlatform.getDefault().getBundleContext();
|
154 |
153 |
Bundle[] bundles = bundleContext.getBundles();
|
155 |
154 |
// java.util.Arrays.sort(bundles, new Comparator<Bundle>() {
|
... | ... | |
160 |
159 |
// return -1;
|
161 |
160 |
// }
|
162 |
161 |
// });
|
163 |
|
HashSet<String> defaultPlugins = new HashSet<String>();
|
|
162 |
HashSet<String> defaultPlugins = new HashSet<>();
|
164 |
163 |
// getDependancies("org.txm.rcp", defaultPlugins);
|
165 |
164 |
|
|
165 |
ClassLoader defaultLoader = EquinoxClassLoader.getSystemClassLoader();
|
|
166 |
|
166 |
167 |
for (Bundle b : bundles) {
|
167 |
168 |
if (b == null) continue;
|
|
169 |
String name = b.getSymbolicName();
|
|
170 |
if (!name.startsWith("org.txm")) continue; // only keep txm plugins (they contains the necessary plugins deps)
|
|
171 |
if (!name.endsWith(".rcp")) continue; // usually TXM *.rcp plugins depends on the *.core plugins
|
|
172 |
if (defaultPlugins.contains(name)) continue;
|
168 |
173 |
|
169 |
|
if (!b.getSymbolicName().startsWith("org.txm")) continue;
|
170 |
|
if (defaultPlugins.contains(b.getSymbolicName())) continue;
|
171 |
|
|
172 |
174 |
BundleWiring bundleWiring = b.adapt(BundleWiring.class);
|
173 |
175 |
if (bundleWiring == null) {
|
174 |
176 |
// System.out.println("GSERunner.createGSERunner(): NO wiring: " + b.getSymbolicName());
|
175 |
177 |
}
|
176 |
178 |
else if (bundleWiring.getClassLoader() != null) {
|
177 |
|
loaders.add(bundleWiring.getClassLoader());
|
|
179 |
EquinoxClassLoader loader = (EquinoxClassLoader) bundleWiring.getClassLoader();
|
|
180 |
|
|
181 |
loaders.add(loader);
|
|
182 |
if (loaders.contains(loader.getParent())) {
|
|
183 |
loaders.remove(loader.getParent());
|
|
184 |
}
|
|
185 |
|
|
186 |
// if ("org.txm.rcp".equals(name)) {
|
|
187 |
// defaultLoader = loader;
|
|
188 |
// }
|
178 |
189 |
// FIXME: debug
|
179 |
190 |
// System.out.println("GSERunner.createGSERunner(): ADD class loader: " + b.getSymbolicName());
|
180 |
191 |
}
|
... | ... | |
185 |
196 |
|
186 |
197 |
Log.fine("Initializing TXMClassLoader with " + loaders.size() + " bundles.");
|
187 |
198 |
// for (ClassLoader l : loaders) System.out.println(l);
|
188 |
|
return new TXMClassLoader(loaders);
|
|
199 |
return new TXMClassLoader(defaultLoader, loaders);
|
189 |
200 |
}
|
190 |
201 |
|
191 |
202 |
/**
|
... | ... | |
201 |
212 |
*/
|
202 |
213 |
@SuppressWarnings("rawtypes")
|
203 |
214 |
public Object run(File script, Binding binding) throws MalformedURLException, ResourceException, ScriptException {
|
204 |
|
return super.run(script.toURI().toURL().toString(), binding);
|
|
215 |
String scriptName = script.toURI().toURL().toString();
|
|
216 |
// Class clazz = this.loadScriptByName(scriptName);
|
|
217 |
//
|
|
218 |
// Script sc = InvokerHelper.createScript(clazz, binding);
|
|
219 |
return super.run(scriptName, binding);
|
205 |
220 |
}
|
206 |
221 |
|
207 |
222 |
/**
|
... | ... | |
231 |
246 |
*/
|
232 |
247 |
@SuppressWarnings("rawtypes")
|
233 |
248 |
public Object runMacro(Class clazz, Map args) throws ResourceException, ScriptException {
|
234 |
|
HashMap<String, Object> arrangedMap = new HashMap<String, Object>();
|
|
249 |
HashMap<String, Object> arrangedMap = new HashMap<>();
|
235 |
250 |
arrangedMap.put("args", args);
|
236 |
251 |
|
237 |
252 |
|
... | ... | |
262 |
277 |
*/
|
263 |
278 |
@SuppressWarnings("rawtypes")
|
264 |
279 |
public Object runMacro(Class clazz) throws ResourceException, ScriptException {
|
265 |
|
HashMap<String, Object> arrangedMap = new HashMap<String, Object>();
|
|
280 |
HashMap<String, Object> arrangedMap = new HashMap<>();
|
266 |
281 |
arrangedMap.put("args", new HashMap<String, Object>());
|
267 |
282 |
return run(clazz.getCanonicalName().replace(".", "/") + ".groovy", new Binding(arrangedMap));
|
268 |
283 |
}
|