Search in sources :

Example 1 with CSourceEntry

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

the class ArduinoGnuMakefileGenerator method initialize.

@Override
public void initialize(int buildKind, IConfiguration cfg, IBuilder _builder, IProgressMonitor monitor1) {
    IBuilder builder1 = _builder;
    // Save the project so we can get path and member information
    this.project = cfg.getOwner().getProject();
    if (builder1 == null) {
        builder1 = cfg.getEditableBuilder();
    }
    try {
        this.projectResources = this.project.members();
    } catch (CoreException e) {
        this.projectResources = null;
    }
    // Save the monitor reference for reporting back to the user
    this.monitor = monitor1;
    // Get the build info for the project
    // this.info = info;
    // Get the name of the build target
    this.buildTargetName = cfg.getArtifactName();
    // Get its extension
    this.buildTargetExt = cfg.getArtifactExtension();
    try {
        // try to resolve the build macros in the target extension
        this.buildTargetExt = ManagedBuildManager.getBuildMacroProvider().resolveValueToMakefileFormat(this.buildTargetExt, "", " ", IBuildMacroProvider.CONTEXT_CONFIGURATION, builder1);
    } catch (BuildMacroException e) {
    /* JABA is not going to write this code */
    }
    try {
        // try to resolve the build macros in the target name
        String resolved = ManagedBuildManager.getBuildMacroProvider().resolveValueToMakefileFormat(this.buildTargetName, "", " ", IBuildMacroProvider.CONTEXT_CONFIGURATION, builder1);
        if (resolved != null) {
            resolved = resolved.trim();
            if (resolved.length() > 0)
                this.buildTargetName = resolved;
        }
    } catch (BuildMacroException e) {
    /* JABA is not going to write this code */
    }
    if (this.buildTargetExt == null) {
        this.buildTargetExt = new String();
    }
    // Cache the build tools
    this.config = cfg;
    this.builder = builder1;
    initToolInfos();
    // set the top build dir path
    this.topBuildDir = this.project.getFolder(cfg.getName()).getFullPath();
    this.srcEntries = this.config.getSourceEntries();
    if (this.srcEntries.length == 0) {
        this.srcEntries = new ICSourceEntry[] { new CSourceEntry(Path.EMPTY, null, ICSettingEntry.RESOLVED | ICSettingEntry.VALUE_WORKSPACE_PATH) };
    } else {
        ICConfigurationDescription cfgDes = ManagedBuildManager.getDescriptionForConfiguration(this.config);
        this.srcEntries = CDataUtil.resolveEntries(this.srcEntries, cfgDes);
    }
}
Also used : IBuilder(org.eclipse.cdt.managedbuilder.core.IBuilder) CoreException(org.eclipse.core.runtime.CoreException) BuildMacroException(org.eclipse.cdt.managedbuilder.macros.BuildMacroException) 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 2 with CSourceEntry

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

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

Aggregations

CSourceEntry (org.eclipse.cdt.core.settings.model.CSourceEntry)3 ICConfigurationDescription (org.eclipse.cdt.core.settings.model.ICConfigurationDescription)3 ICSourceEntry (org.eclipse.cdt.core.settings.model.ICSourceEntry)3 ICProjectDescription (org.eclipse.cdt.core.settings.model.ICProjectDescription)2 CoreException (org.eclipse.core.runtime.CoreException)2 IPath (org.eclipse.core.runtime.IPath)2 Path (org.eclipse.core.runtime.Path)2 HashSet (java.util.HashSet)1 ICExclusionPatternPathEntry (org.eclipse.cdt.core.settings.model.ICExclusionPatternPathEntry)1 ICResourceDescription (org.eclipse.cdt.core.settings.model.ICResourceDescription)1 IBuilder (org.eclipse.cdt.managedbuilder.core.IBuilder)1 BuildMacroException (org.eclipse.cdt.managedbuilder.macros.BuildMacroException)1 IProject (org.eclipse.core.resources.IProject)1 IProjectDescription (org.eclipse.core.resources.IProjectDescription)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1