|
30 | 30 | import org.eclipse.core.runtime.CoreException;
|
31 | 31 | import org.eclipse.core.runtime.IPath;
|
32 | 32 | import org.eclipse.core.runtime.IStatus;
|
| 33 | +import org.eclipse.core.runtime.NullProgressMonitor; |
33 | 34 | import org.eclipse.core.runtime.Path;
|
34 | 35 | import org.eclipse.core.runtime.Status;
|
35 | 36 |
|
36 | 37 | import io.sloeber.core.InternalBoardDescriptor;
|
37 | 38 | import io.sloeber.core.api.BoardDescriptor;
|
| 39 | +import io.sloeber.core.api.IInstallLibraryHandler; |
| 40 | +import io.sloeber.core.api.LibraryDescriptor; |
| 41 | +import io.sloeber.core.api.LibraryManager; |
38 | 42 | import io.sloeber.core.common.Common;
|
39 | 43 | import io.sloeber.core.common.ConfigurationPreferences;
|
40 | 44 | import io.sloeber.core.common.Const;
|
@@ -390,17 +394,46 @@ public static void checkLibraries(IProject affectedProject) {
|
390 | 394 | UnresolvedIncludedHeaders.add(entry.getValue());
|
391 | 395 | }
|
392 | 396 | }
|
393 |
| - Map<String, IPath> availableLibs = getAllInstalledLibraries(configurationDescription); |
394 | 397 | UnresolvedIncludedHeaders.removeAll(alreadyAddedLibs);
|
395 | 398 |
|
396 |
| - availableLibs.keySet().retainAll(UnresolvedIncludedHeaders); |
397 |
| - if (!availableLibs.isEmpty()) { |
| 399 | + IInstallLibraryHandler installHandler =LibraryManager.getInstallLibraryHandler(); |
| 400 | + if (installHandler.autoInstall()) { |
| 401 | + //Check if there are libraries that are not found in the installed libraries |
| 402 | + Map<String, IPath> installedLibs = getAllInstalledLibraries(configurationDescription); |
| 403 | + Set<String> uninstalledIncludedHeaders=new TreeSet<>(UnresolvedIncludedHeaders); |
| 404 | + uninstalledIncludedHeaders.removeAll(installedLibs.keySet()); |
| 405 | + if(!uninstalledIncludedHeaders.isEmpty()) { |
| 406 | + //some libraries may need to be installed |
| 407 | + |
| 408 | + Map<String, LibraryDescriptor> availableLibs=LibraryManager.getLatestInstallableLibraries(uninstalledIncludedHeaders); |
| 409 | + |
| 410 | + if(!availableLibs.isEmpty()) { |
| 411 | + //We now know which libraries to install |
| 412 | + //TODO for now I just install but there should be some user |
| 413 | + //interaction |
| 414 | + availableLibs=installHandler.selectLibrariesToInstall(availableLibs); |
| 415 | + for (Entry<String, LibraryDescriptor> curLib : availableLibs.entrySet()) { |
| 416 | + curLib.getValue().toLibrary().install(new NullProgressMonitor()); |
| 417 | + } |
| 418 | + } |
| 419 | + } |
| 420 | + } |
| 421 | + |
| 422 | + Map<String, IPath> installedLibs = getAllInstalledLibraries(configurationDescription); |
| 423 | + installedLibs.keySet().retainAll(UnresolvedIncludedHeaders); |
| 424 | + if (!installedLibs.isEmpty()) { |
398 | 425 | // there are possible libraries to add
|
399 | 426 | 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); |
| 427 | + + affectedProject.getName() + ": " + installedLibs.keySet().toString())); //$NON-NLS-1$ |
| 428 | + addLibrariesToProject(affectedProject, configurationDescription, installedLibs); |
402 | 429 | try {
|
| 430 | + //TODO remove this logging code if this code is not causing the disrupts |
| 431 | + long startTime = System.nanoTime(); |
403 | 432 | mngr.setProjectDescription(affectedProject, projectDescription, true, null);
|
| 433 | + long duration = (System.nanoTime() - startTime)/ 1000000; //in miliseconds |
| 434 | + if (duration>45000) { |
| 435 | + Common.log(new Status(IStatus.WARNING, Const.CORE_PLUGIN_ID,"setProjectDescription took "+duration+" miliseconds!!!")); //$NON-NLS-1$ //$NON-NLS-2$ |
| 436 | + } |
404 | 437 | } catch (CoreException e) {
|
405 | 438 | // this can fail because the project may already
|
406 | 439 | // be
|
|
0 commit comments