Search in sources :

Example 1 with ICExclusionPatternPathEntry

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

Aggregations

CSourceEntry (org.eclipse.cdt.core.settings.model.CSourceEntry)1 ICConfigurationDescription (org.eclipse.cdt.core.settings.model.ICConfigurationDescription)1 ICExclusionPatternPathEntry (org.eclipse.cdt.core.settings.model.ICExclusionPatternPathEntry)1 ICProjectDescription (org.eclipse.cdt.core.settings.model.ICProjectDescription)1 ICResourceDescription (org.eclipse.cdt.core.settings.model.ICResourceDescription)1 ICSourceEntry (org.eclipse.cdt.core.settings.model.ICSourceEntry)1 IProject (org.eclipse.core.resources.IProject)1 IProjectDescription (org.eclipse.core.resources.IProjectDescription)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 Path (org.eclipse.core.runtime.Path)1