Skip to content

Commit d49130c

Browse files
author
jantje
committed
adding a install handler
1 parent d2c8b4d commit d49130c

File tree

4 files changed

+84
-13
lines changed

4 files changed

+84
-13
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package io.sloeber.core.api;
2+
3+
import java.util.Map;
4+
5+
import io.sloeber.core.managers.Library;
6+
7+
/**
8+
* this interface is to allow the ui to handle the automatic installation
9+
* of libraries.
10+
* If you do not register your implementation of this interface there will be
11+
* no automatic install of libraries
12+
*
13+
* registering your inmplementation is done in the library manager
14+
*
15+
* @author jan
16+
*
17+
*/
18+
19+
public interface IInstallLibraryHandler {
20+
/**
21+
* The core will call this method to find out if you want to install
22+
* the libraries automatically or not
23+
*
24+
* @return true if you want libraries to beinstalled automatically
25+
*/
26+
abstract boolean autoInstall();
27+
/**
28+
* given the set of proposed libraries to install
29+
* let the user decide on what to install
30+
* @param proposedLibsToInstall the libraries Sloeber proposes to install
31+
*
32+
* @return The libraries the user wants to install
33+
*/
34+
abstract Map<String, Library> selectLibrariesToInstall(Map<String, Library> proposedLibsToInstall);
35+
}

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

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import io.sloeber.core.common.Common;
2727
import io.sloeber.core.common.ConfigurationPreferences;
2828
import io.sloeber.core.common.InstancePreferences;
29+
import io.sloeber.core.core.DefaultInstallHandler;
2930
import io.sloeber.core.managers.Library;
3031
import io.sloeber.core.managers.LibraryIndex;
3132
import io.sloeber.core.managers.Manager;
@@ -34,6 +35,7 @@
3435

3536
public class LibraryManager {
3637
static private List<LibraryIndex> libraryIndices;
38+
private static IInstallLibraryHandler myInstallLibraryHandler = new DefaultInstallHandler();
3739

3840
static public List<LibraryIndex> getLibraryIndices() {
3941
if (libraryIndices == null) {
@@ -237,6 +239,7 @@ public static IStatus setLibraryTree(LibraryTree libs, IProgressMonitor monitor,
237239
public static String getPrivateLibraryPathsString() {
238240
return InstancePreferences.getPrivateLibraryPathsString();
239241
}
242+
240243
public static void setPrivateLibraryPaths(String[] libraryPaths) {
241244
InstancePreferences.setPrivateLibraryPaths(libraryPaths);
242245

@@ -296,9 +299,9 @@ static public void loadJson(File jsonFile) {
296299
}
297300

298301
/**
299-
* Install the latest version of all the libraries belonging to this
300-
* category If a earlier version is installed this version will be removed
301-
* before installation of the newer version
302+
* Install the latest version of all the libraries belonging to this category If
303+
* a earlier version is installed this version will be removed before
304+
* installation of the newer version
302305
*
303306
* @param category
304307
*/
@@ -352,30 +355,37 @@ public static void removeAllLibs() {
352355
}
353356

354357
/**
355-
* Searches for all libraries that can be installed but are not yet installed.
356-
* A library is considered installed when 1 version of the library is installed.
358+
* Searches for all libraries that can be installed but are not yet installed. A
359+
* library is considered installed when 1 version of the library is installed.
357360
*
358361
* @return a map of all instalable libraries
359362
*/
360363
public static Map<String, io.sloeber.core.managers.Library> getAllInstallableLibraries() {
361364
Map<String, Library> ret = new HashMap<>();
362365
for (LibraryIndex libraryIndex : libraryIndices) {
363-
ret.putAll(libraryIndex.getLatestInstallableLibraries());
366+
ret.putAll(libraryIndex.getLatestInstallableLibraries());
364367
}
365368

366369
return ret;
367370
}
368371

369-
public static Map<String, io.sloeber.core.managers.Library> getLatestInstallableLibraries(
370-
Set<String> libnames) {
371-
Set<String> remainingLibNames=new TreeSet<>(libnames);
372+
public static Map<String, io.sloeber.core.managers.Library> getLatestInstallableLibraries(Set<String> libnames) {
373+
Set<String> remainingLibNames = new TreeSet<>(libnames);
372374
Map<String, Library> ret = new HashMap<>();
373375
for (LibraryIndex libraryIndex : libraryIndices) {
374-
ret.putAll(libraryIndex.getLatestInstallableLibraries(remainingLibNames));
375-
remainingLibNames.removeAll(ret.keySet());
376+
ret.putAll(libraryIndex.getLatestInstallableLibraries(remainingLibNames));
377+
remainingLibNames.removeAll(ret.keySet());
376378
}
377379

378380
return ret;
379381
}
380382

383+
public static void registerInstallLibraryHandler(IInstallLibraryHandler installLibraryHandler) {
384+
myInstallLibraryHandler = installLibraryHandler;
385+
}
386+
387+
public static IInstallLibraryHandler getInstallLibraryHandler() {
388+
return myInstallLibraryHandler;
389+
}
390+
381391
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package io.sloeber.core.core;
2+
3+
import java.util.Map;
4+
5+
import io.sloeber.core.api.IInstallLibraryHandler;
6+
import io.sloeber.core.managers.Library;
7+
8+
public class DefaultInstallHandler implements IInstallLibraryHandler {
9+
10+
@Override
11+
public boolean autoInstall() {
12+
return false;
13+
}
14+
15+
16+
@Override
17+
public Map<String, Library> selectLibrariesToInstall(Map<String, Library> proposedLibsToInstall) {
18+
19+
return proposedLibsToInstall;
20+
}
21+
22+
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
import io.sloeber.core.InternalBoardDescriptor;
3838
import io.sloeber.core.api.BoardDescriptor;
39+
import io.sloeber.core.api.IInstallLibraryHandler;
3940
import io.sloeber.core.api.LibraryManager;
4041
import io.sloeber.core.common.Common;
4142
import io.sloeber.core.common.ConfigurationPreferences;
@@ -394,7 +395,8 @@ public static void checkLibraries(IProject affectedProject) {
394395
}
395396
UnresolvedIncludedHeaders.removeAll(alreadyAddedLibs);
396397

397-
398+
IInstallLibraryHandler installHandler =LibraryManager.getInstallLibraryHandler();
399+
if (installHandler.autoInstall()) {
398400
//Check if there are libraries that are not found in the installed libraries
399401
Map<String, IPath> installedLibs = getAllInstalledLibraries(configurationDescription);
400402
Set<String> uninstalledIncludedHeaders=new TreeSet<>(UnresolvedIncludedHeaders);
@@ -408,13 +410,15 @@ public static void checkLibraries(IProject affectedProject) {
408410
//We now know which libraries to install
409411
//TODO for now I just install but there should be some user
410412
//interaction
413+
availableLibs=installHandler.selectLibrariesToInstall(availableLibs);
411414
for (Entry<String, Library> curLib : availableLibs.entrySet()) {
412415
curLib.getValue().install(new NullProgressMonitor());
413416
}
414417
}
415418
}
419+
}
416420

417-
installedLibs = getAllInstalledLibraries(configurationDescription);
421+
Map<String, IPath> installedLibs = getAllInstalledLibraries(configurationDescription);
418422
installedLibs.keySet().retainAll(UnresolvedIncludedHeaders);
419423
if (!installedLibs.isEmpty()) {
420424
// there are possible libraries to add

0 commit comments

Comments
 (0)