Search in sources :

Example 1 with ICProjectDescriptionManager

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
                    }
                }
            }
        }
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPath(org.eclipse.core.runtime.IPath) ICProjectDescriptionManager(org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager) CoreException(org.eclipse.core.runtime.CoreException) IInstallLibraryHandler(io.sloeber.core.api.IInstallLibraryHandler) TreeSet(java.util.TreeSet) ICConfigurationDescription(org.eclipse.cdt.core.settings.model.ICConfigurationDescription) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) LibraryDescriptor(io.sloeber.core.api.LibraryDescriptor)

Example 2 with ICProjectDescriptionManager

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();
    }
}
Also used : ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) CoreException(org.eclipse.core.runtime.CoreException) ICProjectDescriptionManager(org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager) ICConfigurationDescription(org.eclipse.cdt.core.settings.model.ICConfigurationDescription)

Example 3 with ICProjectDescriptionManager

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();
    }
}
Also used : ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) CoreException(org.eclipse.core.runtime.CoreException) ICProjectDescriptionManager(org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager) ICConfigurationDescription(org.eclipse.cdt.core.settings.model.ICConfigurationDescription)

Example 4 with ICProjectDescriptionManager

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;
}
Also used : IBuilder(org.eclipse.cdt.managedbuilder.core.IBuilder) ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) IConfiguration(org.eclipse.cdt.managedbuilder.core.IConfiguration) Configuration(org.eclipse.cdt.managedbuilder.internal.core.Configuration) ManagedBuildInfo(org.eclipse.cdt.managedbuilder.internal.core.ManagedBuildInfo) ManagedProject(org.eclipse.cdt.managedbuilder.internal.core.ManagedProject) IToolChain(org.eclipse.cdt.managedbuilder.core.IToolChain) ICProjectDescriptionManager(org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager) CConfigurationData(org.eclipse.cdt.core.settings.model.extension.CConfigurationData) ICConfigurationDescription(org.eclipse.cdt.core.settings.model.ICConfigurationDescription) ConfigurationDescriptor(io.sloeber.core.api.ConfigurationDescriptor)

Example 5 with ICProjectDescriptionManager

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);
            }
        }
    }
}
Also used : ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) ICProjectDescriptionManager(org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager) AbstractSettingsSynchroniser(com.github.sdedwards.m2e_nar.internal.cdt.AbstractSettingsSynchroniser) IMavenProjectFacade(org.eclipse.m2e.core.project.IMavenProjectFacade) NarExecution(com.github.sdedwards.m2e_nar.internal.model.NarExecution)

Aggregations

ICProjectDescription (org.eclipse.cdt.core.settings.model.ICProjectDescription)8 ICProjectDescriptionManager (org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager)8 ICConfigurationDescription (org.eclipse.cdt.core.settings.model.ICConfigurationDescription)6 CoreException (org.eclipse.core.runtime.CoreException)5 AbstractSettingsSynchroniser (com.github.sdedwards.m2e_nar.internal.cdt.AbstractSettingsSynchroniser)2 NarExecution (com.github.sdedwards.m2e_nar.internal.model.NarExecution)2 IConfiguration (org.eclipse.cdt.managedbuilder.core.IConfiguration)2 IToolChain (org.eclipse.cdt.managedbuilder.core.IToolChain)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 IMavenProjectFacade (org.eclipse.m2e.core.project.IMavenProjectFacade)2 NarBuildArtifact (com.github.sdedwards.m2e_nar.internal.model.NarBuildArtifact)1 ConfigurationDescriptor (io.sloeber.core.api.ConfigurationDescriptor)1 IInstallLibraryHandler (io.sloeber.core.api.IInstallLibraryHandler)1 LibraryDescriptor (io.sloeber.core.api.LibraryDescriptor)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1