IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
Packages.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*/
24
25using System.Collections.Generic;
26
27namespace IKVM.Tools.Importer
28{
29 sealed class Packages
30 {
31
32 readonly List<string> packages = new List<string>();
33 readonly Dictionary<string, string> packagesSet = new Dictionary<string, string>();
34
35 internal void DefinePackage(string packageName, string jar)
36 {
37 if (!packagesSet.ContainsKey(packageName))
38 {
39 packages.Add(packageName);
40 packagesSet.Add(packageName, jar);
41 }
42 }
43
44 // returns an array of PackageListAttribute constructor argument arrays
45 internal object[][] ToArray()
46 {
47 List<object[]> list = new List<object[]>();
48 // we use an empty string to indicate we don't yet have a jar,
49 // because null is used for packages that were defined from
50 // the file system (i.e. don't have a jar to load a manifest from)
51 string currentJar = "";
52 List<string> currentList = new List<string>();
53 foreach (string package in packages)
54 {
55 string jar = packagesSet[package];
56 if (jar != currentJar)
57 {
58 if (currentList.Count != 0)
59 {
60 list.Add(new object[] { currentJar, currentList.ToArray() });
61 currentList.Clear();
62 }
63 currentJar = jar;
64 }
65 currentList.Add(package);
66 }
67
68 if (currentList.Count != 0)
69 {
70 list.Add(new object[] { currentJar, currentList.ToArray() });
71 }
72
73 return list.ToArray();
74 }
75
76 }
77
78}