Revision 3004

tmp/org.txm.groovy.core/src/java/org/txm/groovy/core/TXMClassLoader.java (revision 3004)
3 3
import java.util.HashSet;
4 4

  
5 5
import org.eclipse.osgi.internal.loader.EquinoxClassLoader;
6
import org.txm.utils.logger.Log;
7 6

  
8 7
/**
9 8
 * Class loader that looking for a class in all installed RCP Bundle then load it.
......
13 12
 */
14 13
public class TXMClassLoader extends ClassLoader {
15 14
	
16
	private HashSet<ClassLoader> loaders;
15
	private HashSet<EquinoxClassLoader> loaders;
17 16
	
18
	public TXMClassLoader(HashSet<ClassLoader> loaders2) {
17
	ClassLoader defaultLoader;
18
	
19
	public TXMClassLoader(ClassLoader defaultLoader, HashSet<EquinoxClassLoader> loaders2) {
19 20
		this.loaders = loaders2;
20 21
	}
21 22
	
22 23
	@Override
23
	public Class findClass(String name) throws ClassNotFoundException {
24
	public Class<?> findClass(String name) throws ClassNotFoundException {
24 25
		
25 26
		// try with the System class loader
26 27
		try {
27
			return this.getClass().getClassLoader().loadClass(name);
28
			return defaultLoader.loadClass(name);
28 29
		}
29 30
		catch (Exception e) {
30 31
		}
31 32
		
32
		for (ClassLoader cl : loaders) {
33
		for (EquinoxClassLoader cl : loaders) {
33 34
			
34 35
			// FIXME: SJ: tests to speed up this very long process
35 36
			// if(cl instanceof EquinoxClassLoader) {
tmp/org.txm.groovy.core/src/java/org/txm/groovy/core/GSERunner.java (revision 3004)
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
	}
tmp/org.txm.groovy.core/plugin.xml (revision 3004)
16 16
            name="org.txm.groovy.core.GroovyImportEngine">
17 17
      </ImportEngine>
18 18
   </extension>
19
   <extension
20
         point="org.txm.core.engines.ScriptEngine">
21
      <ScriptEngine
22
            class="org.txm.groovy.core.TXMGroovyScriptEngine"
23
            name="Groovy">
24
      </ScriptEngine>
25
   </extension>
19 26

  
20 27
</plugin>

Also available in: Unified diff