use of io.sloeber.core.api.IInstallLibraryHandler in project arduino-eclipse-plugin by Sloeber.
the class Libraries method checkLibraries.
public static void checkLibraries(IProject affectedProject) {
Map<String, String> includeHeaderReplacement = getIncludeHeaderReplacement();
ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
if (mngr != null) {
ICProjectDescription projectDescription = mngr.getProjectDescription(affectedProject, true);
if (projectDescription != null) {
ICConfigurationDescription configurationDescription = projectDescription.getActiveConfiguration();
if (configurationDescription != null) {
Set<String> UnresolvedIncludedHeaders = getUnresolvedProjectIncludes(affectedProject);
Set<String> alreadyAddedLibs = getAllLibrariesFromProject(affectedProject);
// remove pgmspace as it gives a problem
// $NON-NLS-1$
UnresolvedIncludedHeaders.remove("pgmspace");
for (Map.Entry<String, String> entry : includeHeaderReplacement.entrySet()) {
if (UnresolvedIncludedHeaders.contains(entry.getKey())) {
UnresolvedIncludedHeaders.remove(entry.getKey());
UnresolvedIncludedHeaders.add(entry.getValue());
}
}
UnresolvedIncludedHeaders.removeAll(alreadyAddedLibs);
IInstallLibraryHandler installHandler = LibraryManager.getInstallLibraryHandler();
if (installHandler.autoInstall()) {
// Check if there are libraries that are not found in the installed libraries
Map<String, IPath> installedLibs = getAllInstalledLibraries(configurationDescription);
Set<String> uninstalledIncludedHeaders = new TreeSet<>(UnresolvedIncludedHeaders);
uninstalledIncludedHeaders.removeAll(installedLibs.keySet());
if (!uninstalledIncludedHeaders.isEmpty()) {
// some libraries may need to be installed
Map<String, LibraryDescriptor> availableLibs = LibraryManager.getLatestInstallableLibraries(uninstalledIncludedHeaders);
if (!availableLibs.isEmpty()) {
// We now know which libraries to install
// TODO for now I just install but there should be some user
// interaction
availableLibs = installHandler.selectLibrariesToInstall(availableLibs);
for (Entry<String, LibraryDescriptor> curLib : availableLibs.entrySet()) {
curLib.getValue().toLibrary().install(new NullProgressMonitor());
}
}
}
}
Map<String, IPath> installedLibs = getAllInstalledLibraries(configurationDescription);
installedLibs.keySet().retainAll(UnresolvedIncludedHeaders);
if (!installedLibs.isEmpty()) {
// there are possible libraries to add
Common.log(new Status(IStatus.INFO, Const.CORE_PLUGIN_ID, // $NON-NLS-1$
"list of libraries to add to project " + affectedProject.getName() + ": " + // $NON-NLS-1$
installedLibs.keySet().toString()));
addLibrariesToProject(affectedProject, configurationDescription, installedLibs);
try {
// TODO remove this logging code if this code is not causing the disrupts
long startTime = System.nanoTime();
mngr.setProjectDescription(affectedProject, projectDescription, true, null);
// in miliseconds
long duration = (System.nanoTime() - startTime) / 1000000;
if (duration > 45000) {
// $NON-NLS-1$ //$NON-NLS-2$
Common.log(new Status(IStatus.WARNING, Const.CORE_PLUGIN_ID, "setProjectDescription took " + duration + " miliseconds!!!"));
}
} catch (CoreException e) {
// this can fail because the project may already
// be
// deleted
}
}
}
}
}
}
Aggregations