Search in sources :

Example 1 with ICProjectDescription

use of org.eclipse.cdt.core.settings.model.ICProjectDescription in project linuxtools by eclipse.

the class STSymbolManager method getBinaryParser.

/**
 * Retrieve the list of binary parsers defined for the given project.
 * @param project The project.
 * @return The binary parsers for this project.
 */
private List<IBinaryParser> getBinaryParser(IProject project) {
    List<IBinaryParser> parsers = new LinkedList<>();
    ICProjectDescription projDesc = CCorePlugin.getDefault().getProjectDescription(project);
    if (projDesc == null) {
        return parsers;
    }
    ICConfigurationDescription[] cfgs = projDesc.getConfigurations();
    String[] binaryParserIds = CoreModelUtil.getBinaryParserIds(cfgs);
    IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(CCorePlugin.PLUGIN_ID, CCorePlugin.BINARY_PARSER_SIMPLE_ID);
    for (String id : binaryParserIds) {
        IExtension extension = extensionPoint.getExtension(id);
        if (extension != null) {
            IConfigurationElement[] element = extension.getConfigurationElements();
            for (IConfigurationElement element2 : element) {
                if (element2.getName().equalsIgnoreCase("cextension")) {
                    // $NON-NLS-1$
                    try {
                        // $NON-NLS-1$
                        IBinaryParser parser = (IBinaryParser) element2.createExecutableExtension("run");
                        if (parser != null) {
                            parsers.add(parser);
                        }
                    } catch (CoreException e) {
                    // TODO: handle exception ?
                    }
                }
            }
        }
    }
    return parsers;
}
Also used : ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) LinkedList(java.util.LinkedList) IBinaryParser(org.eclipse.cdt.core.IBinaryParser) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) CoreException(org.eclipse.core.runtime.CoreException) IExtension(org.eclipse.core.runtime.IExtension) ICConfigurationDescription(org.eclipse.cdt.core.settings.model.ICConfigurationDescription)

Example 2 with ICProjectDescription

use of org.eclipse.cdt.core.settings.model.ICProjectDescription in project linuxtools by eclipse.

the class CProjectHelper method addDefaultBinaryParser.

/**
 * Add the default binary parser if no binary parser configured.
 *
 * @param project
 * @throws CoreException
 */
private static boolean addDefaultBinaryParser(IProject project) throws CoreException {
    ICConfigExtensionReference[] binaryParsers = CCorePlugin.getDefault().getDefaultBinaryParserExtensions(project);
    if (binaryParsers == null || binaryParsers.length == 0) {
        ICProjectDescription desc = CCorePlugin.getDefault().getProjectDescription(project);
        if (desc == null) {
            return false;
        }
        desc.getDefaultSettingConfiguration().create(CCorePlugin.BINARY_PARSER_UNIQ_ID, CCorePlugin.DEFAULT_BINARY_PARSER_UNIQ_ID);
        CCorePlugin.getDefault().setProjectDescription(project, desc);
    }
    return true;
}
Also used : ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) ICConfigExtensionReference(org.eclipse.cdt.core.settings.model.ICConfigExtensionReference)

Example 3 with ICProjectDescription

use of org.eclipse.cdt.core.settings.model.ICProjectDescription in project arduino-eclipse-plugin by Sloeber.

the class ArduinoLanguageProvider method getCompilerCommand.

@Override
protected String getCompilerCommand(String languageId) {
    String compilerCommand = new String();
    ICProjectDescription prjDesc = CoreModel.getDefault().getProjectDescription(this.currentProject);
    if (prjDesc == null)
        return compilerCommand;
    IEnvironmentVariableManager envManager = CCorePlugin.getDefault().getBuildEnvironmentManager();
    ICConfigurationDescription confDesc = prjDesc.getActiveConfiguration();
    String recipeKey = new String();
    String extraOptions = new String();
    CompileOptions compileOptions = new CompileOptions(confDesc);
    if (languageId.equals("org.eclipse.cdt.core.gcc")) {
        recipeKey = Common.get_ENV_KEY_RECIPE(Const.ACTION_C_to_O);
        extraOptions = compileOptions.get_C_CompileOptions();
    } else if (languageId.equals("org.eclipse.cdt.core.g++")) {
        recipeKey = Common.get_ENV_KEY_RECIPE(Const.ACTION_CPP_to_O);
        extraOptions = compileOptions.get_CPP_CompileOptions();
    } else {
        ManagedBuilderCorePlugin.error("Unable to find compiler command for language " + languageId + " in toolchain=" + getToolchainId());
    }
    extraOptions = extraOptions + " " + compileOptions.get_C_andCPP_CompileOptions() + " " + compileOptions.get_All_CompileOptions();
    try {
        compilerCommand = envManager.getVariable(recipeKey + Const.DOT + "1", confDesc, false).getValue();
        compilerCommand = compilerCommand + envManager.getVariable(recipeKey + Const.DOT + "2", confDesc, false).getValue();
        compilerCommand = compilerCommand + envManager.getVariable(recipeKey + Const.DOT + "3", confDesc, false).getValue();
    } catch (Exception e) {
        compilerCommand = new String();
    }
    compilerCommand = compilerCommand + ' ' + extraOptions;
    return compilerCommand.replaceAll(" -o ", " ");
}
Also used : ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) CompileOptions(io.sloeber.core.api.CompileOptions) IEnvironmentVariableManager(org.eclipse.cdt.core.envvar.IEnvironmentVariableManager) ICConfigurationDescription(org.eclipse.cdt.core.settings.model.ICConfigurationDescription) CoreException(org.eclipse.core.runtime.CoreException)

Example 4 with ICProjectDescription

use of org.eclipse.cdt.core.settings.model.ICProjectDescription 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 5 with ICProjectDescription

use of org.eclipse.cdt.core.settings.model.ICProjectDescription 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)

Aggregations

ICProjectDescription (org.eclipse.cdt.core.settings.model.ICProjectDescription)28 ICConfigurationDescription (org.eclipse.cdt.core.settings.model.ICConfigurationDescription)19 CoreException (org.eclipse.core.runtime.CoreException)13 ICProjectDescriptionManager (org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager)8 IProject (org.eclipse.core.resources.IProject)7 IStatus (org.eclipse.core.runtime.IStatus)6 Status (org.eclipse.core.runtime.Status)6 IConfiguration (org.eclipse.cdt.managedbuilder.core.IConfiguration)5 IPath (org.eclipse.core.runtime.IPath)5 BoardDescriptor (io.sloeber.core.api.BoardDescriptor)4 HashMap (java.util.HashMap)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 AbstractSettingsSynchroniser (com.github.sdedwards.m2e_nar.internal.cdt.AbstractSettingsSynchroniser)2 NarExecution (com.github.sdedwards.m2e_nar.internal.model.NarExecution)2 CompileOptions (io.sloeber.core.api.CompileOptions)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 TreeMap (java.util.TreeMap)2 IContributedEnvironment (org.eclipse.cdt.core.envvar.IContributedEnvironment)2 IEnvironmentVariableManager (org.eclipse.cdt.core.envvar.IEnvironmentVariableManager)2