IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
JarFileExtensions.cs
Go to the documentation of this file.
1using System;
2
3using IKVM.ByteCode.Decoding;
6
7using static IKVM.Util.Jar.JarFileUtil;
8
9namespace IKVM.Util.Jar
10{
11
15 internal static class JarFileExtensions
16 {
17
23 public static ModuleInfo GetModuleInfo(this JarFile jar)
24 {
25 if (jar is null)
26 throw new ArgumentNullException(nameof(jar));
27
28 return GetModuleInfoFromClass(jar) ?? GetModuleInfoFromManifest(jar);
29 }
30
36 static ModuleInfo GetModuleInfoFromClass(JarFile jar)
37 {
38 if (jar is null)
39 throw new ArgumentNullException(nameof(jar));
40
41 var e = jar.GetEntry("module-info.class");
42 if (e == null)
43 return null;
44
45 using var s = e.Value.Open();
46 using var c = ClassFile.Read(s);
47 var m = ModuleDescriptor.Read(c);
48 return new ModuleInfo(m.Name, m.Version);
49 }
50
56 static ModuleInfo GetModuleInfoFromManifest(JarFile jar)
57 {
58 if (jar.Manifest is null)
59 return null;
60
61 return new ModuleInfo(jar.Manifest.MainAttributes.TryGetValue("Automatic-Module-Name", out var name) ? name : null, default);
62 }
63
64 }
65
66}