use of org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager 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
}
}
}
}
}
}
use of org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager in project arduino-eclipse-plugin by Sloeber.
the class Libraries method reAttachLibrariesToProject.
public static void reAttachLibrariesToProject(IProject project) {
Set<String> AllLibrariesOriginallyUsed = getAllLibrariesFromProject(project);
ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
ICProjectDescription projectDescription = mngr.getProjectDescription(project, true);
ICConfigurationDescription[] configurationDescriptions = projectDescription.getConfigurations();
for (ICConfigurationDescription CurItem : configurationDescriptions) {
addLibrariesToProject(project, CurItem, AllLibrariesOriginallyUsed);
}
try {
mngr.setProjectDescription(project, projectDescription, true, null);
} catch (CoreException e) {
e.printStackTrace();
}
}
use of org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager in project arduino-eclipse-plugin by Sloeber.
the class Libraries method removeLibrariesFromProject.
/**
* Removes a set of libraries from a project in each project configuration
*
* @param project
* the project from which to remove libraries
* @param libraries
* set of libraries to remove
*/
public static void removeLibrariesFromProject(IProject project, Set<String> selectedLibraries) {
ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
ICProjectDescription projectDescription = mngr.getProjectDescription(project, true);
ICConfigurationDescription[] configurationDescriptions = projectDescription.getConfigurations();
for (ICConfigurationDescription CurItem : configurationDescriptions) {
removeLibrariesFromProject(project, CurItem, selectedLibraries);
}
try {
mngr.setProjectDescription(project, projectDescription, true, null);
} catch (CoreException e) {
e.printStackTrace();
}
}
use of org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager in project arduino-eclipse-plugin by Sloeber.
the class ShouldHaveBeenInCDT method setCProjectDescription.
/*
* Copied from wizard STDWizardHandler package package
* org.eclipse.cdt.managedbuilder.ui.wizards;; This method creates the
* .cProject file in your project.
*
* BK: modified this and made it work for multiple configs.
*/
/**
* This method creates the .cProject file in your project. it is intended to
* be used with newly created projects. Using this method with project that
* have existed for some time is unknown
*
* @param project
* The newly created project that needs a .cproject file.
* @param alCfgs
* An array-list of configuration descriptors (names, toolchain
* IDs) to be used with this project
* @param isManagedBuild
* When true the project is managed build. Else the project is
* not (read you have to maintain the makefiles yourself)
* @param monitor
* The monitor to follow the process
* @throws CoreException
*/
public static ICProjectDescription setCProjectDescription(IProject project, ArrayList<ConfigurationDescriptor> alCfgs, boolean isManagedBuild, IProgressMonitor monitor) throws CoreException {
ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
ICProjectDescription des = mngr.createProjectDescription(project, false, true);
ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project);
ManagedProject mProj = new ManagedProject(des);
info.setManagedProject(mProj);
monitor.worked(20);
// Iterate across the configurations
for (ConfigurationDescriptor curConfDesc : alCfgs) {
IToolChain tcs = ManagedBuildManager.getExtensionToolChain(curConfDesc.ToolchainID);
Configuration cfg = new Configuration(mProj, (ToolChain) tcs, ManagedBuildManager.calculateChildId(curConfDesc.ToolchainID, null), curConfDesc.configName);
IBuilder bld = cfg.getEditableBuilder();
if (bld != null) {
bld.setManagedBuildOn(isManagedBuild);
// $NON-NLS-1$
cfg.setArtifactName("${ProjName}");
} else {
// $NON-NLS-1$
System.out.println("Messages.StdProjectTypeHandler_3");
}
CConfigurationData data = cfg.getConfigurationData();
ICConfigurationDescription cfgDes = des.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, data);
setDefaultLanguageSettingsProviders(project, curConfDesc, cfg, cfgDes);
}
monitor.worked(50);
return des;
}
use of org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager in project m2e-nar by maven-nar.
the class BuildPathManager method updateBuildPaths.
private void updateBuildPaths(IProject project, IProgressMonitor monitor) throws CoreException {
final IMavenProjectFacade facade = projectManager.getProject(project);
if (facade != null) {
final ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
final ICProjectDescription des = mngr.getProjectDescription(project, true);
if (des != null) {
boolean changed = false;
logger.debug("updateBuildPaths: project=" + project.getName());
final ConfiguratorContext context = new ConfiguratorContext(MavenPlugin.getMaven(), projectManager);
List<NarExecution> narExecutions = MavenUtils.buildCompileNarExecutions(context, facade, monitor);
narExecutions.addAll(MavenUtils.buildTestCompileNarExecutions(context, facade, monitor));
for (NarExecution narSettings : narExecutions) {
if (!narSettings.isSkip()) {
final String os = narSettings.getOS();
final String linkerName = narSettings.getLinkerName();
final AbstractSettingsSynchroniser synchro = SynchroniserFactory.getSettingsSynchroniser(os, linkerName);
changed = updateCdtBuildPaths(des, synchro, narSettings);
}
}
if (changed) {
mngr.setProjectDescription(project, des);
}
}
}
}
Aggregations