Révision 3727
TXM/trunk/bundles/org.txm.groovy.core/src/java/org/txm/groovy/core/TXMClassLoader.java (revision 3727) | ||
---|---|---|
15 | 15 |
*/ |
16 | 16 |
public class TXMClassLoader extends ClassLoader { |
17 | 17 |
|
18 |
/** |
|
19 |
* Index of package names => loaders. |
|
20 |
*/ |
|
18 | 21 |
private HashMap<String, EquinoxClassLoader> loaders; |
19 | 22 |
|
23 |
/** |
|
24 |
* Index of bundle names => loaders. |
|
25 |
*/ |
|
20 | 26 |
private HashMap<String, HashSet<EquinoxClassLoader>> packageToLoaders; |
21 | 27 |
|
28 |
/** |
|
29 |
* Default loader to first look in. |
|
30 |
*/ |
|
22 | 31 |
private ClassLoader defaultLoader; |
23 | 32 |
|
33 |
|
|
24 | 34 |
/** |
25 | 35 |
* |
26 | 36 |
* @param defaultLoader |
27 | 37 |
* @param loaders2 |
28 | 38 |
*/ |
29 | 39 |
public TXMClassLoader(ClassLoader defaultLoader, HashSet<EquinoxClassLoader> loaders2) { |
30 |
this.loaders = new HashMap<>(); |
|
40 |
|
|
41 |
this.defaultLoader = defaultLoader; |
|
31 | 42 |
|
32 | 43 |
boolean useFastIndex = GroovyPreferences.getInstance().getBoolean(GroovyPreferences.FAST_PACKAGE_INDEX); |
33 | 44 |
|
... | ... | |
35 | 46 |
Log.finest("Fast package index option is activated."); //$NON-NLS-1$ |
36 | 47 |
this.packageToLoaders = new HashMap<String, HashSet<EquinoxClassLoader>>(); |
37 | 48 |
} |
49 |
else { |
|
50 |
this.loaders = new HashMap<>(); |
|
51 |
} |
|
38 | 52 |
|
53 |
// build an index of package names => loaders |
|
39 | 54 |
for (EquinoxClassLoader loader : loaders2) { |
40 |
|
|
41 |
String k = loader.getBundle().getSymbolicName(); |
|
42 |
|
|
43 |
loaders.put(k, loader); |
|
44 |
|
|
45 | 55 |
if (useFastIndex) { |
46 | 56 |
Dictionary<String, String> d = loader.getBundle().getHeaders(); |
47 | 57 |
String packagesString = d.get("Export-Package"); //$NON-NLS-1$ |
... | ... | |
58 | 68 |
} |
59 | 69 |
} |
60 | 70 |
} |
71 |
// build an index of bundle names => loaders |
|
72 |
else { |
|
73 |
loaders.put(loader.getBundle().getSymbolicName(), loader); |
|
74 |
} |
|
61 | 75 |
} |
62 | 76 |
// for(String p : packageToLoaders.keySet()) System.out.println(p); |
63 |
this.defaultLoader = defaultLoader; |
|
77 |
|
|
64 | 78 |
} |
65 | 79 |
|
66 | 80 |
@Override |
67 | 81 |
public Class<?> findClass(String name) throws ClassNotFoundException { |
68 | 82 |
|
83 |
|
|
69 | 84 |
// try with the System class loader |
70 | 85 |
try { |
71 | 86 |
Class<?> c = defaultLoader.loadClass(name); |
87 |
|
|
88 |
//System.out.println("+TXMClassLoader.findClass(): class loaded from default loader: " + name + " class:" + c.getCanonicalName()); |
|
89 |
|
|
72 | 90 |
return c; |
73 | 91 |
} |
74 | 92 |
catch (Exception e) { |
... | ... | |
76 | 94 |
|
77 | 95 |
|
78 | 96 |
if (packageToLoaders != null) { |
97 |
//get the package name from the canonical class name |
|
79 | 98 |
String p = null; |
80 | 99 |
int idx = name.lastIndexOf("."); |
81 | 100 |
if (idx > 0) { |
... | ... | |
89 | 108 |
if (loader != null) { |
90 | 109 |
Class<?> c = loader.loadClass(name); |
91 | 110 |
//System.out.println("load from " + loader.getName() + ": " + name); |
111 |
//System.out.println("+TXMClassLoader.findClass(): class loaded from package loaders index: " + name + " class:" + c.getCanonicalName()); |
|
92 | 112 |
return c; |
93 | 113 |
} |
94 | 114 |
} |
95 | 115 |
} |
96 | 116 |
} |
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
//System.out.println("-------TXMClassLoader.findClass(): class not found in default loader or package index: " + name); |
|
122 |
|
|
123 |
|
|
97 | 124 |
//TODO first tests did not boost the class loading |
98 | 125 |
// // try using the class package name |
99 | 126 |
// if (name.startsWith("org.txm.")) { |
TXM/trunk/bundles/org.txm.groovy.core/src/java/org/txm/groovy/core/GroovyPreferences.java (revision 3727) | ||
---|---|---|
3 | 3 |
import org.txm.core.preferences.TXMPreferences; |
4 | 4 |
|
5 | 5 |
public class GroovyPreferences extends TXMPreferences { |
6 |
|
|
6 |
|
|
7 |
//FIXME: SJ: useless? |
|
7 | 8 |
public static final String PREFERENCES_NODE = GroovyPreferences.class.getName();// FrameworkUtil.getBundle(RPreferences.class).getSymbolicName(); |
8 | 9 |
|
9 | 10 |
public static final String VERSION = "version"; //$NON-NLS-1$ |
10 | 11 |
|
11 |
public static String FAST_PACKAGE_INDEX = "fast_package_index"; |
|
12 |
public static final String FAST_PACKAGE_INDEX = "fast_package_index";
|
|
12 | 13 |
|
13 | 14 |
/** |
14 | 15 |
* Gets the instance. |
TXM/trunk/bundles/org.txm.groovy.core/src/java/org/txm/groovy/core/GSERunner.java (revision 3727) | ||
---|---|---|
209 | 209 |
// return -1; |
210 | 210 |
// } |
211 | 211 |
// }); |
212 |
HashSet<String> defaultPlugins = new HashSet<>(); |
|
212 |
//HashSet<String> defaultPlugins = new HashSet<>();
|
|
213 | 213 |
// getDependancies("org.txm.rcp", defaultPlugins); |
214 | 214 |
|
215 | 215 |
ClassLoader defaultLoader = EquinoxClassLoader.getSystemClassLoader(); |
... | ... | |
219 | 219 |
String name = b.getSymbolicName(); |
220 | 220 |
//if (!name.startsWith("org.txm")) continue; // only keep txm plugins (they contains the necessary plugins deps) |
221 | 221 |
//if (name.endsWith(".core")) continue; // usually TXM *.rcp plugins depends on the *.core plugins |
222 |
if (defaultPlugins.contains(name)) continue; |
|
222 |
//if (defaultPlugins.contains(name)) continue;
|
|
223 | 223 |
|
224 | 224 |
BundleWiring bundleWiring = b.adapt(BundleWiring.class); |
225 | 225 |
if (bundleWiring == null) { |
Formats disponibles : Unified diff