|
8 | 8 | import java.io.IOException;
|
9 | 9 | import java.io.Reader;
|
10 | 10 | import java.util.ArrayList;
|
11 |
| -import java.util.Collection; |
12 | 11 | import java.util.HashMap;
|
13 | 12 | import java.util.List;
|
14 | 13 | import java.util.Map;
|
15 |
| -import java.util.Map.Entry; |
16 | 14 | import java.util.Set;
|
17 | 15 | import java.util.TreeMap;
|
18 | 16 | import java.util.TreeSet;
|
@@ -62,194 +60,15 @@ static public List<LibraryIndexJson> getLibraryIndices() {
|
62 | 60 | return libraryIndices;
|
63 | 61 | }
|
64 | 62 |
|
65 |
| - public static LibraryTree getLibraryTree() { |
66 |
| - return new LibraryTree(); |
67 |
| - |
68 |
| - } |
69 |
| - |
70 |
| - public static class LibraryTree { |
71 |
| - |
72 |
| - private TreeMap<String, Category> categories = new TreeMap<>(); |
73 |
| - |
74 |
| - public class Category implements Comparable<Category>, Node { |
75 |
| - private String name; |
76 |
| - protected TreeMap<String, Library> libraries = new TreeMap<>(); |
77 |
| - |
78 |
| - public Category(String name) { |
79 |
| - this.name = name; |
80 |
| - } |
81 |
| - |
82 |
| - @Override |
83 |
| - public String getName() { |
84 |
| - return this.name; |
85 |
| - } |
86 |
| - |
87 |
| - public Collection<Library> getLibraries() { |
88 |
| - return this.libraries.values(); |
89 |
| - } |
90 |
| - |
91 |
| - @Override |
92 |
| - public int compareTo(Category other) { |
93 |
| - return this.name.compareTo(other.name); |
94 |
| - } |
95 |
| - |
96 |
| - @Override |
97 |
| - public boolean hasChildren() { |
98 |
| - return !this.libraries.isEmpty(); |
99 |
| - } |
100 |
| - |
101 |
| - @Override |
102 |
| - public Object[] getChildren() { |
103 |
| - return this.libraries.values().toArray(); |
104 |
| - } |
105 |
| - |
106 |
| - @Override |
107 |
| - public Object getParent() { |
108 |
| - return LibraryTree.this; |
109 |
| - } |
110 |
| - } |
111 |
| - |
112 |
| - public class Library implements Comparable<Library>, Node { |
113 |
| - private String name; |
114 |
| - private String indexName; |
115 |
| - private Category category; |
116 |
| - protected TreeSet<VersionNumber> versions = new TreeSet<>(); |
117 |
| - protected VersionNumber version; |
118 |
| - private String tooltip; |
119 |
| - |
120 |
| - public Library(Category category, String name, String indexName, String tooltip) { |
121 |
| - this.category = category; |
122 |
| - this.name = name; |
123 |
| - this.tooltip = tooltip; |
124 |
| - this.indexName = indexName; |
125 |
| - } |
126 |
| - |
127 |
| - public Collection<VersionNumber> getVersions() { |
128 |
| - return this.versions; |
129 |
| - } |
130 |
| - |
131 |
| - @Override |
132 |
| - public String getName() { |
133 |
| - return name; |
134 |
| - } |
135 |
| - |
136 |
| - public String getTooltip() { |
137 |
| - return tooltip; |
138 |
| - } |
139 |
| - |
140 |
| - public VersionNumber getLatest() { |
141 |
| - return versions.last(); |
142 |
| - } |
143 |
| - |
144 |
| - public VersionNumber getVersion() { |
145 |
| - return version; |
146 |
| - } |
147 |
| - |
148 |
| - public String getIndexName() { |
149 |
| - return indexName; |
150 |
| - } |
151 |
| - |
152 |
| - public void setVersion(VersionNumber version) { |
153 |
| - this.version = version; |
154 |
| - } |
155 |
| - |
156 |
| - @Override |
157 |
| - public int compareTo(Library other) { |
158 |
| - return this.name.compareTo(other.name); |
159 |
| - } |
160 |
| - |
161 |
| - @Override |
162 |
| - public boolean hasChildren() { |
163 |
| - return false; |
164 |
| - } |
165 |
| - |
166 |
| - @Override |
167 |
| - public Object[] getChildren() { |
168 |
| - return null; |
169 |
| - } |
170 |
| - |
171 |
| - @Override |
172 |
| - public Object getParent() { |
173 |
| - return this.category; |
174 |
| - } |
175 |
| - } |
176 |
| - |
177 |
| - public LibraryTree() { |
178 |
| - for (LibraryIndexJson libraryIndex : getLibraryIndices()) { |
179 |
| - for (String categoryName : libraryIndex.getCategories()) { |
180 |
| - Category category = this.categories.get(categoryName); |
181 |
| - if (category == null) { |
182 |
| - category = new Category(categoryName); |
183 |
| - this.categories.put(category.getName(), category); |
184 |
| - } |
185 |
| - for (io.sloeber.core.api.Json.library.LibraryJson library : libraryIndex |
186 |
| - .getLibraries(categoryName)) { |
187 |
| - Library lib = category.libraries.get(library.getName() + " (" + libraryIndex.getName() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ |
188 |
| - if (lib == null) { |
189 |
| - String builder = "Architectures:" + library.getArchitectures().toString() + "\n\n" //$NON-NLS-1$ //$NON-NLS-2$ |
190 |
| - + library.getSentence(); |
191 |
| - lib = new Library(category, library.getName(), libraryIndex.getName(), builder); |
192 |
| - category.libraries.put(library.getName() + " (" + libraryIndex.getName() + ")", lib); //$NON-NLS-1$//$NON-NLS-2$ |
193 |
| - } |
194 |
| - lib.versions.add(library.getVersion()); |
195 |
| - if (library.isInstalled()) { |
196 |
| - lib.version = library.getVersion(); |
197 |
| - } |
198 |
| - } |
199 |
| - } |
200 |
| - } |
201 |
| - } |
202 |
| - |
203 |
| - public Collection<Category> getCategories() { |
204 |
| - return this.categories.values(); |
205 |
| - } |
206 |
| - |
207 |
| - public Collection<Library> getAllLibraries() { |
208 |
| - Set<Library> all = new TreeSet<>(); |
209 |
| - for (Category category : this.categories.values()) { |
210 |
| - all.addAll(category.getLibraries()); |
211 |
| - } |
212 |
| - return all; |
213 |
| - } |
214 |
| - |
215 |
| - private static LibraryIndexJson findLibraryIndex(String name) { |
216 |
| - for (LibraryIndexJson libraryIndex : getLibraryIndices()) { |
217 |
| - if (libraryIndex.getName().equals(name)) |
218 |
| - return libraryIndex; |
219 |
| - } |
220 |
| - return null; |
221 |
| - } |
222 |
| - |
223 |
| - public void reset() { |
224 |
| - for (Library library : this.getAllLibraries()) { |
225 |
| - LibraryIndexJson libraryIndex = findLibraryIndex(library.getIndexName()); |
226 |
| - |
227 |
| - if (libraryIndex != null) { |
228 |
| - io.sloeber.core.api.Json.library.LibraryJson installed = libraryIndex |
229 |
| - .getInstalledLibrary(library.getName()); |
230 |
| - library.setVersion(installed != null ? installed.getVersion() : null); |
231 |
| - } |
232 |
| - } |
| 63 | + public static IStatus setLibraryTree(List<LibraryJson> removeLibs, List<LibraryJson> addLibs, |
| 64 | + IProgressMonitor monitor, MultiStatus status) { |
| 65 | + for (LibraryJson lib : removeLibs) { |
| 66 | + status.add(lib.remove(monitor)); |
| 67 | + if (monitor.isCanceled()) |
| 68 | + return Status.CANCEL_STATUS; |
233 | 69 | }
|
234 |
| - |
235 |
| - } |
236 |
| - |
237 |
| - public static IStatus setLibraryTree(LibraryTree libs, IProgressMonitor monitor, MultiStatus status) { |
238 |
| - for (LibraryTree.Library lib : libs.getAllLibraries()) { |
239 |
| - LibraryIndexJson libraryIndex = getLibraryIndex(lib.getIndexName()); |
240 |
| - |
241 |
| - if (libraryIndex != null) { |
242 |
| - io.sloeber.core.api.Json.library.LibraryJson toRemove = libraryIndex.getInstalledLibrary(lib.getName()); |
243 |
| - if (toRemove != null && !toRemove.getVersion().equals(lib.getVersion())) { |
244 |
| - status.add(toRemove.remove(monitor)); |
245 |
| - } |
246 |
| - io.sloeber.core.api.Json.library.LibraryJson toInstall = libraryIndex.getLibrary(lib.getName(), |
247 |
| - lib.getVersion()); |
248 |
| - if (toInstall != null && !toInstall.isInstalled()) { |
249 |
| - status.add(toInstall.install(monitor)); |
250 |
| - } |
251 |
| - } |
252 |
| - |
| 70 | + for (LibraryJson lib : addLibs) { |
| 71 | + status.add(lib.install(monitor)); |
253 | 72 | if (monitor.isCanceled())
|
254 | 73 | return Status.CANCEL_STATUS;
|
255 | 74 | }
|
@@ -307,10 +126,10 @@ static public void loadJson(File jsonFile) {
|
307 | 126 | public static void installLibrary(String libName) {
|
308 | 127 | Set<String> libNamesToInstall = new TreeSet<>();
|
309 | 128 | libNamesToInstall.add(libName);
|
310 |
| - Map<String, LibraryDescriptor> libsToInstall = LibraryManager.getLatestInstallableLibraries(libNamesToInstall); |
| 129 | + Map<String, LibraryJson> libsToInstall = LibraryManager.getLatestInstallableLibraries(libNamesToInstall); |
311 | 130 | if (!libsToInstall.isEmpty()) {
|
312 |
| - for (Entry<String, LibraryDescriptor> curLib : libsToInstall.entrySet()) { |
313 |
| - curLib.getValue().toLibrary().install(new NullProgressMonitor()); |
| 131 | + for (LibraryJson curLib : libsToInstall.values()) { |
| 132 | + curLib.install(new NullProgressMonitor()); |
314 | 133 | }
|
315 | 134 | }
|
316 | 135 | }
|
@@ -371,9 +190,9 @@ public static void removeAllLibs() {
|
371 | 190 | }
|
372 | 191 | }
|
373 | 192 |
|
374 |
| - public static Map<String, LibraryDescriptor> getLatestInstallableLibraries(Set<String> libnames) { |
| 193 | + public static Map<String, LibraryJson> getLatestInstallableLibraries(Set<String> libnames) { |
375 | 194 | Set<String> remainingLibNames = new TreeSet<>(libnames);
|
376 |
| - Map<String, LibraryDescriptor> ret = new HashMap<>(); |
| 195 | + Map<String, LibraryJson> ret = new HashMap<>(); |
377 | 196 | for (LibraryIndexJson libraryIndex : libraryIndices) {
|
378 | 197 | ret.putAll(libraryIndex.getLatestInstallableLibraries(remainingLibNames));
|
379 | 198 | remainingLibNames.removeAll(ret.keySet());
|
|
0 commit comments