InputStream in = this.getClass().getResourceAsStream("/
Workspace Declarations/cal.platform.car.cws");
if (in == null)
{
System.out.println("didn't find car-jar workspace");
}
CompilerMessageLogger logger = new MessageLogger();
BasicCALServices services =
BasicCALServices.makeCompiled("cal.platform.car.cws",logger);
And get the error (reported by the logger):
Error: ERROR: VaultRegistry: Could not retrieve workspace declaration
"cal.platform.car.cws", revision -1 from the given vault.
ERROR: The specified workspace declaration does not exist:
cal.platform.car.cws
ERROR: Problems encountered while constructing the workspace:
ERROR: VaultRegistry: Could not retrieve workspace declaration
"cal.platform.car.cws", revision -1 from the given vault.
ERROR: The specified workspace declaration does not exist:
cal.platform.car.cws
This works if I have a non-car-jarred workspace which imports
'StandardVault cal.platform.car.cws'
What am I missing?
Thanks,
Tom
Sorry to hear about your problem. If you wouldn't mind, I have a few
questions about the Car-jar:
- what were the options you used for building the Car-jar (was it via
ICE, the Gem Cutter, or the command line tool?)
- is it named cal.platform.car.jar, or has its name been changed?
- has the Car-jar been modified after it was built by the Car tool?
(e.g. unzipped into a directory and then re-zipped)
I have tried building a cal.platform.car.jar myself, and used your code
to load the workspace declaration from it, but could not reproduce the
issue.
If you like, you can send in your Car-jar to my email
(josep...@businessobjects.com), and I could take a further look at
it.
Thanks,
Joseph
#!/bin/sh
CAL_HOME=$HOME/dev/tools/cal-1.6.0
CAL_JARS=$CAL_HOME/Quark/bin/java/release
CAL_EXT_JARS=$CAL_HOME/Quark/lib/Resources/External/java
export CLASSPATH=$CLASSPATH:$CAL_HOME/Quark/bin/cal/debug:$CAL_JARS/
calLibraries.jar:$CAL_JARS/calPlatform.jar:$CAL_JARS/calUtilities.jar:
$CAL_EXT_JARS/antlr.jar:$CAL_EXT_JARS/asm-all-3.0.jar:$CAL_EXT_JARS/
commons-collections-3.1.jar:$CAL_EXT_JARS/icu4j.jar
java org.openquark.cal.services.CarTool cal.platform.cws -keepsource -
jar .
I haven't renamed or modified it, although I have moved it to another
directory.
I've tried running the simple test harness with your Car-jar on Windows
and Linux in an Eclipse environment, and also directly via a shell
script (based on yours) on Linux, and in all 3 cases the
BasicCALServices instance loads successfully with no errors.
You mentioned that if you had a regular workspace declaration (not in a
Car-jar) importing "StandardVault cal.platform.car.cws", then the
BasicCALServices instance loads fine? If that's the case, it may be
interesting for debugging purposes to dump out the configuration of the
workspace, by inserting a line:
System.out.println(services.getCALWorkspace().getDebugInfo());
...after the loading of the BasicCALServices instance. I'd be curious to
see what the results would be.
Cheers,
Joseph
-----Original Message-----
From: Tom Davies [mailto:t...@atlassian.com]
Sent: Friday, September 21, 2007 4:56 PM
To: Joseph Wong
Subject: Car-Jar
Hi Joe,
Here's the jar, thanks for having a look at it.
Regards,
Tom
-----Original Message-----
From: cal_la...@googlegroups.com
[mailto:cal_la...@googlegroups.com] On Behalf Of Tom Davies
Sent: Friday, September 21, 2007 4:40 PM
To: CAL Language Discussion
Thanks for your efforts.
It turns out that the problem is my class loader environment -- CAL is
running in an Intellij IDEA plugin, and the context class loader can't
see the car-jar, while the caller can.
I attach a patch which <del>fixes the bug</del> changes the behaviour
so that my use case works -- if the context class loader is non-null
but doesn't have a resource, the calling class' class loader is
checked.
Do you have a public issue tracker for reporting bugs?
--- ../../tools/cal-1.6.1/QuarkSrc/src/Utilities/org/openquark/util/
ClassInfo.java 2007-09-13 17:21:46.000000000 +1000
+++ src/org/openquark/util/ClassInfo.java 2007-09-23
00:40:10.000000000 +1000
@@ -39,7 +39,7 @@
import java.io.IOException;
import java.net.URL;
-import java.util.Enumeration;
+import java.util.*;
/**
@@ -47,6 +47,53 @@
* @author Edward Lam
*/
public final class ClassInfo {
+ private static interface ClassLoaderOp<T>
+ {
+ T getFromClassLoader(ClassLoader classLoader) throws
Exception;
+ T combine(T fromContext, T fromCaller);
+ boolean stopOnFirstSuccess();
+ }
+
+ private static abstract class NonCombiningOp<T> implements
ClassLoaderOp<T>
+ {
+ public T combine(T fromContext, T fromCaller)
+ {
+ return fromCaller;
+ }
+
+ public boolean stopOnFirstSuccess() { return true; }
+ }
+
+ private static <T> T doOp(ClassLoaderOp<T> op)
+ {
+ T fromContext = null;
+ try
+ {
+ ClassLoader contextClassLoader =
Thread.currentThread().getContextClassLoader();
+ if (contextClassLoader != null)
+ {
+ fromContext =
op.getFromClassLoader(contextClassLoader);
+ }
+ }
+ catch (Exception e)
+ {
+ // ignore
+ }
+ if (fromContext != null && op.stopOnFirstSuccess())
+ {
+ return fromContext;
+ }
+ T fromCaller = null;
+ try
+ {
+ fromCaller =
op.getFromClassLoader(getCallingClass(1).getClassLoader());
+ }
+ catch (Exception e)
+ {
+ // ignore
+ }
+ return op.combine(fromContext, fromCaller);
+ }
/** Singleton finder instance. */
private static final CallingClassFinder FINDER = new
CallingClassFinder();
@@ -117,6 +164,7 @@
* @return the corresponding class.
* @throws ClassNotFoundException if the class could not be
found.
*/
+
public static Class<?> loadClass(String name) throws
ClassNotFoundException {
// Note about implementation: this is how
antlr.Utils.loadClass() does it..
try {
@@ -139,17 +187,16 @@
* @param name the name of the resource
* @return the URL to that resource, or null if that resource
could not be found.
*/
- public static URL getResource(String name) {
- try {
- ClassLoader contextClassLoader =
Thread.currentThread().getContextClassLoader();
- if (contextClassLoader != null) {
- return contextClassLoader.getResource(name);
- }
- return
getCallingClass(1).getClassLoader().getResource(name);
- } catch (Exception e) {
- return
getCallingClass(1).getClassLoader().getResource(name);
+ public static URL getResource(final String name) {
+ return doOp(
+ new NonCombiningOp<URL>()
+ {
+ public URL getFromClassLoader(ClassLoader
classLoader)
+ {
+ return classLoader.getResource(name);
}
+ });
}
/**
@@ -161,19 +208,35 @@
* @return the URLs for the found resources.
* @throws IOException
*/
- public static Enumeration<URL> getResources(String name) throws
IOException {
+ public static Enumeration<URL> getResources(final String name)
throws IOException {
/*
* TODOEL: Does this work??
*/
- try {
- ClassLoader contextClassLoader =
Thread.currentThread().getContextClassLoader();
- if (contextClassLoader != null) {
- return contextClassLoader.getResources(name);
+ return doOp(new ClassLoaderOp<Enumeration<URL>>(){
+
+ public Enumeration<URL> getFromClassLoader(ClassLoader
classLoader) throws IOException
+ {
+ return classLoader.getResources(name);
}
- return
getCallingClass(1).getClassLoader().getResources(name);
- } catch (Exception e) {
- return
getCallingClass(1).getClassLoader().getResources(name);
+ public Enumeration<URL> combine(Enumeration<URL>
fromContext, Enumeration<URL> fromCaller)
+ {
+ List<URL> l = new ArrayList();
+ if (fromContext != null)
+ {
+ l.addAll(Collections.list(fromContext));
+ }
+ if (fromCaller != null)
+ {
+ l.addAll(Collections.list(fromCaller));
+ }
+ return new Vector(l).elements();
+ }
+
+ public boolean stopOnFirstSuccess()
+ {
+ return false;
}
+ });
}
}
I'm having a look at this now.
Can you email me the patch (or patched file) as a separate
attachment? The group posting seems to have messed up the formatting,
and I'm having trouble converting the text into a valid patch.
Note that we also have to deal with classloader issues when using CAL
within the context of an Eclipse plugin. The relevant code is in the
CAL_Eclipse_Bridge project (which consists of three files). Something
similar might be required if the issue can't be solved by playing
around with the context classloaders.
To answer your question about the public issue tracker -- we don't
have one yet, but it's something we definitely have under
consideration. At the moment though the number of bugs we have which
would hang around for any amount of time would be pretty low.
Thanks,
- Edward
The fix will be part of the next release of OpenQuark.
Cheers,
- Edward