Search in sources :

Example 6 with ICSourceEntry

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

the class Libraries method addLibrariesToProject.

/**
 * Adds one or more libraries to a project in a configuration
 *
 * @param project
 *            the project to add the libraries to
 * @param confdesc
 *            the confdesc of the project
 * @param libraries
 *            the list of libraries to add
 * @return true if the configuration description has changed
 */
private static void addLibrariesToProject(IProject project, ICConfigurationDescription confdesc, Map<String, IPath> libraries) {
    List<IPath> foldersToRemoveFromBuildPath = new LinkedList<>();
    for (Entry<String, IPath> CurItem : libraries.entrySet()) {
        try {
            Helpers.addCodeFolder(project, CurItem.getValue(), WORKSPACE_LIB_FOLDER + CurItem.getKey(), confdesc, false);
        } catch (CoreException e) {
            Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, Messages.import_lib_failed, e));
        }
        // Check the libraries to see if there are "unwanted subfolders"
        File[] subFolders = CurItem.getValue().toFile().listFiles();
        for (File file : subFolders) {
            if (// $NON-NLS-1$ //$NON-NLS-2$
            file.isDirectory() && !"src".equals(file.getName()) && !"utility".equals(file.getName()) && !"examples".equalsIgnoreCase(file.getName())) {
                // $NON-NLS-1$
                IPath excludePath = // $NON-NLS-1$
                new Path("/" + project.getName()).append(WORKSPACE_LIB_FOLDER).append(CurItem.getKey()).append(file.getName());
                foldersToRemoveFromBuildPath.add(excludePath);
            }
        }
    }
    if (!foldersToRemoveFromBuildPath.isEmpty()) {
        ICResourceDescription cfgd = confdesc.getResourceDescription(new Path(new String()), true);
        ICSourceEntry[] sourceEntries = cfgd.getConfiguration().getSourceEntries();
        for (IPath curFile : foldersToRemoveFromBuildPath) {
            try {
                sourceEntries = CDataUtil.setExcluded(curFile, true, true, sourceEntries);
            } catch (CoreException e1) {
            // ignore
            }
        }
        try {
            cfgd.getConfiguration().setSourceEntries(sourceEntries);
        } catch (Exception e) {
        // ignore
        }
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) ICResourceDescription(org.eclipse.cdt.core.settings.model.ICResourceDescription) IPath(org.eclipse.core.runtime.IPath) LinkedList(java.util.LinkedList) CoreException(org.eclipse.core.runtime.CoreException) CoreException(org.eclipse.core.runtime.CoreException) ICSourceEntry(org.eclipse.cdt.core.settings.model.ICSourceEntry) IIndexFile(org.eclipse.cdt.core.index.IIndexFile) File(java.io.File)

Example 7 with ICSourceEntry

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

ICSourceEntry (org.eclipse.cdt.core.settings.model.ICSourceEntry)7 IPath (org.eclipse.core.runtime.IPath)5 File (java.io.File)3 CSourceEntry (org.eclipse.cdt.core.settings.model.CSourceEntry)3 ICConfigurationDescription (org.eclipse.cdt.core.settings.model.ICConfigurationDescription)3 CoreException (org.eclipse.core.runtime.CoreException)3 Path (org.eclipse.core.runtime.Path)3 ICProjectDescription (org.eclipse.cdt.core.settings.model.ICProjectDescription)2 ICResourceDescription (org.eclipse.cdt.core.settings.model.ICResourceDescription)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 Set (java.util.Set)1 IIndexFile (org.eclipse.cdt.core.index.IIndexFile)1 ICExclusionPatternPathEntry (org.eclipse.cdt.core.settings.model.ICExclusionPatternPathEntry)1 IBuilder (org.eclipse.cdt.managedbuilder.core.IBuilder)1 IConfiguration (org.eclipse.cdt.managedbuilder.core.IConfiguration)1 IManagedBuildInfo (org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo)1 BuildMacroException (org.eclipse.cdt.managedbuilder.macros.BuildMacroException)1