Skip to content

Commit 1fb2d8d

Browse files
author
jantje
committed
Adding librarydescriptor to api class
1 parent b70f4e4 commit 1fb2d8d

File tree

7 files changed

+73
-19
lines changed

7 files changed

+73
-19
lines changed

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import java.util.Map;
44

5-
import io.sloeber.core.managers.Library;
6-
75
/**
86
* this interface is to allow the ui to handle the automatic installation
97
* of libraries.
@@ -31,5 +29,5 @@ public interface IInstallLibraryHandler {
3129
*
3230
* @return The libraries the user wants to install
3331
*/
34-
abstract Map<String, Library> selectLibrariesToInstall(Map<String, Library> proposedLibsToInstall);
32+
abstract Map<String, LibraryDescriptor> selectLibrariesToInstall(Map<String, LibraryDescriptor> proposedLibsToInstall);
3533
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package io.sloeber.core.api;
2+
3+
import io.sloeber.core.managers.Library;
4+
5+
public class LibraryDescriptor {
6+
private Library library=null;
7+
8+
public LibraryDescriptor(Library value) {
9+
this.library=value;
10+
}
11+
12+
public Library toLibrary() {
13+
// TODO Auto-generated method stub
14+
return this.library;
15+
}
16+
17+
}

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

+14-5
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,16 @@
3232
import io.sloeber.core.managers.Manager;
3333
import io.sloeber.core.managers.Messages;
3434
import io.sloeber.core.tools.Version;
35-
35+
/**
36+
* This class is the main entry point for libraries.
37+
* It handles
38+
* private libraries
39+
* hardware libraries
40+
* installed libraries
41+
*
42+
* @author jan
43+
*
44+
*/
3645
public class LibraryManager {
3746
static private List<LibraryIndex> libraryIndices;
3847
private static IInstallLibraryHandler myInstallLibraryHandler = new DefaultInstallHandler();
@@ -360,18 +369,18 @@ public static void removeAllLibs() {
360369
*
361370
* @return a map of all instalable libraries
362371
*/
363-
public static Map<String, io.sloeber.core.managers.Library> getAllInstallableLibraries() {
364-
Map<String, Library> ret = new HashMap<>();
372+
public static Map<String, LibraryDescriptor> getAllInstallableLibraries() {
373+
Map<String, LibraryDescriptor> ret = new HashMap<>();
365374
for (LibraryIndex libraryIndex : libraryIndices) {
366375
ret.putAll(libraryIndex.getLatestInstallableLibraries());
367376
}
368377

369378
return ret;
370379
}
371380

372-
public static Map<String, io.sloeber.core.managers.Library> getLatestInstallableLibraries(Set<String> libnames) {
381+
public static Map<String, LibraryDescriptor> getLatestInstallableLibraries(Set<String> libnames) {
373382
Set<String> remainingLibNames = new TreeSet<>(libnames);
374-
Map<String, Library> ret = new HashMap<>();
383+
Map<String, LibraryDescriptor> ret = new HashMap<>();
375384
for (LibraryIndex libraryIndex : libraryIndices) {
376385
ret.putAll(libraryIndex.getLatestInstallableLibraries(remainingLibNames));
377386
remainingLibNames.removeAll(ret.keySet());

io.sloeber.core/src/io/sloeber/core/core/DefaultInstallHandler.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import java.util.Map;
44

55
import io.sloeber.core.api.IInstallLibraryHandler;
6-
import io.sloeber.core.managers.Library;
6+
import io.sloeber.core.api.LibraryDescriptor;
77

88
public class DefaultInstallHandler implements IInstallLibraryHandler {
99

@@ -14,7 +14,7 @@ public boolean autoInstall() {
1414

1515

1616
@Override
17-
public Map<String, Library> selectLibrariesToInstall(Map<String, Library> proposedLibsToInstall) {
17+
public Map<String, LibraryDescriptor> selectLibrariesToInstall(Map<String, LibraryDescriptor> proposedLibsToInstall) {
1818

1919
return proposedLibsToInstall;
2020
}

io.sloeber.core/src/io/sloeber/core/managers/LibraryIndex.java

+13-6
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,15 @@
1212
import java.util.regex.Pattern;
1313

1414
import io.sloeber.core.api.Defaults;
15+
import io.sloeber.core.api.LibraryDescriptor;
1516
import io.sloeber.core.tools.Version;
1617

18+
/**
19+
* This class represents a json file that references libraries
20+
*
21+
* @author jan
22+
*
23+
*/
1724
public class LibraryIndex {
1825
private String jsonFileName;
1926
private List<Library> libraries;
@@ -101,11 +108,11 @@ public Map<String, Library> getLatestLibraries() {
101108
*
102109
* @return
103110
*/
104-
public Map<String, Library> getLatestInstallableLibraries() {
105-
Map<String, Library> ret = new HashMap<>();
111+
public Map<String, LibraryDescriptor> getLatestInstallableLibraries() {
112+
Map<String, LibraryDescriptor> ret = new HashMap<>();
106113
for (Entry<String, Library> curLibrary : this.latestLibs.entrySet()) {
107114
if (!curLibrary.getValue().isAVersionInstalled()) {
108-
ret.put(curLibrary.getKey(), curLibrary.getValue());
115+
ret.put(curLibrary.getKey(),new LibraryDescriptor( curLibrary.getValue()));
109116
}
110117
}
111118
return ret;
@@ -147,15 +154,15 @@ public String getName() {
147154
*
148155
* @return
149156
*/
150-
public Map<String, Library> getLatestInstallableLibraries(Set<String> libNames) {
151-
Map<String, Library> ret = new HashMap<>();
157+
public Map<String, LibraryDescriptor> getLatestInstallableLibraries(Set<String> libNames) {
158+
Map<String, LibraryDescriptor> ret = new HashMap<>();
152159
if (libNames.isEmpty()) {
153160
return ret;
154161
}
155162
for (Entry<String, Library> curLibrary : this.latestLibs.entrySet()) {
156163
if (libNames.contains(curLibrary.getKey())) {
157164
if (!curLibrary.getValue().isAVersionInstalled()) {
158-
ret.put(curLibrary.getKey(), curLibrary.getValue());
165+
ret.put(curLibrary.getKey(), new LibraryDescriptor(curLibrary.getValue()));
159166
}
160167
}
161168
}

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import io.sloeber.core.InternalBoardDescriptor;
3838
import io.sloeber.core.api.BoardDescriptor;
3939
import io.sloeber.core.api.IInstallLibraryHandler;
40+
import io.sloeber.core.api.LibraryDescriptor;
4041
import io.sloeber.core.api.LibraryManager;
4142
import io.sloeber.core.common.Common;
4243
import io.sloeber.core.common.ConfigurationPreferences;
@@ -404,15 +405,15 @@ public static void checkLibraries(IProject affectedProject) {
404405
if(!uninstalledIncludedHeaders.isEmpty()) {
405406
//some libraries may need to be installed
406407

407-
Map<String, Library> availableLibs=LibraryManager.getLatestInstallableLibraries(uninstalledIncludedHeaders);
408+
Map<String, LibraryDescriptor> availableLibs=LibraryManager.getLatestInstallableLibraries(uninstalledIncludedHeaders);
408409

409410
if(!availableLibs.isEmpty()) {
410411
//We now know which libraries to install
411412
//TODO for now I just install but there should be some user
412413
//interaction
413414
availableLibs=installHandler.selectLibrariesToInstall(availableLibs);
414-
for (Entry<String, Library> curLib : availableLibs.entrySet()) {
415-
curLib.getValue().install(new NullProgressMonitor());
415+
for (Entry<String, LibraryDescriptor> curLib : availableLibs.entrySet()) {
416+
curLib.getValue().toLibrary().install(new NullProgressMonitor());
416417
}
417418
}
418419
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package io.sloeber.ui.listeners;
2+
3+
import java.util.Map;
4+
5+
import io.sloeber.core.api.IInstallLibraryHandler;
6+
import io.sloeber.core.api.LibraryDescriptor;
7+
8+
public class MyLibraryInstallHandler implements IInstallLibraryHandler {
9+
10+
@Override
11+
public boolean autoInstall() {
12+
// TODO Auto-generated method stub
13+
return true;
14+
}
15+
16+
@Override
17+
public Map<String, LibraryDescriptor> selectLibrariesToInstall(Map<String, LibraryDescriptor> proposedLibsToInstall) {
18+
// TODO Auto-generated method stub
19+
return proposedLibsToInstall;
20+
}
21+
22+
}

0 commit comments

Comments
 (0)