Search in sources :

Example 1 with ICSourceEntry

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

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

the class ProjectUtilities method changeExcludedItem.

private static void changeExcludedItem(IProject project, String targetPath, boolean isFolder, boolean excluded, IProgressMonitor progressMonitor) throws CoreException, BuildException {
    IPath path = project.getFolder(targetPath).getProjectRelativePath();
    System.err.println(String.format("changeExcludedItem(target=%s, isfolder=%s, exclude=%s)", path.toString(), Boolean.toString(isFolder), Boolean.toString(excluded)));
    // ICProjectDescription projectDescription = CoreModel.getDefault().getProjectDescription(project, true);
    // ICConfigurationDescription configDecriptions[] = projectDescription.getConfigurations();
    // for (ICConfigurationDescription configDescription : configDecriptions) {
    // // Exclude in each configuration
    // System.err.println(String.format("Excluding in configuration %s", configDescription.toString()));
    // ICSourceEntry[] sourceEntries         = configDescription.getSourceEntries();
    // ICSourceEntry[] modifiedSourceEntries = CDataUtil.setExcludedIfPossible(path, isFolder, excluded, sourceEntries);
    // configDescription.setSourceEntries(modifiedSourceEntries);
    // }
    // CoreModel.getDefault().setProjectDescription(project, projectDescription);
    IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
    IConfiguration[] configurations = info.getManagedProject().getConfigurations();
    for (IConfiguration configuration : configurations) {
        // Exclude in each configuration
        System.err.println(String.format("Excluding in configuration %s", configuration.toString()));
        ICSourceEntry[] sourceEntries = configuration.getSourceEntries();
        ICSourceEntry[] modifiedSourceEntries = CDataUtil.setExcludedIfPossible(path, isFolder, excluded, sourceEntries);
        configuration.setSourceEntries(modifiedSourceEntries);
    }
}
Also used : IManagedBuildInfo(org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo) IPath(org.eclipse.core.runtime.IPath) ICSourceEntry(org.eclipse.cdt.core.settings.model.ICSourceEntry) IConfiguration(org.eclipse.cdt.managedbuilder.core.IConfiguration)

Example 3 with ICSourceEntry

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

the class AbstractSettingsSynchroniser method setSourceDirs.

private void setSourceDirs(final ICConfigurationDescription conf, final NarBuildArtifact settings) throws CoreException {
    final Map<String, Set<String>> sourceDirs = new HashMap<String, Set<String>>();
    for (final File f : settings.getCppSettings().getSourceDirectories()) {
        sourceDirs.put(f.getPath(), settings.getCppSettings().getExcludes());
    }
    for (final File f : settings.getCSettings().getSourceDirectories()) {
        sourceDirs.put(f.getPath(), settings.getCSettings().getExcludes());
    }
    final ICSourceEntry[] sourceEntries = new ICSourceEntry[sourceDirs.size()];
    int i = 0;
    for (final Map.Entry<String, Set<String>> sourceDir : sourceDirs.entrySet()) {
        sourceEntries[i] = createSourcePathEntry(sourceDir.getKey(), sourceDir.getValue(), 0);
        ++i;
    }
    conf.setSourceEntries(sourceEntries);
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) ICSourceEntry(org.eclipse.cdt.core.settings.model.ICSourceEntry) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with ICSourceEntry

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

the class AbstractSettingsSynchroniser method createSourcePathEntry.

private ICSourceEntry createSourcePathEntry(final String path, final Set<String> excludes, final int flags) {
    IPath[] exclusionPatterns = null;
    if (excludes.size() > 0) {
        exclusionPatterns = new IPath[excludes.size()];
        int i = 0;
        for (String exclude : excludes) {
            exclusionPatterns[i] = Path.fromOSString(exclude);
            ++i;
        }
        logger.debug("Excludes for source path " + path + ": " + Arrays.deepToString(exclusionPatterns));
    }
    final IWorkspaceRoot workspace = ResourcesPlugin.getWorkspace().getRoot();
    final File file = new File(path);
    if (!file.isAbsolute()) {
        return (ICSourceEntry) CDataUtil.createEntry(ICLanguageSettingEntry.SOURCE_PATH, path, null, exclusionPatterns, ICSettingEntry.VALUE_WORKSPACE_PATH | flags);
    } else {
        IContainer container = workspace.getContainerForLocation(Path.fromOSString(path));
        if (container == null) {
            return (ICSourceEntry) CDataUtil.createEntry(ICLanguageSettingEntry.SOURCE_PATH, path, null, exclusionPatterns, flags);
        } else {
            return (ICSourceEntry) CDataUtil.createEntry(ICLanguageSettingEntry.SOURCE_PATH, container.getFullPath().toOSString(), null, exclusionPatterns, ICSettingEntry.VALUE_WORKSPACE_PATH | flags);
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) ICSourceEntry(org.eclipse.cdt.core.settings.model.ICSourceEntry) IContainer(org.eclipse.core.resources.IContainer) File(java.io.File)

Example 5 with ICSourceEntry

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

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