Skip to content

Commit 5309e5a

Browse files
author
jantje
committed
basic implementation
1 parent d93ab26 commit 5309e5a

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,4 +351,19 @@ public static void removeAllLibs() {
351351
}
352352
}
353353

354+
/**
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.
357+
*
358+
* @return a map of all instalable libraries
359+
*/
360+
public static Map<String, io.sloeber.core.managers.Library> getAllInstallableLibraries() {
361+
Map<String, Library> ret = new HashMap<>();
362+
for (LibraryIndex libraryIndex : libraryIndices) {
363+
ret.putAll(libraryIndex.getLatestInstallableLibraries());
364+
}
365+
366+
return ret;
367+
}
368+
354369
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.HashSet;
88
import java.util.List;
99
import java.util.Map;
10+
import java.util.Map.Entry;
1011
import java.util.Set;
1112
import java.util.regex.Pattern;
1213

@@ -93,6 +94,15 @@ public Map<String, Library> getLatestLibraries() {
9394
return this.latestLibs;
9495
}
9596

97+
public Map<String, Library> getLatestInstallableLibraries() {
98+
Map<String, Library> ret = new HashMap<>();
99+
for (Entry<String, Library> curLibrary : this.latestLibs.entrySet()) {
100+
if (getInstalledLibrary(curLibrary.getKey())==null) {
101+
ret.put(curLibrary.getKey(), curLibrary.getValue());
102+
}
103+
}
104+
return ret;
105+
}
96106
public Collection<Library> getLibraries(String category) {
97107
Set<String> categoryLibs = this.categories.get(category);
98108
if (categoryLibs == null) {

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

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@
3030
import org.eclipse.core.runtime.CoreException;
3131
import org.eclipse.core.runtime.IPath;
3232
import org.eclipse.core.runtime.IStatus;
33+
import org.eclipse.core.runtime.NullProgressMonitor;
3334
import org.eclipse.core.runtime.Path;
3435
import org.eclipse.core.runtime.Status;
3536

3637
import io.sloeber.core.InternalBoardDescriptor;
3738
import io.sloeber.core.api.BoardDescriptor;
39+
import io.sloeber.core.api.LibraryManager;
3840
import io.sloeber.core.common.Common;
3941
import io.sloeber.core.common.ConfigurationPreferences;
4042
import io.sloeber.core.common.Const;
@@ -390,15 +392,34 @@ public static void checkLibraries(IProject affectedProject) {
390392
UnresolvedIncludedHeaders.add(entry.getValue());
391393
}
392394
}
393-
Map<String, IPath> availableLibs = getAllInstalledLibraries(configurationDescription);
394395
UnresolvedIncludedHeaders.removeAll(alreadyAddedLibs);
395396

396-
availableLibs.keySet().retainAll(UnresolvedIncludedHeaders);
397-
if (!availableLibs.isEmpty()) {
397+
398+
//Check if there are libraries that are not found in the installed libraries
399+
Map<String, IPath> installedLibs = getAllInstalledLibraries(configurationDescription);
400+
Set<String> uninstalledIncludedHeaders=new TreeSet<>(UnresolvedIncludedHeaders);
401+
uninstalledIncludedHeaders.removeAll(installedLibs.keySet());
402+
if(!uninstalledIncludedHeaders.isEmpty()) {
403+
//some libraries may need to be installed
404+
Map<String, Library> availableLibs = LibraryManager.getAllInstallableLibraries();
405+
availableLibs.keySet().retainAll(uninstalledIncludedHeaders);
406+
if(!availableLibs.isEmpty()) {
407+
//We now know which libraries to install
408+
//TODO for now I just install but there should be some user
409+
//interaction
410+
for (Entry<String, Library> curLib : availableLibs.entrySet()) {
411+
curLib.getValue().install(new NullProgressMonitor());
412+
}
413+
}
414+
}
415+
416+
installedLibs = getAllInstalledLibraries(configurationDescription);
417+
installedLibs.keySet().retainAll(UnresolvedIncludedHeaders);
418+
if (!installedLibs.isEmpty()) {
398419
// there are possible libraries to add
399420
Common.log(new Status(IStatus.INFO, Const.CORE_PLUGIN_ID, "list of libraries to add to project " //$NON-NLS-1$
400-
+ affectedProject.getName() + ": " + availableLibs.keySet().toString())); //$NON-NLS-1$
401-
addLibrariesToProject(affectedProject, configurationDescription, availableLibs);
421+
+ affectedProject.getName() + ": " + installedLibs.keySet().toString())); //$NON-NLS-1$
422+
addLibrariesToProject(affectedProject, configurationDescription, installedLibs);
402423
try {
403424
mngr.setProjectDescription(affectedProject, projectDescription, true, null);
404425
} catch (CoreException e) {

0 commit comments

Comments
 (0)