Search in sources :

Example 36 with ICProjectDescription

use of org.eclipse.cdt.core.settings.model.ICProjectDescription in project usbdm-eclipse-plugins by podonoghue.

the class ProjectUtilities method createNewStyleProjectFolder.

/**
 * @param monitor
 * @param projectHandle
 * @param folder
 * @throws CoreException
 * @throws WriteAccessException
 */
private static void createNewStyleProjectFolder(IProgressMonitor monitor, IProject projectHandle, IFolder folder) throws CoreException, WriteAccessException {
    ICSourceEntry newEntry = new CSourceEntry(folder, null, 0);
    ICProjectDescription description = CCorePlugin.getDefault().getProjectDescription(projectHandle);
    ICConfigurationDescription[] configs = description.getConfigurations();
    for (int i = 0; i < configs.length; i++) {
        ICConfigurationDescription config = configs[i];
        ICSourceEntry[] entries = config.getSourceEntries();
        Set<ICSourceEntry> set = new HashSet<ICSourceEntry>();
        for (int j = 0; j < entries.length; j++) {
            if (new Path(entries[j].getValue()).segmentCount() == 1)
                continue;
            set.add(entries[j]);
        }
        set.add(newEntry);
        config.setSourceEntries(set.toArray(new ICSourceEntry[set.size()]));
    }
    CCorePlugin.getDefault().setProjectDescription(projectHandle, description, false, monitor);
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) ICSourceEntry(org.eclipse.cdt.core.settings.model.ICSourceEntry) ICConfigurationDescription(org.eclipse.cdt.core.settings.model.ICConfigurationDescription) CSourceEntry(org.eclipse.cdt.core.settings.model.CSourceEntry) ICSourceEntry(org.eclipse.cdt.core.settings.model.ICSourceEntry) HashSet(java.util.HashSet)

Example 37 with ICProjectDescription

use of org.eclipse.cdt.core.settings.model.ICProjectDescription in project m2e-nar by maven-nar.

the class CProjectConfigurator method getCdtProject.

private ICProjectDescription getCdtProject(IProject project, IToolChain tc, String artefactType, IProgressMonitor monitor) throws CoreException {
    try {
        ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
        if (!project.hasNature(CCProjectNature.CC_NATURE_ID)) {
            MavenNarPlugin.getDefault().log("Configuring project with " + tc.getUniqueRealName() + " tool chain");
            // Add the C++ Nature
            CCorePlugin.getDefault().convertProjectToNewCC(project, ManagedBuildManager.CFG_DATA_PROVIDER_ID, monitor);
            ICProjectDescription des = mngr.createProjectDescription(project, false, false);
            IManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project);
            List<IConfiguration> cfgs = getCfgs(tc, artefactType);
            if (cfgs.isEmpty()) {
                throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, "Cannot find any configurations"));
            }
            IConfiguration cf = cfgs.get(0);
            IManagedProject mProj = ManagedBuildManager.createManagedProject(project, cf.getProjectType());
            info.setManagedProject(mProj);
            return des;
        } else {
            ICProjectDescription des = mngr.getProjectDescription(project, true);
            return des;
        }
    } catch (BuildException e) {
        throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, "Cannot create CDT managed project", e));
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IManagedProject(org.eclipse.cdt.managedbuilder.core.IManagedProject) ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) IManagedBuildInfo(org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo) CoreException(org.eclipse.core.runtime.CoreException) ICProjectDescriptionManager(org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager) BuildException(org.eclipse.cdt.managedbuilder.core.BuildException) IConfiguration(org.eclipse.cdt.managedbuilder.core.IConfiguration)

Example 38 with ICProjectDescription

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

the class Sketch method addCodeFolder.

/**
 * Adds a folder to the project and adds the folder to the linked folders if
 * needed Stores the projectDescription if it has changed
 *
 * @param project
 *            the project to add the folder to
 * @param path
 *            the path that needs adding to the project
 *
 * @throws CoreException
 */
public static void addCodeFolder(IProject project, Path path) throws CoreException {
    boolean projDescNeedsSaving = false;
    CoreModel coreModel = CoreModel.getDefault();
    ICProjectDescription projectDescription = coreModel.getProjectDescription(project);
    List<IPath> includeFolders = Helpers.addCodeFolder(project, path, path.lastSegment(), false);
    for (ICConfigurationDescription curConfig : projectDescription.getConfigurations()) {
        if (Helpers.addIncludeFolder(curConfig, includeFolders, true)) {
            projDescNeedsSaving = true;
        }
    }
    if (projDescNeedsSaving) {
        coreModel.getProjectDescriptionManager().setProjectDescription(project, projectDescription, true, null);
    }
}
Also used : ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) IPath(org.eclipse.core.runtime.IPath) CoreModel(org.eclipse.cdt.core.model.CoreModel) ICConfigurationDescription(org.eclipse.cdt.core.settings.model.ICConfigurationDescription)

Example 39 with ICProjectDescription

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

the class SloeberProject method convertToArduinoProject.

/**
 * convenient method to create project
 *
 * @param proj1Name
 * @param object
 * @param proj1BoardDesc
 * @param codeDesc
 * @param proj1CompileDesc
 * @param otherDesc
 * @param nullProgressMonitor
 * @return
 */
public static void convertToArduinoProject(IProject project, IProgressMonitor monitor) {
    if (project == null) {
        return;
    }
    final IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IWorkspaceRoot root = workspace.getRoot();
    ICoreRunnable runnable = new ICoreRunnable() {

        @Override
        public void run(IProgressMonitor internalMonitor) throws CoreException {
            IndexerController.doNotIndex(project);
            try {
                // create a sloeber project
                SloeberProject sloeberProject = new SloeberProject(project);
                if (!sloeberProject.readConfigFromFiles()) {
                    String RELEASE = "Release";
                    sloeberProject.setBoardDescription(RELEASE, new BoardDescription(), false);
                    sloeberProject.setCompileDescription(RELEASE, new CompileDescription());
                    sloeberProject.setOtherDescription(RELEASE, new OtherDescription());
                // we failed to read from disk so we set opourselfves some values
                // faking the stuf is in memory
                }
                String configName = sloeberProject.myBoardDescriptions.keySet().iterator().next();
                BoardDescription boardDescriptor = sloeberProject.getBoardDescription(configName, true);
                // Add the arduino code folders
                List<IPath> addToIncludePath = Helpers.addArduinoCodeToProject(project, boardDescriptor);
                // make the eclipse project a cdt project
                CCorePlugin.getDefault().createCProject(null, project, new NullProgressMonitor(), ManagedBuilderCorePlugin.MANAGED_MAKE_PROJECT_ID);
                // add the required natures
                ManagedCProjectNature.addManagedNature(project, internalMonitor);
                ManagedCProjectNature.addManagedBuilder(project, internalMonitor);
                // $NON-NLS-1$
                ManagedCProjectNature.addNature(project, "org.eclipse.cdt.core.ccnature", internalMonitor);
                ManagedCProjectNature.addNature(project, Const.ARDUINO_NATURE_ID, internalMonitor);
                // make the cdt project a managed build project
                // $NON-NLS-1$
                IProjectType sloeberProjType = ManagedBuildManager.getProjectType("io.sloeber.core.sketch");
                ManagedBuildManager.createBuildInfo(project);
                IManagedProject newProject = ManagedBuildManager.createManagedProject(project, sloeberProjType);
                ManagedBuildManager.setNewProjectVersion(project);
                // Copy over the Sloeber configs
                IConfiguration defaultConfig = null;
                IConfiguration[] configs = sloeberProjType.getConfigurations();
                for (int i = 0; i < configs.length; ++i) {
                    IConfiguration curConfig = newProject.createConfiguration(configs[i], // $NON-NLS-1$
                    sloeberProjType.getId() + "." + i);
                    curConfig.setArtifactName(newProject.getDefaultArtifactName());
                    // Make the first configuration the default
                    if (i == 0) {
                        defaultConfig = curConfig;
                    }
                }
                ManagedBuildManager.setDefaultConfiguration(project, defaultConfig);
                Map<String, String> configs2 = new HashMap<>();
                CCorePlugin cCorePlugin = CCorePlugin.getDefault();
                ICProjectDescription prjCDesc = cCorePlugin.getProjectDescription(project);
                ICConfigurationDescription activeConfig = prjCDesc.getActiveConfiguration();
                for (String curConfigName : sloeberProject.myBoardDescriptions.keySet()) {
                    ICConfigurationDescription curConfigDesc = prjCDesc.getConfigurationByName(curConfigName);
                    if (curConfigDesc == null) {
                        String id = CDataUtil.genId(null);
                        curConfigDesc = prjCDesc.createConfiguration(id, curConfigName, activeConfig);
                    }
                    Helpers.addIncludeFolder(curConfigDesc, addToIncludePath, true);
                    String curConfigKey = getConfigKey(curConfigDesc);
                    sloeberProject.myEnvironmentVariables.put(curConfigKey, sloeberProject.getEnvVars(curConfigKey));
                    configs2.put(curConfigName, curConfigDesc.getId());
                }
                sloeberProject.myIsInMemory = true;
                sloeberProject.createSloeberConfigFiles(prjCDesc);
                SubMonitor refreshMonitor = SubMonitor.convert(internalMonitor, 3);
                project.refreshLocal(IResource.DEPTH_INFINITE, refreshMonitor);
                cCorePlugin.setProjectDescription(project, prjCDesc, true, null);
            } catch (Exception e) {
                Common.log(new Status(IStatus.INFO, io.sloeber.core.Activator.getId(), "Project conversion failed: ", // $NON-NLS-1$
                e));
            }
            IndexerController.index(project);
        }
    };
    try {
        workspace.run(runnable, root, IWorkspace.AVOID_UPDATE, monitor);
    } catch (Exception e) {
        // $NON-NLS-1$
        Common.log(new Status(IStatus.INFO, io.sloeber.core.Activator.getId(), "Project conversion failed: ", e));
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) HashMap(java.util.HashMap) ICoreRunnable(org.eclipse.core.runtime.ICoreRunnable) IManagedProject(org.eclipse.cdt.managedbuilder.core.IManagedProject) CCorePlugin(org.eclipse.cdt.core.CCorePlugin) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IPath(org.eclipse.core.runtime.IPath) IProjectType(org.eclipse.cdt.managedbuilder.core.IProjectType) SubMonitor(org.eclipse.core.runtime.SubMonitor) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IWorkspace(org.eclipse.core.resources.IWorkspace) ICConfigurationDescription(org.eclipse.cdt.core.settings.model.ICConfigurationDescription) IConfiguration(org.eclipse.cdt.managedbuilder.core.IConfiguration)

Example 40 with ICProjectDescription

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

the class SloeberProject method getDecoratedText.

/**
 * get the text for the decorator
 *
 * @param text
 * @return
 */
public String getDecoratedText(String text) {
    if (!isInMemory()) {
        configure();
    }
    ICProjectDescription prjDesc = CoreModel.getDefault().getProjectDescription(myProject);
    if (prjDesc != null) {
        ICConfigurationDescription confDesc = prjDesc.getActiveConfiguration();
        if (confDesc != null) {
            // do not use getBoardDescriptor below as this will cause a infinite loop at
            // project creation
            BoardDescription boardDescriptor = myBoardDescriptions.get(getConfigKey(confDesc));
            if (boardDescriptor == null) {
                // $NON-NLS-1$
                return text + " Project not configured";
            }
            String boardName = boardDescriptor.getBoardName();
            String portName = boardDescriptor.getActualUploadPort();
            if (portName.isEmpty()) {
                portName = Messages.decorator_no_port;
            }
            if (boardName.isEmpty()) {
                boardName = Messages.decorator_no_platform;
            }
            return text + ' ' + boardName + ' ' + ':' + portName;
        }
    }
    return text;
}
Also used : ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) ICConfigurationDescription(org.eclipse.cdt.core.settings.model.ICConfigurationDescription)

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