Révision 269

tmp/org.txm.rcp/src/main/java/org/txm/rcpapplication/commands/ExecuteGroovyScript.java (revision 269)
43 43
import org.eclipse.core.commands.ExecutionEvent;
44 44
import org.eclipse.core.commands.ExecutionException;
45 45
import org.eclipse.core.internal.runtime.InternalPlatform;
46
import org.eclipse.core.runtime.FileLocator;
46 47
import org.eclipse.core.runtime.IProgressMonitor;
47 48
import org.eclipse.core.runtime.IStatus;
48 49
import org.eclipse.core.runtime.Platform;
......
64 65
import org.txm.cooccurrence.core.functions.Cooccurrence.CLine;
65 66
import org.txm.rcpapplication.Messages;
66 67
import org.txm.rcpapplication.TXMClassLoader;
68
import org.txm.rcpapplication.actions.GetConcordancesDialog;
67 69
import org.txm.rcpapplication.editors.TxtEditor;
68 70
import org.txm.rcpapplication.swt.dialog.LastOpened;
69 71
import org.txm.rcpapplication.swt.widget.parameters.UIParameterException;
......
220 222
					scriptRootDir+"/import/", //$NON-NLS-1$
221 223
			}; 
222 224

  
225
			ArrayList<String> roots2 = new ArrayList<String>(200);
226
			roots2.add(roots[0]);
227
			roots2.add(roots[1]);
228
			roots2.add(roots[2]);
229
			
230
			
223 231
			HashMap<String, Bundle> bundleWithActivators = new HashMap<String, Bundle>();
224 232
			HashSet<ClassLoader> loaders = new HashSet<ClassLoader>();
225 233
			BundleContext bundleContext = InternalPlatform.getDefault().getBundleContext();
234
			String[] bundlesRoots = new String[bundleContext.getBundles().length];
235
			
226 236
			for (Bundle b : bundleContext.getBundles()) {
227
				String acName = b.getHeaders().get("Bundle-Activator");
228
				if (acName != null) {
229
					if (!bundleWithActivators.containsKey(b.getSymbolicName())) {
230
						bundleWithActivators.put(b.getSymbolicName(),b);
231
					} else {
232
						Bundle b2 = bundleWithActivators.get(b.getSymbolicName());
233
						if (b2.getVersion().compareTo(b.getVersion()) < 0) {
234
							bundleWithActivators.put(b.getSymbolicName(),b);
235
						}
236
					}
237
				
238
				//FIXME: debug
239
				System.out.println("ExecuteGroovyScript.executeScript(): bundle symbolic name: " + b.getSymbolicName());
240
				System.out.println("ExecuteGroovyScript.executeScript(): bundle id: " + b.getBundleId());
241
				System.out.println("ExecuteGroovyScript.executeScript(): bundle location: " + b.getLocation());
242
				try {
243
					System.out.println("ExecuteGroovyScript.executeScript(): bundle file location: " + FileLocator.getBundleFile(b).getAbsolutePath() + "\\bin\\");
237 244
				}
238
			}
239
			
240
			for (Bundle b : bundleWithActivators.values()) {
245
				catch(IOException e) {
246
					// TODO Auto-generated catch block
247
					e.printStackTrace();
248
				}
249
				
241 250
				try {
242
					String acName = b.getHeaders().get("Bundle-Activator");
243
					Class<?> ac = b.loadClass(acName);
244
					loaders.add(ac.getClassLoader());
245
				} catch (ClassNotFoundException e) {
251
					roots2.add(FileLocator.getBundleFile(b).getAbsolutePath());
252
				}
253
				catch(IOException e) {
254
					// TODO Auto-generated catch block
246 255
					e.printStackTrace();
247 256
				}
257
				
258
//				String acName = b.getHeaders().get("Bundle-Activator");
259
//				if (acName != null) {
260
//					if (!bundleWithActivators.containsKey(b.getSymbolicName())) {
261
//						bundleWithActivators.put(b.getSymbolicName(),b);
262
//					} else {
263
//						Bundle b2 = bundleWithActivators.get(b.getSymbolicName());
264
//						if (b2.getVersion().compareTo(b.getVersion()) < 0) {
265
//							bundleWithActivators.put(b.getSymbolicName(),b);
266
//						}
267
//					}
268
//				}
248 269
			}
249
			Log.info("Initialized TXMClassLoader with "+loaders.size()+ " bundles.");
250
			TXMClassLoader scl = new TXMClassLoader(loaders);
270
			
271
//			for (Bundle b : bundleWithActivators.values()) {
272
//				try {
273
//					String acName = b.getHeaders().get("Bundle-Activator");
274
//					Class<?> ac = b.loadClass(acName);
275
//					loaders.add(ac.getClassLoader());
276
//					//FIXME: debug
277
//					System.out.println("ExecuteGroovyScript.executeScript(): loaders: " + ac.getClassLoader());
278
//				} catch (ClassNotFoundException e) {
279
//					e.printStackTrace();
280
//				}
281
//			}
282
//			Log.info("Initialized TXMClassLoader with "+loaders.size()+ " bundles.");
283
//			TXMClassLoader scl = new TXMClassLoader(loaders);
251 284

  
252 285
			try {
253
				gse = new GSERunner(roots, scl);
286
				//gse = new GSERunner(roots, scl);
287
				String[] roots3 = roots2.toArray(new String[roots2.size()]);
288
				gse = new GSERunner(roots3, ExecuteGroovyScript.class.getClassLoader());
254 289
			} catch (IOException e) {
255 290
				e.printStackTrace();
256 291
			}
tmp/org.txm.rcp/src/main/java/org/txm/rcpapplication/commands/CreateMacro.java (revision 269)
52 52
import org.txm.rcpapplication.views.fileexplorer.Explorer;
53 53
import org.txm.rcpapplication.views.fileexplorer.MacroExplorer;
54 54
import org.txm.utils.AsciiUtils;
55
import org.txm.utils.IOUtils;
55
import org.txm.utils.io.IOUtils;
56 56
// TODO: Auto-generated Javadoc
57 57
/**
58 58
 * Handler: creates a macro template
tmp/org.txm.rcp/src/main/java/org/txm/rcpapplication/commands/ExecuteGroovyMacro.java (revision 269)
44 44
import org.eclipse.ui.handlers.HandlerUtil;
45 45
import org.eclipse.ui.ide.FileStoreEditorInput;
46 46
import org.txm.Toolbox;
47
import org.txm.rcpapplication.Application;
48 47
import org.txm.rcpapplication.editors.TxtEditor;
49
import org.txm.rcpapplication.preferences.ScriptPreferenceInitializer;
50
import org.txm.rcpapplication.preferences.ScriptPreferencePage;
51 48
import org.txm.rcpapplication.swt.dialog.LastOpened;
52 49
// TODO: Auto-generated Javadoc
53 50
/**
tmp/org.txm.rcp/src/main/java/org/txm/rcpapplication/commands/ExecuteImportScript.java (revision 269)
33 33

  
34 34
import java.io.File;
35 35
import java.util.ArrayList;
36
import java.util.HashMap;
37
import java.util.HashSet;
36 38
import java.util.logging.Level;
37 39

  
38 40
import org.eclipse.core.commands.AbstractHandler;
39 41
import org.eclipse.core.commands.ExecutionEvent;
40 42
import org.eclipse.core.commands.ExecutionException;
43
import org.eclipse.core.internal.runtime.InternalPlatform;
41 44
import org.eclipse.core.runtime.IProgressMonitor;
42 45
import org.eclipse.core.runtime.IStatus;
43 46
import org.eclipse.core.runtime.Platform;
......
50 53
import org.eclipse.swt.widgets.FileDialog;
51 54
import org.eclipse.swt.widgets.Shell;
52 55
import org.eclipse.ui.handlers.HandlerUtil;
56
import org.osgi.framework.Bundle;
57
import org.osgi.framework.BundleContext;
53 58
import org.txm.Toolbox;
54 59
import org.txm.importer.xtz.ImportKeys;
55 60
import org.txm.objects.Base;
......
57 62
import org.txm.rcpapplication.Application;
58 63
import org.txm.rcpapplication.Messages;
59 64
import org.txm.rcpapplication.StatusLine;
65
import org.txm.rcpapplication.TXMClassLoader;
60 66
import org.txm.rcpapplication.commands.workspace.LoadBinaryCorpus;
61 67
import org.txm.rcpapplication.preferences.ScriptPreferenceInitializer;
62 68
import org.txm.rcpapplication.preferences.ScriptPreferencePage;
......
158 164
		String scriptRootDir = service.getString(Application.PLUGIN_ID,
159 165
				ScriptPreferencePage.SCRIPT_ROOT_DIR,
160 166
				ScriptPreferenceInitializer.SCRIPT_ROOT_DIR_DEFAULT, null);
161
		ClassLoader parent = ExecuteImportScript.class.getClassLoader();
162
		final GroovyClassLoader loader = new GroovyClassLoader(parent);
163
		final String[] roots = new String[] { 
164
				script.getParent(),
165
				scriptRootDir };
167
		
168
		//FIXME: old version
169
//		ClassLoader parent = ExecuteImportScript.class.getClassLoader();
170
//		final GroovyClassLoader loader = new GroovyClassLoader(parent);
171
//		final String[] roots = new String[] { 
172
//				script.getParent(),
173
//				scriptRootDir };
174
		
166 175
		params.load(); // reload params
167 176

  
177
		//FIXME: new version
178
		final String[] roots = new String[] { 
179
				scriptRootDir+"/user/", //$NON-NLS-1$
180
				scriptRootDir+"/macro/", //$NON-NLS-1$
181
				scriptRootDir+"/import/", //$NON-NLS-1$
182
		}; 
183
		System.err.println("ExecuteImportScript.executeScript(); retrieving bundles class loaders.");
184
		HashMap<String, Bundle> bundleWithActivators = new HashMap<String, Bundle>();
185
		HashSet<ClassLoader> loaders = new HashSet<ClassLoader>();
186
		BundleContext bundleContext = InternalPlatform.getDefault().getBundleContext();
187
		for (Bundle b : bundleContext.getBundles()) {
188
			String acName = b.getHeaders().get("Bundle-Activator");
189
			if (acName != null) {
190
				if (!bundleWithActivators.containsKey(b.getSymbolicName())) {
191
					bundleWithActivators.put(b.getSymbolicName(),b);
192
				} else {
193
					Bundle b2 = bundleWithActivators.get(b.getSymbolicName());
194
					if (b2.getVersion().compareTo(b.getVersion()) < 0) {
195
						bundleWithActivators.put(b.getSymbolicName(),b);
196
					}
197
				}
198
			}
199
		}
200
		
201
		for (Bundle b : bundleWithActivators.values()) {
202
			try {
203
				String acName = b.getHeaders().get("Bundle-Activator");
204
				Class<?> ac = b.loadClass(acName);
205
				loaders.add(ac.getClassLoader());
206
				//FIXME: debug
207
				System.out.println("ExecuteImportScript.executeScript(): " + ac.getClassLoader());
208
			} catch (ClassNotFoundException e) {
209
				e.printStackTrace();
210
			}
211
		}
212
		Log.info("Initialized TXMClassLoader with "+loaders.size()+ " bundles.");
213
		final TXMClassLoader loader = new TXMClassLoader(loaders);
214
		
215
		// FIXME: end of new version
216
		
217
		
168 218
		// the binary directory which is going to be created
169 219

  
170 220
		final File basedir = new File(corporadir, params.name);
......
208 258
					//org.txm.Toolbox.shutdownSearchEngine();
209 259
					monitor.worked(5);
210 260

  
211
					if (ExecuteImportScript.gse == null)
261
					//if (ExecuteImportScript.gse == null)
212 262
						ExecuteImportScript.gse = new GroovyScriptEngine(roots, loader);
213 263

  
214 264
					Binding binding = new Binding();
......
319 369
		int idx = scriptPackage.indexOf("Loader");
320 370
		scriptPackage = "org/txm/importer/" + scriptPackage.substring(0, idx);
321 371
		
322
		return BundleUtils.replaceFilesIfNewer("org.txm.toolbox", "src/groovy", scriptPackage, 
372
		return BundleUtils.replaceFilesIfNewer("org.txm.core", "src/groovy", scriptPackage, 
323 373
				script.getName(), script);
324 374
	}
325 375
}

Formats disponibles : Unified diff