Search in sources :

Example 31 with ICProjectDescription

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

the class RemoteProxyCMainTab method initializeProgramName.

/**
 * Set the program name attributes on the working copy based on the
 * ICElement.
 * @param cElement The element to get data from.
 * @param config The configuration to initialize
 */
protected void initializeProgramName(ICElement cElement, ILaunchConfigurationWorkingCopy config) {
    boolean renamed = false;
    if (!(cElement instanceof IBinary)) {
        cElement = cElement.getCProject();
    }
    if (cElement instanceof ICProject) {
        IProject project = cElement.getCProject().getProject();
        String name = project.getName();
        ICProjectDescription projDes = CCorePlugin.getDefault().getProjectDescription(project);
        if (projDes != null) {
            String buildConfigName = projDes.getActiveConfiguration().getName();
            // Bug 234951
            name = NLS.bind(LaunchMessages.CMainTab_Configuration_name, name, buildConfigName);
        }
        name = getLaunchConfigurationDialog().generateName(name);
        config.rename(name);
        renamed = true;
    }
    IBinary binary = null;
    if (cElement instanceof ICProject) {
        IBinary[] bins = getBinaryFiles((ICProject) cElement);
        if (bins != null && bins.length == 1) {
            binary = bins[0];
        }
    } else if (cElement instanceof IBinary) {
        binary = (IBinary) cElement;
    }
    String projectDir = EMPTY_STRING;
    IProject project = null;
    try {
        project = ConfigUtils.getProject(ConfigUtils.getProjectName(config));
    } catch (CoreException e) {
        setErrorMessage(fPreviouslyCheckedWorkingDirErrorMsg = ProxyLaunchMessages.error_accessing_working_directory);
    }
    if (project != null) {
        try {
            projectDir = RemoteProxyManager.getInstance().getRemoteProjectLocation(project);
        } catch (CoreException e) {
            setErrorMessage(fPreviouslyCheckedWorkingDirErrorMsg = ProxyLaunchMessages.error_accessing_working_directory);
        }
    }
    String path = EMPTY_STRING;
    if (binary != null) {
        path = binary.getResource().getProjectRelativePath().toOSString();
        if (!renamed) {
            String name = binary.getElementName();
            int index = name.lastIndexOf('.');
            if (index > 0) {
                name = name.substring(0, index);
            }
            name = getLaunchConfigurationDialog().generateName(name);
            config.rename(name);
            renamed = true;
        }
    }
    config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, projectDir + IPath.SEPARATOR + path);
    if (!renamed) {
        String name = getLaunchConfigurationDialog().generateName(cElement.getCProject().getElementName());
        config.rename(name);
    }
}
Also used : ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) ICProject(org.eclipse.cdt.core.model.ICProject) CoreException(org.eclipse.core.runtime.CoreException) IBinary(org.eclipse.cdt.core.model.IBinary) IProject(org.eclipse.core.resources.IProject)

Example 32 with ICProjectDescription

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

the class BoardDescriptor method createProject.

/*
	 * Method to create a project based on the board
	 */
public IProject createProject(String projectName, URI projectURI, ArrayList<ConfigurationDescriptor> cfgNamesAndTCIds, CodeDescriptor codeDescription, CompileOptions compileOptions, IProgressMonitor monitor) throws Exception {
    IProject projectHandle;
    projectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(Common.MakeNameCompileSafe(projectName));
    // try {
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    final IProjectDescription desc = workspace.newProjectDescription(projectHandle.getName());
    desc.setLocationURI(projectURI);
    projectHandle.create(desc, monitor);
    if (monitor.isCanceled()) {
        throw new OperationCanceledException();
    }
    projectHandle.open(IResource.BACKGROUND_REFRESH, monitor);
    // Creates the .cproject file with the configurations
    ICProjectDescription prjCDesc = ShouldHaveBeenInCDT.setCProjectDescription(projectHandle, cfgNamesAndTCIds, true, monitor);
    // Add the C C++ AVR and other needed Natures to the project
    Helpers.addTheNatures(desc);
    // Add the Arduino folder
    Helpers.createNewFolder(projectHandle, Const.ARDUINO_CODE_FOLDER_NAME, null);
    for (ConfigurationDescriptor curConfig : cfgNamesAndTCIds) {
        ICConfigurationDescription configurationDescription = prjCDesc.getConfigurationByName(curConfig.configName);
        compileOptions.save(configurationDescription);
        save(configurationDescription);
    }
    // Set the path variables
    // ArduinoHelpers.setProjectPathVariables(prjCDesc.getActiveConfiguration());
    // Intermediately save or the adding code will fail
    // Release is the active config (as that is the "IDE" Arduino
    // type....)
    ICConfigurationDescription defaultConfigDescription = prjCDesc.getConfigurationByName(cfgNamesAndTCIds.get(0).configName);
    ICResourceDescription cfgd = defaultConfigDescription.getResourceDescription(new Path(new String()), true);
    ICExclusionPatternPathEntry[] entries = cfgd.getConfiguration().getSourceEntries();
    if (entries.length == 1) {
        Path[] exclusionPath = new Path[6];
        exclusionPath[0] = new Path(LIBRARY_PATH_SUFFIX + "/?*/**/?xamples/**");
        exclusionPath[1] = new Path(LIBRARY_PATH_SUFFIX + "/?*/**/?xtras/**");
        exclusionPath[2] = new Path(LIBRARY_PATH_SUFFIX + "/?*/**/test*/**");
        exclusionPath[3] = new Path(LIBRARY_PATH_SUFFIX + "/?*/**/third-party/**");
        exclusionPath[4] = new Path(LIBRARY_PATH_SUFFIX + "/**/._*");
        exclusionPath[5] = new Path(LIBRARY_PATH_SUFFIX + "/?*/utility/*/*");
        ICExclusionPatternPathEntry newSourceEntry = new CSourceEntry(entries[0].getFullPath(), exclusionPath, ICSettingEntry.VALUE_WORKSPACE_PATH);
        ICSourceEntry[] out = null;
        out = new ICSourceEntry[1];
        out[0] = (ICSourceEntry) newSourceEntry;
        try {
            cfgd.getConfiguration().setSourceEntries(out);
        } catch (CoreException e) {
        // ignore
        }
    } else {
    // this should not happen
    }
    Set<String> librariesToInstall = codeDescription.createFiles(projectHandle, monitor);
    Libraries.addLibrariesToProject(projectHandle, defaultConfigDescription, librariesToInstall);
    prjCDesc.setActiveConfiguration(defaultConfigDescription);
    prjCDesc.setCdtProjectCreated();
    CoreModel.getDefault().getProjectDescriptionManager().setProjectDescription(projectHandle, prjCDesc, true, null);
    projectHandle.setDescription(desc, new NullProgressMonitor());
    projectHandle.refreshLocal(IResource.DEPTH_INFINITE, null);
    monitor.done();
    return projectHandle;
}
Also used : ICResourceDescription(org.eclipse.cdt.core.settings.model.ICResourceDescription) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) ICSourceEntry(org.eclipse.cdt.core.settings.model.ICSourceEntry) IWorkspace(org.eclipse.core.resources.IWorkspace) ICExclusionPatternPathEntry(org.eclipse.cdt.core.settings.model.ICExclusionPatternPathEntry) IProjectDescription(org.eclipse.core.resources.IProjectDescription) ICConfigurationDescription(org.eclipse.cdt.core.settings.model.ICConfigurationDescription) ICSourceEntry(org.eclipse.cdt.core.settings.model.ICSourceEntry) CSourceEntry(org.eclipse.cdt.core.settings.model.CSourceEntry)

Example 33 with ICProjectDescription

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

the class Libraries method addLibrariesToProject.

public static void addLibrariesToProject(IProject project, Set<String> selectedLibraries) {
    ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
    ICProjectDescription projectDescription = mngr.getProjectDescription(project, true);
    ICConfigurationDescription configurationDescription = projectDescription.getActiveConfiguration();
    addLibrariesToProject(project, configurationDescription, 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 34 with ICProjectDescription

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

the class Common method setBuildEnvironmentVariable.

public static void setBuildEnvironmentVariable(IProject project, String envName, String value) {
    ICProjectDescription prjDesc = CoreModel.getDefault().getProjectDescription(project);
    setBuildEnvironmentVariable(prjDesc.getDefaultSettingConfiguration(), envName, value);
}
Also used : ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription)

Example 35 with ICProjectDescription

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

the class ExplorerLabelDecorator method decorateText.

@Override
public String decorateText(String text, Object element) {
    IProject proj = (IProject) element;
    if (proj.isOpen()) {
        if (Sketch.isSketch(proj)) {
            ICProjectDescription prjDesc = CoreModel.getDefault().getProjectDescription(proj);
            if (prjDesc == null) {
                return new String();
            }
            ICConfigurationDescription configurationDescription = prjDesc.getActiveConfiguration();
            BoardDescriptor boardDescriptor = BoardDescriptor.makeBoardDescriptor(configurationDescription);
            String boardName = boardDescriptor.getBoardName();
            String portName = boardDescriptor.getUploadPort();
            if (portName.isEmpty()) {
                // $NON-NLS-1$
                portName = "no port";
            }
            if (boardName.isEmpty()) {
                // $NON-NLS-1$
                boardName = "no Board";
            }
            return text + ' ' + boardName + ' ' + ':' + portName;
        }
    }
    return null;
}
Also used : ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) ICConfigurationDescription(org.eclipse.cdt.core.settings.model.ICConfigurationDescription) BoardDescriptor(io.sloeber.core.api.BoardDescriptor) IProject(org.eclipse.core.resources.IProject)

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