Search in sources :

Example 21 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 ret = new String();
    ICProjectDescription prjDesc = CoreModel.getDefault().getProjectDescription(currentProject);
    if (prjDesc == null)
        return ret;
    ICConfigurationDescription confDesc = prjDesc.getActiveConfiguration();
    String codanVarName = new String();
    if (languageId.equals("org.eclipse.cdt.core.gcc")) {
        codanVarName = Const.CODAN_C_to_O;
    } else if (languageId.equals("org.eclipse.cdt.core.g++")) {
        codanVarName = Const.CODAN_CPP_to_O;
    } else {
        ManagedBuilderCorePlugin.error("Unable to find compiler command for language " + languageId + " in toolchain=" + getToolchainId());
    }
    try {
        IEnvironmentVariableManager envManager = CCorePlugin.getDefault().getBuildEnvironmentManager();
        ret = envManager.getVariable(codanVarName, confDesc, false).getValue();
    } catch (Exception e) {
        ret = new String();
    }
    return ret;
}
Also used : ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) ICConfigurationDescription(org.eclipse.cdt.core.settings.model.ICConfigurationDescription) IEnvironmentVariableManager(org.eclipse.cdt.core.envvar.IEnvironmentVariableManager)

Example 22 with ICProjectDescription

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

the class SloeberConfigurationVariableSupplier method getSloeberProject.

private static SloeberProject getSloeberProject(IConfiguration configuration) {
    ICConfigurationDescription confDesc = ManagedBuildManager.getDescriptionForConfiguration(configuration);
    ICProjectDescription projDesc = confDesc.getProjectDescription();
    IProject project = projDesc.getProject();
    return SloeberProject.getSloeberProject(project);
}
Also used : ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) ICConfigurationDescription(org.eclipse.cdt.core.settings.model.ICConfigurationDescription) IProject(org.eclipse.core.resources.IProject)

Example 23 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 confDesc = projectDescription.getActiveConfiguration();
            if (confDesc != null) {
                Set<String> UnresolvedIncludedHeaders = getUnresolvedProjectIncludes(affectedProject);
                Set<String> alreadyAddedLibs = getAllLibrariesFromProject(affectedProject);
                // remove pgmspace as it gives a problem
                // $NON-NLS-1$
                UnresolvedIncludedHeaders.remove("pgmspace");
                if (UnresolvedIncludedHeaders.isEmpty()) {
                    return;
                }
                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(confDesc);
                    Set<String> uninstalledIncludedHeaders = new TreeSet<>(UnresolvedIncludedHeaders);
                    uninstalledIncludedHeaders.removeAll(installedLibs.keySet());
                    if (!uninstalledIncludedHeaders.isEmpty()) {
                        // some libraries may need to be installed
                        Map<String, ArduinoLibraryVersion> availableLibs = LibraryManager.getLatestInstallableLibraries(uninstalledIncludedHeaders);
                        if (!availableLibs.isEmpty()) {
                            // Ask the user which libs need installing
                            availableLibs = installHandler.selectLibrariesToInstall(availableLibs);
                            for (Entry<String, ArduinoLibraryVersion> curLib : availableLibs.entrySet()) {
                                LibraryManager.install(curLib.getValue(), new NullProgressMonitor());
                            }
                        }
                    }
                }
                Map<String, IPath> installedLibs = getAllInstalledLibraries(confDesc);
                installedLibs.keySet().retainAll(UnresolvedIncludedHeaders);
                if (!installedLibs.isEmpty()) {
                    // there are possible libraries to add
                    Common.log(new Status(IStatus.INFO, CORE_PLUGIN_ID, // $NON-NLS-1$
                    "list of libraries to add to project " + affectedProject.getName() + // $NON-NLS-1$
                    ": " + installedLibs.keySet().toString()));
                    Map<String, List<IPath>> foldersToChange = addLibrariesToProject(affectedProject, installedLibs);
                    if (adjustProjectDescription(confDesc, foldersToChange)) {
                        try {
                            mngr.setProjectDescription(affectedProject, projectDescription, true, null);
                        } 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) ArduinoLibraryVersion(io.sloeber.core.api.Json.ArduinoLibraryVersion) CoreException(org.eclipse.core.runtime.CoreException) IInstallLibraryHandler(io.sloeber.core.api.IInstallLibraryHandler) TreeSet(java.util.TreeSet) LinkedList(java.util.LinkedList) List(java.util.List) ICConfigurationDescription(org.eclipse.cdt.core.settings.model.ICConfigurationDescription) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 24 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) {
    boolean descNeedsSet = false;
    Set<String> AllLibrariesOriginallyUsed = getAllLibrariesFromProject(project);
    ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
    ICProjectDescription projDesc = mngr.getProjectDescription(project, true);
    ICConfigurationDescription[] configurationDescriptions = projDesc.getConfigurations();
    for (ICConfigurationDescription curconfDesc : configurationDescriptions) {
        Map<String, List<IPath>> foldersToChange = addLibrariesToProject(project, curconfDesc, AllLibrariesOriginallyUsed);
        descNeedsSet = descNeedsSet || adjustProjectDescription(curconfDesc, foldersToChange);
    }
    if (descNeedsSet) {
        try {
            mngr.setProjectDescription(project, projDesc, 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) LinkedList(java.util.LinkedList) List(java.util.List) ICConfigurationDescription(org.eclipse.cdt.core.settings.model.ICConfigurationDescription)

Example 25 with ICProjectDescription

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

the class RegressionTest method issue555.

/**
 * make sure when switching between a board with variant file and without the
 * build still succeeds
 */
@Test
public void issue555() {
    if (MySystem.getTeensyPlatform().isEmpty()) {
        // skip test due to no teensy install folder provided
        // do not fail as this will always fail on travis
        System.out.println("skipping the test because teensy is not installed.");
        return;
    }
    System.out.println("Teensy is installed at " + MySystem.getTeensyPlatform());
    BoardDescription unoBoardid = Arduino.uno().getBoardDescriptor();
    BoardDescription teensyBoardid = Teensy.Teensy3_1().getBoardDescriptor();
    IProject theTestProject = null;
    CodeDescription codeDescriptor = CodeDescription.createDefaultIno();
    String projectName = "issue555";
    NullProgressMonitor monitor = new NullProgressMonitor();
    try {
        theTestProject = SloeberProject.createArduinoProject(projectName, null, unoBoardid, codeDescriptor, new CompileDescription(), monitor);
        // for the indexer
        Shared.waitForAllJobsToFinish();
    } catch (Exception e) {
        e.printStackTrace();
        fail("Failed to create the project:" + projectName);
        return;
    }
    try {
        theTestProject.build(IncrementalProjectBuilder.FULL_BUILD, monitor);
        if (Shared.hasBuildErrors(theTestProject)) {
            fail("Failed to compile the project:" + projectName + " as uno  build errors");
        }
    } catch (CoreException e) {
        e.printStackTrace();
        fail("Failed to compile the project:" + unoBoardid.getBoardName() + " as uno exception");
    }
    SloeberProject arduinoProject = SloeberProject.getSloeberProject(theTestProject);
    ICProjectDescription cProjectDescription = CCorePlugin.getDefault().getProjectDescription(theTestProject);
    arduinoProject.setBoardDescription(cProjectDescription.getActiveConfiguration().getName(), teensyBoardid, true);
    Shared.waitForAllJobsToFinish();
    try {
        theTestProject.build(IncrementalProjectBuilder.FULL_BUILD, monitor);
        if (Shared.hasBuildErrors(theTestProject)) {
            Shared.waitForAllJobsToFinish();
            theTestProject.build(IncrementalProjectBuilder.FULL_BUILD, monitor);
            if (Shared.hasBuildErrors(theTestProject)) {
                fail("Failed to compile the project:" + projectName + " as teensy");
            }
        }
    } catch (CoreException e) {
        e.printStackTrace();
        fail("Failed to compile the project:" + unoBoardid.getBoardName() + " as teensy exception");
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) BoardDescription(io.sloeber.core.api.BoardDescription) CodeDescription(io.sloeber.core.api.CodeDescription) CoreException(org.eclipse.core.runtime.CoreException) SloeberProject(io.sloeber.core.api.SloeberProject) CompileDescription(io.sloeber.core.api.CompileDescription) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) Test(org.junit.Test)

Aggregations

ICProjectDescription (org.eclipse.cdt.core.settings.model.ICProjectDescription)45 ICConfigurationDescription (org.eclipse.cdt.core.settings.model.ICConfigurationDescription)31 CoreException (org.eclipse.core.runtime.CoreException)17 IProject (org.eclipse.core.resources.IProject)13 Status (org.eclipse.core.runtime.Status)10 ICProjectDescriptionManager (org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager)9 IPath (org.eclipse.core.runtime.IPath)9 IStatus (org.eclipse.core.runtime.IStatus)9 CCorePlugin (org.eclipse.cdt.core.CCorePlugin)8 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)8 IConfiguration (org.eclipse.cdt.managedbuilder.core.IConfiguration)7 IOException (java.io.IOException)5 BoardDescription (io.sloeber.core.api.BoardDescription)4 CodeDescription (io.sloeber.core.api.CodeDescription)4 CompileDescription (io.sloeber.core.api.CompileDescription)4 HashMap (java.util.HashMap)4 LinkedList (java.util.LinkedList)4 IWorkspace (org.eclipse.core.resources.IWorkspace)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 BoardDescriptor (io.sloeber.core.api.BoardDescriptor)3