IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
ImportState.cs
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2014 Jeroen Frijters
3
4 This software is provided 'as-is', without any express or implied
5 warranty. In no event will the authors be held liable for any damages
6 arising from the use of this software.
7
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it
10 freely, subject to the following restrictions:
11
12 1. The origin of this software must not be misrepresented; you must not
13 claim that you wrote the original software. If you use this software
14 in a product, an acknowledgment in the product documentation would be
15 appreciated but is not required.
16 2. Altered source versions must be plainly marked as such, and must not be
17 misrepresented as being the original software.
18 3. This notice may not be removed or altered from any source distribution.
19
20 Jeroen Frijters
21 jeroen@frijters.net
22
23*/
24using System;
25using System.Collections.Generic;
26using System.IO;
27using System.Text.RegularExpressions;
28using System.Threading;
29
30using IKVM.Reflection;
32using IKVM.Runtime;
33
34namespace IKVM.Tools.Importer
35{
36
40 sealed class ImportState
41 {
42
43 internal List<Jar> jars = new List<Jar>();
44 private Dictionary<string, int> jarMap = new Dictionary<string, int>();
45 internal int classesJar = -1;
46 internal int resourcesJar = -1;
47 internal bool nojarstubs;
48 internal FileInfo path;
49 internal FileInfo keyfile;
50 internal string keycontainer;
51 internal bool delaysign;
52 internal byte[] publicKey;
53 internal StrongNameKeyPair keyPair;
54 internal Version version;
55 internal string fileversion;
56 internal FileInfo iconfile;
57 internal FileInfo manifestFile;
58 internal bool targetIsModule;
59 internal string assembly;
60 internal string mainClass;
61 internal ApartmentState apartment;
62 internal PEFileKinds target;
63 internal bool guessFileKind;
64 internal string[] unresolvedReferences; // only used during command line parsing
65 internal Dictionary<string, string> legacyStubReferences = new Dictionary<string, string>(); // only used during command line parsing
66 internal Assembly[] references;
67 internal string[] peerReferences;
68 internal bool crossReferenceAllPeers = true;
69 internal string[] classesToExclude; // only used during command line parsing
70 internal FileInfo remapfile;
71 internal Dictionary<string, string> props;
72 internal bool noglobbing;
73 internal CodeGenOptions codegenoptions;
74 internal DebugMode debugMode = DebugMode.Portable;
75 internal string debugFileName;
76 internal bool compressedResources;
77 internal string[] privatePackages;
78 internal string[] publicPackages;
79 internal string sourcepath;
80 internal Dictionary<string, string> externalResources;
81 internal string classLoader;
82 internal PortableExecutableKinds pekind = PortableExecutableKinds.ILOnly;
83 internal ImageFileMachine imageFileMachine = ImageFileMachine.I386;
84 internal ulong baseAddress;
85 internal uint fileAlignment;
86 internal bool highentropyva;
87 internal List<ImportClassLoader> sharedclassloader; // should *not* be deep copied in Copy(), because we want the list of all compilers that share a class loader
88 internal HashSet<string> suppressWarnings = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
89 internal HashSet<string> errorWarnings = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
90 internal bool warnaserror; // treat all warnings as errors
91 internal List<string> proxies = new List<string>();
92 internal object[] assemblyAttributeAnnotations;
93 internal bool warningLevelHigh;
94 internal bool noParameterReflection;
95 internal bool bootstrap;
96 internal string log;
97
98 internal ImportState Copy()
99 {
100 ImportState copy = (ImportState)MemberwiseClone();
101 copy.jars = Copy(jars);
102 copy.jarMap = new Dictionary<string, int>(jarMap);
103 if (props != null)
104 {
105 copy.props = new Dictionary<string, string>(props);
106 }
107 if (externalResources != null)
108 {
109 copy.externalResources = new Dictionary<string, string>(externalResources);
110 }
111 copy.suppressWarnings = new(suppressWarnings, StringComparer.OrdinalIgnoreCase);
112 copy.errorWarnings = new(errorWarnings, StringComparer.OrdinalIgnoreCase);
113 return copy;
114 }
115
116 private static List<Jar> Copy(List<Jar> jars)
117 {
118 List<Jar> newJars = new List<Jar>();
119 foreach (Jar jar in jars)
120 {
121 newJars.Add(jar.Copy());
122 }
123 return newJars;
124 }
125
126 internal Jar GetJar(string file)
127 {
128 if (jarMap.TryGetValue(file, out var existingJar))
129 return jars[existingJar];
130
131 jarMap.Add(file, jars.Count);
132 return CreateJar(Path.GetFileName(file));
133 }
134
135 Jar CreateJar(string jarName)
136 {
137 int count = 0;
138 var name = jarName;
139 retry:
140 foreach (var jar in jars)
141 {
142 if (jar.Name == name)
143 {
144 name = Path.GetFileNameWithoutExtension(jarName) + "-" + (++count) + Path.GetExtension(jarName);
145 goto retry;
146 }
147 }
148
149 var newJar = new Jar(name);
150 jars.Add(newJar);
151 return newJar;
152 }
153
154 internal Jar GetClassesJar()
155 {
156 if (classesJar == -1)
157 {
158 classesJar = jars.Count;
159 CreateJar("classes.jar");
160 }
161
162 return jars[classesJar];
163 }
164
165 internal bool IsClassesJar(Jar jar)
166 {
167 return classesJar != -1 && jars[classesJar] == jar;
168 }
169
170 internal Jar GetResourcesJar()
171 {
172 if (resourcesJar == -1)
173 {
174 resourcesJar = jars.Count;
175 CreateJar("resources.jar");
176 }
177
178 return jars[resourcesJar];
179 }
180
181 internal bool IsResourcesJar(Jar jar)
182 {
183 return resourcesJar != -1 && jars[resourcesJar] == jar;
184 }
185
186 internal bool IsExcludedClass(string className)
187 {
188 if (classesToExclude != null)
189 for (int i = 0; i < classesToExclude.Length; i++)
190 if (Regex.IsMatch(className, classesToExclude[i]))
191 return true;
192
193 return false;
194 }
195
196 }
197
198}
Holds some state for an instance of ImportContext.