예제 #1
0
파일: JavaTask.cs 프로젝트: timmahon/ikvm
        private bool GenerateStubs()
        {
            // we start by creating the stubs for the boot classes
            string stubpath = GetStubPath();

            Directory.CreateDirectory(stubpath);
            // note that File.GetLastWriteTime() returns Jan 1st, 1601 for non-existing files, so that works out nicely
            if (File.GetLastWriteTime(Path.Combine(stubpath, "rt.jar")) < File.GetLastWriteTime(Path.Combine(GetAssemblyPath(), "IKVM.OpenJDK.Core.dll")))
            {
                if (!GenerateStub("IKVM.OpenJDK.Core", Path.Combine(stubpath, "rt.jar")))
                {
                    return(false);
                }
            }
            // now generate stubs for the referenced assemblies
            Dictionary <string, string> stubs = new Dictionary <string, string>();

            using (IKVM.Reflection.Universe universe = new IKVM.Reflection.Universe(IKVM.Reflection.UniverseOptions.MetadataOnly))
            {
                foreach (string reference in references)
                {
                    using (IKVM.Reflection.RawModule module = universe.OpenRawModule(reference))
                    {
                        string fileName = Path.Combine(stubpath, module.GetAssemblyName().Name + "__" + module.ModuleVersionId.ToString("N") + ".jar");
                        stubs.Add(fileName, null);
                        if (!File.Exists(fileName))
                        {
                            if (!GenerateStub(reference, fileName))
                            {
                                return(false);
                            }
                        }
                    }
                }
            }
            // clean up any left-over stubs
            foreach (string file in Directory.GetFiles(stubpath, "*.jar"))
            {
                if (!stubs.ContainsKey(file) && Path.GetFileName(file) != "rt.jar")
                {
                    File.Delete(file);
                }
            }
            return(true);
        }
        private static System.Reflection.Assembly LoadPlugin(IKVM.Reflection.Assembly asm)
        {
            foreach (var name in asm.GetManifestResourceNames())
            {
                if (name.EndsWith(".dll", StringComparison.OrdinalIgnoreCase))
                {
                    using (var strm = asm.GetManifestResourceStream(name))
                        using (var ms = new MemoryStream())
                            using (var uni = new IKVM.Reflection.Universe()) {
                                strm.CopyTo(ms);
                                ms.Position = 0;
                                string referenceName = uni.LoadAssembly(uni.OpenRawModule(ms, name)).GetName().Name;
                                var    result        = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => a.GetName().Name == referenceName);
                                if (result == null)
                                {
                                    result = System.Reflection.Assembly.Load(ms.ToArray());
                                }
                                return(result);
                            }
                }
            }

            return(null);
        }
		private static System.Reflection.Assembly LoadPlugin(IKVM.Reflection.Assembly asm) {
			foreach (var name in asm.GetManifestResourceNames()) {
				if (name.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)) {
					using (var strm = asm.GetManifestResourceStream(name))
					using (var ms = new MemoryStream())
					using (var uni = new IKVM.Reflection.Universe()) {
						strm.CopyTo(ms);
						ms.Position = 0;
						string referenceName = uni.LoadAssembly(uni.OpenRawModule(ms, name)).GetName().Name;
						var result = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => a.GetName().Name == referenceName);
						if (result == null)
							result = System.Reflection.Assembly.Load(ms.ToArray());
						return result;
					}
				}
			}

			return null;
		}
예제 #4
0
		private bool GenerateStubs()
		{
			// we start by creating the stubs for the boot classes
			string stubpath = GetStubPath();
			Directory.CreateDirectory(stubpath);
			// note that File.GetLastWriteTime() returns Jan 1st, 1601 for non-existing files, so that works out nicely
			if (File.GetLastWriteTime(Path.Combine(stubpath, "rt.jar")) < File.GetLastWriteTime(Path.Combine(GetAssemblyPath(), "IKVM.OpenJDK.Core.dll")))
			{
				if (!GenerateStub("IKVM.OpenJDK.Core", Path.Combine(stubpath, "rt.jar")))
				{
					return false;
				}
			}
			// now generate stubs for the referenced assemblies
			Dictionary<string, string> stubs = new Dictionary<string, string>();
			using (IKVM.Reflection.Universe universe = new IKVM.Reflection.Universe(IKVM.Reflection.UniverseOptions.MetadataOnly))
			{
				foreach (string reference in references)
				{
					using (IKVM.Reflection.RawModule module = universe.OpenRawModule(reference))
					{
						string fileName = Path.Combine(stubpath, module.GetAssemblyName().Name + "__" + module.ModuleVersionId.ToString("N") + ".jar");
						stubs.Add(fileName, null);
						if (!File.Exists(fileName))
						{
							if (!GenerateStub(reference, fileName))
							{
								return false;
							}
						}
					}
				}
			}
			// clean up any left-over stubs
			foreach (string file in Directory.GetFiles(stubpath, "*.jar"))
			{
				if (!stubs.ContainsKey(file) && Path.GetFileName(file) != "rt.jar")
				{
					File.Delete(file);
				}
			}
			return true;
		}