/// <summary> /// Creates a new <c>java.net.URLClassLoader</c> that wraps the /// resource URL closure of the given starting assembly list. /// </summary> /// <param name="startingList">The starting list.</param> /// <returns>A new <c>java.net.URLClassLoader</c></returns> //[CLSCompliant(false)] public static ClassLoader CreateLoader(List <Assembly> startingList) { URL[] urls = IkvmResourceLoaderFactory.FindResourceURLClosure( startingList); return(new URLClassLoader(urls)); }
/// <summary> /// Gets an embedded session using the given properties. /// </summary> /// <remarks> /// It is assumed (but not checked) that the given properties /// object requests a session with a res: protocol database /// instance; work is performed toward configuring and locking /// the ambient class loading environment to correctly handle /// searching the transitive closure of <c>ikvmres:</c> /// protocol resources reachable by compile-time reference, /// starting with the assemblies referenced on the call stack, /// as well as the entry level, calling and executing assemblies /// and their related satellite assemblies. /// </remarks> /// <param name="properties">The properties.</param> /// <returns>an embedded session</returns> internal static HsqlSession NewEmbeddedResSession( HsqlProperties properties) { StackTrace trace = new StackTrace(); java.util.Set set = new java.util.HashSet(); foreach (StackFrame frame in trace.GetFrames()) { set.add(frame.GetMethod().DeclaringType.Assembly.FullName); } List <Assembly> startingList = new List <Assembly>(); foreach (string name in set.toArray()) { try { startingList.Add(Assembly.Load(name)); } catch { } } startingList.Add(Assembly.GetExecutingAssembly()); startingList.Add(Assembly.GetCallingAssembly()); if (Assembly.GetEntryAssembly() != null) { startingList.Add(Assembly.GetEntryAssembly()); } java.lang.ClassLoader loader = IkvmResourceLoaderFactory.CreateLoader(startingList); lock (s_resLock) { org.hsqldb.lib.ResourceStreamProvider.setLoader(loader); return(HsqlSession.Factory.NewEmbeddedSession(properties)); } }
/// <summary> /// Adds the given assembly to the included set, if and only /// if it is not contained by the encountered set and it /// is not a system assembly; a core HSQLDB assembly; an /// IKVM assembly; an NUnit assembly or a TestDriven.NET /// assembly. /// </summary> /// <remarks> /// The exclusion list could be made much larger to produce /// a higher quality included set, but at what price? /// </remarks> /// <param name="encountered">The assemblies encountered so far.</param> /// <param name="included">The assemblies included so far.</param> /// <param name="entry">The assembly to add.</param> internal static void AddAssembly( Set encountered, Set included, Assembly entry) { if (entry == null || encountered.contains(entry)) { return; } else { encountered.add(entry); } string simpleName = entry.GetName().Name; // ignored (performance optimization) if (simpleName == "System" || simpleName == "mscorlib" || simpleName == "Org.Hsqldb" || simpleName.StartsWith("System.") || simpleName.StartsWith("IKVM.") || simpleName.StartsWith("nunit.") || simpleName.StartsWith("TestDriven.")) { return; } else { included.add(entry); } try { Assembly satellite = entry.GetSatelliteAssembly(CultureInfo.CurrentCulture); IkvmResourceLoaderFactory.AddAssembly( encountered, included, satellite); } catch (Exception ex) { #if DEBUG Debug.WriteLine(ex); #endif } AssemblyName[] referencedAssemblies = entry.GetReferencedAssemblies(); for (int i = 0; i < referencedAssemblies.Length; i++) { AssemblyName assemblyName = referencedAssemblies[i]; try { Assembly referencedAssembly = Assembly.Load(assemblyName); IkvmResourceLoaderFactory.AddAssembly( encountered, included, referencedAssembly); } catch (System.Exception ex) { #if DEBUG Debug.WriteLine(ex); #endif } } }