Executes the exporter.
47 {
48 var references = new List<string>();
51 references.Add(reference);
52
53 var libpaths = new List<string>();
55 foreach (var library
in options.
Libraries)
56 libpaths.Add(library);
57
58 var namespaces = new List<string>();
61 namespaces.Add(ns);
62
64 {
65
66
68 }
69
70
71 var coreLibName = FindCoreLibName(references, libpaths);
72 if (coreLibName == null)
73 {
75 return 1;
76 }
77
78
79 var universe = new Universe(coreLibName);
81 assemblyResolver.Warning +=
new AssemblyResolver.WarningEvent(Resolver_Warning);
82 assemblyResolver.Init(universe, options.
NoStdLib, references, libpaths);
83
84 var cache = new Dictionary<string, Assembly>();
85 foreach (var reference in references)
86 {
87 Assembly[] dummy = null;
88 if (assemblyResolver.ResolveReference(cache,
ref dummy, reference) ==
false)
89 {
91 return 1;
92 }
93 }
94
95 Assembly assembly = null;
96 try
97 {
98 file =
new FileInfo(options.
Assembly);
99 }
100 catch (FileNotFoundException)
101 {
103 return 1;
104 }
105 catch (Exception x)
106 {
108 return 1;
109 }
110
111 if (file != null && file.Exists)
112 {
113 assembly = assemblyResolver.LoadFile(options.
Assembly);
114 }
115 else
116 {
117 assembly = assemblyResolver.LoadWithPartialName(options.
Assembly);
118 }
119
122
123 int rc = 0;
124 if (assembly == null)
125 {
126 rc = 1;
128 }
129 else
130 {
131 Assembly runtimeAssembly = null;
132 Assembly baseAssembly = null;
133
135 {
136 var runtimeAssemblyPath = references.FirstOrDefault(i => Path.GetFileNameWithoutExtension(i) == "IKVM.Runtime");
137 if (runtimeAssemblyPath != null)
138 runtimeAssembly = assemblyResolver.LoadFile(runtimeAssemblyPath);
139
140 if (runtimeAssembly == null || runtimeAssembly.__IsMissing)
141 {
143 return 1;
144 }
145
146 compiler =
new StaticCompiler(universe, assemblyResolver, runtimeAssembly);
147 context =
new RuntimeContext(
new RuntimeContextOptions(), diagnostics,
new ManagedTypeResolver(compiler,
null),
true, compiler);
148 context.
ClassLoaderFactory.SetBootstrapClassLoader(
new RuntimeBootstrapClassLoader(context));
149 }
150 else
151 {
152
153 var runtimeAssemblyPath = references.FirstOrDefault(i => Path.GetFileNameWithoutExtension(i) == "IKVM.Runtime");
154 if (runtimeAssemblyPath != null)
155 runtimeAssembly = assemblyResolver.LoadFile(runtimeAssemblyPath);
156
157 var baseAssemblyPath = references.FirstOrDefault(i => Path.GetFileNameWithoutExtension(i) == "IKVM.Java");
158 if (baseAssemblyPath != null)
159 baseAssembly = assemblyResolver.LoadFile(baseAssemblyPath);
160
161 if (runtimeAssembly == null || runtimeAssembly.__IsMissing)
162 {
164 return 1;
165 }
166
167 if (baseAssembly == null || runtimeAssembly.__IsMissing)
168 {
170 return 1;
171 }
172
173 compiler =
new StaticCompiler(universe, assemblyResolver, runtimeAssembly);
174 context =
new RuntimeContext(
new RuntimeContextOptions(), diagnostics,
new ManagedTypeResolver(compiler, baseAssembly),
false, compiler);
175 }
176
178 {
180 return 1;
181 }
182
183 if (options.
Output ==
null)
184 options.Output = assembly.GetName().Name + ".jar";
185
186 try
187 {
188 using (zipFile =
new ZipArchive(
new FileStream(options.
Output, FileMode.Create), ZipArchiveMode.Create))
189 {
190 try
191 {
192 var assemblies = new List<Assembly>();
193 assemblies.Add(assembly);
194
196 LoadSharedClassLoaderAssemblies(compiler, assembly, assemblies);
197
198 foreach (var asm in assemblies)
199 {
200 if (ProcessTypes(context, asm.GetTypes()) != 0)
201 {
202 rc = 1;
204 break;
205 }
206
207 if (options.
Forwarders && ProcessTypes(context,
asm.ManifestModule.__GetExportedTypes()) != 0)
208 {
209 rc = 1;
211 break;
212 }
213 }
214 }
215 catch (Exception x)
216 {
218 diagnostics.
UnknownWarning($
"Assembly reflection encountered an error. Resultant JAR may be incomplete. ({x.Message})");
219
220 rc = 1;
221 }
222 }
223 }
224 catch (InvalidDataException e)
225 {
226 rc = 1;
228 }
229 }
230
231 return rc;
232 }
Maintains services relevant to an instane of the IKVM runtime.
AttributeHelper AttributeHelper
Gets the AttributeHelper associated with this instance of the runtime.
RuntimeClassLoaderFactory ClassLoaderFactory
Gets the RuntimeClassLoaderFactory associated with this instance of the runtime.
void ReferenceNotFound(string arg0)
The 'ReferenceNotFound' diagnostic.
void InputFileNotFound(string arg0)
The 'InputFileNotFound' diagnostic.
void ErrorReadingFile(string arg0, string arg1)
The 'ErrorReadingFile' diagnostic.
void RuntimeNotFound()
The 'RuntimeNotFound' diagnostic.
void ExportingImportsNotSupported()
The 'ExportingImportsNotSupported' diagnostic.
void UnknownWarning(string arg0)
The 'UnknownWarning' diagnostic.
void CoreClassesMissing()
The 'CoreClassesMissing' diagnostic.
void InvalidZip(string name)
The 'InvalidZip' diagnostic.