Skip to content

Commit 3df8802

Browse files
author
jantje
committed
#1339 moved libraryTree class to gui
still need to do the install part removed the ([index name]) from the library name and added the indexname to the tooltip Added a (can update) tag when a newer version is available
1 parent 04d9d94 commit 3df8802

File tree

7 files changed

+273
-278
lines changed

7 files changed

+273
-278
lines changed

io.sloeber.core/META-INF/MANIFEST.MF

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Export-Package: cc.arduino.packages;x-internal:=true,
3232
cc.arduino.packages.ssh;x-internal:=true,
3333
io.sloeber.core;x-friends:="io.sloeber.tests",
3434
io.sloeber.core.api,
35+
io.sloeber.core.api.Json.library,
3536
io.sloeber.core.api.Json.packages,
3637
io.sloeber.core.builder;x-internal:=true,
3738
io.sloeber.core.common;x-friends:="io.sloeber.tests",

io.sloeber.core/src/io/sloeber/core/api/Json/library/LibraryIndexJson.java

+6-7
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import com.google.gson.annotations.JsonAdapter;
2121

2222
import io.sloeber.core.api.Defaults;
23-
import io.sloeber.core.api.LibraryDescriptor;
2423
import io.sloeber.core.api.VersionNumber;
2524

2625
/**
@@ -123,11 +122,11 @@ public Map<String, LibraryJson> getLatestLibraries() {
123122
*
124123
* @return
125124
*/
126-
public Map<String, LibraryDescriptor> getLatestInstallableLibraries() {
127-
Map<String, LibraryDescriptor> ret = new HashMap<>();
125+
public Map<String, LibraryJson> getLatestInstallableLibraries() {
126+
Map<String, LibraryJson> ret = new HashMap<>();
128127
for (Entry<String, LibraryJson> curLibrary : this.latestLibs.entrySet()) {
129128
if (!curLibrary.getValue().isAVersionInstalled()) {
130-
ret.put(curLibrary.getKey(), new LibraryDescriptor(curLibrary.getValue()));
129+
ret.put(curLibrary.getKey(), curLibrary.getValue());
131130
}
132131
}
133132
return ret;
@@ -159,15 +158,15 @@ public String getName() {
159158
*
160159
* @return
161160
*/
162-
public Map<String, LibraryDescriptor> getLatestInstallableLibraries(Set<String> libNames) {
163-
Map<String, LibraryDescriptor> ret = new HashMap<>();
161+
public Map<String, LibraryJson> getLatestInstallableLibraries(Set<String> libNames) {
162+
Map<String, LibraryJson> ret = new HashMap<>();
164163
if (libNames.isEmpty()) {
165164
return ret;
166165
}
167166
for (Entry<String, LibraryJson> curLibrary : this.latestLibs.entrySet()) {
168167
if (libNames.contains(curLibrary.getKey())) {
169168
if (!curLibrary.getValue().isAVersionInstalled()) {
170-
ret.put(curLibrary.getKey(), new LibraryDescriptor(curLibrary.getValue()));
169+
ret.put(curLibrary.getKey(), curLibrary.getValue());
171170
}
172171
}
173172
}

io.sloeber.core/src/io/sloeber/core/api/Json/library/LibraryJson.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,15 @@ public class LibraryJson implements Comparable<LibraryJson> {
5252
private String archiveFileName;
5353
private int size;
5454
private String checksum;
55+
private LibraryIndexJson myParent;
56+
5557
public static final String LIBRARY_SOURCE_FODER = "src"; //$NON-NLS-1$
5658

5759
@SuppressWarnings("nls")
5860
public LibraryJson(JsonElement json, LibraryIndexJson libraryIndexJson) {
5961
JsonObject jsonObject = json.getAsJsonObject();
6062
try {
63+
myParent = libraryIndexJson;
6164
name = getSafeString(jsonObject, "name");
6265
version = getSafeVersion(jsonObject, "version");
6366
author = getSafeString(jsonObject, "author");
@@ -221,7 +224,11 @@ public Collection<IPath> getSources(IProject project) {
221224

222225
@Override
223226
public int compareTo(LibraryJson other) {
224-
return this.name.compareTo(other.name);
227+
int ret = this.name.compareTo(other.name);
228+
if (ret == 0) {
229+
ret = this.version.compareTo(other.version);
230+
}
231+
return ret;
225232
}
226233

227234
/**
@@ -247,4 +254,7 @@ public IStatus remove(IProgressMonitor monitor) {
247254
return Status.OK_STATUS;
248255
}
249256

257+
public LibraryIndexJson getParent() {
258+
return myParent;
259+
}
250260
}

io.sloeber.core/src/io/sloeber/core/api/LibraryManager.java

+13-194
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88
import java.io.IOException;
99
import java.io.Reader;
1010
import java.util.ArrayList;
11-
import java.util.Collection;
1211
import java.util.HashMap;
1312
import java.util.List;
1413
import java.util.Map;
15-
import java.util.Map.Entry;
1614
import java.util.Set;
1715
import java.util.TreeMap;
1816
import java.util.TreeSet;
@@ -62,194 +60,15 @@ static public List<LibraryIndexJson> getLibraryIndices() {
6260
return libraryIndices;
6361
}
6462

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;
23369
}
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));
25372
if (monitor.isCanceled())
25473
return Status.CANCEL_STATUS;
25574
}
@@ -307,10 +126,10 @@ static public void loadJson(File jsonFile) {
307126
public static void installLibrary(String libName) {
308127
Set<String> libNamesToInstall = new TreeSet<>();
309128
libNamesToInstall.add(libName);
310-
Map<String, LibraryDescriptor> libsToInstall = LibraryManager.getLatestInstallableLibraries(libNamesToInstall);
129+
Map<String, LibraryJson> libsToInstall = LibraryManager.getLatestInstallableLibraries(libNamesToInstall);
311130
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());
314133
}
315134
}
316135
}
@@ -371,9 +190,9 @@ public static void removeAllLibs() {
371190
}
372191
}
373192

374-
public static Map<String, LibraryDescriptor> getLatestInstallableLibraries(Set<String> libnames) {
193+
public static Map<String, LibraryJson> getLatestInstallableLibraries(Set<String> libnames) {
375194
Set<String> remainingLibNames = new TreeSet<>(libnames);
376-
Map<String, LibraryDescriptor> ret = new HashMap<>();
195+
Map<String, LibraryJson> ret = new HashMap<>();
377196
for (LibraryIndexJson libraryIndex : libraryIndices) {
378197
ret.putAll(libraryIndex.getLatestInstallableLibraries(remainingLibNames));
379198
remainingLibNames.removeAll(ret.keySet());

io.sloeber.core/src/io/sloeber/core/api/Node.java

-11
This file was deleted.

io.sloeber.core/src/io/sloeber/core/tools/Libraries.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838

3939
import io.sloeber.core.api.BoardDescription;
4040
import io.sloeber.core.api.IInstallLibraryHandler;
41-
import io.sloeber.core.api.LibraryDescriptor;
4241
import io.sloeber.core.api.LibraryManager;
4342
import io.sloeber.core.api.SloeberProject;
4443
import io.sloeber.core.api.VersionNumber;
@@ -423,7 +422,7 @@ public static void checkLibraries(IProject affectedProject) {
423422
if (!uninstalledIncludedHeaders.isEmpty()) {
424423
// some libraries may need to be installed
425424

426-
Map<String, LibraryDescriptor> availableLibs = LibraryManager
425+
Map<String, LibraryJson> availableLibs = LibraryManager
427426
.getLatestInstallableLibraries(uninstalledIncludedHeaders);
428427

429428
if (!availableLibs.isEmpty()) {
@@ -432,8 +431,8 @@ public static void checkLibraries(IProject affectedProject) {
432431
// be some user
433432
// interaction
434433
availableLibs = installHandler.selectLibrariesToInstall(availableLibs);
435-
for (Entry<String, LibraryDescriptor> curLib : availableLibs.entrySet()) {
436-
curLib.getValue().toLibrary().install(new NullProgressMonitor());
434+
for (Entry<String, LibraryJson> curLib : availableLibs.entrySet()) {
435+
curLib.getValue().install(new NullProgressMonitor());
437436
}
438437
}
439438
}

0 commit comments

Comments
 (0)