Hi Luke,
you are right about trickiness of Eclipse and its classloader
infrastructure. Please see thread `Where to find Eclipse-plugin
sources?' where I've reported issue while using
BasicCALServices.makeCompiled call from inside the Eclipse plug-in.
Well, the issue seems to be caused by Eclipse classloaders as it
seems. I've kind of fixed that by really crude hack where in
BasicNullaryEnvironment's getFile methods I try to use Eclipse's way
of transforming bundle's URL to real file URL by using reflection.
This way the code is compilable even w/o Eclipse plugins on the
classpath and once run outside of the Eclipse it simply throws
exception and continues with usual Quark way.
I'm attaching the patch below for your reference. Please let me know
if this is includable into Quark or if you do have different strategy
how to proceed in this case.
Thanks,
Karel
--- /export/home/karel/vcs/Open-Quark/src/CAL_Platform/src/org/
openquark/cal/services/BasicNullaryEnvironment.java Wed Au
g 18 15:12:13 2010
+++ BasicNullaryEnvironment.java Sat Sep 11 18:16:48 2010
@@ -190,6 +190,31 @@
*/
private static File getFile(ResourcePath.Folder folder, boolean
createDirectoryIfAbsent) {
URL resourceURL = getURL(folder);
+ // here we need to check if we're working inside the Eclipse
or not
+ // Let's use introspection for this as we'd not like to
depend on
+ // Eclipse stuff here.
+ boolean insideEclipse = false;
+ try {
+ Class floaderClass =
Class.forName("org.eclipse.core.runtime.FileLocator");
+ Class urlClass = Class.forName("java.net.URL");
+ java.lang.reflect.Method m = null;
+ if (floaderClass != null) {
+ m = floaderClass.getMethod("toFileURL", urlClass);
+ }
+ if (floaderClass != null
+ && m != null) {
+ // Wow! This looks like Eclipse from inside!
+ URL backupResourceURL = resourceURL;
+ Object result = m.invoke(null, new Object[]
{backupResourceURL});
+ insideEclipse = true;
+ resourceURL = (URL)result;
+ }
+ }
+ catch (Exception ex) {
+ }
+// if (!insideEclipse) {
+// System.err.println("That's boring stand-alone Java app
probably...");
+// }
// Check whether the resource does not currently exist.
if (resourceURL != null) {
@@ -236,6 +261,32 @@
// If the file exists, return it.
URL resourceURL = getURL(filePath);
+ // here we need to check if we're working inside the Eclipse
or not
+ // Let's use introspection for this as we'd not like to
depend on
+ // Eclipse stuff here.
+ boolean insideEclipse = false;
+ try {
+ Class floaderClass =
Class.forName("org.eclipse.core.runtime.FileLocator");
+ Class urlClass = Class.forName("java.net.URL");
+ java.lang.reflect.Method m = null;
+ if (floaderClass != null) {
+ m = floaderClass.getMethod("toFileURL", urlClass);
+ }
+ if (floaderClass != null
+ && m != null) {
+ // Wow! This looks like Eclipse from inside!
+ URL backupResourceURL = resourceURL;
+ Object result = m.invoke(null, new Object[]
{backupResourceURL});
+ insideEclipse = true;
+ resourceURL = (URL)result;
+ }
+ }
+ catch (Exception ex) {
+ }
+// if (!insideEclipse) {
+// System.err.println("That's boring stand-alone Java app
probably...");
+// }
+
if (resourceURL != null) {
URI resourceURI = WorkspaceLoader.urlToUri(resourceURL);